2010-03-12 01:57 AM
stm32 standard library and thread safety
2011-05-17 04:43 AM
It's worse than you think. Hardware values (like RTC) can change without interrupts happening.
Suppose the RTC happens to be 0x2345 (high) and 0xFFFF (low) And you read the low value = 0xFFFF Then the RTC counts once to 0x2346 (high) and 0x0000 (low) Then you read the high value as 0x2346. Your return value is 0x2346FFFF - much higher than real-time. I do code like: uint16_t h1, l, h2; h2 = RTC_CNTH; do { /* code to catch overflow from low short to high short */ h1 = h2; l = RTC_CNTL; h2 = RTC_CNTH; } while (h1 != h2); return l | (h1 << 16); Hope this helps, Danish2011-05-17 04:43 AM
Very useful comment, indeed.
Thanks a lot. M