Microchip® Advanced Software Framework

Quickstart guide for AT25DFx component.

This is the quickstart guide for the AT25DFx SerialFlash component, 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 the basic use case, the AT25DFx component are configured for:

  • The type of the AT25DFx component is AT25DF321
  • The AT25DF321 is connected to the module SPI0
  • The SPI is configured as master mode
  • The SPI master speed is 12MHz
  • The SPI transfer uses 8 bits mode
  • The chip select used by the AT25DF321 is 3
  • There is one AT25DFx device to be managed
  • The memory ID used for the AT25DF321 is 1
  • 1024 bytes of data beginning from block 0 will be written to the AT25DF321
  • 1024 bytes of data will be read from the block 0 of the AT25DF321

Setup steps

Prerequisites

  1. System Clock Management (sysclock)
  2. Parallel Input/Output Controller (pio)
  3. Power Management Controller (pmc)
  4. Serial Peripheral Interface (SPI)

Example code

Content of conf_at25dfx.h

#define AT25DFX_USES_SPI_MASTER_SERVICE
#define AT25DFX_SPI_MODULE SPI0
#define AT25DFX_CS 3
#define AT25DFX_MEM_CNT 1
#define AT25DFX_MEM_ID 1
#define AT25DFX_SPI_MASTER_SPEED 12000000
#define AT25DFX_SPI_BITS 8
#define AT25DFX_MEM_TYPE AT25DFX_321

A specific size of RAM buffer must be added; The access address and size in the SerialFlash must be defined:

#define AT25DFX_TEST_BLOCK_ADDR (0)
#define AT25DFX_TEST_DATA_SIZE (1024)
static uint32_t ram_buff[1024];

Add to application C-file:

Workflow

  1. Ensure that conf_at25dfx.h is present and contains the following configuration symbol. This configuration file is used by the driver and should not be included by the user.
    • #define AT25DFX_USES_SPI_MASTER_SERVICE
      #define AT25DFX_SPI_MODULE SPI0
      #define AT25DFX_CS 3
      #define AT25DFX_MEM_CNT 1
      #define AT25DFX_MEM_ID 1
      #define AT25DFX_SPI_MASTER_SPEED 12000000
      #define AT25DFX_SPI_BITS 8
      #define AT25DFX_MEM_TYPE AT25DFX_321
  2. Enable the system clock:
  3. Enable PIO configurations for SPI master:
  4. Initialize the AT25DF321 component; it will set all the configurations defined in the conf_at25dfx.h:
  5. Set the target AT25DF321 device active, the AT25DF321 can be accessed from now on:
  6. The AT25DF321 will be protected from writing by default, so a unprotect is necessary:

Usage steps

Example code

Add to, e.g., main loop in application C-file:

Workflow

  1. Start writing the data to the AT25DFx321:
  2. Start reading the data from the AT25DFx321: