Skip to contentSkip to conversation

arm: stm32f4: fix a bug when only first sector gets erased

PATCH Superseded Vadzim Dambrouski 2 participants 3 messages Oct 19, 2015 – Oct 22, 2015

Subsystems (2)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/2 arm: stm32f4: fix a bug when only first sector gets erased

flash_lock call is inside a for cycle, so after the first iteration flash is locked and no more sectors can be erased.

---

 arch/arm/cpu/armv7m/stm32f4/flash.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
arch/arm/cpu/armv7m/stm32f4/flash.c +1 -1
index e5c6111..ae63790 100644
@@ -114,9 +114,9 @@ int flash_erase(flash_info_t *info, int first, int last)
 			;
 
 		clrbits_le32(&STM32_FLASH->cr, STM32_FLASH_CR_SER);
-		stm32f4_flash_lock(1);
 	}
 
+	stm32f4_flash_lock(1);
 	return 0;
 }
 
Signature · 1 line
2.6.1
#1 lore raw

PATCH 2/2 arm: stm32f4: fix a bug when a random sector gets erased

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.

---

 arch/arm/cpu/armv7m/stm32f4/flash.c       | 3 +++
 arch/arm/include/asm/arch-stm32f4/stm32.h | 1 +
 2 files changed, 4 insertions(+)
arch/arm/cpu/armv7m/stm32f4/flash.c +3 -0
index ae63790..dd058bd 100644
@@ -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));
arch/arm/include/asm/arch-stm32f4/stm32.h +1 -0
index 3ed3801..7ca6dc3 100644
@@ -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,
Signature · 1 line
2.6.1
#2 lore raw

PATCH 1/2 arm: stm32f4: fix a bug when only first sector gets erased

In reply to Vadzim Dambrouski

Hello Vadzim,

Quoted 2 lines · Vadzim Dambrouski

flash_lock call is inside a for cycle, so after the first iteration flash is locked and no more sectors can be erased.

Nitpick: the commit summary explains the problem well, but not the (admittedly) trivial solution; just add it:

flash_lock call is inside a for cycle, so after the first iteration flash is locked and no more sectors can be erased. Move flash_lock out of the loop.

Quoted 1 line

Amicalement,

Signature · 1 line
Albert.