Skip to main content
Mohammad A
Senior
May 31, 2017
Solved

Store constant variables in Flash

  • May 31, 2017
  • 8 replies
  • 9477 views
Posted on May 31, 2017 at 20:54

I am trying to figure out how to store a constant variable (a constant string of chars) on flash, so it does not occupy valuable blocks of RAM to store a const. In AVR there was something called PROGMEM, but here I can't find any similar method to do so.

How can I store a constant array of chars in the Flash memory?

#variable #flash #ram
This topic has been closed for replies.
Best answer by Tesla DeLorean
Posted on May 31, 2017 at 21:38

static const unsigned char foo[] = { 0x01, 0x02, 0x03, 0x04 };

8 replies

Tesla DeLorean
Tesla DeLoreanBest answer
Guru
May 31, 2017
Posted on May 31, 2017 at 21:38

static const unsigned char foo[] = { 0x01, 0x02, 0x03, 0x04 };

Tips, Buy me a coffee, or three.. PayPal Venmo (See Profile) Up vote any posts that you find helpful, it shows what's working..
Mohammad A
Senior
May 31, 2017
Posted on May 31, 2017 at 22:16

shouldn't I only use const without static keyword? because when I use const without static, I can find my variable inside map file in .rodata and stored inside FLASH section

 .rodata 0x08003be4 0x8 Src/main.o
 0x08003be4 constvar�?�?

but when I add static keyword, I can't find constvar in the map file.

Actually what does static do here if only adding const makes the variable to be stored in the flash section?

Danish1
Lead III
May 31, 2017
Posted on May 31, 2017 at 22:24

static (in that context) just means that the data isn't visible outside that file. I guess as a consequence it won't show in the map file.

Viktor POHORELY
ST Employee
June 7, 2017
Posted on June 07, 2017 at 18:16

One example from Keil project to force array at given address. You could force it similary to generic address as well.

variable_t volatile array_storage[NUMBER_OF_RECORDS] __attribute__((at(FLASH_ADDRESS))) = {