Skip to content

Commit 3f2e986

Browse files
Merge pull request #5012 from LMESTM/issue5004_ticker_16b
STM32_us_ticker_16b: keep code to cope with past event
2 parents e0bc631 + f2eb77a commit 3f2e986

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

targets/TARGET_STM/us_ticker_16b.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,7 @@ void us_ticker_set_interrupt(timestamp_t timestamp)
152152
*/
153153
uint32_t current_time = us_ticker_read();
154154
uint32_t delta = timestamp - current_time;
155+
/* Note: The case of delta <= 0 is handled in MBED upper layer */
155156
oc_int_part = (delta - 1) >> 16;
156157
if ( ((delta - 1) & 0xFFFF) >= 0x8000 &&
157158
__HAL_TIM_GET_FLAG(&TimMasterHandle, TIM_FLAG_CC1) == SET ) {
@@ -169,6 +170,9 @@ void us_ticker_set_interrupt(timestamp_t timestamp)
169170

170171
void us_ticker_fire_interrupt(void)
171172
{
173+
/* When firing the event, the number of 16 bits counter wrap-ups (oc_int)
174+
* must be re-initialized */
175+
oc_int_part = 0;
172176
HAL_TIM_GenerateEvent(&TimMasterHandle, TIM_EVENTSOURCE_CC1);
173177
}
174178

0 commit comments

Comments
 (0)