Уточню, это f105/f107. Там "When the STRT bit in the Flash memory
control register is set (to launch an erase operation), the BSY bit
in the Flash memory status register goes high one cycle later". void
flash_unlock(void)
{
FLASH->KEYR = KEY1;
FLASH->KEYR = KEY2;
}
void
flash_lock(void)
{
FLASH->CR |= FLASH_CR_LOCK;
}
void
flash_erase(int addr)
{
flash_unlock();
FLASH->CR = FLASH_CR_PER;
FLASH->AR = addr;
FLASH->CR = FLASH_CR_PER | FLASH_CR_STRT;
(void)FLASH->SR; // delay to account for errata, doesn't work without this
while (FLASH->SR & FLASH_SR_BSY) ;
FLASH->CR = 0;
flash_lock();
}