Skip to main content
Explorer
January 19, 2024
Solved

Using Timer Global Interrupt crashes board

  • January 19, 2024
  • 2 replies
  • 4774 views

I have an Arduino Giga (STM32H7). I'm trying to generate an interrupt on the Catch/Compare even of TIM5_CH3. TIM5 is set to one pulse mode and triggered as a slave to TIM1, they generate some PWMs; everything is working absolutely fine there. Also, I've successfully used the CC interrupt of TIM1, and now I'm trying to do the same for TIM5, which only has a global interrupt handler. I've reduced my program to its simplest form for demonstration purposes:

 

 

TIM5->DIER = 0; //disable all interrups on TIM5
TIM5->SR = 0; //set all flags down
TIM5->DIER |= TIM_DIER_CC3IE; //enable interrupt from CH3

NVIC_EnableIRQ(TIM5_IRQn); //enable TIM5 ISR
	
// I don't set the priority here, doesn't seem to matter


extern "C" void TIM5_IRQHandler(void){
 TIM5->SR = 0; //set all flags to 0 again
}

 

 

For some reason, this makes the board unresponsive. I feel like I'm missing something obvious, even though this feels very safe. Only CH3 can generate an interrupt, which it does successfully (since it only crashes when the DIER_CC3IE is set). Then I just set its flag to 0 again (and all others, just for the sake of it).

Any help would be greatly appreciated! 

 

 

 

 

 

    This topic has been closed for replies.
    Best answer by Pepijn

    Alright, I found the issue. TIM5 is used by the Arduino Giga for things such as writing to the serial port. It probably has other uses as well, but I noted that anytime Serial.println() was called for example, the counter TIM5 CR1 CEN would be enabled... And I'm sure the system interferes and somehow constantly triggers the ISR. So yeah, there seems to be no way to fix this, and it's rather unfortunate that there is no proper documentation from Arduino's side telling me that TIM5 is used for system tasks, but at least I know now... Thanks for the help anyways!

    2 replies

    Super User
    January 19, 2024

    Is that channel set up in input capture mode? Set a breakpoint in the interrupt and show the value of all TIM5 registers when it gets there.

    Issue is no doubt that the interrupt gets called repeatedly, likely correctly.

    PepijnAuthor
    Explorer
    January 19, 2024

    I set it as output capture, to generate a PWM (which works correctly), using

     

     

     TIM5->CCMR2 &= TIM_CCMR2_OC3M_Msk; // for TIM5_CH3
     TIM5->CCMR2 |= (0x7UL << TIM_CCMR2_OC3M_Pos);

     

     

    Super User
    January 19, 2024

    Okay, so you're getting an interrupt on every pulse of the PWM. What is your pulse frequency?

    PepijnAuthorAnswer
    Explorer
    January 20, 2024

    Alright, I found the issue. TIM5 is used by the Arduino Giga for things such as writing to the serial port. It probably has other uses as well, but I noted that anytime Serial.println() was called for example, the counter TIM5 CR1 CEN would be enabled... And I'm sure the system interferes and somehow constantly triggers the ISR. So yeah, there seems to be no way to fix this, and it's rather unfortunate that there is no proper documentation from Arduino's side telling me that TIM5 is used for system tasks, but at least I know now... Thanks for the help anyways!

    Explorer
    April 24, 2024

    Where did you find proof that TIM5 was being used elsewhere?  We are trying to use if to count pulses from a hardware encoder.  When the pulses cause it to count down, we seem to loose our Ethernet/TCP communications and LinkStatus.  Counting up does not cause the crash.  If we don't configure TIM5 but just read the value, it appears to be set up as a microsecond counter.  Reprogramming TIM5 for our use does not seem to effect the system micros() or millis()  counters.  Only when it is counting down do we see the Ethernet issue.  It seems to be a waste of a good 32-bit timer to dedicate it to system use.  Is there any way around this?

    PepijnAuthor
    Explorer
    May 2, 2024

    Hi, it has been some time so my memory might be failing me somewhat. However, what I remember doing was trying to get TIM5 to work, but for some reason it wouldn't work properly. At some point I compared every single registry entry to another timer which I had set up in an identical manner. And then I remember finding what I wrote, basically that anytime I use the serial.print(), CR1 CEN would be enabled, even if I had disabled it prior. Maybe that's incorrect, but that was what I seemed to find back then... You can test it yourself I suppose :)

    Also, on the other arduino's like the Mega some programmable timers are used for system functionality, so it's not out of the question. And to your point of wasting a timer, well, it has 10+ other timers you can use still I think...