The Arduino hangs.
But upon reboot... success! The page of flash was written correctly.
If I try using EEFC1, the Arduino remains responsive but the page is not written.
I have come to the conclusion that I must use the IAP function stored in the ROM.
How to call this, I am unsure.
The example given in the datasheet passes it two arguments. The EEFC ID (0 or 1) and the contents to write to the EEFC_FCR register.
However, the description of the function specifies it only takes one argument.
In any case, I am unable to call it successfully. The Arduino simply hangs.
Perhaps there is some way to run a function from ram.
using EEFC to write flash has some troubles that are not reported in the datasheet (I've obtained such informations directly from Atmel and by looking the source code from ASF):
You should execute code from SRAM during writes (the official reason is that the flash "page" you're writing could contain the code that is currently running)
You must disable interrupts during writes (to avoid the chance of executing ISR code in flash memory for the same reason of 1)
Flash page buffering-before-write should be done 32-bit at a time (you can't write one byte at a time for example... wrong writes happens)
FWS (Flash Wait States) register should be set to 6 (look at the errata corrige at the end of the datasheet)
I'm writing a Flash library to use in Arduino IDE that take cares of all the above here: