This is an automated email from Gerrit.

Bruno FLEURETTE (bruno.fleure...@gmail.com) just uploaded a new patch set to 
Gerrit, which you can find at http://openocd.zylin.com/362

-- gerrit

commit 0bc901bbd1c4a9e33517eee4c86b0a7b0db743bc
Author: Bruno FLEURETTE <bruno.fleure...@gmail.com>
Date:   Tue Jan 10 16:21:00 2012 +0100

    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: I518f9932742176a9629cacdfaa99c70f26d86aed
    Signed-off-by: Bruno FLEURETTE <bruno.fleure...@gmail.com>

diff --git a/src/flash/nor/stm32f2x.c b/src/flash/nor/stm32f2x.c
index 479df8a..3775376 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;
 
-       /* unlock flash registers */
-       int retval = target_write_u32(target, STM32_FLASH_KEYR, KEY1);
+       /* 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 */
+       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
OpenOCD-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/openocd-devel

Reply via email to