Microchip® Advanced Software Framework

Quickstart guide for SAM FLASHCALW driver

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

  1. 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

  1. Set system clock source as fast RC oscillator:
    • #define CONFIG_SYSCLK_SOURCE SYSCLK_SRC_RCFAST
  2. Set fast RC oscillator as 12MHz:
    • #define CONFIG_RCFAST_FRANGE 2
  3. 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)
static const uint32_t write_data = MAGIC_NUM;
flashcalw_memcpy((void *)PAGE_ADDRESS, &write_data, 4, true);
flashcalw_memcpy((void *)USER_PAGE_ADDRESS, &write_data, 4, true);

Workflow

  1. Define the written locations and magic number:
    • #define MAGIC_NUM 0x4c4d5441
    • #define PAGE_ADDRESS (FLASH_ADDR + FLASH_SIZE - FLASH_PAGE_SIZE)
    • USER_PAGE_ADDRESS (FLASH_USER_PAGE_ADDR + 8)
    • 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;
  2. Write the magic number to the flash array:
  3. Write the magic number to the user page: