break;
default:
- return ERROR_INVALID_ARGUMENTS;
+ return ERROR_COMMAND_SYNTAX_ERROR;
}
return ERROR_OK;
break;
default:
- return ERROR_INVALID_ARGUMENTS;
+ return ERROR_COMMAND_SYNTAX_ERROR;
}
return ERROR_OK;
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);
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)) {
return ERROR_TARGET_NOT_HALTED;
}
- pc = armv7m->arm.pc;
if (!current) {
buf_set_u32(pc->value, 0, 32, address);
pc->dirty = true;
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;
}
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;
}