Microchip® Advanced Software Framework

 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
AT25DFx SerialFlash component driver.

See Quickstart guide for AT25DFx component..

This is a driver for the AT25DFx SerialFlash memories. It provides functions for initialization, read and write operations.

Dependencies

This driver depends on the following modules:

Modules

 
 Quick Start Guide(s)
 In this section you can find a list of all Quick Start guides related to the AT25DFx SerialFlash component driver..
 

Data Structures

struct  at25_cmd
 SerialFlash transfers request prepared by the AT25 driver. More...
 

Macros

#define AT25DFX_BLOCK_ERASE_CMD   AT25_BLOCK_ERASE_64K
 AT25 block erase command. More...
 
#define AT25DFX_BLOCK_SIZE   (64*1024)
 AT25 block size. More...
 
#define AT25DFX_DEV_ID   0x0001441F
 AT25 device ID. More...
 
#define AT25DFX_PAGE_SIZE   256
 The page size of AT25DF series is always 256. More...
 
#define AT25DFX_SIZE   (512 * 1024)
 AT25 total size. More...
 

Typedefs

typedef struct at25_cmd at25_cmd_t
 SerialFlash transfers request prepared by the AT25 driver. More...
 

Functions

static at25_status_t at25dfx_enable_write (void)
 Enable critical write operation on a SerialFlash device, such as sector protection, status register, etc. More...
 
at25_status_t at25dfx_erase_block (uint32_t address)
 Erase the specified block of the SerialFlash. More...
 
at25_status_t at25dfx_erase_chip (void)
 Erase all the content of the memory chip. More...
 
at25_status_t at25dfx_initialize (void)
 Initialize the SerialFlash. More...
 
at25_status_t at25dfx_mem_check (void)
 Check if the SerialFlash is valid. More...
 
at25_status_t at25dfx_protect_chip (uint8_t protect_type)
 Protect the SerialFlash device. More...
 
at25_status_t at25dfx_protect_sector (uint32_t address, uint8_t protect_type)
 Protect/unprotect the specific sector. More...
 
at25_status_t at25dfx_read (uint8_t *data, uint16_t size, uint32_t address)
 Read data from the specified address on the SerialFlash. More...
 
static at25_status_t at25dfx_read_dev_id (uint32_t *dev_id)
 Read and return the SerialFlash device ID. More...
 
at25_status_t at25dfx_read_sector_protect_status (uint32_t address)
 Read sector protection status. More...
 
at25_status_t at25dfx_read_status (uint8_t *status)
 Read and return the status register of the SerialFlash. More...
 
static at25_status_t at25dfx_send_command (at25_cmd_t *at25cmd)
 Start an AT25DFx command transfer. More...
 
void at25dfx_set_mem_active (uint8_t cs)
 Select the SerialFlash by the corresponding chip select. More...
 
static at25_status_t at25dfx_wait_ready (void)
 Wait for the SerialFlash device to be ready to accept new commands. More...
 
at25_status_t at25dfx_write (uint8_t *data, uint16_t size, uint32_t address)
 Write data at the specified address on the serial firmware SerialFlash. More...
 
at25_status_t at25dfx_write_status (uint8_t status)
 Write the given value in the status register of the SerialFlash device. More...
 

Variables

static uint8_t active_sf_cs = AT25DFX_MEM_ID
 Activated SerialFlash chip select, default to device 1. More...
 

#define AT25DFX_BLOCK_ERASE_CMD   AT25_BLOCK_ERASE_64K

AT25 block erase command.

Referenced by at25dfx_erase_block().

#define AT25DFX_BLOCK_SIZE   (64*1024)

AT25 block size.

#define AT25DFX_DEV_ID   0x0001441F

AT25 device ID.

Referenced by at25dfx_mem_check().

#define AT25DFX_PAGE_SIZE   256

The page size of AT25DF series is always 256.

Referenced by at25dfx_write().

#define AT25DFX_SIZE   (512 * 1024)

AT25 total size.

Referenced by at25dfx_erase_block(), at25dfx_read(), and at25dfx_write().

typedef struct at25_cmd at25_cmd_t

SerialFlash transfers request prepared by the AT25 driver.

This structure is sent to the at25_send_command function which is application dependent. This function transforms at25_cmd_t request into api command request.

static at25_status_t at25dfx_enable_write ( void  )
static

Enable critical write operation on a SerialFlash device, such as sector protection, status register, etc.

Returns
AT25_SUCCESS if the device has been unprotected; otherwise return AT25_ERROR_PROTECTED.

References at25_cmd::address, AT25_WRITE_ENABLE, at25dfx_send_command(), at25_cmd::cmd, at25_cmd::cmd_size, at25_cmd::data, at25_cmd::data_size, and NULL.

Referenced by at25dfx_erase_block(), at25dfx_erase_chip(), at25dfx_protect_chip(), at25dfx_protect_sector(), and at25dfx_write().

at25_status_t at25dfx_erase_block ( uint32_t  address)

Erase the specified block of the SerialFlash.

Parameters
addressAddress of the block to erase.
Returns
AT25_SUCCESS if successful; otherwise return AT25_ERROR_PROTECTED if the device is protected or AT25_ERROR_BUSY if busy executing a command.

References at25_cmd::address, AT25_ERROR, AT25_ERROR_BUSY, AT25_ERROR_PROTECTED, AT25_STATUS_RDYBSY, AT25_STATUS_RDYBSY_READY, AT25_STATUS_SWP, AT25_STATUS_SWP_PROTNONE, AT25_SUCCESS, AT25DFX_BLOCK_ERASE_CMD, at25dfx_enable_write(), at25dfx_read_status(), at25dfx_send_command(), AT25DFX_SIZE, at25dfx_wait_ready(), at25_cmd::cmd, at25_cmd::cmd_size, at25_cmd::data, at25_cmd::data_size, and NULL.

Referenced by main(), and run_test_at25dfx_data_access().

at25_status_t at25dfx_erase_chip ( void  )

Erase all the content of the memory chip.

Returns
AT25_SUCCESS if the device has been unprotected; otherwise return AT25_ERROR_PROTECTED.

References at25_cmd::address, AT25_CHIP_ERASE_2, AT25_ERROR_PROTECTED, AT25_STATUS_SWP, AT25_STATUS_SWP_PROTNONE, AT25_SUCCESS, at25dfx_enable_write(), at25dfx_read_status(), at25dfx_send_command(), at25dfx_wait_ready(), at25_cmd::cmd, at25_cmd::cmd_size, at25_cmd::data, at25_cmd::data_size, and NULL.

at25_status_t at25dfx_initialize ( void  )

Initialize the SerialFlash.

Returns
AT25_SUCCESS for success, AT25_ERROR_INIT for error.

References AT25_SUCCESS, and at25dfx_spi_init().

Referenced by main(), and run_test_at25dfx_init().

at25_status_t at25dfx_mem_check ( void  )

Check if the SerialFlash is valid.

It will read the device id from the device and compare the value set in the configuration file.

Returns
AT25_SUCCESS for success, AT25_ERROR_NOT_FOUND for error.

References AT25_ERROR_NOT_FOUND, AT25_SUCCESS, AT25DFX_DEV_ID, and at25dfx_read_dev_id().

Referenced by main(), and run_test_at25dfx_init().

at25_status_t at25dfx_protect_chip ( uint8_t  protect_type)

Protect the SerialFlash device.

Parameters
protect_typeAT25_TYPE_PROTECT to protect the sector, AT25_TYPE_UNPROTECT to unprotect.
Returns
AT25_SUCCESS if the device has been protected; otherwise return the AT25 error code.

References AT25_ERROR, AT25_GLOBAL_PROTECT_VALUE, AT25_STATUS_SPRL, AT25_STATUS_SWP, AT25_SUCCESS, AT25_TYPE_PROTECT, at25dfx_enable_write(), at25dfx_read_status(), and at25dfx_write_status().

Referenced by main(), run_test_at25dfx_data_access(), and run_test_at25dfx_protect().

at25_status_t at25dfx_protect_sector ( uint32_t  address,
uint8_t  protect_type 
)

Protect/unprotect the specific sector.

Parameters
addressAddress to be protected.
protect_typeAT25_TYPE_PROTECT to protect the sector, AT25_TYPE_UNPROTECT to unprotect.
Returns
Sector protect operation status.

References at25_cmd::address, AT25_PROTECT_SECTOR, AT25_TYPE_PROTECT, AT25_UNPROTECT_SECTOR, at25dfx_enable_write(), at25dfx_send_command(), at25_cmd::cmd, at25_cmd::cmd_size, at25_cmd::data, at25_cmd::data_size, and NULL.

Referenced by run_test_at25dfx_protect().

at25_status_t at25dfx_read ( uint8_t *  data,
uint16_t  size,
uint32_t  address 
)

Read data from the specified address on the SerialFlash.

Parameters
dataData buffer.
sizeNumber of bytes to read.
addressRead address.
Returns
AT25_SUCCESS if successful; otherwise, failed.

References at25_cmd::address, AT25_ERROR, AT25_READ_ARRAY_LF, at25dfx_send_command(), AT25DFX_SIZE, at25_cmd::cmd, at25_cmd::cmd_size, data, at25_cmd::data, and at25_cmd::data_size.

Referenced by main(), and run_test_at25dfx_data_access().

static at25_status_t at25dfx_read_dev_id ( uint32_t *  dev_id)
static

Read and return the SerialFlash device ID.

Parameters
p_dev_idPointer to the data of the device ID.
Returns
AT25_SUCCESS if the device ID has been read out; otherwise failed.

References at25_cmd::address, AT25_READ_JEDEC_ID, at25dfx_send_command(), at25_cmd::cmd, at25_cmd::cmd_size, at25_cmd::data, and at25_cmd::data_size.

Referenced by at25dfx_mem_check().

at25_status_t at25dfx_read_sector_protect_status ( uint32_t  address)

Read sector protection status.

Parameters
ul_addressSector address to be read.
Returns
Sector protect status, AT25_ERROR when failed.

References at25_cmd::address, AT25_ERROR, AT25_READ_SECTOR_PROT, AT25_SECTOR_PROTECTED, AT25_SECTOR_PROTECTED_VALUE, AT25_SECTOR_UNPROTECTED, AT25_SECTOR_UNPROTECTED_VALUE, at25dfx_send_command(), at25_cmd::cmd, at25_cmd::cmd_size, at25_cmd::data, and at25_cmd::data_size.

Referenced by run_test_at25dfx_protect().

at25_status_t at25dfx_read_status ( uint8_t *  status)

Read and return the status register of the SerialFlash.

Parameters
statusPointer to an AT25 device status.
Returns
AT25_SUCCESS for success, otherwise for error.

References at25_cmd::address, AT25_READ_STATUS, at25dfx_send_command(), at25_cmd::cmd, at25_cmd::cmd_size, at25_cmd::data, at25_cmd::data_size, and status.

Referenced by at25dfx_erase_block(), at25dfx_erase_chip(), at25dfx_protect_chip(), at25dfx_wait_ready(), at25dfx_write(), and run_test_at25dfx_protect().

static at25_status_t at25dfx_send_command ( at25_cmd_t at25cmd)
static

Start an AT25DFx command transfer.

This is a non blocking function. It will return as soon as the transfer is started.

Parameters
pat25_cmd_tPointer to the command transfer request.
Returns
AT25_SUCCESS if the transfer has been started successfully; otherwise return AT25_ERROR_SPI if the driver is in use.

References at25_cmd::address, AT25_BYTE_PAGE_PROGRAM, AT25_ERROR_SPI, AT25_SUCCESS, AT25_WRITE_STATUS, at25dfx_spi_deselect_device(), at25dfx_spi_read_packet(), at25dfx_spi_select_device(), at25dfx_spi_write_packet(), at25_cmd::cmd, at25_cmd::cmd_size, at25_cmd::data, at25_cmd::data_size, and STATUS_OK.

Referenced by at25dfx_enable_write(), at25dfx_erase_block(), at25dfx_erase_chip(), at25dfx_protect_sector(), at25dfx_read(), at25dfx_read_dev_id(), at25dfx_read_sector_protect_status(), at25dfx_read_status(), at25dfx_write(), and at25dfx_write_status().

void at25dfx_set_mem_active ( uint8_t  cs)

Select the SerialFlash by the corresponding chip select.

Parameters
csSerialFlash chip select.

Referenced by main(), and run_test_at25dfx_init().

static at25_status_t at25dfx_wait_ready ( void  )
static

Wait for the SerialFlash device to be ready to accept new commands.

Returns
AT25_SUCCESS if successful; otherwise failed.

References AT25_STATUS_RDYBSY, AT25_STATUS_RDYBSY_READY, AT25_SUCCESS, and at25dfx_read_status().

Referenced by at25dfx_erase_block(), at25dfx_erase_chip(), and at25dfx_write().

at25_status_t at25dfx_write ( uint8_t *  data,
uint16_t  size,
uint32_t  address 
)

Write data at the specified address on the serial firmware SerialFlash.

The page(s) to program must have been erased prior to writing. This function handles page boundary crossing automatically.

Parameters
dataData buffer.
sizeNumber of bytes in buffer.
addressWrite address.
Returns
AT25_SUCCESS if successful; otherwise, return AT25_WRITE_ERROR if there has been an error during the data programming.

References at25_cmd::address, AT25_BYTE_PAGE_PROGRAM, AT25_ERROR, AT25_ERROR_WRITE, AT25_STATUS_EPE, AT25_STATUS_EPE_ERROR, AT25_SUCCESS, at25dfx_enable_write(), AT25DFX_PAGE_SIZE, at25dfx_read_status(), at25dfx_send_command(), AT25DFX_SIZE, at25dfx_wait_ready(), at25_cmd::cmd, at25_cmd::cmd_size, data, at25_cmd::data, at25_cmd::data_size, and Min.

Referenced by main(), and run_test_at25dfx_data_access().

at25_status_t at25dfx_write_status ( uint8_t  status)

Write the given value in the status register of the SerialFlash device.

Parameters
statusStatus to write.
Returns
AT25_SUCCESS if successful; otherwise failed.

References at25_cmd::address, AT25_WRITE_STATUS, at25dfx_send_command(), at25_cmd::cmd, at25_cmd::cmd_size, at25_cmd::data, and at25_cmd::data_size.

Referenced by at25dfx_protect_chip().

uint8_t active_sf_cs = AT25DFX_MEM_ID
static

Activated SerialFlash chip select, default to device 1.