This basic example shows how to use the Enhance Embedded Flash (EEFC) peripheral available on the newest Atmel samv7 Microcontrollers. It details steps required to program the internal flash, and manage secure and lock bits.
This package can be used with SAMV71 Xplained Ultra board or SAME70 Xplained board.
The samv7/e7 ROM code embeds small In Application Programming Procedure. Since this function is executed from ROM, this allows Flash programming (such as sector write) to be done by code running in Flash.
The IAP function entry point is retrieved by reading the NMI vector in ROM (). This function takes two argument in parameter: bank index (0 or 1) and the command to be sent to the EEFC.
static uint32_t (*IAP_PerformCommand)(uint32_t, uint32_t);
IAP_PerformCommand = (uint32_t (*)(uint32_t, uint32_t)) *((uint32_t *)
0x00100008);
IAP_PerformCommand(0, (0x5A << 24) | (argument << 8) | command);
IAP function returns the value of the MC_FSR register. The required steps are:
The samv7/e7 features a security bit, based on a specific General Purpose NVM bit 0. When the security is enabled, any access to the Flash, SRAM, Core Registers and Internal Peripherals either through the ICE interface is forbidden. This example will reproduce this scene.
-- EEFC Programming Example xxx -- -- xxxxxx-xx -- Compiled: xxx xx xxxx xx:xx:xx -- -I- Unlocking last page -I- Writing last page with walking bit pattern -I- Checking page contents .................. ok -I- Locking last page -I- Try to program the locked page... -I- Please open Segger's JMem program -I- Read memory at address 0x0043FF00 to check contents -I- Press any key to continue... -I- Good job! -I- Now set the security bit -I- Press any key to continue to see what happened... -I- Setting GPNVM #0 -I- All tests done