cancel
Showing results for 
Search instead for 
Did you mean: 

STM32F4 Discovery Board: TIM6, LED Blink problem with Cube IDE (Code Generation)

CYara.1
Associate II

Hello,

I'm trying to do basic led blink with STM32F4 Dicovery Board with timer6 using Cube IDE.

As you see in picture 84 Mhz clock divided by 8400 and counts to 10000 so i aimed 1 second toggle.

Also interrupt option of timer 6 is enabled which dosen't seem in picture.

Also Led is in GPIO_Output mode.

Here is my interrupt fuciton:

/**
  * @brief This function handles TIM6 global interrupt, DAC1 and DAC2 underrun error interrupts.
  */
void TIM6_DAC_IRQHandler(void)
{
  /* USER CODE BEGIN TIM6_DAC_IRQn 0 */
 
  /* USER CODE END TIM6_DAC_IRQn 0 */
  HAL_TIM_IRQHandler(&htim6);
  /* USER CODE BEGIN TIM6_DAC_IRQn 1 */
 
  HAL_GPIO_TogglePin(LD6_GPIO_Port, LD6_Pin);
 
  /* USER CODE END TIM6_DAC_IRQn 1 */
}

And i did nothin at main.c

Any suggestion ?

5 REPLIES 5
Javier1
Principal

you forgot to tell us what is your actual problem..... the led is not blinking?

Debugging: did you put a break point inside the TIM6 IRQ, does your program reach the IRQ function at all?

  • CUBEMX config should be 8400-1 and 10000-1 to aim 1 second interrupt
  • in your main.c you should have placed HAL_TIM_Base_Start HAL_TIM_Base_Start_IT(&htim6) at some point after /* USER CODE BEGIN 2 */
we dont need to firmware by ourselves, lets talk
CYara.1
Associate II

Hi Mr. Javier,

Thank you for your answer.

The problem is LED not blinking.

I did changes 8400-1 - 10000-1 and also add the HAL_TIM_Base_Start(&htim6) after /* USER CODE BEGIN 2 */

Still dosen't work.

I put a break point inside TIM6 IRQ and it looks like program DOSEN'T reach the IRQ function.

What do you think i should do now?

TDK
Guru

> And i did nothin at main.c

If you want the timer to generate interrupts, you need to call HAL_TIM_Base_Start_IT to start it.

If you feel a post has answered your question, please click "Accept as Solution".
CYara.1
Associate II

I changed HAL_TIM_Base_Start(&htim6) to HAL_TIM_Base_Start_IT(&htim6)

I added HAL_NVIC_SetPriority(TIM6_DAC_IRQn, 0, 1);

  HAL_NVIC_EnableIRQ(TIM6_DAC_IRQn); before Base_Start_IT...

And added  __HAL_TIM_CLEAR_FLAG(&htim6, TIM_FLAG_UPDATE); after toggling LED in interrupt callback.

Finally works. I don't know which one is real solution.

it probably was HAL_TIM_Base_Start_IT , i forgot to add the _IT, my bad

we dont need to firmware by ourselves, lets talk