I'm having trouble understanding how self-programming may be implemented on a SAM processor (I'm using a SAM E54 Xplained board). I have a firmware update that I load from an SD card into RAM, and I want to overwrite the flash with that firmware.
I've looked at the flash writing example provided by Atmel START, which just has initialization code in driver_init.c and then makes a call to flash_write() to write data to the address 0x3200. I thought I could simply extended this by writing the firmware update to flash a page at a time (starting at address 0x1000 to avoid the vector table), but the code faults somewhere within flash_write().
Further research seems to suggest there's more to self-programming, but it's unclear what the other steps are. I've tried putting the flash writing code below the address 0x1000, and writing to pages beyond 0x1000, and I've tried running the update code from RAM, though there variables become corrupt (stack issues?).
Can someone help guide me towards how I may implement self-programming?
Edit: Looks like I somehow posted under Atmel Studio, but I can't find a way to move this thread, or delete and recreate it?