This quick start will read, unprotect, erase and write bytes to an AT25DF081A that is connected to the SPI interface on EXT1 header of SAM D20 Xplained Pro or EXT3 of SAM D21 Xplained Pro.
The SERCOM SPI will be configured with the following settings:
For SAM D20 Xplained Pro
- 500 kHz baud rate
- SCK, MISO and MOSI on EXT1 header's SPI pins
For SAM D21 Xplained Pro
- 120 kHz baud rate
- SCK, MISO and MOSI on EXT3
The AT25DFx driver instance will be configured with the following settings:
For SAM D20 Xplained Pro
- CS on EXT1 header's SS0 pin
For SAM D21 Xplained Pro
Setup
Prerequisites
There are no special setup requirements for this use-case.
Code
Add to the main application source file, outside of any functions:
#define AT25DFX_BUFFER_SIZE (10)
Create a new function for initializing the AT25DFx:
{
at25dfx_spi_config.mode_specific.master.baudrate = AT25DFX_CLOCK_SPEED;
at25dfx_spi_config.mux_setting = AT25DFX_SPI_PINMUX_SETTING;
at25dfx_spi_config.pinmux_pad0 = AT25DFX_SPI_PINMUX_PAD0;
at25dfx_spi_config.pinmux_pad1 = AT25DFX_SPI_PINMUX_PAD1;
at25dfx_spi_config.pinmux_pad2 = AT25DFX_SPI_PINMUX_PAD2;
at25dfx_spi_config.pinmux_pad3 = AT25DFX_SPI_PINMUX_PAD3;
}
If not already present, add to the initialization code:
Workflow
- Create read and write buffers.
#define AT25DFX_BUFFER_SIZE (10)
- Create global instances of SPI and AT25DFx chip.
- Create a function to contain the AT25DFx initialization code.
- Create local instances of SPI and AT25DFx configurations.
- Initialize the SPI for AT25DFx connected to EXT1 header.
at25dfx_spi_config.mode_specific.master.baudrate = AT25DFX_CLOCK_SPEED;
at25dfx_spi_config.mux_setting = AT25DFX_SPI_PINMUX_SETTING;
at25dfx_spi_config.pinmux_pad0 = AT25DFX_SPI_PINMUX_PAD0;
at25dfx_spi_config.pinmux_pad1 = AT25DFX_SPI_PINMUX_PAD1;
at25dfx_spi_config.pinmux_pad2 = AT25DFX_SPI_PINMUX_PAD2;
at25dfx_spi_config.pinmux_pad3 = AT25DFX_SPI_PINMUX_PAD3;
- Initialize the AT25DFx instance for AT25DF081A, with Slave Select on the SS_0 pin on EXT1.
Use Case
Code
Copy into main application:
Workflow
- Wakeup serialFlash.
- Check that the SerialFlash is present.
- Read out the first AT25DFX_BUFFER_SIZE bytes, starting at the very first flash address.
- Disable protection of the second sector.
- Note
- This device has sectors with a uniform size of 64 kB, so the address
0x10000
marks the start of the second sector. This can differ between devices.
- Erase the first 4 kB of the second 64 kB block (64-68 kB range).
- Write AT25DFX_BUFFER_SIZE bytes, starting at the beginning of the sector and the newly erased memory locations.
- Enable protection of all sectors, to prevent accidental erases of content.
- Put SerialFlash device to sleep, to conserve power.