使用HAL驱动在stm32上模拟EEPROM

8
我正在尝试在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。在使用EEPROM_emulation API之前是否需要调用“Flash_Unlock()”?如果是,调用“Flash_Unlock()”的HAL等效方法是什么?在CubeMX上需要进行哪些特殊配置设置以使用EEPROM模拟?

1
你正在寻找HAL_FLASH_Unlock(),但是STM32Cube为一些板提供了示例,例如STM32Cube_FW_F4_V1.21.0/Projects/STM32F4-Discovery/Applications/EEPROM/EEPROM_Emulation - phoenix
1个回答

9
ST Microelectronics提供了使用HAL驱动程序的示例代码。问题在于他们的文档到处都是,谷歌搜索可能无法找到正确的页面。
这是适合您的正确文档链接: document
搜索"EEPROM_Emulation"。您会发现样例代码在NUCLEO-F091RC固件示例下提供。样例代码应该能回答您的问题。

2
一直在Google搜索这个,但从未意识到我一直拥有它,它在CubeMX存储库中...非常感谢。 - sam byte

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接