AnsweredAssumed Answered

Need help with timer interrupts using STM32F7 and Mbed

Question asked by Daniel Holanda on Dec 30, 2015
Latest reply on Apr 15, 2016 by Clive One
Hello everyone!

I'm having troubles using timer interrupts in with Mbed and a STM32F7 discovery kit. I thought about using Mbed's "ticker", but I need an interrupt every 0.125us (8MHz).

I tried to create a simple code to toggle an LED every 500ms in order to test a simple timer interrupt with Mbed, but it's not working. The LED turns on at the beginning but the program just freezes after the HAL_NVIC_EnableIRQ().

Can anyone help? Any help would be extremely appreciated. Here is my code so far:
#include "mbed.h"
 
DigitalOut myled(LED1);
 
TIM_HandleTypeDef TIM_Handle;
 
int main() { 
 
    myled = 1;
     
    __TIM4_CLK_ENABLE();
    TIM_Handle.Init.Prescaler = 671;
    TIM_Handle.Init.CounterMode = TIM_COUNTERMODE_UP;
    TIM_Handle.Init.Period = 62499;
    TIM_Handle.Instance = TIM4;   //Same timer whose clocks we enabled
    HAL_TIM_Base_Init(&TIM_Handle);     // Init timer
    HAL_TIM_Base_Start_IT(&TIM_Handle); // start timer interrupts
    HAL_NVIC_SetPriority(TIM4_IRQn, 0, 1);
    HAL_NVIC_EnableIRQ(TIM4_IRQn);  //This is the line that freezes everything
     
    myled = 0;
    while(1)
    {
    }
  
}
 
 
void TIM4_IRQHandler(void)
{
    if (__HAL_TIM_GET_FLAG(&TIM_Handle, TIM_FLAG_UPDATE) != RESET)      //In case other interrupts are also running
    {
        if (__HAL_TIM_GET_ITSTATUS(&TIM_Handle, TIM_IT_UPDATE) != RESET)
        {
            __HAL_TIM_CLEAR_FLAG(&TIM_Handle, TIM_FLAG_UPDATE);
            myled=!myled;
        }
    }
}
OBS: I used the interrupt example available here

Outcomes