arm: stm32f4: fix a bug when a random sector gets erased
authorVadzim Dambrouski <pftbest@gmail.com>
Fri, 23 Oct 2015 18:14:07 +0000 (21:14 +0300)
committerAlbert ARIBAUD <albert.u.boot@aribaud.net>
Tue, 10 Nov 2015 15:48:50 +0000 (16:48 +0100)
Old sector number is not being cleared from FLASH_CR register. For example
when first erased sector was 001 and then you want to erase sector 010,
sector 011 gets erased instead.
This patch clears old sector number from FLASH_CR register before a new
one is written.

Signed-off-by: Vadzim Dambrouski <pftbest@gmail.com>
arch/arm/cpu/armv7m/stm32f4/flash.c
arch/arm/include/asm/arch-stm32f4/stm32.h

index ae6379070f23f993a0062ea9be5f78430e41e0bf..dd058bd643030274db020536b99fd808418a92bc 100644 (file)
@@ -97,6 +97,9 @@ int flash_erase(flash_info_t *info, int first, int last)
                while (readl(&STM32_FLASH->sr) & STM32_FLASH_SR_BSY)
                        ;
 
+               /* clear old sector number before writing a new one */
+               clrbits_le32(&STM32_FLASH->cr, STM32_FLASH_CR_SNB_MASK);
+
                if (bank == 0) {
                        setbits_le32(&STM32_FLASH->cr,
                                     (i << STM32_FLASH_CR_SNB_OFFSET));
index 3ed3801dfe7d9d045d19110c70d4000029461002..7ca6dc3de8e75abcd9ca27be9f5acf2a1769a66e 100644 (file)
@@ -104,6 +104,7 @@ struct stm32_flash_regs {
 #define STM32_FLASH_CR_STRT            (1 << 16)
 #define STM32_FLASH_CR_LOCK            (1 << 31)
 #define STM32_FLASH_CR_SNB_OFFSET      3
+#define STM32_FLASH_CR_SNB_MASK                (15 << STM32_FLASH_CR_SNB_OFFSET)
 
 enum clock {
        CLOCK_CORE,