Where are const variables stored on attiny's?
Until shortly I thought that all variables where saved in the RAM, also on the newer attiny's. But then I wondered, why the program or data space never increased, when I added some const char's.
./toolchain_microchip/bin/avr-objcopy -j .text -j .data -j .rodata -O ihex main.elf main.hex
***********************************************************
Device: attiny3217
Program: 6326 bytes (19.3% Full)
Data: 119 bytes (5.8% Full)
***********************************************************
Extending a const char variable just left the values untouched. I then started to look for a command where I could check the storage usage in detail. That's where avr-size
comes to play.
./toolchain_microchip/bin/avr-size -A main.elf
main.elf :
section size addr
.data 0 8402944
.text 6326 0
.rodata 633 39094
.bss 119 8402944
.eeprom 8 8454144
.comment 91 0
.note.gnu.avr.deviceinfo 64 0
.debug_aranges 96 0
.debug_info 8502 0
.debug_abbrev 7654 0
.debug_line 779 0
.debug_str 3361 0
Total 27633
Constant variables are automatically stored in the .rodata
section. According to the gnu compiler doc, data saved in .rodata
stays in the flash, because the newer attiny chips have special LD*
instructions which can be used with the fact that the flash memory is mapped into the RAM address space.