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
SRAM.
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.
1 | struct ConfigLine
|
2 | {
|
3 | uint8_t uint8;
|
4 | uint16_t uint16a [ 2 ];
|
5 |
|
6 | uint8_t uint8_2;
|
7 |
|
8 | char String [ 32 ];
|
9 | };
|
10 | typedef struct ConfigLine ConfigLine_t;
|
11 | typedef ConfigLine_t *ConfigLine_h;
|
12 |
|
13 |
|
14 | #define ConfigLine_tP const ConfigLine_t PROGMEM
|
15 | #define ConfigLine_hP const ConfigLine_h PROGMEM
|
16 |
|
17 | //typedef ConfigLine_t PROGMEM ConfigLine_tP;
|
18 | //typedef const ConfigLine_h PROGMEM ConfigLine_hP;
|
19 |
|
20 |
|
21 | // Init fields: uint8 uint16a uint8_2 String
|
22 | ConfigLine_t ConfigLine0 = { 0x55, { 0x1234, 0xABCD }, 0xAA, "First test string" };
|
23 | ConfigLine_t ConfigLine1 = { 0xAA, { 0x5678, 0xFEDC }, 0x55, "Second test string" };
|
24 |
|
25 | ConfigLine_h Configs [ 2 ] =
|
26 | {
|
27 | &ConfigLine0,
|
28 | &ConfigLine1
|
29 | };
|
30 |
|
31 | // Init fields: uint8 uint16a uint8_2 String
|
32 | const ConfigLine_t ConfigLine0_P PROGMEM = { 0x55, { 0x1234, 0xABCD }, 0xAA, "First test string" };
|
33 | const ConfigLine_t ConfigLine1_P PROGMEM = { 0xAA, { 0x5678, 0xFEDC }, 0x55, "Second test string" };
|
34 |
|
35 | const ConfigLine_hP Configs_P [ 2 ] PROGMEM =
|
36 | {
|
37 | &ConfigLine0_P, // < Line 43
|
38 | &ConfigLine1_P
|
39 | }; // < 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