AnsweredAssumed Answered

Why are HAL Lookup tables located in RAM?

Question asked by richard on Jun 14, 2016
Latest reply on Jun 15, 2016 by richard
I notice that the HAL locates some lookup tables in RAM. For example, in stm32f1xx_hal_rcc.c:

uint32_t HAL_RCC_GetSysClockFreq(void)
{
#if   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};
#else
  const uint8_t aPLLMULFactorTable[16] = { 2,  3,  4,  5,  6,  7,  8,  9, 10, 11, 12, 13, 14, 15, 16, 16};
#if 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};
#else
  const uint8_t aPredivFactorTable[2] = { 1, 2};
#endif /*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)
{
#if   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};
#else
  static const uint8_t aPLLMULFactorTable[16] = { 2,  3,  4,  5,  6,  7,  8,  9, 10, 11, 12, 13, 14, 15, 16, 16};
#if 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};
#else
  static const uint8_t aPredivFactorTable[2] = { 1, 2};
#endif /*RCC_CFGR2_PREDIV1*/


Thanks,
Richard

Outcomes