How to implement multiple interrupt timers using HAL libraries
I'm trying to get multiple timers with interrupts working on an STM32L462 using the provided HAL libraries in CubeIDE 1.14, but every time the chip comes out of reset, it crashes after starting the second timer. Here is the relevant code:
int main(void) {
MX_TIM15_Init();
MX_TIM2_Init();
...
HAL_TIM_Base_Start_IT(&htim2);
HAL_TIM_Base_Start_IT(&htim15);
...
}
// TIMER Interrupts
void HAL_TIM_PeriodElapsedCallback(TIM_HandleTypeDef *htim)
{
if (htim->Instance == TIM2) {
events.HEARTBEAT = 1;
}
if (htim->Instance == TIM15) {
events.DEBOUNCE = 1;
}
}
I can't this to work. Only when I disable the second interrupt or start the timer without interrupt will the chip start. I tried stepping through and it just gets stuck stepping indefinitely. This other topic seems to indicate it is possible, but I don't know how. Thinking about how the handler is set up, how could htim->Instance be two different values. That's impossible. So after more reading, I did try enabling 'Register Callbacks' configuration for timers, and then calling HAL_TIM_RegisterCallback before calling HAL_TIM_Base_Start_IT for each timer. It still didn't work, and stops when starting the second timer still. I don't understand what could be going on. Anyone ever get this setup? Thanks for any advice.
