2019-09-12 03:23 PM
char *address = (char *) 0x4000;
void flashwrite(char dat)
{
// thanks to https://github.com/midnight-wonderer/stm8-eeprom-bug/blob/workaround-//method/src/firmware.c
// one Mr. Sarun Rattanasiri
while ((FLASH->IAPSR & FLASH_IAPSR_DUL)==0)
{
FLASH->DUKR = FLASH_RASS_KEY1;
FLASH->DUKR = FLASH_RASS_KEY2;
}
*address = 0;
*address = dat;
FLASH->IAPSR &= ~FLASH_IAPSR_DUL;
}