Skip to main content
Associate III
June 19, 2025
Solved

HAL_Delay blocks code

  • June 19, 2025
  • 9 replies
  • 844 views

Hello, I have a custom board wich is based on the evspin32g4-dual Board. I generated the code with motorcontrol work bench and could upload it with a j-link. I added an uart output in the startup and noticed that it kept printing it, so the board was constantly resetting. When I stepped through the code the problem was in HAL_Delay, as the HAL_GetTick() function always returned the same value, thus not leaving the function. Could there be an error with the external Crystal? I am using a ECS-240-8-37-CKM-TR with 8pF caps.

Screenshot 2025-06-19 130223.png

Thanks!

Best answer by TDK

 

If it's resetting, look at RCC->CSR after startup to determine why.

9 replies

ST Employee
June 19, 2025

Hello @QuirinS

The HAL_GetTick() function relies on the SysTick timer, which in turn depends on a stable clock source, so yes, probably it's an issue with the crystal. 

You can refer to AN2867 for oscillator design guidelines.

LCE
Principal II
June 19, 2025

I would try to verify this by building a version using the internal oscillator (HSI).

Check the PLL settings to get the same system clock rate as with the HSE.

QuirinSAuthor
Associate III
June 19, 2025

Thanks for your reply, I just checked the project and HSI is already in use. 

QuirinS_0-1750335876374.png

 

TDK
Super User
June 19, 2025

If the code is running, it's not likely a crystal problem.

Probably you're calling HAL_Delay in an interrupt context, or with interrupts disabled.

Set SysTick priority to 0 and everything else above that.

"If you feel a post has answered your question, please click ""Accept as Solution""."
QuirinSAuthor
Associate III
June 19, 2025

I was able to step over the delay and ran into a breakpoint in SysTick_Handler, so the reset is caused by something else.

 

TDK
TDKBest answer
Super User
June 19, 2025

 

If it's resetting, look at RCC->CSR after startup to determine why.

"If you feel a post has answered your question, please click ""Accept as Solution""."
LCE
Principal II
June 19, 2025

Well, then "run a little further"! ;) 

QuirinSAuthor
Associate III
June 19, 2025

I checked the reset cause and the RCC_FLAG_PINRST was set, i disabled the reset pin by setting the nrst_mode = 2 with cube programmer but its still the same problem

Tesla DeLorean
Guru
June 19, 2025

Do you start a watch dog timer? Have one on your board?

Otherwise constantly resetting is more likely a hardware/board level issue.

Perhaps scope NRST/NRESET pin check if it is periodic, and what that period is.

Check supply isn't browning out

Check VCAP pins if present, should have around 4u7 F total on them, and 1.25 V

The Systick is normally enabled/started in HAL_Init() code.

Tips, Buy me a coffee, or three.. PayPal VenmoUp vote any posts that you find helpful, it shows what's working..
QuirinSAuthor
Associate III
June 25, 2025

The Buck converter was the problem, thus causing a brownout