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
- System Clock Management (sysclock)
- Parallel Input/Output Controller (pio)
- Power Management Controller (pmc)
- 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:
void at25dfx_init(void)
{
}
Workflow
- 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
- Enable the system clock:
- Enable PIO configurations for SPI master:
- Initialize the AT25DF321 component; it will set all the configurations defined in the conf_at25dfx.h:
- Set the target AT25DF321 device active, the AT25DF321 can be accessed from now on:
- 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:
at25dfx_write(ram_buff, AT25DFX_TEST_DATA_SIZE, AT25DFX_TEST_BLOCK_ADDR);
at25dfx_read(ram_buff, AT25DFX_TEST_DATA_SIZE, AT25DFX_TEST_BLOCK_ADDR);
Workflow
- Start writing the data to the AT25DFx321:
at25dfx_write(ram_buff, AT25DFX_TEST_DATA_SIZE, AT25DFX_TEST_BLOCK_ADDR);
- Start reading the data from the AT25DFx321:
at25dfx_read(ram_buff, AT25DFX_TEST_DATA_SIZE, AT25DFX_TEST_BLOCK_ADDR);