我正在尝试在 stm32f0 上模拟 EEPROM。STM 提供了一份应用说明。
在样本main.c
中,
int main(void)
{
/*!< At this stage the microcontroller clock setting is already configured,
this is done through SystemInit() function which is called from startup
file (startup_stm32f0xx.s) before to branch to application main.
To reconfigure the default setting of SystemInit() function, refer to
system_stm32f0xx.c file
*/
/* Unlock the Flash Program Erase controller */
FLASH_Unlock();
/* EEPROM Init */
EE_Init();
/* --- Store successively many values of the three variables in the EEPROM ---*/
/* Store 0x1000 values of Variable1 in EEPROM */
for (VarValue = 1; VarValue <= 0x64; VarValue++)
{
EE_WriteVariable(VirtAddVarTab[0], VarValue);
}
/* read the last stored variables data*/
EE_ReadVariable(VirtAddVarTab[0], &VarDataTab[0]);
/* Store 0x2000 values of Variable2 in EEPROM */
for (VarValue = 1; VarValue <= 0xC8; VarValue++)
{
EE_WriteVariable(VirtAddVarTab[1], VarValue);
}
/* read the last stored variables data*/
EE_ReadVariable(VirtAddVarTab[0], &VarDataTab[0]);
EE_ReadVariable(VirtAddVarTab[1], &VarDataTab[1]);
/* Store 0x3000 values of Variable3 in EEPROM */
for (VarValue = 1; VarValue <= 0x1C2; VarValue++)
{
EE_WriteVariable(VirtAddVarTab[2], VarValue);
}
/* read the last stored variables data*/
EE_ReadVariable(VirtAddVarTab[0], &VarDataTab[0]);
EE_ReadVariable(VirtAddVarTab[1], &VarDataTab[1]);
EE_ReadVariable(VirtAddVarTab[2], &VarDataTab[2]);
while (1);
}
Flash_Unlock()
是STM标准外设库中使用的函数。但是,我使用的是自动生成使用 HAL 驱动程序的代码的 CubeMX。是否Flash_Unlock()
必须先调用才能使用 EEPROM_emulation API?如果是,那么调用的 HAL 等效项是什么Flash_Unlock()
?要在 CubeMX 上进行任何特殊配置设置以使用 EEPROM 仿真吗?