(plain text version)
Hi,

I was sometimes faced to the following errors when I was trying to erase or
write a fw to the my STM32 flash:

Error: JTAG-DP STICKY ERROR
Error: MEM_AP_CSW 0x23000052, MEM_AP_TAR 0x40023c08
Error: JTAG-DP STICKY ERROR
Error: MEM_AP_CSW 0x23000052, MEM_AP_TAR 0x40023c08

After some time of debugging. it appeared the stm32f2xx generates an error
when you try to write something on the FLASH_KEYR register (0x40023c08) and
the flash access has already been unlocked.

Here is the patch I submit to your approval: in the stm32x_unlock_reg()
function I propose to first read the FLASH_CR register and check whether the
flash access is locked or not before writing to the FLASH_KEYR register.

Thanks!

Bruno FLEURETTE
diff --git a/src/flash/nor/stm32f2x.c b/src/flash/nor/stm32f2x.c
index 7c07c53..0eb2693 100644
--- a/src/flash/nor/stm32f2x.c
+++ b/src/flash/nor/stm32f2x.c
@@ -235,8 +235,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;
 
------------------------------------------------------------------------------
Write once. Port to many.
Get the SDK and tools to simplify cross-platform app development. Create 
new or port existing apps to sell to consumers worldwide. Explore the 
Intel AppUpSM program developer opportunity. appdeveloper.intel.com/join
http://p.sf.net/sfu/intel-appdev
_______________________________________________
OpenOCD-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/openocd-devel

Reply via email to