This is the mail archive of the
mailing list for the GCC project.
Re: AVR __progmem__ variable reading
- From: David Brown <david dot brown at hesbynett dot no>
- To: Łukasz Kostka <lukasz dot kostka at netng dot pl>, gcc at gcc dot gnu dot org
- Date: Sat, 23 Feb 2019 16:34:21 +0100
- Subject: Re: AVR __progmem__ variable reading
- References: <AA53195D-2F98-4CEA-A012-54ADD8C7CCB1@netng.pl>
On 22/02/2019 23:34, Łukasz Kostka wrote:
I am using for a while now gcc and especially __progmem__ attribute. I’d like to report a feature request for gcc to handle reading from flash memory variables. Compiler has all the knowledge (target device, availability of LPM, ELPM instructions etc.) in order to properly interpret variable is accessed (eg. by array subscription).
This would remove need for any assembly code written to do this.
Make user code much cleaner.
GCC having all this knowledge can optimize end assembly code.
Simple attribute addition will switch from array in memory to array in flash.
Can serve as future implementations for other platforms.
What do you think ?
You don't need to write assembly to read flash data with AVR gcc - you
have never needed it. To use the "progmem" attribute, include the
<avr/pgmspace.h> header and use the macros and functions from there,
such as "pgm_read_byte".
Newer versions of AVR gcc have named address spaces, making the process
simpler. I must admit I haven't written any AVR code since these were
added to the compiler, but I assume they work fine: