Skip to content

Commit 4c03193

Browse files
authored
Merge pull request #2086 from svastm/fix_mbed_23_l0
[STM32L0XX] Remove stabilization of the timer
2 parents 5af16c9 + a9b3b9c commit 4c03193

File tree

1 file changed

+18
-27
lines changed

1 file changed

+18
-27
lines changed

hal/targets/hal/TARGET_STM/TARGET_STM32L0/us_ticker.c

Lines changed: 18 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@
3535

3636
static TIM_HandleTypeDef TimMasterHandle;
3737
static int us_ticker_inited = 0;
38-
static bool us_ticker_stabilized = false;
3938

4039
volatile uint16_t SlaveCounter = 0;
4140
volatile uint32_t oc_int_part = 0;
@@ -64,32 +63,24 @@ uint32_t us_ticker_read()
6463

6564
if (!us_ticker_inited) us_ticker_init();
6665

67-
// There's a situation where the first tick still may overflow and to avoid
68-
// it we need to check if our ticker has stabilized and due to that we need
69-
// to return only the lower part of your 32 bit software timer.
70-
if (us_ticker_stabilized) {
71-
do {
72-
// For some reason on L0xx series we need to read and clear the
73-
// overflow flag which give extra time to propelry handle possible
74-
// hiccup after ~60s
75-
if (__HAL_TIM_GET_FLAG(&TimMasterHandle, TIM_FLAG_CC1OF) == SET) {
76-
__HAL_TIM_CLEAR_FLAG(&TimMasterHandle, TIM_FLAG_CC1OF);
77-
}
78-
cntH_old = SlaveCounter;
79-
if (__HAL_TIM_GET_FLAG(&TimMasterHandle, TIM_FLAG_UPDATE) == SET) {
80-
cntH_old += 1;
81-
}
82-
cntL = TIM_MST->CNT;
83-
84-
cntH = SlaveCounter;
85-
if (__HAL_TIM_GET_FLAG(&TimMasterHandle, TIM_FLAG_UPDATE) == SET) {
86-
cntH += 1;
87-
}
88-
} while(cntH_old != cntH);
89-
} else {
90-
us_ticker_stabilized = true;
91-
return (uint32_t) TIM_MST->CNT;
92-
}
66+
do {
67+
// For some reason on L0xx series we need to read and clear the
68+
// overflow flag which give extra time to propelry handle possible
69+
// hiccup after ~60s
70+
if (__HAL_TIM_GET_FLAG(&TimMasterHandle, TIM_FLAG_CC1OF) == SET) {
71+
__HAL_TIM_CLEAR_FLAG(&TimMasterHandle, TIM_FLAG_CC1OF);
72+
}
73+
cntH_old = SlaveCounter;
74+
if (__HAL_TIM_GET_FLAG(&TimMasterHandle, TIM_FLAG_UPDATE) == SET) {
75+
cntH_old += 1;
76+
}
77+
cntL = TIM_MST->CNT;
78+
79+
cntH = SlaveCounter;
80+
if (__HAL_TIM_GET_FLAG(&TimMasterHandle, TIM_FLAG_UPDATE) == SET) {
81+
cntH += 1;
82+
}
83+
} while(cntH_old != cntH);
9384

9485
// Glue the upper and lower part together to get a 32 bit timer
9586
return (uint32_t)(cntH << 16 | cntL);

0 commit comments

Comments
 (0)