cancel
Showing results for 
Search instead for 
Did you mean: 

STM32F103C8 the first 4096 bytes of FLASH memory are not erased

Michael_2025
Visitor

Maybe someone has encountered such a problem: the first 4 pages of FLASH memory are not erased
Why are the first 4 pages not erased when the read protection bit is set?
If the protection bit is disabled, then the same pages are erased without problems.
Code snippet:
...
void FLASH_Page_erase(uint16_t Adress) {
if (READ_BIT(FLASH->CR, FLASH_CR_LOCK)) {
FLASH_Unlock();
}
SET_BIT(FLASH->CR, FLASH_CR_PER);
FLASH->AR = Adress;
SET_BIT(FLASH->CR, FLASH_CR_STRT);
while (READ_BIT(FLASH->SR, FLASH_SR_BSY));
while (READ_BIT(FLASH->SR, FLASH_SR_EOP) == 0);
CLEAR_BIT(FLASH->CR, FLASH_CR_PER);
FLASH_Lock();
}

for(uint8_t i = 0; i < 20; i++) {
FLASH_Page_erase(i);
}
...

2 REPLIES 2
MM..1
Chief III

Maybe your showed code is here ? Or flash write page protection bits is set .

>>Why are the first 4 pages not erased when the read protection bit is set?

To prevent your "secure" boot loader from being erased

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..