Skip to main content
MikeDB
Senior II
May 31, 2019
Solved

STM32CubeIDE and Const variables in Flash memory

  • May 31, 2019
  • 2 replies
  • 2320 views

I've created a large (8192 byte) array I want to put in Flash memory with the code, It compiles fine but the data doesn't appear in any of the output files.

Is there a switch or something I'm missing in STM32CubeIDE ?

It's in the main declarations so doesn't need static.

const uint16_t   LogSine[4096] = {32768,32963,33155,33345,33532,33717 ........ };

This topic has been closed for replies.
Best answer by turboscrew

So your program doesn't get the right values? I think the data should be in a rodata section.

Maybe you should check that the rodata-section placement in the linker script?

Consts should be there even if you didn't use C runtime libraries. Initialized globals won't be.

2 replies

After Forever
Senior III
May 31, 2019

Do you actually use the array somewhere in the code? If not then the compiler/linker can and should remove it.

MikeDB
MikeDBAuthor
Senior II
May 31, 2019

Yes

R2 = LogSine[(Oscptr->OscAM_Phase >> 20) & 0x00000FFF] * Oscptr->OscAM_Level;

I've checked the .list file and it's definitely being accessed.

After Forever
Senior III
May 31, 2019

Well then that's strange. Do you see the values of the array in the debugger? And how exactly are you checking that "the data doesn't appear in any of the output files"?

turboscrew
Senior III
May 31, 2019

So your program doesn't get the right values? I think the data should be in a rodata section.

Maybe you should check that the rodata-section placement in the linker script?

Consts should be there even if you didn't use C runtime libraries. Initialized globals won't be.

MikeDB
MikeDBAuthor
Senior II
May 31, 2019

Thanks - now I know where to look. I was assuming CubeIDE sorted out all these things automatically but obviously not.