2021-01-13 05:28 AM
My code as a below;
void EEPROM_WriteByte(unsigned int address, unsigned char value)
{
FLASH->DUKR = 0xAE;
FLASH->DUKR = 0x56;
(*(uint8_t *)(0x9FC0 + address)) = value;
FLASH->IAPSR &= FLASH_MemType_Data;
}
unsigned char EEPROM_ReadByte(unsigned int address)
{
unsigned char *ptr = (uint8_t *)(0x9FC0 + address);
return (*ptr);
}
2021-01-19 02:36 AM
While I don't know the STM8L001, this is how I do it with a STM8S103
void save_byte_eeprom(uint8_t *location, uint8_t data)
{
FLASH_Unlock(FLASH_MEMTYPE_DATA);
FLASH_EraseByte((uint32_t) location);
DELAY_ms(20);
FLASH_ProgramByte((uint32_t) location, data);
DELAY_ms(20);
FLASH_Lock(FLASH_MEMTYPE_DATA);
}