summaryrefslogtreecommitdiff
path: root/chip
diff options
context:
space:
mode:
Diffstat (limited to 'chip')
-rw-r--r--chip/stm32/flash-f.c9
-rw-r--r--chip/stm32/registers.h2
2 files changed, 9 insertions, 2 deletions
diff --git a/chip/stm32/flash-f.c b/chip/stm32/flash-f.c
index bf0b9ab81c..f1e5b4d85f 100644
--- a/chip/stm32/flash-f.c
+++ b/chip/stm32/flash-f.c
@@ -82,6 +82,10 @@ static int unlock(int locks)
static void lock(void)
{
+#if defined(CHIP_FAMILY_STM32F0) || defined(CHIP_FAMILY_STM32F3)
+ /* FLASH_CR_OPTWRE was set by writing the keys in unlock(). */
+ STM32_FLASH_CR &= ~FLASH_CR_OPTWRE;
+#endif
STM32_FLASH_CR |= FLASH_CR_LOCK;
}
@@ -147,10 +151,13 @@ static int erase_optb(void)
return rv;
/* Must be set in 2 separate lines. */
- STM32_FLASH_CR |= FLASH_CR_OPTSTRT;
+ STM32_FLASH_CR |= FLASH_CR_OPTER;
STM32_FLASH_CR |= FLASH_CR_STRT;
rv = wait_busy();
+
+ STM32_FLASH_CR &= ~FLASH_CR_OPTER;
+
if (rv)
return rv;
lock();
diff --git a/chip/stm32/registers.h b/chip/stm32/registers.h
index b8035620f0..03a2c3be00 100644
--- a/chip/stm32/registers.h
+++ b/chip/stm32/registers.h
@@ -1342,7 +1342,7 @@ typedef volatile struct stm32_spi_regs stm32_spi_regs_t;
#define FLASH_CR_PG (1 << 0)
#define FLASH_CR_PER (1 << 1)
#define FLASH_CR_OPTPG (1 << 4)
-#define FLASH_CR_OPTSTRT (1 << 5)
+#define FLASH_CR_OPTER (1 << 5)
#define FLASH_CR_STRT (1 << 6)
#define FLASH_CR_LOCK (1 << 7)
#define FLASH_CR_OPTWRE (1 << 9)