From 26a8013502953e7125b732eadff862c0cda10d08 Mon Sep 17 00:00:00 2001 From: francisco Date: Wed, 3 Jul 2019 09:30:03 +0200 Subject: [PATCH] stm32l4/flashpage: fix page erase - The PNB in FLASH_CR wasn't cleared before every erase operation and the new value was just stacked on top. After a couple of erase the PNB written was overlapping with old ones failing to erase the correct page. --- cpu/stm32_common/periph/flashpage.c | 1 + 1 file changed, 1 insertion(+) diff --git a/cpu/stm32_common/periph/flashpage.c b/cpu/stm32_common/periph/flashpage.c index ba304dc26c..3ac163e592 100644 --- a/cpu/stm32_common/periph/flashpage.c +++ b/cpu/stm32_common/periph/flashpage.c @@ -111,6 +111,7 @@ static void _erase_page(void *page_addr) } pn = (uint8_t)page; #endif + CNTRL_REG &= ~FLASH_CR_PNB; CNTRL_REG |= (uint32_t)(pn << FLASH_CR_PNB_Pos); CNTRL_REG |= FLASH_CR_STRT; #else /* CPU_FAM_STM32F0 || CPU_FAM_STM32F1 */