diff --git a/cores/arduino/HardwareTimer.cpp b/cores/arduino/HardwareTimer.cpp index 3c325d287c..424770b286 100644 --- a/cores/arduino/HardwareTimer.cpp +++ b/cores/arduino/HardwareTimer.cpp @@ -35,9 +35,6 @@ /* Private Variables */ timerObj_t *HardwareTimer_Handle[TIMER_NUM] = {NULL}; -IRQn_Type getTimerUpIrq(TIM_TypeDef *tim); -IRQn_Type getTimerCCIrq(TIM_TypeDef *tim); - /** * @brief HardwareTimer constructor: set default configuration values * @param Timer instance ex: TIM1, ... @@ -913,6 +910,15 @@ void HardwareTimer::setPWM(uint32_t channel, PinName pin, uint32_t frequency, ui */ void HardwareTimer::setInterruptPriority(uint32_t preemptPriority, uint32_t subPriority) { + // Set Update interrupt priority for immediate use + HAL_NVIC_SetPriority(getTimerUpIrq(_timerObj.handle.Instance), preemptPriority, subPriority); + + // Set Capture/Compare interrupt priority if timer provides a unique IRQ + if (getTimerCCIrq(_timerObj.handle.Instance) != getTimerUpIrq(_timerObj.handle.Instance)) { + HAL_NVIC_SetPriority(getTimerCCIrq(_timerObj.handle.Instance), preemptPriority, subPriority); + } + + // Store priority for use if timer is re-initialized _timerObj.preemptPriority = preemptPriority; _timerObj.subPriority = subPriority; }