简体   繁体   中英

avr-gcc: How to use __attribute__((address)) with EEMEM?

Are these attributes incompatible? The address attribute seems to be ignored, emitting no warnings (-Wall).

(For reference, EEMEM is defined in eeprom.h as: #define EEMEM __attribute__((section(".eeprom"))) .)

Using a declaration like:

uint8_t storedFlags EEMEM __attribute__((address (100)));

(and similarly for all the others) results in the variables being placed in whatever order the linker prefers, ignoring my attribute. Order of attributes doesn't make a difference.

I am aware of the preferred method (creating sections and passing their locations to the linker). I was just looking to shove them around for the moment, as I'm in active development and adding and removing allocations in EEPROM; I'd rather things not move around every other build so I don't have to reprogram EEPROM from default values every damn time. Worst of all, I'm sure I've done precisely this before, and had it work. Version differences? Coincidental assignments? (I have GCC 3.4 and 8.1, not sure what that project used; I'm using 8.1 for this one.)

Thedocumentation for the address attribute states:

Variables with the address attribute are used to address memory-mapped peripherals that may lie outside the io address range.

Looking at the AVR memory space shows the I/O addresses fall under the SRAM data memory space.

This explains why your construct doesn't work as expected since EEMEM and the address attribute map to conflicting memory sections.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM