stlink: add none 32bit memory read/write functions
This patch add none 32bit memory read/write functions. Change-Id: Ie3a761cf006249b30d0691d1ea167d69a012c36a Signed-off-by: Mathias K <kesmtp@freenet.de> Reviewed-on: http://openocd.zylin.com/367 Tested-by: jenkins Reviewed-by: Spencer Oliver <spen@spen-soft.co.uk>__archive__
parent
37b575367b
commit
c2ab3b4d5e
|
@ -560,31 +560,46 @@ static int stm32_stlink_read_memory(struct target *target, uint32_t address,
|
||||||
uint8_t *buffer)
|
uint8_t *buffer)
|
||||||
{
|
{
|
||||||
int res;
|
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;
|
uint32_t c;
|
||||||
struct stlink_interface_s *stlink_if = target_to_stlink(target);
|
struct stlink_interface_s *stlink_if = target_to_stlink(target);
|
||||||
|
|
||||||
if (!count || !buffer)
|
if (!count || !buffer)
|
||||||
return ERROR_COMMAND_SYNTAX_ERROR;
|
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) {
|
if (size != 4) {
|
||||||
LOG_DEBUG("%s %x %d %d", __func__, address, size, count);
|
count *= size;
|
||||||
return ERROR_COMMAND_SYNTAX_ERROR;
|
buffer_threshold = 64;
|
||||||
|
addr_increment = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
while (count) {
|
while (count) {
|
||||||
if (count > 128)
|
if (count > buffer_threshold)
|
||||||
c = 128;
|
c = buffer_threshold;
|
||||||
else
|
else
|
||||||
c = count;
|
c = count;
|
||||||
|
|
||||||
res =
|
if (size != 4)
|
||||||
stlink_if->layout->api->read_mem32(stlink_if->fd, address,
|
res =
|
||||||
|
stlink_if->layout->api->read_mem8(stlink_if->fd, address,
|
||||||
c, dst);
|
c, dst);
|
||||||
|
else
|
||||||
|
res =
|
||||||
|
stlink_if->layout->api->read_mem32(stlink_if->fd, address,
|
||||||
|
c, (uint32_t *)dst);
|
||||||
|
|
||||||
if (res != ERROR_OK)
|
if (res != ERROR_OK)
|
||||||
return res;
|
return res;
|
||||||
dst += c;
|
|
||||||
address += (c * 4);
|
address += (c * addr_increment);
|
||||||
|
dst += (c * addr_increment);
|
||||||
count -= c;
|
count -= c;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -596,31 +611,46 @@ static int stm32_stlink_write_memory(struct target *target, uint32_t address,
|
||||||
const uint8_t *buffer)
|
const uint8_t *buffer)
|
||||||
{
|
{
|
||||||
int res;
|
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;
|
uint32_t c;
|
||||||
struct stlink_interface_s *stlink_if = target_to_stlink(target);
|
struct stlink_interface_s *stlink_if = target_to_stlink(target);
|
||||||
|
|
||||||
if (!count || !buffer)
|
if (!count || !buffer)
|
||||||
return ERROR_COMMAND_SYNTAX_ERROR;
|
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) {
|
if (size != 4) {
|
||||||
LOG_DEBUG("%s %x %d %d", __func__, address, size, count);
|
count *= size;
|
||||||
return ERROR_COMMAND_SYNTAX_ERROR;
|
buffer_threshold = 64;
|
||||||
|
addr_increment = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
while (count) {
|
while (count) {
|
||||||
if (count > 128)
|
if (count > buffer_threshold)
|
||||||
c = 128;
|
c = buffer_threshold;
|
||||||
else
|
else
|
||||||
c = count;
|
c = count;
|
||||||
|
|
||||||
res =
|
if (size != 4)
|
||||||
stlink_if->layout->api->write_mem32(stlink_if->fd, address,
|
res =
|
||||||
c, dst);
|
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)
|
if (res != ERROR_OK)
|
||||||
return res;
|
return res;
|
||||||
dst += c;
|
|
||||||
address += (c * 4);
|
address += (c * addr_increment);
|
||||||
|
dst += (c * addr_increment);
|
||||||
count -= c;
|
count -= c;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue