Skip to content

Commit 777692c

Browse files
committed
Timer 16bit: Remove volatile variables. This solved many fails with MBED_24 test.
1 parent f8e18cd commit 777692c

File tree

1 file changed

+4
-8
lines changed

1 file changed

+4
-8
lines changed

targets/TARGET_STM/us_ticker_16b.c

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -67,10 +67,8 @@ uint32_t us_ticker_read() {
6767

6868
if (!us_ticker_inited) us_ticker_init();
6969

70-
tim_it_update = 0; // Clear TIM_IT_UPDATE event flag
71-
7270
#if defined(TARGET_STM32L0)
73-
volatile uint16_t cntH_old, cntH, cntL;
71+
uint16_t cntH_old, cntH, cntL;
7472
do {
7573
// For some reason on L0xx series we need to read and clear the
7674
// overflow flag which give extra time to propelry handle possible
@@ -83,25 +81,23 @@ uint32_t us_ticker_read() {
8381
cntH_old += 1;
8482
}
8583
cntL = TIM_MST->CNT;
86-
8784
cntH = SlaveCounter;
8885
if (__HAL_TIM_GET_FLAG(&TimMasterHandle, TIM_FLAG_UPDATE) == SET) {
8986
cntH += 1;
9087
}
9188
} while(cntH_old != cntH);
92-
9389
// Glue the upper and lower part together to get a 32 bit timer
94-
counter = (uint32_t)(cntH << 16 | cntL);
90+
return (uint32_t)(cntH << 16 | cntL);
9591
#else
92+
tim_it_update = 0; // Clear TIM_IT_UPDATE event flag
9693
counter = TIM_MST->CNT + (uint32_t)(SlaveCounter << 16); // Calculate new time stamp
97-
#endif
98-
9994
if (tim_it_update == 1) {
10095
return tim_it_counter; // In case of TIM_IT_UPDATE return the time stamp that was calculated in timer_irq_handler()
10196
}
10297
else {
10398
return counter; // Otherwise return the time stamp calculated here
10499
}
100+
#endif
105101
}
106102

107103
void us_ticker_set_interrupt(timestamp_t timestamp) {

0 commit comments

Comments
 (0)