Question
HAL bug - array overflow in HAL_RCC_GetSysClockFreq()
Posted on June 10, 2016 at 17:23
The purpose of this post is to save other developers the time I have spent tracking this down. Bear with me on this - its messy.
Line 1108, of stm32f1xx_hal_rcc.c isif (pllmul == aPLLMULFactorTable[(uint32_t)(RCC_CFGR_PLLMULL6_5) >> POSITION_VAL(RCC_CFGR_PLLMULL)])
You'll need to know that&sharpdefine RCC_CFGR_PLLMULL6_5 ((uint32_t)0x00340000)
&sharpdefine RCC_CFGR_PLLMULL ((uint32_t)0x003C0000) andconst uint8_t aPLLMULFactorTable[12] = {0, 0, 4, 5, 6, 7, 8, 9, 0, 0, 0, 13};
You'll find that(RCC_CFGR_PLLMULL6_5) >> POSITION_VAL(RCC_CFGR_PLLMULL)
is a constant that evaluates to 13. And when this is used to indexaPLLMULFactorTable
[12], it generates an array bounds overflow. This would seem to be a bug in the HAL library (though please tell me if I have got this wrong). I encountered this in trying to understand why I was occasionally getting the wrong baudrate. Scary, eh? #hal-bug