Microchip® Advanced Software Framework

at25dfx.h File Reference

API driver for AT25DFx SerialFlash component.

Copyright (c) 2012-2018 Microchip Technology Inc. and its subsidiaries.

#include "compiler.h"
#include "conf_at25dfx.h"

Macros

#define AT25_BLOCK_ERASE_32K   0x52
 Block erase command code (32K block) More...
 
#define AT25_BLOCK_ERASE_4K   0x20
 Block erase command code (4K block) More...
 
#define AT25_BLOCK_ERASE_64K   0xD8
 Block erase command code (64K block) More...
 
#define AT25_BYTE_PAGE_PROGRAM   0x02
 Byte/page program command code. More...
 
#define AT25_CHIP_ERASE_1   0x60
 Chip erase command code 1. More...
 
#define AT25_CHIP_ERASE_2   0xC7
 Chip erase command code 2. More...
 
#define AT25_DEEP_PDOWN   0xB9
 Deep power-down command code. More...
 
#define AT25_GLOBAL_PROTECT_VALUE   0x3C
 Global protection data. More...
 
#define AT25_PROTECT_SECTOR   0x36
 Protect sector command code. More...
 
#define AT25_READ_ARRAY   0x0B
 Read array command code. More...
 
#define AT25_READ_ARRAY_LF   0x03
 Read array (low frequency) command code. More...
 
#define AT25_READ_JEDEC_ID   0x9F
 Read manufacturer and device ID command code. More...
 
#define AT25_READ_SECTOR_PROT   0x3C
 Read sector protection registers command code. More...
 
#define AT25_READ_STATUS   0x05
 Read status register command code. More...
 
#define AT25_RES_DEEP_PDOWN   0xAB
 Resume from deep power-down command code. More...
 
#define AT25_SECTOR_PROTECTED_VALUE   0xff
 Sector Protection Register value is 1 (sector is protected) More...
 
#define AT25_SECTOR_UNPROTECTED_VALUE   0x0
 Sector Protection Register value is 0 (sector is unprotected) More...
 
#define AT25_SEQUENTIAL_PROGRAM_1   0xAD
 Sequential program mode command code 1. More...
 
#define AT25_SEQUENTIAL_PROGRAM_2   0xAF
 Sequential program mode command code 2. More...
 
#define AT25_STATUS_EPE   (1 << 5)
 Erase/program error bit. More...
 
#define AT25_STATUS_EPE_ERROR   (1 << 5)
 Erase or program error is detected. More...
 
#define AT25_STATUS_EPE_SUCCESS   (0 << 5)
 Erase or program operation was successful. More...
 
#define AT25_STATUS_RDYBSY   (1 << 0)
 Device ready/busy status bit. More...
 
#define AT25_STATUS_RDYBSY_BUSY   (1 << 0)
 Device is busy with internal operations. More...
 
#define AT25_STATUS_RDYBSY_READY   (0 << 0)
 Device is ready. More...
 
#define AT25_STATUS_SPRL   (1 << 7)
 Sector protection registers locked bit. More...
 
#define AT25_STATUS_SPRL_LOCKED   (1 << 7)
 Sector protection registers are locked. More...
 
#define AT25_STATUS_SPRL_UNLOCKED   (0 << 7)
 Sector protection registers are unlocked. More...
 
#define AT25_STATUS_SWP   (3 << 2)
 Software protection status bitfield. More...
 
#define AT25_STATUS_SWP_PROTALL   (3 << 2)
 All sectors are software protected. More...
 
#define AT25_STATUS_SWP_PROTNONE   (0 << 2)
 No sector is software protected. More...
 
#define AT25_STATUS_SWP_PROTSOME   (1 << 2)
 Some sectors are software protected. More...
 
#define AT25_STATUS_WEL   (1 << 1)
 Write enable latch status bit. More...
 
#define AT25_STATUS_WEL_DISABLED   (0 << 1)
 Device is not write enabled. More...
 
#define AT25_STATUS_WEL_ENABLED   (1 << 1)
 Device is write enabled. More...
 
#define AT25_STATUS_WPP   (1 << 4)
 Write protect pin status bit. More...
 
#define AT25_STATUS_WPP_ASSERTED   (1 << 4)
 Write protect signal is asserted. More...
 
#define AT25_STATUS_WPP_NOTASSERTED   (0 << 4)
 Write protect signal is not asserted. More...
 
#define AT25_TYPE_PROTECT   0x1
 Protect type code. More...
 
#define AT25_TYPE_UNPROTECT   0x0
 Unprotect type code. More...
 
#define AT25_UNPROTECT_SECTOR   0x39
 Unprotect sector command code. More...
 
#define AT25_WRITE_DISABLE   0x04
 Write disable command code. More...
 
#define AT25_WRITE_ENABLE   0x06
 Write enable command code. More...
 
#define AT25_WRITE_STATUS   0x01
 Write status register command code. More...
 
#define AT25DFX_0161   3 /* AT26DF0161 */
 
#define AT25DFX_021   8 /* AT25DF021 */
 
#define AT25DFX_041A   0 /* AT25DF041A */
 Supporting AT25 device type. More...
 
#define AT25DFX_081A   2 /* AT26DF081A */
 
#define AT25DFX_161   1 /* AT25DF161 */
 
#define AT25DFX_161A   4 /* AT26DF161A */
 
#define AT25DFX_321   5 /* AT25DF321 */
 
#define AT25DFX_321A   6 /* AT25DF321A */
 
#define AT25DFX_512B   7 /* AT25DF512B */
 
#define AT25DFX_641A   9 /* AT25DF641A */
 

Typedefs

typedef enum at25_status at25_status_t
 AT25 operation status, each operation returns one of the following status. More...
 

Enumerations

enum  at25_status {
  AT25_SUCCESS = 0,
  AT25_SECTOR_PROTECTED,
  AT25_SECTOR_UNPROTECTED,
  AT25_ERROR_INIT,
  AT25_ERROR_NOT_FOUND,
  AT25_ERROR_WRITE,
  AT25_ERROR_BUSY,
  AT25_ERROR_PROTECTED,
  AT25_ERROR_SPI,
  AT25_ERROR
}
 AT25 operation status, each operation returns one of the following status. More...
 

Functions

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...
 
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...
 
void at25dfx_set_mem_active (uint8_t cs)
 Select the SerialFlash by the corresponding chip select. 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...
 

#define AT25_BLOCK_ERASE_32K   0x52

Block erase command code (32K block)

#define AT25_BLOCK_ERASE_4K   0x20

Block erase command code (4K block)

#define AT25_BLOCK_ERASE_64K   0xD8

Block erase command code (64K block)

#define AT25_BYTE_PAGE_PROGRAM   0x02

Byte/page program command code.

Referenced by at25dfx_send_command(), and at25dfx_write().

#define AT25_CHIP_ERASE_1   0x60

Chip erase command code 1.

#define AT25_CHIP_ERASE_2   0xC7

Chip erase command code 2.

Referenced by at25dfx_erase_chip().

#define AT25_DEEP_PDOWN   0xB9

Deep power-down command code.

#define AT25_GLOBAL_PROTECT_VALUE   0x3C

Global protection data.

Referenced by at25dfx_protect_chip().

#define AT25_PROTECT_SECTOR   0x36

Protect sector command code.

Referenced by at25dfx_protect_sector().

#define AT25_READ_ARRAY   0x0B

Read array command code.

#define AT25_READ_ARRAY_LF   0x03

Read array (low frequency) command code.

Referenced by at25dfx_read().

#define AT25_READ_JEDEC_ID   0x9F

Read manufacturer and device ID command code.

Referenced by at25dfx_read_dev_id().

#define AT25_READ_SECTOR_PROT   0x3C

Read sector protection registers command code.

Referenced by at25dfx_read_sector_protect_status().

#define AT25_READ_STATUS   0x05

Read status register command code.

Referenced by at25dfx_read_status().

#define AT25_RES_DEEP_PDOWN   0xAB

Resume from deep power-down command code.

#define AT25_SECTOR_PROTECTED_VALUE   0xff

Sector Protection Register value is 1 (sector is protected)

Referenced by at25dfx_read_sector_protect_status().

#define AT25_SECTOR_UNPROTECTED_VALUE   0x0

Sector Protection Register value is 0 (sector is unprotected)

Referenced by at25dfx_read_sector_protect_status().

#define AT25_SEQUENTIAL_PROGRAM_1   0xAD

Sequential program mode command code 1.

#define AT25_SEQUENTIAL_PROGRAM_2   0xAF

Sequential program mode command code 2.

#define AT25_STATUS_EPE   (1 << 5)

Erase/program error bit.

Referenced by at25dfx_write().

#define AT25_STATUS_EPE_ERROR   (1 << 5)

Erase or program error is detected.

Referenced by at25dfx_write().

#define AT25_STATUS_EPE_SUCCESS   (0 << 5)

Erase or program operation was successful.

#define AT25_STATUS_RDYBSY   (1 << 0)

Device ready/busy status bit.

Referenced by at25dfx_erase_block(), and at25dfx_wait_ready().

#define AT25_STATUS_RDYBSY_BUSY   (1 << 0)

Device is busy with internal operations.

#define AT25_STATUS_RDYBSY_READY   (0 << 0)

Device is ready.

Referenced by at25dfx_erase_block(), and at25dfx_wait_ready().

#define AT25_STATUS_SPRL   (1 << 7)

Sector protection registers locked bit.

Referenced by at25dfx_protect_chip().

#define AT25_STATUS_SPRL_LOCKED   (1 << 7)

Sector protection registers are locked.

#define AT25_STATUS_SPRL_UNLOCKED   (0 << 7)

Sector protection registers are unlocked.

#define AT25_STATUS_SWP   (3 << 2)

Software protection status bitfield.

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

#define AT25_STATUS_SWP_PROTALL   (3 << 2)

All sectors are software protected.

#define AT25_STATUS_SWP_PROTNONE   (0 << 2)

No sector is software protected.

Referenced by at25dfx_erase_block(), and at25dfx_erase_chip().

#define AT25_STATUS_SWP_PROTSOME   (1 << 2)

Some sectors are software protected.

#define AT25_STATUS_WEL   (1 << 1)

Write enable latch status bit.

#define AT25_STATUS_WEL_DISABLED   (0 << 1)

Device is not write enabled.

#define AT25_STATUS_WEL_ENABLED   (1 << 1)

Device is write enabled.

#define AT25_STATUS_WPP   (1 << 4)

Write protect pin status bit.

#define AT25_STATUS_WPP_ASSERTED   (1 << 4)

Write protect signal is asserted.

#define AT25_STATUS_WPP_NOTASSERTED   (0 << 4)

Write protect signal is not asserted.

#define AT25_TYPE_PROTECT   0x1

Protect type code.

Referenced by at25dfx_protect_chip(), and at25dfx_protect_sector().

#define AT25_TYPE_UNPROTECT   0x0

Unprotect type code.

#define AT25_UNPROTECT_SECTOR   0x39

Unprotect sector command code.

Referenced by at25dfx_protect_sector().

#define AT25_WRITE_DISABLE   0x04

Write disable command code.

#define AT25_WRITE_ENABLE   0x06

Write enable command code.

Referenced by at25dfx_enable_write().

#define AT25_WRITE_STATUS   0x01

Write status register command code.

Referenced by at25dfx_send_command(), and at25dfx_write_status().

#define AT25DFX_0161   3 /* AT26DF0161 */
#define AT25DFX_021   8 /* AT25DF021 */
#define AT25DFX_041A   0 /* AT25DF041A */

Supporting AT25 device type.

#define AT25DFX_081A   2 /* AT26DF081A */
#define AT25DFX_161   1 /* AT25DF161 */
#define AT25DFX_161A   4 /* AT26DF161A */
#define AT25DFX_321   5 /* AT25DF321 */
#define AT25DFX_321A   6 /* AT25DF321A */
#define AT25DFX_512B   7 /* AT25DF512B */
#define AT25DFX_641A   9 /* AT25DF641A */

typedef enum at25_status at25_status_t

AT25 operation status, each operation returns one of the following status.

AT25 operation status, each operation returns one of the following status.

Enumerator
AT25_SUCCESS 
AT25_SECTOR_PROTECTED 

Current operation successful.

AT25_SECTOR_UNPROTECTED 

Sector protected.

AT25_ERROR_INIT 

Sector unprotected.

AT25_ERROR_NOT_FOUND 

Initialization error: p_at25->pdesc is not initialized.

AT25_ERROR_WRITE 

The specific SerialFlash Not found.

AT25_ERROR_BUSY 

Write error returned by the SerialFlash.

AT25_ERROR_PROTECTED 

Current operation failed, SerialFlash is busy.

AT25_ERROR_SPI 

Current operation failed, SerialFlash is protected.

AT25_ERROR 

SPI transfer failed.

Current operation failed