This is the quickstart guide for the SAM FLASHCALW driver, with step-by-step instructions on how to configure and use the driver in a selection of use cases.
The use cases contain several code fragments. The code fragments in the steps for setup can be copied into a custom initialization function, while the steps for usage can be copied into, e.g., the main application function.
Basic use case
In this basic use case, the last page page and the user page will be written with a specific magic number.
Prerequisites
- System Clock Management (Sysclock)
Setup steps
- Note
- The CLK_FLASHCALW_AHB, CLK_FLASHCALW_APB are enabled by default.
Example code
Enable the following macro in the conf_clock.h:
#define CONFIG_SYSCLK_SOURCE SYSCLK_SRC_RCFAST
#define CONFIG_RCFAST_FRANGE 2
Add the following code in the application C-file:
Workflow
- Set system clock source as fast RC oscillator:
#define CONFIG_SYSCLK_SOURCE SYSCLK_SRC_RCFAST
- Set fast RC oscillator as 12MHz:
#define CONFIG_RCFAST_FRANGE 2
- Initialize the system clock.
Usage steps
Example code
Add to, e.g., main loop in application C-file:
#define MAGIC_NUM 0x4c4d5441
#define PAGE_ADDRESS (FLASH_ADDR + FLASH_SIZE - FLASH_PAGE_SIZE)
#define USER_PAGE_ADDRESS (FLASH_USER_PAGE_ADDR + 8)
Workflow
- Define the written locations and magic number:
#define MAGIC_NUM 0x4c4d5441
#define PAGE_ADDRESS (FLASH_ADDR + FLASH_SIZE - FLASH_PAGE_SIZE)
- Note
- The storage location must not at the beginning of the user page as the first 2 words of the user page is reserved.
static const uint32_t write_data = MAGIC_NUM;
- Write the magic number to the flash array:
- Write the magic number to the user page: