I'm new to RTOS and having some troubles understanding a strange behavior:
I have a STM32 microcontroller running FreeRTOS and an RTC interrupt running, too.
The RTC interrupt just updates a volatile uint32_t
variable named SystemTime
:
void HAL_RTC_AlarmAEventCallback(RTC_HandleTypeDef *hrtc) {
UNUSED(hrtc);
SystemTime++;
}
Additionally, I have another task that runs every 100 mS.
It just prints the SystemTime
value if it has changed.
static void ToggleLEDThread(void const *argument) {
(void) argument;
static uint32_t ost;
uint32_t tst;
for (;;) {
#if 0
tst = SystemTime;
if (ost != tst) {
xprintf("<%d>\n", tst);
ost = tst;
}
#else
if (ost != SystemTime) {
xprintf("<%d>\n", SystemTime);
ost = SystemTime;
}
#endif
vTaskDelay(100);
}
}
It works as expected if #if 1
(using a temporary variable), but when #if 0
, the code runs ok for some time before it stops printing and after a few seconds starts to print again.
There is another task that prints some other values once a second.
Output when it's working:
V:1139 O:1091
<35>
V:1139 O:1123
<36>
V:1140 O:1154
<37>
V:1140 O:1186
<38>
V:1139 O:1218
<39>
V:1139 O:1249
<40>
V:1139 O:1281
<41>
V:1139 O:1313
<42>
V:1139 O:1344
<43>
V:1139 O:1376
<44>
V:1139 O:1408
<45>
V:1139 O:1439
<46>
V:1140 O:1471
<47>
V:1139 O:1503
<48>
V:1139 O:1535
<49>
V:1139 O:1566
<50>
V:1140 O:1598
<51>
V:1139 O:1630
<52>
V:1139 O:1661
Output when the problem happens:
V:1139 O:1091
<35>
V:1139 O:1123
<36>
V:1140 O:1154
<37>
V:1140 O:1186
<38>
V:1139 O:1218
<39>
V:1139 O:1249
<40>
V:1139 O:1281
<41>
V:1139 O:1313
<42>
V:1139 O:1344
V:1139 O:1376
V:1139 O:1408
V:1139 O:1439
V:1140 O:1471
V:1139 O:1503
V:1139 O:1535
V:1139 O:1566
<50>
V:1140 O:1598
<51>
V:1139 O:1630
<52>
V:1139 O:1661
Any ideas?