Go Down

Topic: PROGMEM no longer working with 0013? (Read 2251 times) previous topic - next topic


Feb 24, 2009, 02:12 pm Last Edit: Feb 25, 2009, 10:23 am by ahoeben Reason: 1
The code below was working for me in 0012 0011 (see update below), but it seems to crash the AVR / return to the bootloader on the strcpy_P() line when uploaded to a stock diecimila.

Code: [Select]

#include <avr/pgmspace.h>

char string_1[] PROGMEM = "String 1";
char string_2[] PROGMEM = "String 2";
char string_3[] PROGMEM = "String 3";
char string_4[] PROGMEM = "String 4";
char string_5[] PROGMEM = "String 5";

PGM_P PROGMEM string_table[] =

void setup()                    

char buffer[10];
void loop()                     // run over and over again
   for (unsigned char i = 0; i < 5; i++)
      strcpy_P(buffer, (char * )pgm_read_word(&(string_table[i])));
      Serial.println( buffer );
      delay( 500 );

update: code worked in 0011, not 0012


Feb 24, 2009, 03:04 pm Last Edit: Feb 24, 2009, 03:06 pm by mikalhart Reason: 1
That PROGMEM stuff is awfully subtle.  If you change the string_table to

Code: [Select]
PROGMEM const char *string_table[] =

it will work under 0013.  (At least it does for me.)



See also http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1228107706/0#0
(though it looks like your problem may be different.)


Good observation, westw.  It may be the same problem, since the main difference in ahoeben's implementation and mine is that his uses PGM_P, which maps indirectly to prog_char.



Feb 25, 2009, 10:07 am Last Edit: Feb 25, 2009, 01:35 pm by ahoeben Reason: 1
I was wrong about my code working in 0012. The last version it worked with as posted is 0011, so it does seem to be the same issue as posted by westfw.

Between 0011 and 0012, newer versions of avr-gcc (4.3.0) and avr-libc (1.6) were included. Some more about the issue here:

With Mikal's changes, I can confirm the code works with 0013. So there seems to be a workaround. Yay!

This page should probably be updated to reflect this workaround:


I changed the docs a bit.

Can someone have a go at recommending which form for variable declarations we should recommend to users

dataType variableName[] PROGMEM = {};    // eenie
dataType PROGMEM variableName[] = {};    // meenie, minie
PROGMEM  dataType  variableName[] = {};  // mo

From the discussion, seems like form 3 should be the current form.


Please note that PROGMEM is not part of the Arduino language and disseminating this information throughout the Arduino community should be done at your own risk.

Go Up