Skip to content

Commit bff6151

Browse files
committed
STM32Gx: flash: clear programming mode before erasing
As described in 3.3.8, if erasing while another mode's "enable" bit is set, a programming sequence error will be raised. This change makes sure this will not happen for an erase operation.
1 parent 589e244 commit bff6151

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

src/stlink-lib/common_flash.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1122,6 +1122,10 @@ int32_t stlink_erase_flash_page(stlink_t *sl, stm32_addr_t flashaddr) {
11221122
stlink_read_debug32(sl, FLASH_Gx_CR, &val);
11231123
// sec 3.7.5 - PNB[9:0] is offset by 3. PER is 0x2.
11241124
val &= ~(0x7FF << 3);
1125+
// sec 3.3.8 - Error PGSERR
1126+
// * In the page erase sequence: PG, FSTPG and MER1 are not cleared when PER is set
1127+
val &= ~(1 << FLASH_Gx_CR_MER1 | 1 << FLASH_Gx_CR_MER2);
1128+
val &= ~(1 << FLASH_Gx_CR_PG);
11251129
// Products of the Gx series with more than 128K of flash use 2 banks.
11261130
// In this case we need to specify which bank to erase (sec 3.7.5 - BKER)
11271131
if (sl->flash_size > (128 * 1024) &&

0 commit comments

Comments
 (0)