cancel
Showing results for 
Search instead for 
Did you mean: 

What is the best way to re-enable SysTick after resuming from sleep, specifically for interrupts?

antfarmer
Associate III

If you put an MCU in sleep mode with WFI, such as the STM32L452, you are supposed to suspend the SysTick and resume it after. Usually this is done in the main thread context. However, when you have an interrupt, I believe the next instruction will be in the IRQ handlers. Would the only way to ensure the SysTick be running within any ISR be to call HAL_ResumeTick within each interrupt handler? Seems like there should be a better way.

2 REPLIES 2

If you have a spare 32-bit TIM counter you could perhaps use that to count time rather than using a 1ms interrupt in increment a count?

Is servicing an interrupt like this chronically burdensome on the system? Say compared to having LEDs light up or other subcomponents in the system draw current directly or via load apparent to the GPIO driver?

You should be able to gate via the NVIC or a bit on the SysTick control register.

Tips, buy me a coffee, or three.. PayPal Venmo Up vote any posts that you find helpful, it shows what's working..

Thanks for your response. Yes, actually I'm using a 32-bit timer (without interrupt) as a microsecond counter that I find useful for performance debugging. Most of my interrupts are fairly simple where a flag bit is set and then handled in the main loop. There are just a couple edge cases where one interrupt has priority over the others and in that case, I need to quickly cancel any ongoing operations (ADC for example), and handle the higher priority one. I actually don't really use SysTick much, but I would be concerned that the HAL calls that might occur in these edge-case interrupts may rely on it and get stuck in a timeout loop or something like that. I would prefer some way to restart systick as soon as the cpu resumes rather than after the interrupt completes. I guess I could just add resume in every IRQ handler, but it just seems like messy code.

 

To your question on burden: time-wise not really, these are mostly edge-cases, but if they do occur, they may take longer than a normal ISR in that they have to interact with some HAL calls. Maybe I misunderstand the question, but as far as power, I think everything is accounted for, as the circuit has FET's for almost all the peripheral devices so they can be powered down as needed.

 

I'm not sure I understand what you mean by gating via NVIC or systick register. Can you explain that?