From c73ec5c00f65087f8c2cb22b4b266a0343703009 Mon Sep 17 00:00:00 2001 From: Alexandre Abadie Date: Sun, 27 May 2018 15:11:59 +0200 Subject: [PATCH] cpu/stm32_common/periph: don't lock if flash is already locked --- cpu/stm32_common/periph/flash_common.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/cpu/stm32_common/periph/flash_common.c b/cpu/stm32_common/periph/flash_common.c index 34f92e75f06f..61c6d8d10fd6 100644 --- a/cpu/stm32_common/periph/flash_common.c +++ b/cpu/stm32_common/periph/flash_common.c @@ -38,8 +38,8 @@ void _unlock(void) { - DEBUG("[flash-common] unlocking the flash module\n"); if (CNTRL_REG & CNTRL_REG_LOCK) { + DEBUG("[flash-common] unlocking the flash module\n"); KEY_REG = FLASH_KEY1; KEY_REG = FLASH_KEY2; } @@ -47,6 +47,8 @@ void _unlock(void) void _lock(void) { - DEBUG("[flash-common] locking the flash module\n"); - CNTRL_REG |= CNTRL_REG_LOCK; + if (!(CNTRL_REG & CNTRL_REG_LOCK)) { + DEBUG("[flash-common] locking the flash module\n"); + CNTRL_REG |= CNTRL_REG_LOCK; + } }