self programming on AVR128DA48

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

I tried self programming on the AVR128DA48. I have set BOOTSIZE=4, my program fits into the BOOT section (<2KB). The following code works:

 

  while(NVMCTRL.STATUS & (NVMCTRL_FBUSY_bm|NVMCTRL_EEBUSY_bm));
  NVMCTRL.CTRLB=NVMCTRL_FLMAP_SECTION3_gc;
  _PROTECTED_WRITE_SPM(NVMCTRL.CTRLA,NVMCTRL_CMD_FLWR_gc);
  p=(unsigned char *) 0x8400;
  *p=0xab;
  NVMCTRL.CTRLA=NVMCTRL_CMD_NOOP_gc;

The page from section 3 is programmed as expected (Address 0x18400 in code space). 

 

When I set p to some value below 0x8400 (0x8000 or 0x8200), programming fails and NVMCTRL.STATUS  returns a WRITEPROTECT error.

 

I have no idea why this happens because the address that should be programmed is outside the boot section.

 

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

I took a look at the AVR128DA Silicon errata, I ran into the bug that is described in 2.4.1 (Flash mapping into Data Space Not Working Properly).

Last Edited: Mon. Jun 15, 2020 - 10:59 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Yeah there are a few quirks. One that took me a while to figure out, is that the eeprom erase/write command (EEERWR) is interrupted if you write a NOOP to the CTRLA register before the erase part of EEERWR finishes.

In that case, the write part of the command is never executed; the eeprom will only be erased and no data is actually written.

 

Note: observed from UPDI access, IDK is self-programming behaves the same.