Skip to content

Commit 5895006

Browse files
committed
STM32L0 - Add patch done previously on these devices. This solves MBED_24 test.
1 parent a2e686b commit 5895006

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

targets/TARGET_STM/stm_us_ticker_16b.c

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,32 @@ uint32_t us_ticker_read()
6868

6969
tim_it_update = 0; // Clear TIM_IT_UPDATE event flag
7070

71+
#if defined(TARGET_STM32L0)
72+
volatile uint16_t cntH_old, cntH, cntL;
73+
do {
74+
// For some reason on L0xx series we need to read and clear the
75+
// overflow flag which give extra time to propelry handle possible
76+
// hiccup after ~60s
77+
if (__HAL_TIM_GET_FLAG(&TimMasterHandle, TIM_FLAG_CC1OF) == SET) {
78+
__HAL_TIM_CLEAR_FLAG(&TimMasterHandle, TIM_FLAG_CC1OF);
79+
}
80+
cntH_old = SlaveCounter;
81+
if (__HAL_TIM_GET_FLAG(&TimMasterHandle, TIM_FLAG_UPDATE) == SET) {
82+
cntH_old += 1;
83+
}
84+
cntL = TIM_MST->CNT;
85+
86+
cntH = SlaveCounter;
87+
if (__HAL_TIM_GET_FLAG(&TimMasterHandle, TIM_FLAG_UPDATE) == SET) {
88+
cntH += 1;
89+
}
90+
} while(cntH_old != cntH);
91+
92+
// Glue the upper and lower part together to get a 32 bit timer
93+
counter = (uint32_t)(cntH << 16 | cntL);
94+
#else
7195
counter = TIM_MST->CNT + (uint32_t)(SlaveCounter << 16); // Calculate new time stamp
96+
#endif
7297

7398
if (tim_it_update == 1) {
7499
return tim_it_counter; // In case of TIM_IT_UPDATE return the time stamp that was calculated in timer_irq_handler()

0 commit comments

Comments
 (0)