[AVR GCC] Store const data in flash without PROGMEM option

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

Hi all,

 

I know that normally one would use the PROGMEM or __flash directives to store a given data into flash. But the problem is that some libraries, like uGFX, are written without it and are using only the const declaration to store in program memory, since normally other proprietary compilers are doing that automatically.

Is there an option/tweak on the linker instructions or anything else to store any variable declared as const without any other special attribute, into flash? OR at least to avoid to tweak all the files of a third party library?

 

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

thexeno wrote:
since normally other proprietary compilers are doing that automatically.

Didn't GCC (and maybe CodeVision) >>used<< to do it that way?  Which toolchains are these that still do not recognize/honor AVR8 address spaces?  How do these example toolchains resolve the conflict (which e.g. __flash helps to address) between the "real" C meaning of "const" and the desired __flash equivalent?

You can put lipstick on a pig, but it is still a pig.

I've never met a pig I didn't like, as long as you have some salt and pepper.

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

GCC has __flash and __memx now but you can still use PROGMEM
G++ only has PROGMEM

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

Depending on how else the const keyword is used in those libraries, and how those entities are referenced, it may be possible to write macros which change const to const __flash, print( to print_P(PSTR(, etc. Then include those macros on the command line when building the library.

You will have to examine the libraries to determine what macros you'll need to provide.

"Experience is what enables you to recognise a mistake the second time you make it."

"Good judgement comes from experience.  Experience comes from bad judgement."

"Wisdom is always wont to arrive late, and to be a little approximate on first possession."

"When you hear hoofbeats, think horses, not unicorns."

"Fast.  Cheap.  Good.  Pick two."

"We see a lot of arses on handlebars around here." - [J Ekdahl]

 

Last Edited: Sat. Nov 18, 2017 - 06:04 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

> Is there an option/tweak on the linker instructions or anything else to store any variable declared as const without any other

> special attribute, into flash?

 

Yes.  You can use your own linker description file and put .rodata into flash (.text) instead of into ram (.data).

 

But your program will cease to work because this won't adjust respective accesses; the library will still contain LD and LDS instructions, not LPM as needed to access flash.

 

If you have the library sources available and the license allows you to adjust the sources, you can use __flash qualifier on desired objects and associated pointers.  Using progmem is usually more work because you have to add inline asm to all reads from flash.

 

Starting a new project, you can also switch to a µc that supports flash visible in ram like the devices that avr-gcc v8 files under avrxmega3:

 

http://gcc.gnu.org/onlinedocs/gc...

 

You can use standard c/c++ without overhead, all const stuff will reside in flash (except for the consts that are shredded by c++).  There is no device support in libc, though, so you need to add your headers and start-up code.

 

Or find some distribution that adds these devices as avrxmega2, mixing them up with devices without the flash-in-ram feature. There is libc support, but due to the mixup, the linker puts .rodata in ram. Then you can use standard c/c++ but have to adjust your linker description.

 

 

avrfreaks does not support Opera. Profile inactive.