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; + } }