How do you access PROGMEM_DECLARE array?

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

Atmel Raven IAR code has for example

#define _MEMATTR  __flash
#define PROGMEM_DECLARE(x) _MEMATTR x
....
PROGMEM_DECLARE(static const unsigned int)LCD_character_table[] = // Character definitions 
table.
    (AS_A|AS_B|AS_C|AS_D|AS_E|AS_F),// '0'
    ..

where the table is accessed by

seg=LCD_character_table[c];

Works in GCC when the array index is a constant but loads from data space when the array index is variable.

It works when the array is in data space,

static const unsigned int)LCD_character_table[] = // Character definitions 
table.

but what access would allow use of program flash? I have tried

   seg=(prog_uint16_t)LCD_character_table[c];
   seg=PROGMEM_DECLARE((unsigned int*) &LCD_character_table[c]);
   seg=PROGMEM_READ_WORD(LCD_character_table[c]);

with no joy :-(

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

um __flash does not place things in progmem for GCC. I suggest you read the pgmspace.h documentation for avrlibc.

http://www.nongnu.org/avr-libc/u...

Writing code is like having sex.... make one little mistake, and you're supporting it for life.

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

Thanks, that led me to try

seg=pgm_read_word_near(&LCD_character_table[c])

which works. I don't know why, but keeping the PROGMEM_DECLARE for the array takes 128 bytes off the size of the .data segment without changing the size of the .text segment.

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

Quote:

which works. I don't know why, but keeping the PROGMEM_DECLARE for the array takes 128 bytes off the size of the .data segment without changing the size of the .text segment.

That's the whole point - .data is the static SRAM and .text is the program FLASH data. By using the _flash attribute (aliased to PROGMEM in GCC for compatibility with IAR) you prevent the data from occupying constant space in SRAM and instead only read it out of FLASH memory space when needed.

- Dean :twisted:

Make Atmel Studio better with my free extensions. Open source and feedback welcome!