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;
------------------------------------------------------------------------------
Ridiculously easy VDI. With Citrix VDI-in-a-Box, you don't need a complex
infrastructure or vast IT resources to deliver seamless, secure access to
virtual desktops. With this all-in-one solution, easily deploy virtual
desktops for less than the cost of PCs and save 60% on VDI infrastructure
costs. Try it free! http://p.sf.net/sfu/Citrix-VDIinabox
_______________________________________________
OpenOCD-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/openocd-devel