使用HAL驱动程序在stm32上进行EEPROM仿真

8 stm32 flash-memory eeprom stm32f0

我试图在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);
}
Run Code Online (Sandbox Code Playgroud)

Flash_Unlock()是STM标准外设库中使用的函数.但是,我正在使用CubeMX自动生成使用HAL驱动程序的代码.Flash_Unlock()在使用EEPROM_emulation API之前是否需要调用?如果是,那么呼叫的HAL等价是Flash_Unlock()多少?在CubeMX上进行任何特殊配置设置以使用EEPROM仿真?

use*_*486 9

ST Microelectronics确实使用HAL驱动程序提供了示例代码.问题是他们的文档到处都是,谷歌搜索可能不会让你找到正确的页面.

这是适合您的正确文档.

搜索"EEPROM_Emulation".您会发现示例代码是在NUCLEO -F091RC固件示例下提供的.示例代码应该回答您的问题.

  • 一直在谷歌上搜索这个 hi &amp; lo,但从来没有意识到我在 CubeMX repo 中拥有它......非常感谢。 (2认同)