2024-06-07 11:28 AM - last edited on 2024-06-07 02:12 PM by Tesla DeLorean
Hi Community,
I am working on a project with a custom board that uses both HSE (24MHz) and LSE (32.768KHz) clock sources. TIM6 is used as a time base source because SysTick is used by the RTOS. When running a debug session I can see that it is going into an infinite loop at the following code in the HAL library.
/* Wait till LSE is ready */
while (READ_BIT(RCC->BDCR, RCC_BDCR_LSERDY) == 0U)
{
if((HAL_GetTick() - tickstart) > RCC_LSE_TIMEOUT_VALUE)
{
return HAL_TIMEOUT;
}
}
After a closer look, it is found that HAL_GetTick is returning 0 every time because of which it went into an infinite loop but it should not be zero at this point because it is initialized in the HAL_Init with HAL_InitTick which in turn runs TIM6 ISR and should start updating the tick.
Why is that so?
PS: The configuration and code generation is done using STM32CubeIDE. This code ran effectively on a Nucleo Board. But not running on a custom board.
2024-06-07 01:09 PM - edited 2024-06-07 01:11 PM
> This code ran effectively on a Nucleo Board. But not running on a custom board.
So : on your custom board : no running clock...or wrong.
Did you check with a scope , clks running ok ?
+
show circuit of your board...maybe something wrong.
+
and a pic...if possible.
2024-06-07 02:16 PM - edited 2024-06-07 03:19 PM
Need to make sure NVIC has TIM6 Interrupt enabled, that there's an TIM6_IRQHandler in the vector table, it calls into the HAL, and your callback increments the tick count.
Make sure it's not task switching.
There's not good reason it would work on a NUCLEO vs CUSTOM
If the MCU uses a VCAP pin, make sure that has a capacitor and is at 1.25V
Have your Error_Handler() and HardFault_Handler() output actionable data if it ends there.
It shouldn't hard to pin down why the TIM6 isn't enabled or interrupting.
2024-06-07 02:42 PM - edited 2024-06-07 02:44 PM
The infinite loop is not because the tick counter does not count, but primarily because your LSE does not start. And that's probably a HW design problem.
JW
PS My guess is that at that point TIM6 is simply not yet set up, I may be wrong, but I don't care, I don't use Cube.
2024-06-07 03:25 PM
TIM6 clocking and interrupting, and LSE starting, or not, should be relatively easy to determine.
HAL_Init() would be where SysTick would be fired up. Usually does that before the other MX horsery
The MCU and NUCLEO board weren't called out, I tentatively edited the title with the STM32G4 based on post history.
2024-06-07 05:04 PM - edited 2024-06-07 05:13 PM
Hmm this can be tricky, if the clock source of TIM6 depends on LSE or PLL. It will cause circular dependency, or a deadlock, whatever you prefer. During initial setup of clocks the systick is more robust. The RTOS issue can be resolved by some hacking of the generated code.
As Jan wrote, the LSE fails to start, this is the root cause. Since this is a custom board, all bets are off.
NOTE: HAL_Init() calls setup of the HAL timer, no matter is it systick or TIM. So that after HAL_Init() HAL_GetTick() must work... unless when it does not.
2024-06-09 09:58 PM
@Tesla DeLorean Yes I am using STM32G4 it does not come with a VCAP pin.
2024-06-09 10:02 PM
@AScha.3 @Tesla DeLorean @Pavel A. @waclawek.jan Thanks for your inputs. I am checking with the hardware team to look into the external crystal to make sure it is functional.
I will update it here once it is fixed.
2024-06-10 01:36 AM
You perhaps could've started with checking/setting the LSE drive higher.
JW
2024-06-16 08:55 PM
Hi @waclawek.jan, I tried setting the LSE drive higher but had no luck. I can't see a waveform on LSE.