cancel
Showing results for 
Search instead for 
Did you mean: 

HAL_delay() issue infinite loop

Kyrpav
Associate III

I am using a nucleo-f767zi to control a reverdi tft display.

The project in CUBEMX ide is using freertos and there for the time base is changed from systick to TIM6.

I am trying to task enable sequence for the screen but i see that i am stack in an infinite loop in HAL_delay() function.

I debbugged it and i see that when i stepped into the code program stops at :

 

 

 __weak void HAL_Delay(uint32_t Delay)
{
  uint32_t tickstart = HAL_GetTick();
  uint32_t wait = Delay;

  /* Add a freq to guarantee minimum wait */
  if (wait < HAL_MAX_DELAY)
  {
    wait += (uint32_t)(uwTickFreq);
  }

// it is blocked in side this loop. which means that HAL_GetTick() has issue. 
  while ((HAL_GetTick() - tickstart) < wait)
  {
  }
}

 

It seems that HAL_GetTick has issue so this means that i am missing some setup.

Can you someone guide me where to look?

Project identifies TIM6 as base time and the interrupt is there in ioc

1 ACCEPTED SOLUTION

Accepted Solutions
TDK
Guru

When it's stuck:

  • Check that TIM6 is running by observing TIM6->CNT.
  • Check that interrupts are enabled in general and specifically for TIM6 by looking at TIM6->DIER.
  • Check that you're not in an interrupt of high priority.
If you feel a post has answered your question, please click "Accept as Solution".

View solution in original post

7 REPLIES 7
Sarra.S
ST Employee

Hello @Kyrpav

Check/ live watch the HAL_GetTick() function to see if it's returning the correct value, also check the tick freq in the HAL_InitTick() 

 

To give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.

TDK
Guru

When it's stuck:

  • Check that TIM6 is running by observing TIM6->CNT.
  • Check that interrupts are enabled in general and specifically for TIM6 by looking at TIM6->DIER.
  • Check that you're not in an interrupt of high priority.
If you feel a post has answered your question, please click "Accept as Solution".
Kyrpav
Associate III

The HAL_GetTick() gives same value all time in each loop. this value is thevalue that gets until it gets in this while loop then the value does not change at all.

Kyrpav_2-1692371741483.png

Kyrpav_3-1692371832196.png

About interrupt high priority i have (or i did not know where to look for this.)

Kyrpav_0-1692376393238.png

I changed the priority from 15 to 0 but Hal_InitTick is i think for SysTick based on what i see in code except if i am wrong.

for the TIM6->DIER from the SFRs view  and the registers o see that value is always 1 but CNT registart changes in every step over.

 

 

__weak HAL_StatusTypeDef HAL_InitTick(uint32_t TickPriority)
{
  /* Configure the SysTick to have interrupt in 1ms time basis*/
  if (HAL_SYSTICK_Config(SystemCoreClock / (1000U / uwTickFreq)) > 0U)
  {
    return HAL_ERROR;
  }

  /* Configure the SysTick IRQ priority */
  if (TickPriority < (1UL << __NVIC_PRIO_BITS))
  {
    HAL_NVIC_SetPriority(SysTick_IRQn, TickPriority, 0U);
    uwTickPrio = TickPriority;
  }
  else
  {
    return HAL_ERROR;
  }

  /* Return function status */
  return HAL_OK;
}

 

Do i need to make changes in this file and what stm32f7xx_hal.c for th e Hal_InitTick()? Am i suppose to change this file at all or it is something else that needs to be done?

Thank you @Sarra.S and @TDK for trying to help

 

 

TDK
Guru

Okay so DIER=1 and the timer is running, which means the interrupt wants to fire. The NVIC bit also needs set but I bet it is. Now you need to determine why it's not firing. Probably interrupts are disabled, or you're running in a higher-priority interrupt.

Where are you calling HAL_Delay from?

Show the contents of the SCB registers, in particular ICSR.

TDK_0-1692385313514.png

 

If you feel a post has answered your question, please click "Accept as Solution".
Kyrpav
Associate III

For the interrupt and the priorities i have from ioc this:

 

Kyrpav_0-1692390163872.png

This does not mean that it is ok? I also tried to make tim6 also priority = 0 from 15 but no change

And from the freertos i have two tasks with normal priority

Kyrpav_1-1692390309573.png

The Hal_delay i am calling it inside the main.c i am doing it after touchgfx init and before osKernel and freertos init.

As you see i am trying to make disp pin to go HIgh and to identify it without checking pin cause i do not now how to do it in debug from software side easily i use also one of the leds of the nukleo board.

Kyrpav_2-1692391241639.png

For the contents of the SCB registers, in particular ICSR what am i expecting to see as proper behaviour?

Kyrpav
Associate III

Sorry for the delay. it seems that after Hal_Init function i have this stable

Kyrpav_1-1692395134226.png

and after letting it too much time stuck in the while loop i see also

Kyrpav_2-1692395678911.png

Tried also to enable interupts with __enable_irq() or should i try to enable interrupt only for tim6  like :

 

  /* Initialize all configured peripherals */
  MX_GPIO_Init();
  MX_LTDC_Init();
  MX_DMA2D_Init();
  MX_CRC_Init();
  MX_TouchGFX_Init();
  /* Call PreOsInit function */
  MX_TouchGFX_PreOSInit();
  /* USER CODE BEGIN 2 */
  __enable_irq();
  HAL_Delay(10);
  HAL_GPIO_WritePin(LTDC_DISP_GPIO_Port, LTDC_DISP_Pin, GPIO_PIN_SET);
  HAL_GPIO_WritePin(LED_BLUE_GPIO_Port, LED_BLUE_Pin, GPIO_PIN_SET);
  HAL_Delay(250);
  HAL_GPIO_WritePin(LED_BLUE_GPIO_Port, LED_BLUE_Pin, GPIO_PIN_RESET);
  /* USER CODE END 2 */

 

And for the sysTick is see:

Kyrpav_0-1692396265199.png

Trying to enable it with HAL_NVIC enable irw i found this strange thing that the TIM6 irq defined by the system it self includes DAC on the name :

  HAL_NVIC_EnableIRQ(TIM6_DAC_IRQn);

  Also if you see previous posts for ioc and NVIC page it says "Time base: TIM6 global interrupt, DAC1 and DAC2 ...

but i have nothing set for DAC

Kyrpav_1-1692397029283.png

Maybe link to zip file with the project could also help

https://mega.nz/file/SlUQCARA#UqG_ZCWWC0KIs_FuVe785gZQrhLI05bTdZ94X5lUydA

I seems that when i set TIM6 priority at for which means more than LTDC it worked.

 

Kyrpav_0-1692463542703.png

then i think i burned stlink but i opened another ticket for this. about the priorities is this the proper or the setup should be different in general