Question
Why are HAL Lookup tables located in RAM?
Posted on June 14, 2016 at 11:10
I notice that the HAL locates some lookup tables in RAM. For example, in stm32f1xx_hal_rcc.c:
uint32_t HAL_RCC_GetSysClockFreq(void)
{ &sharpif defined(RCC_CFGR2_PREDIV1SRC) const uint8_t aPLLMULFactorTable[14] = {0, 0, 4, 5, 6, 7, 8, 9, 0, 0, 0, 0, 0, 13}; const uint8_t aPredivFactorTable[16] = { 1, 2, 3, 4, 5, 6, 7, 8, 9,10, 11, 12, 13, 14, 15, 16}; &sharpelse const uint8_t aPLLMULFactorTable[16] = { 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 16}; &sharpif defined(RCC_CFGR2_PREDIV1) const uint8_t aPredivFactorTable[16] = { 1, 2, 3, 4, 5, 6, 7, 8, 9,10, 11, 12, 13, 14, 15, 16}; &sharpelse const uint8_t aPredivFactorTable[2] = { 1, 2}; &sharpendif /*RCC_CFGR2_PREDIV1*/ [note that this code extract includes a fix for another HAL bug.] There are lots of reasons locating lookup tables in RAM is a bad thing (e.g. performance, memory, robustness). Is there some reason why it was necessary in this case? If not, please could you remedy this in the next release of the Hal Libraries? One way is to add the ''static'' keyword. uint32_t HAL_RCC_GetSysClockFreq(void) { &sharpif defined(RCC_CFGR2_PREDIV1SRC) static const uint8_t aPLLMULFactorTable[14] = {0, 0, 4, 5, 6, 7, 8, 9, 0, 0, 0, 0, 0, 13}; static const uint8_t aPredivFactorTable[16] = { 1, 2, 3, 4, 5, 6, 7, 8, 9,10, 11, 12, 13, 14, 15, 16}; &sharpelse static const uint8_t aPLLMULFactorTable[16] = { 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 16}; &sharpif defined(RCC_CFGR2_PREDIV1) static const uint8_t aPredivFactorTable[16] = { 1, 2, 3, 4, 5, 6, 7, 8, 9,10, 11, 12, 13, 14, 15, 16}; &sharpelse static const uint8_t aPredivFactorTable[2] = { 1, 2}; &sharpendif /*RCC_CFGR2_PREDIV1*/ Thanks, Richard #hal