cleanup: rename armv4_5 to arm for readability
[openocd.git] / src / target / stm32_stlink.c
index baa6b7488cea60ee11b23044bb6749d037270f8b..dec2b24bf1ac9a670aad91642cbb4759311cc297 100644 (file)
@@ -98,7 +98,7 @@ static int stm32_stlink_load_core_reg_u32(struct target *target,
                break;
 
        default:
-               return ERROR_INVALID_ARGUMENTS;
+               return ERROR_COMMAND_SYNTAX_ERROR;
        }
 
        return ERROR_OK;
@@ -184,7 +184,7 @@ static int stm32_stlink_store_core_reg_u32(struct target *target,
                break;
 
        default:
-               return ERROR_INVALID_ARGUMENTS;
+               return ERROR_COMMAND_SYNTAX_ERROR;
        }
 
        return ERROR_OK;
@@ -225,7 +225,7 @@ static int stm32_stlink_target_create(struct target *target,
        struct cortex_m3_common *cortex_m3 = calloc(1, sizeof(struct cortex_m3_common));
 
        if (!cortex_m3)
-               return ERROR_INVALID_ARGUMENTS;
+               return ERROR_COMMAND_SYNTAX_ERROR;
 
        stm32_stlink_init_arch_info(target, cortex_m3, target->tap);
 
@@ -245,7 +245,7 @@ static int stm32_stlink_examine(struct target *target)
        if (target->tap->hasidcode == false) {
                LOG_ERROR("no IDCODE present on device");
 
-               return ERROR_INVALID_ARGUMENTS;
+               return ERROR_COMMAND_SYNTAX_ERROR;
        }
 
        if (!target_was_examined(target)) {
@@ -511,7 +511,6 @@ static int stm32_stlink_step(struct target *target, int current,
                return ERROR_TARGET_NOT_HALTED;
        }
 
-       pc = armv7m->arm.pc;
        if (!current) {
                buf_set_u32(pc->value, 0, 32, address);
                pc->dirty = true;
@@ -561,31 +560,46 @@ static int stm32_stlink_read_memory(struct target *target, uint32_t address,
                                    uint8_t *buffer)
 {
        int res;
-       uint32_t *dst = (uint32_t *) buffer;
+       uint32_t buffer_threshold = 128;
+       uint32_t addr_increment = 4;
+       uint8_t *dst = buffer;
        uint32_t c;
        struct stlink_interface_s *stlink_if = target_to_stlink(target);
 
        if (!count || !buffer)
-               return ERROR_INVALID_ARGUMENTS;
+               return ERROR_COMMAND_SYNTAX_ERROR;
+
+       LOG_DEBUG("%s %x %d %d", __func__, address, size, count);
+
+       /* prepare byte count, buffer threshold
+        * and address increment for none 32bit access
+        */
        if (size != 4) {
-               LOG_DEBUG("%s %x %d %d", __func__, address, size, count);
-               return ERROR_INVALID_ARGUMENTS;
+               count *= size;
+               buffer_threshold = 64;
+               addr_increment = 1;
        }
 
        while (count) {
-               if (count > 128)
-                       c = 128;
+               if (count > buffer_threshold)
+                       c = buffer_threshold;
                else
                        c = count;
 
-               res =
-                   stlink_if->layout->api->read_mem32(stlink_if->fd, address,
+               if (size != 4)
+                       res =
+                               stlink_if->layout->api->read_mem8(stlink_if->fd, address,
                                                       c, dst);
+               else
+                       res =
+                               stlink_if->layout->api->read_mem32(stlink_if->fd, address,
+                                                      c, (uint32_t *)dst);
 
                if (res != ERROR_OK)
                        return res;
-               dst += c;
-               address += (c * 4);
+
+               address += (c * addr_increment);
+               dst += (c * addr_increment);
                count -= c;
        }
 
@@ -597,31 +611,46 @@ static int stm32_stlink_write_memory(struct target *target, uint32_t address,
                                     const uint8_t *buffer)
 {
        int res;
-       uint32_t *dst = (uint32_t *) buffer;
+       uint32_t buffer_threshold = 128;
+       uint32_t addr_increment = 4;
+       const uint8_t *dst = buffer;
        uint32_t c;
        struct stlink_interface_s *stlink_if = target_to_stlink(target);
 
        if (!count || !buffer)
-               return ERROR_INVALID_ARGUMENTS;
+               return ERROR_COMMAND_SYNTAX_ERROR;
+
+       LOG_DEBUG("%s %x %d %d", __func__, address, size, count);
+
+       /* prepare byte count, buffer threshold
+        * and address increment for none 32bit access
+        */
        if (size != 4) {
-               LOG_DEBUG("%s %x %d %d", __func__, address, size, count);
-               return ERROR_INVALID_ARGUMENTS;
+               count *= size;
+               buffer_threshold = 64;
+               addr_increment = 1;
        }
 
        while (count) {
-               if (count > 128)
-                       c = 128;
+               if (count > buffer_threshold)
+                       c = buffer_threshold;
                else
                        c = count;
 
-               res =
-                   stlink_if->layout->api->write_mem32(stlink_if->fd, address,
-                                                       c, dst);
+               if (size != 4)
+                       res =
+                               stlink_if->layout->api->write_mem8(stlink_if->fd, address,
+                                                      c, dst);
+               else
+                       res =
+                               stlink_if->layout->api->write_mem32(stlink_if->fd, address,
+                                                      c, (uint32_t *)dst);
 
                if (res != ERROR_OK)
                        return res;
-               dst += c;
-               address += (c * 4);
+
+               address += (c * addr_increment);
+               dst += (c * addr_increment);
                count -= c;
        }
 

Linking to existing account procedure

If you already have an account and want to add another login method you MUST first sign in with your existing account and then change URL to read https://review.openocd.org/login/?link to get to this page again but this time it'll work for linking. Thank you.

SSH host keys fingerprints

1024 SHA256:YKx8b7u5ZWdcbp7/4AeXNaqElP49m6QrwfXaqQGJAOk gerrit-code-review@openocd.zylin.com (DSA)
384 SHA256:jHIbSQa4REvwCFG4cq5LBlBLxmxSqelQPem/EXIrxjk gerrit-code-review@openocd.org (ECDSA)
521 SHA256:UAOPYkU9Fjtcao0Ul/Rrlnj/OsQvt+pgdYSZ4jOYdgs gerrit-code-review@openocd.org (ECDSA)
256 SHA256:A13M5QlnozFOvTllybRZH6vm7iSt0XLxbA48yfc2yfY gerrit-code-review@openocd.org (ECDSA)
256 SHA256:spYMBqEYoAOtK7yZBrcwE8ZpYt6b68Cfh9yEVetvbXg gerrit-code-review@openocd.org (ED25519)
+--[ED25519 256]--+
|=..              |
|+o..   .         |
|*.o   . .        |
|+B . . .         |
|Bo. = o S        |
|Oo.+ + =         |
|oB=.* = . o      |
| =+=.+   + E     |
|. .=o   . o      |
+----[SHA256]-----+
2048 SHA256:0Onrb7/PHjpo6iVZ7xQX2riKN83FJ3KGU0TvI0TaFG4 gerrit-code-review@openocd.zylin.com (RSA)