Forum: µC & Digital Electronics Storing array of struct in Flash using PROGMEM

Author: woife (Guest)
Posted on:

Rate this post
0 useful
not useful
Hello Community!

I would like to create a self-defined structure for a configuration (for 
Timers, UARTs, etc.) and store different configurations in an array.

The described concept works great when everything is stored in SRAM.
But as these differente configurations would be constant, and only be 
read at run-time, I would like store them in Flash-memory and not waste 

However, when i try to define them as Flash-memory using the PROGMEM 
attribute, I get the following error-message in avr-gcc:

"main.c 47 warning: initialization discards qualifiers from pointer 
target type
main.c 49 warning: initialization discards qualifiers from pointer 
target type"

Here is a minimal example code that procudes these errors. The code 
defines a structure and thenn tries to declare a an array of this 
structe once in SRAM (this works) and once in Flarh (doesn't work).

Everything that should be in Flash has a _P appended. An appended _h 
means "handler".
The defines for ConfigLine_tP and ConfigLine_hP are because of a warning 
with the corresponding typedefs, but I will see about this on later. 
First I would like to be able to compile the file.
struct  ConfigLine
  uint8_t    uint8;
  uint16_t    uint16a  [ 2  ];

  uint8_t    uint8_2;

  char      String  [ 32  ];
typedef  struct  ConfigLine          ConfigLine_t;
typedef        ConfigLine_t        *ConfigLine_h;

#define ConfigLine_tP const ConfigLine_t PROGMEM
#define ConfigLine_hP const ConfigLine_h PROGMEM

//typedef        ConfigLine_t  PROGMEM  ConfigLine_tP;
//typedef  const    ConfigLine_h  PROGMEM  ConfigLine_hP;

//  Init fields:            uint8    uint16a            uint8_2  String
ConfigLine_t  ConfigLine0  =  {  0x55,  {  0x1234,  0xABCD  },    0xAA,    "First test string"  };
ConfigLine_t  ConfigLine1  =  {  0xAA,  {  0x5678,  0xFEDC  },    0x55,    "Second test string"  };

ConfigLine_h  Configs  [ 2 ]    =

//  Init fields:                        uint8    uint16a            uint8_2  String
const  ConfigLine_t  ConfigLine0_P  PROGMEM  =  {  0x55,  {  0x1234,  0xABCD  },    0xAA,    "First test string"  };
const  ConfigLine_t  ConfigLine1_P  PROGMEM  =  {  0xAA,  {  0x5678,  0xFEDC  },    0x55,    "Second test string"  };

const  ConfigLine_hP  Configs_P  [ 2 ]  PROGMEM  =
  &ConfigLine0_P,    // < Line 43
};                // < Line 45

I would be glad if anyone could explain me what happens here/why it 
doesn't work or point me to a Flash/PROGMEM-Tutorial that covers more 
details than "Storing constant strings" in Flash.

best regards, Wolfgang


Entering an e-mail address is optional. If you want to receive reply notifications by e-mail, please log in.

Rules — please read before posting

  • Post long source code as attachment, not in the text
  • Posting advertisements is forbidden.

Formatting options

  • [c]C code[/c]
  • [avrasm]AVR assembler code[/avrasm]
  • [code]code in other languages, ASCII drawings[/code]
  • [math]formula (LaTeX syntax)[/math]

Bild automatisch verkleinern, falls nötig
Note: the original post is older than 6 months. Please don't ask any new questions in this thread, but start a new one.