aboutsummaryrefslogtreecommitdiff
path: root/src/flash
diff options
context:
space:
mode:
authorBruno FLEURETTE <bruno.fleurette@gmail.com>2012-01-10 16:21:00 +0100
committerSpencer Oliver <spen@spen-soft.co.uk>2012-01-12 20:39:41 +0000
commit32d3063cf55fd4fc36d17b89647d86ea3c7cf9ab (patch)
treef23077e84ff8d9d67e248a44609983502a0c8e0d /src/flash
parent06d1580ff77e6b685af07f15fa01710de85c4c2e (diff)
flash: pre-check flash unlock for stm32f2x
add checking of the current flash lock status before performing the unlock sequence (which would fail in an unlocked state) Change-Id: I693294c9cd2f59e69cb5bf3338120052fd680b1e Signed-off-by: Bruno FLEURETTE <bruno.fleurette@gmail.com> Signed-off-by: Øyvind Harboe <oyvind.harboe@zylin.com> Reviewed-on: http://openocd.zylin.com/363 Reviewed-by: Øyvind Harboe <oyvindharboe@gmail.com> Reviewed-by: Spencer Oliver <spen@spen-soft.co.uk> Tested-by: jenkins Reviewed-by: Mathias Küster <kesmtp@freenet.de>
Diffstat (limited to 'src/flash')
-rw-r--r--src/flash/nor/stm32f2x.c12
1 files changed, 11 insertions, 1 deletions
diff --git a/src/flash/nor/stm32f2x.c b/src/flash/nor/stm32f2x.c
index 479df8af..591b326b 100644
--- a/src/flash/nor/stm32f2x.c
+++ b/src/flash/nor/stm32f2x.c
@@ -234,8 +234,18 @@ static int stm32x_unlock_reg(struct target *target)
{
uint32_t ctrl;
+ /* first check if not already unlocked
+ * otherwise writing on STM32_FLASH_KEYR will fail
+ */
+ int retval = target_read_u32(target, STM32_FLASH_CR, &ctrl);
+ if (retval != ERROR_OK)
+ return retval;
+
+ if ((ctrl & FLASH_LOCK) == 0)
+ return ERROR_OK;
+
/* unlock flash registers */
- int retval = target_write_u32(target, STM32_FLASH_KEYR, KEY1);
+ retval = target_write_u32(target, STM32_FLASH_KEYR, KEY1);
if (retval != ERROR_OK)
return retval;