cancel
Showing results for 
Search instead for 
Did you mean: 

STM32F100RBT Avoiding RTC Time Race When Setting Alarm For 1 Second

ISeed
Senior

Hello,

I have a system using STM32F100RBT needs wake up from standby mode every second.

Some operations it conducts when it wakes might take longer than a second.

Each time before going to sleep, I read the current RTC time, and set an alarm for this time + 1 second.

The problem is that the RTC resolution is 1 second, and this is also the interval I'm waiting.

I need to avoid a time race, where an RTC second increases just between reading the RTC and going to standby.

One option is, assuming the system won't be awake longer than an hour, to use the systick milliseconds, and be stuck in a busy-wait before reading the RTC, if (systick % 1000 > 990) (having a 10ms buffer).

This will work only if I'm guaranteed that the systick starts ticking the moment RTC reaches a full second (or with a small, but constant delay, without an accumulating error).

  1. Do I have this guarantee about systick? (something I would like to know regardless, as doing black-boxtests might give me a false positive)
  2. Any other recommended way to deal with this?

Thanks!

3 REPLIES 3
ISeed
Senior

Anyone? :)

Unfortunately you keep opening threads on materially the same topic, and I haven't used F1 series parts actively in a decade, and used a different library. I have relatively little interest is reopening that can of worms in an unpaid capacity.

a) Remember the last Alarm point, and advance that number.

b) Use a different prescaler so the 32-bit RTC count has a finer granularity.

https://community.st.com/s/question/0D50X0000BdendXSQQ/stm32f100-rtc-wake-from-standby-is-always-1-second-late

https://community.st.com/s/question/0D50X0000Bddv0mSQA/exit-standby-every-second-from-rtc-on-stm32f100rbt

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
ISeed
Senior

First of all, thank you!

these topics, while similar in dealing with RTC on a 1 second level, are all different in their specific question, and were opened at different times after I found some temporary workaround:

  • how to exit standby
  • the fact that RTC exits standby 1 second too late
  • how to avoid a time race

This is to attract a quick, direct answers, rather than a long, developing correspondence, and help future users with their search.

Is there a different approach on these forums?