aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPiotr Esden-Tempski2013-02-26 15:25:55 -0800
committerPiotr Esden-Tempski2013-02-26 15:25:55 -0800
commit5e7ec39440087cb507e3e1fc4c83fa8225733c80 (patch)
tree3ebcb5155ab7a2a5c342afa4e98aeda900574081
parentbc853e7ebddf0cbe9abce161afcb0c0ee02c2567 (diff)
FLASH: Make sure that the flash unlock register state is cleared before trying to unlock the flash.
-rw-r--r--lib/stm32/f1/flash.c3
-rw-r--r--lib/stm32/f2/flash.c7
-rw-r--r--lib/stm32/f4/flash.c7
3 files changed, 17 insertions, 0 deletions
diff --git a/lib/stm32/f1/flash.c b/lib/stm32/f1/flash.c
index 49f182c..babfc45 100644
--- a/lib/stm32/f1/flash.c
+++ b/lib/stm32/f1/flash.c
@@ -52,6 +52,9 @@ void flash_set_ws(u32 ws)
void flash_unlock(void)
{
+ /* Clear the unlock state. */
+ FLASH_CR |= FLASH_CR_LOCK;
+
/* Authorize the FPEC access. */
FLASH_KEYR = FLASH_KEYR_KEY1;
FLASH_KEYR = FLASH_KEYR_KEY2;
diff --git a/lib/stm32/f2/flash.c b/lib/stm32/f2/flash.c
index 0b9f834..c41ddf2 100644
--- a/lib/stm32/f2/flash.c
+++ b/lib/stm32/f2/flash.c
@@ -78,6 +78,9 @@ void flash_set_ws(u32 ws)
void flash_unlock(void)
{
+ /* Clear the unlock state. */
+ FLASH_CR |= FLASH_CR_LOCK;
+
/* Authorize the FPEC access. */
FLASH_KEYR = FLASH_KEYR_KEY1;
FLASH_KEYR = FLASH_KEYR_KEY2;
@@ -130,6 +133,10 @@ void flash_clear_status_flags(void)
void flash_unlock_option_bytes(void)
{
+ /* Clear the unlock state. */
+ FLASH_OPTCR |= FLASH_OPTCR_OPTLOCK;
+
+ /* Unlock the option bytes. */
FLASH_OPTKEYR = FLASH_OPTKEYR_KEY1;
FLASH_OPTKEYR = FLASH_OPTKEYR_KEY2;
}
diff --git a/lib/stm32/f4/flash.c b/lib/stm32/f4/flash.c
index 75446ea..a204543 100644
--- a/lib/stm32/f4/flash.c
+++ b/lib/stm32/f4/flash.c
@@ -78,6 +78,9 @@ void flash_set_ws(u32 ws)
void flash_unlock(void)
{
+ /* Clear the unlock sequence state. */
+ FLASH_CR |= FLASH_CR_LOCK;
+
/* Authorize the FPEC access. */
FLASH_KEYR = FLASH_KEYR_KEY1;
FLASH_KEYR = FLASH_KEYR_KEY2;
@@ -130,6 +133,10 @@ void flash_clear_status_flags(void)
void flash_unlock_option_bytes(void)
{
+ /* Clear the unlock state. */
+ FLASH_OPTCR |= FLASH_OPTCR_OPTLOCK;
+
+ /* Unlock option bytes. */
FLASH_OPTKEYR = FLASH_OPTKEYR_KEY1;
FLASH_OPTKEYR = FLASH_OPTKEYR_KEY2;
}