Go Down

Topic: PGM_P p = PSTR () problem for included SD library or sdfatlib (Read 1 time) previous topic - next topic



this might already be reported or known, but here goes anyway:

Using the included SD library or sdfatlib directly (http://code.google.com/p/sdfatlib/issues/detail?id=27) I am having problems compiling on avr-gcc-4.6.1 (Arch Linux) using arduino 22. I have already this patch applied: http://ix.io/1Uz against pins_arduino.h, but I have to do the following aswell to be able to compile (just avoiding the problem..):

Code: [Select]

diff -ru old/libraries/SD/utility/SdFile.cpp new/libraries/SD/utility/SdFile.cpp
--- old/libraries/SD/utility/SdFile.cpp 2011-02-16 16:56:10.000000000 +0100
+++ new/libraries/SD/utility/SdFile.cpp 2011-10-06 14:51:03.433583165 +0200
@@ -256,7 +256,8 @@
       i = 8;   // place for extension
     } else {
       // illegal FAT characters
-      PGM_P p = PSTR("|<>^+=?/[];,*\"\\");
+      char pp[] = "|<>^+=?/[];,*\"\\";
+      char *p = pp;
       uint8_t b;
       while ((b = pgm_read_byte(p++))) if (b == c) return false;
       // check size and only allow ASCII printable characters

Otherwise I will get the error:
Code: [Select]

build/lib_00/SD/utility/SdFile.cpp: In static member function 'static uint8_t SdFile::make83Name(const char*, uint8_t*)':
build/lib_00/SD/utility/SdFile.cpp:259:17: error: variable '__c' must be const in order to be put into read-only section by means of '__attribute__((progmem))'
build/lib_00/SD/utility/SdFile.cpp:259:17: warning: only initialized variables can be placed into program memory area [enabled by default]
scons: *** [build/lib_00/SD/utility/SdFile.o] Error 1

Any ideas to how to fix this, and whether this is an Arduino or AVR-GCC issue? Is probably related to: http://arduino.cc/forum/index.php?topic=66710.0

- Gaute


Hi Gaute,

I have the same problem - were you able to fix it?



There is a problem with older versions of PSTR and avr-gcc-4.6.1.

See this http://www.avrfreaks.net/index.php?name=PNphpBB2&file=viewtopic&p=871000.

pgmspace.h is in this folder arduino-0022/hardware/tools/avr/avr/include/avr.

Change the definition of PSTR from this:
Code: [Select]

# define PSTR(s) (__extension__({static char __c[] PROGMEM = (s); &__c[0];}))

to this:
Code: [Select]

# define PSTR(s) (__extension__({static const char __c[] PROGMEM = (s); &__c[0];}))

Go Up