From f06bc0fd79e2b16365c87cfb14d8dd64e6826535 Mon Sep 17 00:00:00 2001 From: Gareth McMullin Date: Wed, 30 Jul 2014 20:27:30 +1200 Subject: Minor fixes to stm32f1 flash routines. --- src/stm32f1.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'src/stm32f1.c') 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; -- cgit v1.2.3