avr-chat
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[avr-chat] Data in program space - old vs. new


From: Bob von Knobloch
Subject: [avr-chat] Data in program space - old vs. new
Date: Fri, 19 Apr 2013 11:06:16 +0200
User-agent: Mozilla/5.0 (X11; Linux i686; rv:17.0) Gecko/20130329 Thunderbird/17.0.5

This just a note that might help someone.
While updating a project written using the old, deprecated syntax of "prog_char" etc. I noticed a 'gotcha'.

I had a number of text strings:

prog_char txt1[] = "Some txt";
prog_char txt2[] = "Some more txt";
... etc

and an array of pointers to them:
prog_char* ptrs_to_text[] = {txt1, txt2 ...};         // Case 1

The new version is:
char txt1[] PROGMEM = "Some txt";
char txt2[] PROGMEM = "Some more txt";
... etc

and an array of pointers to them:
char* ptrs_to_text[] PROGMEM = {txt1, txt2 ...};      // Case 2

Seeing that nothing worked any more, I investigated.
In case 1, the strings are in flash, but the array is in ram.
Case 2 has both the strings and the array in flash, as needs a pgm_read_word to access each pointer.

It's sort of obvious after the event but I though I'd point it out.
Perhaps a small mention on the website where the "prog_char" stuff is mentioned as deprecated?

Regards,

Bob
--
The Sun is out, the sky is blue, it's time to drive the MR2.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]