Adding variable that does not change on firmware upload

Hello,

I'm designing a custom board with the Atmega328PB with firmware that should be able to tell which hardware it's running on. So it needs to contain a variable that does not update when the firmware is updated.

It seems like I have two options:

  • Modifying the bootloader to include a constant variable
  • Saving the hardware version to EEPROM once

Has anybody encountered this issue before? What would be the best option and/or is there another/better way of doing it?

EEPROM would be the easiest of the two to implement

If you have free pins, you could use them, 2 pins = 4 different Hardwares, or 1 Analog pin and 2 resistors.

A common approach is to connect I/O pins to jumpers or dip switches on the board. Read them when booting up.