2019-04-15 06:56 PM
Hi all,
I have an STM151 system (our own PCB) running FreeRTOS. As recommended, I leave TIM6 for the FreeRTOS timer,. and am using TIM2 to provide a source for the HAL_Tick timebase.
In the BeforeSleepTasks (ie when all RTOS tasks are idle and the CPU goes into the tickless idle state, I stop TIM2, otherwise its interrupt will wake the CPU every milllisec.
HAL_TIM_Base_Stop_IT(&htim2);
When it wakes from an interrupt, I restart the timer:
HAL_TIM_Base_Start_IT(&htim2);
And here is the TIM2 interrupt service routine:
void TIM2_IRQHandler(void)
{
TIM2->SR &= ~0x01; // clear the interrupt pending flag
HAL_IncTick();
}
OK, this all works well.
However, under certain circumstances (usually when plugging a USB cable in (I have a virtual USB port)), the TIM2 IRQ handler does not get triggered.
The timer is running (I can pause it in Atollic and see that the CNT register is incremmenting. The interrupt flag is being set OK (I can view it as bit 0 of the SR register).
But the IRQ service routine above does not execute.
Might there be some lower level interrupt masking function that has been activated, preventing the TIM2 interrupt from functioning?
Many thanks for your help,
Steve
2019-04-15 10:43 PM
Does the IRQ flag get to the NVIC registers (pending/active)?
2019-04-17 04:50 PM
I believe the answer is yes but please confirm I am looking in the correct place:
TIM2 is interrupt no. 28
I therefore look in bit 28 of ISER0 and find it is set, ie the interrupt is enabled
Also, bit 28 of ISPR0 is set, implying that there is a pending interrupt in this channel.
I'm wondering now if the global interrupt flag has been cleared, but can't see how to check this - PRIMASK is always 1 in the Atollic IDE when the target is paused, but I suppose this is probably because it is paused :-).