Initialize eeprom without overwriting first byte

Go To Last Post
2 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

So I have a structure with configuration information that I store in internal eeprom starting at address 0x01, and this structure has some initial values. The byte at address 0x00 in the eeprom is the OSCCAL value.

In production I can start with programming the eeprom from the .eep file, and after that write the OSCCAL value to address 0 and everything will be fine. But during development I reprogram the eeprom every time I download the code and debug, so the OSCCAL value is erased. Is there some way to make the project so that the first byte in the eeprom don't get initialized? (Besides from the obvious, simple way of just initialize the OSCCAL from the code when debugging...)

/COLA

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Maybe put the OSCCAL vale at the END address in the EEPROM?

Otherwise another solution would be to identify the linker script being used (one of the .x files in \winavr\avr\lib\ldscripts) and edit the:
MEMORY

{
  text   (rx)   : ORIGIN = 0, LENGTH = 128K
  data   (rw!x) : ORIGIN = 0x800060, LENGTH = 0xffa0
  eeprom (rw!x) : ORIGIN = 0x810000, LENGTH = 64K
}

change that to 0x810001

Or give a --section-start to the linker to reposition the .eeprom section

But I'd just stick OSCCAL at the end!

(BTW some of the AVRs are susceptible to EEPROM location 0 being corrupted in lower power situations so personally I'd avoid it anyway - if you locate your struct{} there then maybe make the first element "uint8_t dont_care;" or something?)