Skip to main content
Senior
September 27, 2021
Question

EEPROM emulation error when using TIM timebase

  • September 27, 2021
  • 1 reply
  • 1103 views

I am using the example project from the xcube eeprom v3.0.0 as a reference to add EEPROM emulation to my project using the STM32G431RB. The example project works fine, but my project uses FREERTOS so I have changed my timebase source to a timer. This seems to make the initialization function EE_Init(EE_FORCED_ERASE) fail, returning "EE_ERASE_ERROR".

Through debugging, I found that the "EE_Init" fails in the "HAL_FLASHEx_Erase" function when "FLASH_WaitForLastOperation" returns an error. In debug, I noticed that the error results from the FLASH.SR register having the PGSERR set. I added the FLASH.SR to my debug expressions and found that the bit is set before I even call "EE_Init". It turns out the PGSERR bit gets set in "HAL_InitTick" when calling "HAL_NVIC_EnableIRQ(TIM1_TRG_COM_TIM17_IRQn)". Of course, this only happens if I use TIM17 as my timebase instead of systick (I tried other timers as well and they all produce the same behavior). It seems that maybe some NVIC register is not mapped properly in the CubeMX generated code?

I was able to get the EEPROM emulation working by calling "FLASH->SR |= FLASH_FLAG_SR_ERRORS" to clear the flash status register right after "HAL_Init()" in main.

This topic has been closed for replies.

1 reply

Explorer
October 27, 2023

Thank you for sharing the info. It seems to be issue even now after 2 years you published this post.