Need help with this error: variable 'f_SignalFormat' must be const in order to be put into read-only section by means of '__attribute__((progmem))'

Go To Last Post
9 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hi

I am attempting to compile code that I did not write.

I get this error:

Error    1    variable 'f_SignalFormat' must be const in order to be put into read-only section by means of '__attribute__((progmem))' 

I have made the line bold where the error occurs. I am using the latest Atmel studio with the default GCC C compiler.

The chip is an Xmega64A3U

 

After looking at Dean Camera's pdf regarding the PROGMEM stuff I have not been able to establish where the fault lies.

All help is welcome.

 

Thanks

 

This is a small snippet of code:

 

const SignalFormat_t f_SignalFormat_NTSCi PROGMEM =
{
#define SCANLINE        US_TO_TICKS( 63.5 )
#define HSYNC            US_TO_TICKS( 4.37 )
#define HALFSCANLINE    (SCANLINE / 2)
#define SHORTSYNC        (HSYNC / 2)
#define BROADSYNC        (HALFSCANLINE - HSYNC)
    {'N','T','S','i'},
    {
        { 20,    HSYNC,        SCANLINE,        SyncPatternInfo_FieldStart_bm },
        { 233,    HSYNC,        SCANLINE,        SyncPatternInfo_Display_bm }, 
        { 1,    HSYNC,        HALFSCANLINE,    SyncPatternInfo_Normal_bm },
        { 6,    SHORTSYNC,    HALFSCANLINE,    SyncPatternInfo_Normal_bm }, 
        { 6,    BROADSYNC,    HALFSCANLINE,    SyncPatternInfo_Normal_bm },  
        { 5,    SHORTSYNC,    HALFSCANLINE,    SyncPatternInfo_Normal_bm },  
        { 1,    SHORTSYNC,    SCANLINE,        SyncPatternInfo_Normal_bm },  
        { 20,    HSYNC,        SCANLINE,        SyncPatternInfo_FieldStart_bm },
        { 233,    HSYNC,        SCANLINE,        SyncPatternInfo_Display_bm },  
        { 6,    SHORTSYNC,    HALFSCANLINE,    SyncPatternInfo_Normal_bm },   
        { 6,    BROADSYNC,    HALFSCANLINE,    SyncPatternInfo_Normal_bm },  
        { 6,    SHORTSYNC,    HALFSCANLINE,    SyncPatternInfo_LastPattern_bm }   
    }
#undef SCANLINE
#undef HALFSCANLINE
#undef HSYNC
#undef SHORTSYNC
#undef BROADSYNC
} ;

static const SignalFormat_t *f_SignalFormat[] PROGMEM = {
    &f_SignalFormat_PAL,
    &f_SignalFormat_NTSC,
    &f_SignalFormat_576i,
    &f_SignalFormat_NTSCi
} ;

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

After looking at Dean Camera's pdf regarding the PROGMEM stuff I have not been able to establish where the fault lies.

I think Dean may have updated PDF versions of his tutorials?

 

Anyway the point is that from avr-gcc 4.6 onwards it has insisted that either PROGMEM (or now __flash) are also used with "const". Makes a lot of sense when you think about it. If something wasn't const you probably wouldn't want a fixed copy in flash.

 

I guess you are getting an error from your SingalFormat[] array? The point is that not only do you want the array itself to be const and in PROGMEM but the TARGET of the pointers are also const too. So I guess you want something like:

static const SignalFormat_t const *f_SignalFormat[] PROGMEM = {
    &f_SignalFormat_PAL,
    &f_SignalFormat_NTSC,
    &f_SignalFormat_576i,
    &f_SignalFormat_NTSCi
} ;

I always have trouble with this though (I tend to use cdecl to check) but maybe that second "const" wants to be on the other side of the '*' ?

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0
 static const SignalFormat_t * const f_SignalFormat[] PROGMEM = {
    &f_SignalFormat_PAL,
    &f_SignalFormat_NTSC,
    &f_SignalFormat_576i,
    &f_SignalFormat_NTSCi
} ;

EDIT: Cliff is too fast for me!  I too have trouble remembering sometimes.  As he mentions, this is useful:

http://cdecl.org/

 

 

 

"Experience is what enables you to recognise a mistake the second time you make it."

"Good judgement comes from experience.  Experience comes from bad judgement."

"Wisdom is always wont to arrive late, and to be a little approximate on first possession."

"When you hear hoofbeats, think horses, not unicorns."

"Fast.  Cheap.  Good.  Pick two."

"We see a lot of arses on handlebars around here." - [J Ekdahl]

 

Last Edited: Mon. Sep 14, 2015 - 01:53 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Rats. I knew I'd get it wrong - that'll teach me to guess rather than trying it! blush

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Wow you guys are fast... and accurate laugh ... it works!!!!

Thanks to both of you and also for that link.

I like AVR's but the GCC way of working with flash really is a pain.

I think the way KeilC51 does it is great... forget about being 100% c correct.. just make it easy lol

 

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

PROGMEM has be supplanted by __flash.  The former still has it's uses (in the form of macros like PSTR() and the _P variants of many functions, but for declaring constants use the latter instead.

 

While PROGMEM is provided by AVR Libc, the newer __flash is part of AVR GCC since 4.7.x

"Experience is what enables you to recognise a mistake the second time you make it."

"Good judgement comes from experience.  Experience comes from bad judgement."

"Wisdom is always wont to arrive late, and to be a little approximate on first possession."

"When you hear hoofbeats, think horses, not unicorns."

"Fast.  Cheap.  Good.  Pick two."

"We see a lot of arses on handlebars around here." - [J Ekdahl]

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

With the Keilc51 compiler some pointers have an extra byte to tell the compiler which memory space its pointing to, has GCC implemented any thing like that now that it uses __flash?

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

"Experience is what enables you to recognise a mistake the second time you make it."

"Good judgement comes from experience.  Experience comes from bad judgement."

"Wisdom is always wont to arrive late, and to be a little approximate on first possession."

"When you hear hoofbeats, think horses, not unicorns."

"Fast.  Cheap.  Good.  Pick two."

"We see a lot of arses on handlebars around here." - [J Ekdahl]

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

davidgrm wrote:

With the Keilc51 compiler some pointers have an extra byte to tell the compiler which memory space its pointing to, has GCC implemented any thing like that now that it uses __flash?

Even if your toolchain and version supports "generic" AVR8 pointers [to various memory spaces], do you >>really<< want the additional storage overhead as well as the needed "silent overloading" in operation?  I know that I don't.

You can put lipstick on a pig, but it is still a pig.

I've never met a pig I didn't like, as long as you have some salt and pepper.