mbed library sources. Supersedes mbed-src.
Fork of mbed-dev by
Diff: targets/TARGET_STM/hal_tick_16b.c
- Revision:
- 167:e84263d55307
- Parent:
- 165:e614a9f1c9e2
- Child:
- 173:e131a1973e81
--- a/targets/TARGET_STM/hal_tick_16b.c Thu Jun 08 15:02:37 2017 +0100 +++ b/targets/TARGET_STM/hal_tick_16b.c Wed Jun 21 17:46:44 2017 +0100 @@ -24,14 +24,10 @@ extern volatile uint32_t SlaveCounter; extern volatile uint32_t oc_int_part; -extern volatile uint16_t oc_rem_part; -extern volatile uint8_t tim_it_update; -extern volatile uint32_t tim_it_counter; volatile uint32_t PreviousVal = 0; void us_ticker_irq_handler(void); -void set_compare(uint16_t count); #if defined(TARGET_STM32F0) void timer_update_irq_handler(void) { @@ -39,7 +35,6 @@ void timer_irq_handler(void) { #endif - uint16_t cnt_val = TIM_MST->CNT; TimMasterHandle.Instance = TIM_MST; // Clear Update interrupt flag @@ -47,8 +42,6 @@ if (__HAL_TIM_GET_IT_SOURCE(&TimMasterHandle, TIM_IT_UPDATE) == SET) { __HAL_TIM_CLEAR_IT(&TimMasterHandle, TIM_IT_UPDATE); SlaveCounter++; - tim_it_counter = cnt_val + (uint32_t)(SlaveCounter << 16); - tim_it_update = 1; } } @@ -57,7 +50,6 @@ // Used for mbed timeout (channel 1) and HAL tick (channel 2) void timer_oc_irq_handler(void) { - uint16_t cnt_val = TIM_MST->CNT; TimMasterHandle.Instance = TIM_MST; #endif @@ -65,23 +57,18 @@ if (__HAL_TIM_GET_FLAG(&TimMasterHandle, TIM_FLAG_CC1) == SET) { if (__HAL_TIM_GET_IT_SOURCE(&TimMasterHandle, TIM_IT_CC1) == SET) { __HAL_TIM_CLEAR_IT(&TimMasterHandle, TIM_IT_CC1); - if (oc_rem_part > 0) { - set_compare(oc_rem_part); // Finish the remaining time left - oc_rem_part = 0; - } else { + if (oc_int_part > 0) { - set_compare(0xFFFF); - oc_rem_part = cnt_val; // To finish the counter loop the next time oc_int_part--; } else { - us_ticker_irq_handler(); + us_ticker_irq_handler(); } - } } } // Channel 2 for HAL tick if (__HAL_TIM_GET_FLAG(&TimMasterHandle, TIM_FLAG_CC2) == SET) { + if (__HAL_TIM_GET_IT_SOURCE(&TimMasterHandle, TIM_IT_CC2) == SET) { __HAL_TIM_CLEAR_IT(&TimMasterHandle, TIM_IT_CC2); uint32_t val = __HAL_TIM_GET_COUNTER(&TimMasterHandle); @@ -118,11 +105,16 @@ TimMasterHandle.Init.Prescaler = (uint32_t)(SystemCoreClock / 1000000) - 1; // 1 us tick TimMasterHandle.Init.ClockDivision = 0; TimMasterHandle.Init.CounterMode = TIM_COUNTERMODE_UP; -#ifdef TARGET_STM32F0 +#if !defined(TARGET_STM32L0) + TimMasterHandle.Init.RepetitionCounter = 0; +#endif +#ifdef TIM_AUTORELOAD_PRELOAD_DISABLE TimMasterHandle.Init.AutoReloadPreload = TIM_AUTORELOAD_PRELOAD_DISABLE; #endif HAL_TIM_Base_Init(&TimMasterHandle); + //LL_TIM_EnableUpdateEvent(TimMasterHandle.Instance); + // Configure output compare channel 1 for mbed timeout (enabled later when used) HAL_TIM_OC_Start(&TimMasterHandle, TIM_CHANNEL_1); @@ -131,6 +123,8 @@ PreviousVal = __HAL_TIM_GET_COUNTER(&TimMasterHandle); __HAL_TIM_SET_COMPARE(&TimMasterHandle, TIM_CHANNEL_2, PreviousVal + HAL_TICK_DELAY); + + // Configure interrupts // Update interrupt used for 32-bit counter // Output compare channel 1 interrupt for mbed timeout