aboutsummaryrefslogtreecommitdiff
path: root/src/stm32f1.c
diff options
context:
space:
mode:
authorGareth McMullin2014-07-30 20:27:30 +1200
committerGareth McMullin2014-07-30 20:27:30 +1200
commitf06bc0fd79e2b16365c87cfb14d8dd64e6826535 (patch)
tree5f4bb46b56720a129fac08284a2ef8578adf6c8d /src/stm32f1.c
parentfad6eb3c148ac463c04c3762fc21b03a4db1f8e2 (diff)
Minor fixes to stm32f1 flash routines.
Diffstat (limited to 'src/stm32f1.c')
-rw-r--r--src/stm32f1.c6
1 files changed, 4 insertions, 2 deletions
diff --git a/src/stm32f1.c b/src/stm32f1.c
index d3cb234..237135f 100644
--- a/src/stm32f1.c
+++ b/src/stm32f1.c
@@ -228,7 +228,7 @@ static int stm32f1_flash_erase(struct target_s *target, uint32_t addr, int len,
uint16_t sr;
addr &= ~(pagesize - 1);
- len &= ~(pagesize - 1);
+ len = (len + pagesize - 1) & ~(pagesize - 1);
stm32f1_flash_unlock(ap);
@@ -273,6 +273,8 @@ static int stm32f1_flash_write(struct target_s *target, uint32_t dest,
ADIv5_AP_t *ap = adiv5_target_ap(target);
uint32_t offset = dest % 4;
uint32_t words = (offset + len + 3) / 4;
+ if (words > 256)
+ return -1;
uint32_t data[2 + words];
/* Construct data buffer used by stub */
@@ -284,7 +286,7 @@ static int stm32f1_flash_write(struct target_s *target, uint32_t dest,
/* Write stub and data to target ram and set PC */
target_mem_write_words(target, 0x20000000, (void*)stm32f1_flash_write_stub, 0x2C);
- target_mem_write_words(target, 0x2000002C, data, len + 8);
+ target_mem_write_words(target, 0x2000002C, data, sizeof(data));
target_pc_write(target, 0x20000000);
if(target_check_error(target))
return -1;