From 76e93e9fd716dfa6dadfa65e0843013b314dcfdf Mon Sep 17 00:00:00 2001 From: Pat Hickey Date: Mon, 15 Oct 2012 19:23:15 -0700 Subject: [PATCH] AP_Common: PSTR def has specific version for avr-gcc 4.6 compatibility * Also a small change in FastSerial/vprintf.cpp, which duplicates the PSTR definition * Won't effect others using earlier versions of avr-gcc --- libraries/AP_Common/AP_Common.h | 6 ++++++ libraries/FastSerial/vprintf.cpp | 5 +++++ 2 files changed, 11 insertions(+) diff --git a/libraries/AP_Common/AP_Common.h b/libraries/AP_Common/AP_Common.h index 798571be41..98cb5bd618 100644 --- a/libraries/AP_Common/AP_Common.h +++ b/libraries/AP_Common/AP_Common.h @@ -94,8 +94,14 @@ typedef struct { #endif # undef PSTR + /* Need const type for progmem - new for avr-gcc 4.6 */ + # if __AVR__ && __GNUC__ == 4 && __GNUC_MINOR__ > 5 + # define PSTR(s) (__extension__({static const prog_char __c[] PROGMEM = (s); \ + (const prog_char_t *)&__c[0]; })) + #else # define PSTR(s) (__extension__({static prog_char __c[] PROGMEM = (s); \ (prog_char_t *)&__c[0]; })) + #endif #endif // a varient of PSTR() for progmem strings passed to %S in printf() diff --git a/libraries/FastSerial/vprintf.cpp b/libraries/FastSerial/vprintf.cpp index fa435ac54e..898475cc4d 100644 --- a/libraries/FastSerial/vprintf.cpp +++ b/libraries/FastSerial/vprintf.cpp @@ -52,7 +52,12 @@ extern "C" { #undef PROGMEM #define PROGMEM __attribute__(( section(".progmem.data") )) #undef PSTR + /* Need const type for progmem - new for avr-gcc 4.6 */ + #if __GNUC__ == 4 && __GNUC_MINOR__ > 5 +#define PSTR(s) (__extension__({static const prog_char __c[] PROGMEM = (s); &__c[0];})) + #else #define PSTR(s) (__extension__({static prog_char __c[] PROGMEM = (s); &__c[0];})) + #endif #ifdef GETBYTE #undef GETBYTE