2018-01-13 09:32 AM
Hi Guys.
I am the bare register programmer but yesterday I was asked to find the error in someone's code.
And the second function called :
SystemClock_Config()
The timeouts are counted using the SysTick counter updated in the interrupt but the problem is that the interrupt is enabled at the end of this function. For example if HSE fails the program stacks in the HSE enable attempt .
I
#rcc #stm32 #hal-bug2018-01-14 03:36 PM
If HSE fails, a NMI should normally occur, it's priority is higher than systick. There you handle such things.
-- pa
2018-01-14 05:26 PM
Only if the CSS is activated. This bug is different.
while(__HAL_RCC_GET_FLAG(RCC_FLAG_HSERDY) == RESET)
{ if((HAL_GetTick() - tickstart ) > HSE_TIMEOUT_VALUE) { return HAL_TIMEOUT; } }As you see here: it uses the HAL_GetTick() function. But at this point SysTick is not activated and its interrupt is disabled so the HAL_GetTick() function will return zero all the time and here we have the dead loop. It is an obvious mistake.
2018-01-14 08:44 PM
At lease in my F4Cube and L4Cube hal library,
usually
HAL_Init(), called in the very beginning of main, would initialize the SysTick timer and set its interrupt priority. Then comes theSystemClockConfig(). You may check why your SysTick is not yet initialized at this moment. (as the whole HAL library always requires SysTick to check timeout.)2018-01-15 01:23 AM
The function is called HAL_InitTick but it does not actually enable the tick interrupt.
__weak HAL_StatusTypeDef HAL_InitTick(uint32_t TickPriority)
{ /*Configure the SysTick to have interrupt in 1ms time basis*/ HAL_SYSTICK_Config(SystemCoreClock / 1000U); /*Configure the SysTick IRQ priority */ HAL_NVIC_SetPriority(SysTick_IRQn, TickPriority ,0U);/* Return function status */
return HAL_OK;2018-01-15 02:51 AM
The Cortex core interrupts (IRQn < 0) don't have a NVIC enable bit, unlike the vendor-specific interrupt lines, NVIC_EnableIRQ() or
NVIC_DisableIRQ()
therefore shall not be called with these. The SysTick_Config() /HAL_SYSTICK_Config()
enables the interrupt generation of the SysTick's counter overflow (SysTick/
CTRL/TICKINT bit), which is the only thing necessary to get SysTick interrupts.2018-01-15 03:11 AM
At least in the F3xx library it does not and the HSE failure causes the dead loop. Tested & debugged.