Skip to content

Commit

Permalink
Merge pull request #1062 from sjasonsmith/PR/HardwareTimerPriority
Browse files Browse the repository at this point in the history
Fixed setting HardwareTimer interrupt priority
  • Loading branch information
fpistm authored May 13, 2020
2 parents 3a9c71c + ebf27ee commit 6b5f0ab
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions cores/arduino/HardwareTimer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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, ...
Expand Down Expand Up @@ -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;
}
Expand Down

0 comments on commit 6b5f0ab

Please sign in to comment.