先找到芯片的Reference manual手册,找到EEPROM的内存地址
EERPOM定义
#define EEPROM_BASE_ADDR 0x08080000
#define EEPROM_BYTE_SIZE 0x03FF
void eeprom_test_write();
void eeprom_test_read();
这里使用的是一次写入4个字节
//eeprom写测试
void eeprom_test_write()
{
uint16_t i;
HAL_FLASHEx_DATAEEPROM_Unlock();
for(i=0;i<EEPROM_BYTE_SIZE/4;i++)
{
HAL_FLASHEx_DATAEEPROM_Program(FLASH_TYPEPROGRAMDATA_WORD,EEPROM_BASE_ADDR+(i*4),i);
}
HAL_FLASHEx_DATAEEPROM_Lock();
}
//eeprom读测试
void eeprom_test_read()
{
uint32_t temp;
for(uint8_t i=0;i<EEPROM_BYTE_SIZE/4;i++)
{
temp = *(__IO uint32_t*)(EEPROM_BASE_ADDR+(i*4));
printf("data:%x\t",temp);
}
}
测试效果
如果要写byte或HALFWORD使用下面的参数
#define FLASH_TYPEPROGRAMDATA_BYTE (0x00U) /*!<Program byte (8-bit) at a specified address.*/
#define FLASH_TYPEPROGRAMDATA_HALFWORD (0x01U) /*!<Program a half-word (16-bit) at a specified address.*/
#define FLASH_TYPEPROGRAMDATA_WORD (0x02U) /*!<Program a word (32-bit) at a specified address.*/
|