From 0591b2bcd457cd7e383544bc5ad18f7c41621ad2 Mon Sep 17 00:00:00 2001 From: Martin Kojtal <0xc0170@gmail.com> Date: Mon, 26 Jun 2017 15:20:54 +0100 Subject: [PATCH] STM32: fix us ticker set event timestamp While we are handling new timestamp, disable ticker's interrupt. --- targets/TARGET_STM/us_ticker_32b.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/targets/TARGET_STM/us_ticker_32b.c b/targets/TARGET_STM/us_ticker_32b.c index 90ce35aad1a..f00705234a9 100644 --- a/targets/TARGET_STM/us_ticker_32b.c +++ b/targets/TARGET_STM/us_ticker_32b.c @@ -44,14 +44,16 @@ uint32_t us_ticker_read() void us_ticker_set_interrupt(timestamp_t timestamp) { TimMasterHandle.Instance = TIM_MST; + // disable IT while we are handling the correct timestamp + __HAL_TIM_DISABLE_IT(&TimMasterHandle, TIM_IT_CC1); // Set new output compare value __HAL_TIM_SET_COMPARE(&TimMasterHandle, TIM_CHANNEL_1, (uint32_t)timestamp); - // Enable IT - __HAL_TIM_ENABLE_IT(&TimMasterHandle, TIM_IT_CC1); // Check if timestamp has already passed, and if so, set the event immediately if ((int32_t)(timestamp - TIM_MST->CNT) <= 0) { LL_TIM_GenerateEvent_CC1(TimMasterHandle.Instance); } + // Enable IT + __HAL_TIM_ENABLE_IT(&TimMasterHandle, TIM_IT_CC1); } void us_ticker_disable_interrupt(void)