0

I have a strange issue with the RTC of an STM32 F407 in one of my projects.

Abstract: The function HAL_RTC_GetTime(...) updates the output value only once, then remains at the same valule, but it updates if I set a breakpoint in this function.

Description: I have recently updated from CubeIDE 1.8.0 to CubeIDE 1.9.0. At one of my projects I have these strange issues, described above. Before the update of the IDE all worked fine. After the Update these strange issues occur. This might be a coincidence, but 2 days ago all worked fine.

What have I done to resolve this issue: first of all, I set some breakpoints along the call chain and finally in the HAL function, where the return value is generated. I found out this way, that the members of the RTC_TimeTypeDef struct are updated correctly if the debugger stops the execution of the programm, but is NOT updated, when the brakpoint is removed.

My first guess was: ok, something went wrong with the drivers during the Update to CubeMX 6.5 / CubeIDE 1.9.0

Attempt 1: I removed the RTC from the Project Setup, compliled the Project (was OK), added the RTC to the Project again, with the same behaviour.

Attempt 2: I created a backup of all my code, deleted the project, created it new, restored my code and tried again. With the same result (mind = blown) I did not expect this, because - at least now - all files generated by CubeMX had to be generated new from scratch with the latest drivers.

In the debugger window I can see that the members Hours, Minutes, Seconds of the Struct "RTC_TimeTypeDef" do not change at all, instead DayLightSaving and StoreOperation are changing randomly, while SubSeconds seem to count correctly.

Debugger Outpus

Furthermore: The RTC Timer itself seems to work correctly as hrtc->Instance->TR seems to count the seconds

For me it looks like some bitmasks or whatever are messed up and instead of shifting the Hours, Minutes and Seconds into the members of the Structm, HAL_RTC_GetTime(...) shifts these values into DayLightSaving and StoreOperation.

Has anyone an idea, what's going on here? Especially why it works when a breakpoint is set, but otherwise not? Any hint, how I could track this down is appreciated.

My workaround will most probably be, that I use the value from hrtc->Instance->TR directly and write my own conversion. But I'd really like to understand whats going wrong here.

Thank you and best regards, Chris

Chris_B
  • 359
  • 5
  • 13
  • You should post your code. – Armandas Mar 12 '22 at 01:19
  • Posting the Code does not much sense, as the issue within the HAL_RTC_GetTime(...) function, where the members of the output struct are simply not updated as intended. And HAL_RTC_GetTime(...) is created by CubeMX during the Code Generation. It's simply a STM32 HAL function from the STM32 Drivers – Chris_B Mar 12 '22 at 11:01

1 Answers1

1

Solved!

The trick is: you have to read the Date after reading the time on an STM32F40x!

see: https://community.st.com/s/question/0D73W000001Nvn5SAC

Obviously the "Live Expression" probe in the CubeIDE also triggers the "ReadDate()" function. This is IMHO the reason, why the RTC was working fine, when a probe on that variable is set, but otherwise not.

Chris_B
  • 359
  • 5
  • 13