Re: String array in ROM gives error in spite of following example code.
Georg-Johann Lay <[email protected]>
| Newsgroups | gmane.comp.hardware.avr.gcc |
|---|---|
| Message-ID | <[email protected]> |
Am 06/12/2014 12:23 PM, schrieb Royce Pereira:
> Hi,
>
> I recently updated WinAVR to a newer version of the AVR-GCC toolchain,
> downloaded from the Atmel site.
>
> My version is this:
>
> avr-gcc (AVR_8_bit_GNU_Toolchain_3.4.3_1072) 4.8.1
>
> My code was compiling without errors before, but with this version, it
> is giving errors in spite of following the instructions in the faq
> section of the avr-libc document.
> //---------------------------------------------
> #include <avr/io.h>
> #include <avr/pgmspace.h>
>
> const char ptmpUP_msg[] PROGMEM = "Upper Temp" ;
> const char ptmpDN_msg[] PROGMEM = "Lower Temp" ;
> const char ptmpCLG_msg[] PROGMEM = "Chiller Temp" ;
>
> PGM_P pgtmp_msg[] PROGMEM =
> { ptmpUP_msg, ptmpDN_msg, ptmpCLG_msg,} ;
>
> //------------------------------------------------------
> The above code gives the following error:
>
> error: variable 'pgtmp_msg' must be const in order to be put into
> read-only section by means of '__attribute__((progmem))'
Read the GCC release notes, it's mentioned in "Caveats":
https://gcc.gnu.org/gcc-4.6/changes.html
Just qualify objects that shall go into flash as const.
If you prefer progmem and pgm_read_*, the definitions read:
#include <avr/pgmspace.h>
const char ptmpUP_msg[] PROGMEM = "Upper Temp";
const char ptmpDN_msg[] PROGMEM = "Lower Temp";
const char ptmpCLG_msg[] PROGMEM = "Chiller Temp";
const char* const pgtmp_msg[] PROGMEM =
{ ptmpUP_msg, ptmpDN_msg, ptmpCLG_msg };
If you prefer __flash, the definitions read:
const __flash char ptmpUP_msg[] = "Upper Temp";
const __flash char ptmpDN_msg[] = "Lower Temp";
const __flash char ptmpCLG_msg[] = "Chiller Temp";
const __flash char* const __flash pgtmp_msg[] =
{ ptmpUP_msg, ptmpDN_msg, ptmpCLG_msg };
pgtmp_msg is const and located in flash. And it contains elements that are
pointers to const locations in flash.
Johann