First off thanks to all for the help. I've read several hundred threads over the years from AVRFreaks.net and they have been super helpful. I have come to recognize users like clawson and abcminiuser among many others as very helpful and professional.
The issue:
I want to place a marker in my HEX file at the beginning of a struct so that I can search the file with custom software and observe certain aspects about the firmware. To be clear, this struct is in no way used in the firmware but simply offers metadata for the file itself. This allows me to enforce that the productCode matches the device as well as give hints to the user as to the firmware version, etc. Here is the struct from my header:
struct __attribute__((packed)) ProductKey { char const searchKey[10] = { "UniqueKey" }; uint16_t productCode = 37; uint8_t const fwMaj = 1; uint8_t const fwMin = 9; }; typedef struct ProductKey ProductKey;
Then in a cpp file I do the following in global scope:
const ProductKey pk __attribute__((used, progmem));
Unfortunately this doesn't write the struct to the HEX file unless I remove progmem but doing that increases my dynamic memory footprint (SRAM). So essentially the "used" attribute isn't working as I would expect if progmem is also used.
I can get it to work if I reference one of the members of the struct in an initializer somewhere, as follows:
... char tmp[10]; strcpy_P(tmp, pk.searchKey); ...
...but that is cheating with respect to the "used" attribute which just doesn't seem to work in conjunction with progmem. I suppose I could be satisfied with this approach (I get my RAM back when the variable goes out of scope) but I don't like it. Am I missing something that could cause issues later?
My environment:
I'm working under Arduino IDE with ATmega1284p. I would rather be working with Atmel Studio (now Microchip Studio) and avoid dependence on the Arduino libraries but there's so much code and not enough time to make the switch.