This basic example shows how to use the Flash service available on the Atmel SAM microcontrollers. It details steps required to program the internal flash, and manage secure and lock bits.
This package can be used with SAM evaluation kits.
The program performs the following set of commands:
The SAM MCU features a security bit, based on a specific General Purpose NVM bit 0. When the security bit is enabled, any access to the Flash, SRAM, Core Registers and Internal Peripherals through the ICE interface is forbidden. This example will reproduce this scene.
The SAM MCU ROM code embeds small In-Application Programming (IAP) Procedure. Since this function is executed from ROM, this allows Flash programming (such as sector write) to be done when code is running out of Flash. We will use IAP function by default in flash driver.
Using Atmel Studio or Segger to debug, to be able to correctly watch the changes in the flash through the Memory view or through Segger J-Mem, caching needs to be disabled. This can be done in the Tool tab in the Project Properties in Atmel Studio. We also need to place a breakpoint in the flash_write function then do a Step Out to see the changes, otherwise stopping the program execution anywhere just shows 0xFFs instead of the walking pattern.