cancel
Showing results for 
Search instead for 
Did you mean: 

Why my project stuck in HAL_Delay()?

Skane
Associate III

Hi,

i have started this project using X-Cube-IOTA1 package and i added all libraries i need to replicate the same project example which is IOTA-Client. i manage to compile my version and run in the the STM32 B-L4S5-IOTA1 using freeRTOS, but the problem is, the program stuck (infinite loop, or hangs out) in the "WIFI_RESET_MODULE();" in "SPI_WIFI_ResetModule(...)" function, is hangs exactly in the HAL_Delay(500), if i lower the period to 10 it works also, if i keep the 500 period and remove the HAL_GPIO_WritePin(GPIOE, GPIO_PIN_8, GPIO_PIN_SET); (which is located just before that HAL_Delay(500)) also the program works. so i don't think it's a problem from HAL_Gettick() which happen to other ppl and it returns 0 all the time, it's not in my case, also the interruption of systick is fine, i spend days looking for answer but i couldn't find the correct solution.

so if someone have a clue what's going on or what is the problem and how to solve it, i will be thankful, and if you need to see the whole project, i will upload it to github

best regards

-- update --

The section i'm having a problem with is this:

#define WIFI_RESET_MODULE() do{\
                              HAL_GPIO_WritePin(GPIOE, GPIO_PIN_8, GPIO_PIN_RESET);\
                              HAL_Delay(10);\
                              HAL_GPIO_WritePin(GPIOE, GPIO_PIN_8, GPIO_PIN_SET);\
                              HAL_Delay(500);\ << I'm stuck here>>
                            }while(0);

if i lower the 500 period to 10, it's not stuck any more, also if i remove the HAL_GPIO_WritePin(GPIOE, GPIO_PIN_8, GPIO_PIN_SET) i don't face this issue for this macro.

7 REPLIES 7
S.Ma
Principal

I recall that the default systick for hal delay could use other hw timers, especially when rtos were used. Related topic?

LCE
Principal

Are you really 100% sure that Systick has highest interrupt priority in case it is called from some ISR?

Skane
Associate III

Hi,

i had this issue even when i didn't use freeRTOS, also i tested again the project after i changed the timebase source of the SYS mode in the device configuration tools (i used TIM6) and still the same issue.

AJOY.1
Associate

Check whether uwTick is incrementing.

Skane
Associate III

Hi,

i changed the interrupt priority to 0 (it was 15)

#define TICK_INT_PRIORITY           0U   /*!< tick interrupt priority */

and still the same problem, also i'm using TIM6 as timebase source,

Hi,

i get stuck in Hal_Gettick(); so it doesn't return 0 or something, because the previous delay is working fine, i did an update in the topic, have a look please

Mat1
Associate III

Hi,

I had the same problem.

There is a very nice description on digikey how to change the timebase for HAL getting-started-with-stm32-introduction-to-freertos on digikey .

The important snippet out of that:

SysTick is a special timer in most ARM processors that’s generally reserved for operating system purposes. By default, SysTick in an STM32 will trigger an interrupt every 1 ms. If we’re using the STM32 HAL, by default, SysTick will be used for things like HAL_Delay() and HAL_GetTick(). As a result, the STM32 HAL framework gives SysTick a very high priority. However, FreeRTOS needs SysTick for its scheduler, and it requires SysTick to be a much lower priority.

We can fix this conflict in a few ways, but the easiest is to assign another, unused timer as the timebase source for HAL. Timers 6 and 7 in most STM32 microcontrollers are usually very basic, which makes them perfect as a timebase for HAL. Go to System Core > SYS and under Mode, change the Timebase Source to TIM6.

This not fully solved my problem. The other points where:

  • Go to System Core > NVIC, there change Time base: TIM6 global interrupt to 0
  • Make sure that the right HAL_InitTick() function is called. There is a weak one in Drivers\STM32G4xx_HAL_Driver\Src\stm32g4xx_hal.c which inits SysTick and not TIM6