cancel
Showing results for 
Search instead for 
Did you mean: 

STM32CubeIDE and Const variables in Flash memory

MikeDB
Lead

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 ........ };

1 ACCEPTED SOLUTION

Accepted Solutions
turboscrew
Senior III

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.

View solution in original post

6 REPLIES 6

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

Yes

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

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

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"?

I haven't programmed the device yet as the data is obviously not there - 8192 bytes of data tends to show up in any file format

turboscrew
Senior III

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.

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