Random HAL_RTC_SetDate error on arch_max/STM32F407 board when setting RTC time?

Hi,

When testing a arch_max based project, I run into some mysterious problem. The app will sync RTC time to a remote NTP server every 6 hours. Occasionally system will crash and output “HAL_RTC_SetDate error” into console. Similar app running on STM32F401RE with ESP8266 doesn’t have such problem.

Can anybody provide some pointers on how to debug?

Thanks.

++ MbedOS Error Info ++
Error Status: 0x80FF0100 Code: 256 Module: 255
Error Message: Fatal Run-time error
Location: 0x801C017
Error Value: 0x0
Current Thread: main  Id: 0x20005B40 Entry: 0x8014FEB StackSize: 0x2000 StackMem: 0x2000B3C0 SP: 0x2000D18C 
For more info, visit: https://mbed.com/s/error?error=0x80FF0100&tgt=ARCH_MAX
-- MbedOS Error Info --
HAL_RTC_SetDate error

For anyone who is interested or runs into similar problem, the issue is hunted down to:

HAL_PWR_DisableBkUpAccess();

This line of code is called after saving some variables into RTC backup registers. When this line executes, it messes up HAL_RTC_SetDate() which is called by set_time();

I was under the impression that this line only disables access to RTC backup registers and backup SRAM, but according to user manual, despite its name, it also disables access to RTC registers. Its counter part is called during RTC initialization.

Line 54:

HAL_PWR_EnableBkUpAccess();
1 Like