AVR-GCC and strings in flash WITHOUT needing PSTR() Wrapper

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

Hello all,

Is there a way to tell the compiler/linker that all strings should be stored in flash without needing to specifically wrap each with the PSTR() macro?

 

I know that there is a PSTR() macro that should be used to wrap a string to declare that it should be in flash.

However I have an existing codebase that I am porting to avr_gcc and its a big and error-prone job to add PTR to every const string.

 

I was hoping that there is a 'magic' switch that can be turned on to tell the tools to 'just do it'?

 

FWIW: I am coming to avr-gcc from many (happy) years using ImageCraft AVR tools which has exactly this feature built in.

I 'need' avr-gcc because I need the ASF and the USB goodness it provides (and Imagecraft does not compile the gcc dialect 'out of the box')

 

 

Thanks in Advance..

Ivan Vernot

//realtimedesigns.com.au

 

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

No.

avr-gcc has standard library functions that cannot handle a pointer to char in flash.

grep is your friend.  It can make your task much less error-prone.

Others might suggest awk.

 

I have occasionally defined macros like this:

#define printf_Q(format, ...)  printf_P(PSTR(format), __VA_ARGS__)

In case it isn't obvious, printf_P is the version of printf that takes a format string in program memory.

 

My expectation is that avr-gcc with __flash has an appropriately #define-d PSTR macro.

 

Edit: (corrected #define)

Iluvatar is the better part of Valar.

Last Edited: Tue. Jun 9, 2015 - 04:59 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Just wait until Hell freezes over.
Meanwhile, edit your Imagecraft code to replace every reference to regular strxxxx() functions with the equivalent strxxxx_P() version. Yes you can automate it with a SED script but you will still need human oversight.
David.

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

@skeeve - the printf_Q() macro is a clever idea - I'll try it..

@david.prentice - yeah I've been knitting thick socks and practicing my grep/ARK/SED foo in anticipation wink

 

Looks like there's no such thing as a free lunch magic linker commands.

Will go the search and replace path...

 

Hmm... enlightenedNow if Imagecraft could just digest the gcc dialect enlightened

(but that is a post for another mailing list - been there, done that - without success. sad 

 

 

Thanks All.

Ivan

 

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

And  C++

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

OP's real problem is knowing when he is done.

To do that, I suggest a rule: Any correct line with an explicit string must also contain the sequence @-- .

Unprocessed strings can be found with grep -nF \" victim.c  | grep -vF @-- .

 

If you are using __flash, avr-gcc's type-checking will help find errors.

Iluvatar is the better part of Valar.

Last Edited: Thu. Jun 11, 2015 - 12:33 AM