cancel
Showing results for 
Search instead for 
Did you mean: 

Need help with timer interrupts using STM32F7 and Mbed

danielhn1992
Associate
Posted on December 30, 2015 at 23:27

Hello everyone!

I'm having troubles using timer interrupts in with Mbed and aSTM32F7 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 theHAL_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

https://lostwire.wordpress.com/2015/01/12/timer-interrupt-on-stm32f4-using-hal/

.

2 REPLIES 2
Posted on April 15, 2016 at 21:21

8 MHz is an impractically high rate to use interrupts. Get the timer to toggle a signal by itself, in hardware.

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