金牌会员
- 积分
- 1835
- 金钱
- 1835
- 注册时间
- 2014-12-4
- 在线时间
- 717 小时
|
发表于 2016-6-4 15:19:25
|
显示全部楼层
贴一个STM8S内部EEPROM读写的函数,可参考
void SysEepromWriteOnebyte(uint32_t Address, uint8_t Data)
{
uint8_t flagstatus = 0x00;
uint32_t timeout = ((uint32_t)0xFFFFF);
FLASH->CR1 &= (uint8_t)(~0x01);
FLASH->CR1 |= (uint8_t)0x00;
//FLASH_Unlock(FLASH_MEMTYPE_DATA);
FLASH->DUKR = 0xAE; // Warning: keys are reversed on data memory !!!
FLASH->DUKR = 0x56;
//FLASH_WaitForLastOperation(FLASH_MEMTYPE_DATA);
/*while ((flagstatus == 0x00) && (timeout != 0x00))
{
flagstatus = (uint8_t)(FLASH->IAPSR & (FLASH_IAPSR_EOP | FLASH_IAPSR_WR_PG_DIS));
timeout--;
}*/
//FLASH_ProgramByte(Address, Data);
*(PointerAttr uint8_t*) (uint16_t)Address = Data;
//FLASH_WaitForLastOperation(FLASH_MEMTYPE_DATA);
timeout = ((uint32_t)0xFFFFF);
while ((flagstatus == 0x00) && (timeout != 0x00))
{
flagstatus = (uint8_t)(FLASH->IAPSR & (FLASH_IAPSR_EOP | FLASH_IAPSR_WR_PG_DIS));
timeout--;
}
//FLASH_Lock(FLASH_MEMTYPE_DATA);
// Lock memory
FLASH->IAPSR &= (uint8_t)0xF7;
}
u8 SysEepromReadOnebyte(uint32_t Address)
{
return (*(PointerAttr uint8_t *) (uint16_t)Address);
//return FLASH_ReadByte(Address);
} |
|