I have a quick question. I'm trying to place a variable in a fixed flash address, so that it can easily be altered in the hex file prior to uploading to the avr, without having to recompile in between.
classic application: serial numbers.
anyway, it seemed to work, (I can identify the numbers in the compiled hex file, so I could alter them there). This is how I did it for my ATMEGA328P:
PART_NUMBER_ADDRESS = 0x7FF1 SERIAL_NUMBER_ADDRESS = 0x7FF2 LDFLAGS += -Wl,--section-start=.part_number=$(PART_NUMBER_ADDRESS) LDFLAGS += -Wl,--section-start=.serial_number=$(SERIAL_NUMBER_ADDRESS)
in my main code (global)
uint8_t part_number __attribute__ ((section (".part_number"))) = 'A'; uint32_t serial_number __attribute__ ((section (".serial_number"))) = 0x30313233;
This is the end of the Hex-file:
... :1078E000FCCF9093C6009D3011F49AE0F6CF089536 :1078F0008091C00087FFFCCF8091C6000895F89466 :02790000FFCFB7 :087902000070314133323130D5 :017FF100414E :047FF20033323130C5 :040000030000700089 :00000001FF
you can clearly see the 'A' (0x41) and the 0x30313233 (in reverse).
so that seemed to work, but whenever I try to access the declared variables "part_number" or "serial_number"
I get something completely different!
I know I could just read them out using pgm_read_byte_near(0x7FF1) from pgmspace.h, but I'm trying to learn things, so I'm wondering why the above does not work as it is.