px-lib  0.9.2
Cross-platform embedded library and documentation for 8/16/32-bit microcontrollers
px_at25s.h : Adesto AT25S Serial Flash Driver

Description

Driver that communicates with an Adesto AT25S Serial Flash using SPI.

File(s):

Reference:

Example:

#include "px_board.h"
#include "px_spi.h"
#include "px_at25s.h"
static uint8_t data[PX_AT25S_PAGE_SIZE];
static px_spi_handle_t px_sf_spi_handle;
int main(void)
{
uint8_t status;
uint16_t i;
// Initialise modules
px_spi_open2(&px_sf_spi_handle,
BOARD_SPI_CS_SF,
0x00);
px_at25s_init(&px_at25s_spi_handle);
// Write a page of Serial Flash
for(i = 0; i<PX_AT25S_PAGE_SIZE; i++)
{
data[i] = (uint8_t)(i&0xff);
}
px_at25s_wr_page(data, 0);
// Read a page of Serial Flash
px_at25s_rd_page(data, 0);
}

Macros

#define PX_AT25S_CFG_DEVICE   PX_CFG_DEV_AT25SF041
 Specify device. More...
 
#define PX_AT25S_CFG_DEVICE   PX_CFG_DEV_AT25SF041
 Specify device. More...
 
#define PX_AT25S_CFG_DEVICE   PX_CFG_DEV_AT25SF041
 Specify device. More...
 
#define PX_AT25S_PAGE_SIZE   256
 AT25S page size. More...
 
#define PX_AT25S_FLASH_SIZE_BYTES   (PX_AT25S_PAGES * PX_AT25S_PAGE_SIZE)
 Flash size (in bytes) More...
 
#define PX_AT25S_ADR_MAX   (PX_AT25S_FLASH_SIZE_BYTES - 1)
 Maximum adress. More...
 
#define PX_AT25S_MAX_SPI_CLOCK_HZ   33000000
 Maximum SPI Clock rate. More...
 
#define PX_AT25S_SPI_MODE   PX_SPI_MODE0
 SPI Clock / Data phase. More...
 
#define PX_AT25S_SPI_DATA_ORDER   PX_SPI_DATA_ORDER_MSB
 SPI Data order. More...
 
#define PX_AT25S_CFG_DEVICE   PX_CFG_DEV_AT25SF041
 Specify device. More...
 

Enumerations

enum  px_at25s_block_t
 AT25S block selection. More...
 

Functions

void px_at25s_init (px_spi_handle_t *handle)
 Initialise driver. More...
 
void px_at25s_deep_power_down (void)
 Power down device to minimise power consumption. More...
 
void px_at25s_resume_from_deep_power_down (void)
 Power up device to resume communication. More...
 
void px_at25s_rd (void *buffer, uint32_t address, uint16_t nr_of_bytes)
 Read data from Serial Flash. More...
 
void px_at25s_rd_page (void *buffer, uint16_t page)
 Read a page from Serial Flash. More...
 
void px_at25s_rd_page_offset (void *buffer, uint16_t page, uint8_t start_byte_in_page, uint8_t nr_of_bytes)
 Partial read of data in a page of Serial Flash. More...
 
void px_at25s_wr_page (const void *buffer, uint16_t page)
 Write a page from Serial Flash. More...
 
void px_at25s_wr_page_offset (const void *buffer, uint16_t page, uint8_t start_byte_in_page, uint8_t nr_of_bytes)
 Partial write of data in a page of Serial Flash. More...
 
void px_at25s_erase (px_at25s_block_t block, uint16_t page)
 Erase a block of Serial Flash. More...
 
bool px_at25s_ready (void)
 Check if Serial Flash is ready for the next read or write access. More...
 
uint8_t px_at25s_rd_status_reg1 (void)
 Read status register 1 of the Serial Flash. More...
 
void px_at25s_rd_man_and_dev_id (uint8_t *buffer)
 Read Manufacturer and Device ID. More...
 

List of supported AT25S devices

#define PX_CFG_DEV_AT25SF041   0
 4 Mbit, 2.5-3.6V 104 MHz Standard Serial Flash More...
 
#define PX_CFG_DEV_AT25SF081   1
 8 Mbit, 2.5-3.6V 104 MHz Standard Serial Flash More...
 
#define PX_CFG_DEV_AT25SF161   2
 16 Mbit, 2.5-3.6V 104 MHz Standard Serial Flash More...
 
#define PX_CFG_DEV_AT25SF321   3
 32 Mbit, 2.5-3.6V 104 MHz Standard Serial Flash More...
 
#define PX_CFG_DEV_AT25SF641   4
 64 Mbit, 2.5-3.6V 104 MHz Standard Serial Flash More...
 

AT25S block sizes

#define PX_AT25S_BLOCK_SIZE_4KB   (4 * 1024)
 
#define PX_AT25S_BLOCK_SIZE_32KB   (32 * 1024)
 
#define PX_AT25S_BLOCK_SIZE_64KB   (64 * 1024)
 

Pages per block

#define PX_AT25S_PAGES_PER_BLOCK_4KB   (PX_AT25S_BLOCK_SIZE_4KB / PX_AT25S_PAGE_SIZE)
 
#define PX_AT25S_PAGES_PER_BLOCK_32KB   (PX_AT25S_BLOCK_SIZE_32KB / PX_AT25S_PAGE_SIZE)
 
#define PX_AT25S_PAGES_PER_BLOCK_64KB   (PX_AT25S_BLOCK_SIZE_64KB / PX_AT25S_PAGE_SIZE)
 

Status register 1

#define PX_AT25S_STATUS_REG1_SRP0   7
 Status Register Protection bit 0. More...
 
#define PX_AT25S_STATUS_REG1_SEC   6
 Block Protection. More...
 
#define PX_AT25S_STATUS_REG1_TB   5
 Top or Bottom Protection. More...
 
#define PX_AT25S_STATUS_REG1_BP2   4
 Block Protection bit 2. More...
 
#define PX_AT25S_STATUS_REG1_BP1   3
 Block Protection bit 1. More...
 
#define PX_AT25S_STATUS_REG1_BP0   2
 Block Protection bit 0. More...
 
#define PX_AT25S_STATUS_REG1_WEL   1
 Write Enable Latch Status. More...
 
#define PX_AT25S_STATUS_REG1_BSY   0
 Ready/Busy Status. More...
 

Macro Definition Documentation

◆ PX_AT25S_CFG_DEVICE [1/4]

#define PX_AT25S_CFG_DEVICE   PX_CFG_DEV_AT25SF041

Specify device.

Definition at line 33 of file px_at25s_cfg.h.

◆ PX_AT25S_CFG_DEVICE [2/4]

#define PX_AT25S_CFG_DEVICE   PX_CFG_DEV_AT25SF041

Specify device.

Definition at line 33 of file px_at25s_cfg.h.

◆ PX_AT25S_CFG_DEVICE [3/4]

#define PX_AT25S_CFG_DEVICE   PX_CFG_DEV_AT25SF041

Specify device.

Definition at line 33 of file px_at25s_cfg.h.

◆ PX_CFG_DEV_AT25SF041

#define PX_CFG_DEV_AT25SF041   0

4 Mbit, 2.5-3.6V 104 MHz Standard Serial Flash

Definition at line 59 of file px_at25s.h.

◆ PX_CFG_DEV_AT25SF081

#define PX_CFG_DEV_AT25SF081   1

8 Mbit, 2.5-3.6V 104 MHz Standard Serial Flash

Definition at line 60 of file px_at25s.h.

◆ PX_CFG_DEV_AT25SF161

#define PX_CFG_DEV_AT25SF161   2

16 Mbit, 2.5-3.6V 104 MHz Standard Serial Flash

Definition at line 61 of file px_at25s.h.

◆ PX_CFG_DEV_AT25SF321

#define PX_CFG_DEV_AT25SF321   3

32 Mbit, 2.5-3.6V 104 MHz Standard Serial Flash

Definition at line 62 of file px_at25s.h.

◆ PX_CFG_DEV_AT25SF641

#define PX_CFG_DEV_AT25SF641   4

64 Mbit, 2.5-3.6V 104 MHz Standard Serial Flash

Definition at line 63 of file px_at25s.h.

◆ PX_AT25S_PAGE_SIZE

#define PX_AT25S_PAGE_SIZE   256

AT25S page size.

Definition at line 67 of file px_at25s.h.

◆ PX_AT25S_FLASH_SIZE_BYTES

#define PX_AT25S_FLASH_SIZE_BYTES   (PX_AT25S_PAGES * PX_AT25S_PAGE_SIZE)

Flash size (in bytes)

Definition at line 107 of file px_at25s.h.

◆ PX_AT25S_ADR_MAX

#define PX_AT25S_ADR_MAX   (PX_AT25S_FLASH_SIZE_BYTES - 1)

Maximum adress.

Definition at line 110 of file px_at25s.h.

◆ PX_AT25S_STATUS_REG1_SRP0

#define PX_AT25S_STATUS_REG1_SRP0   7

Status Register Protection bit 0.

Definition at line 114 of file px_at25s.h.

◆ PX_AT25S_STATUS_REG1_SEC

#define PX_AT25S_STATUS_REG1_SEC   6

Block Protection.

Definition at line 115 of file px_at25s.h.

◆ PX_AT25S_STATUS_REG1_TB

#define PX_AT25S_STATUS_REG1_TB   5

Top or Bottom Protection.

Definition at line 116 of file px_at25s.h.

◆ PX_AT25S_STATUS_REG1_BP2

#define PX_AT25S_STATUS_REG1_BP2   4

Block Protection bit 2.

Definition at line 117 of file px_at25s.h.

◆ PX_AT25S_STATUS_REG1_BP1

#define PX_AT25S_STATUS_REG1_BP1   3

Block Protection bit 1.

Definition at line 118 of file px_at25s.h.

◆ PX_AT25S_STATUS_REG1_BP0

#define PX_AT25S_STATUS_REG1_BP0   2

Block Protection bit 0.

Definition at line 119 of file px_at25s.h.

◆ PX_AT25S_STATUS_REG1_WEL

#define PX_AT25S_STATUS_REG1_WEL   1

Write Enable Latch Status.

Definition at line 120 of file px_at25s.h.

◆ PX_AT25S_STATUS_REG1_BSY

#define PX_AT25S_STATUS_REG1_BSY   0

Ready/Busy Status.

Definition at line 121 of file px_at25s.h.

◆ PX_AT25S_MAX_SPI_CLOCK_HZ

#define PX_AT25S_MAX_SPI_CLOCK_HZ   33000000

Maximum SPI Clock rate.

Definition at line 125 of file px_at25s.h.

◆ PX_AT25S_SPI_MODE

#define PX_AT25S_SPI_MODE   PX_SPI_MODE0

SPI Clock / Data phase.

Definition at line 127 of file px_at25s.h.

◆ PX_AT25S_SPI_DATA_ORDER

#define PX_AT25S_SPI_DATA_ORDER   PX_SPI_DATA_ORDER_MSB

SPI Data order.

Definition at line 129 of file px_at25s.h.

◆ PX_AT25S_CFG_DEVICE [4/4]

#define PX_AT25S_CFG_DEVICE   PX_CFG_DEV_AT25SF041

Specify device.

Definition at line 33 of file px_at25s_cfg_template.h.

Enumeration Type Documentation

◆ px_at25s_block_t

AT25S block selection.

Definition at line 70 of file px_at25s.h.

Function Documentation

◆ px_at25s_init()

void px_at25s_init ( px_spi_handle_t handle)

Initialise driver.

Parameters
handleSPI handle to use for SPI slave device

Definition at line 95 of file px_at25s.c.

◆ px_at25s_deep_power_down()

void px_at25s_deep_power_down ( void  )

Power down device to minimise power consumption.

Definition at line 103 of file px_at25s.c.

◆ px_at25s_resume_from_deep_power_down()

void px_at25s_resume_from_deep_power_down ( void  )

Power up device to resume communication.

Definition at line 111 of file px_at25s.c.

◆ px_at25s_rd()

void px_at25s_rd ( void *  buffer,
uint32_t  address,
uint16_t  nr_of_bytes 
)

Read data from Serial Flash.

This function reads data from Serial Flash and stores it in the specified buffer.

Parameters
bufferBuffer to store read data
address0 to PX_AT25S_ADR_MAX
nr_of_bytesNumber of bytes to read

Definition at line 119 of file px_at25s.c.

◆ px_at25s_rd_page()

void px_at25s_rd_page ( void *  buffer,
uint16_t  page 
)

Read a page from Serial Flash.

This function reads a page of data from Serial Flash and stores it in the specified buffer. The buffer must be at least PX_AT25S_PAGE_SIZE bytes in size to accomodate a full page.

The Serial Flash has PX_AT25S_PAGES pages.

Parameters
[out]bufferBuffer to store read data
[in]page0 to (PX_AT25S_PAGES-1)

Definition at line 141 of file px_at25s.c.

◆ px_at25s_rd_page_offset()

void px_at25s_rd_page_offset ( void *  buffer,
uint16_t  page,
uint8_t  start_byte_in_page,
uint8_t  nr_of_bytes 
)

Partial read of data in a page of Serial Flash.

This function reads part of a page of data from Serial Flash and stores it in the specified buffer. The buffer must be at least nr_of_bytes in size to the read data.

Only read up to the end of the specified page. If the page boundary is exceeded, the index will wrap to the start of the page, i.e. only the content of the specified page will be read.

Parameters
[out]bufferBuffer to store read data
[in]page0 to (PX_AT25S_PAGES-1)
[in]start_byte_in_pageIndex of first byte to read (0 to PX_AT25S_PAGE_SIZE - 1)
[in]nr_of_bytesNumber of bytes to read

Definition at line 148 of file px_at25s.c.

◆ px_at25s_wr_page()

void px_at25s_wr_page ( const void *  buffer,
uint16_t  page 
)

Write a page from Serial Flash.

This function writes a page of data to Serial Flash using the specified buffer as the source. The buffer must contain at least PX_AT25S_PAGE_SIZE bytes of data.

The Serial Flash has PX_AT25S_PAGES pages.

Parameters
[in]bufferBuffer containing data to be written
[in]page0 to (PX_AT25S_PAGES-1)

Definition at line 158 of file px_at25s.c.

◆ px_at25s_wr_page_offset()

void px_at25s_wr_page_offset ( const void *  buffer,
uint16_t  page,
uint8_t  start_byte_in_page,
uint8_t  nr_of_bytes 
)

Partial write of data in a page of Serial Flash.

This function writes a part of a page of data to Serial Flash using the specified buffer as source. The buffer must contain at least nr_of_bytes of data.

Note

Only write up to the end of the specified page. If the page boundary is exceeded, the index will wrap to the start of the page, i.e. only the content of the specified page will be written.

Parameters
[in]bufferBuffer containing data to be written
[in]page0 to (PX_AT25S_PAGES-1)
[in]start_byte_in_pageIndex of first byte to write (0 to PX_AT25S_PAGE_SIZE - 1)
[in]nr_of_bytesNumber of bytes to write

Definition at line 180 of file px_at25s.c.

◆ px_at25s_erase()

void px_at25s_erase ( px_at25s_block_t  block,
uint16_t  page 
)

Erase a block of Serial Flash.

This function erases a block of Serial Flash. The Serial Flash has PX_AT25S_PAGES pages.

Parameters
block4KB, 32KB or 64KB
page0 to (PX_AT25S_PAGES-1); must be an integer multiple of block size

Definition at line 205 of file px_at25s.c.

◆ px_at25s_ready()

bool px_at25s_ready ( void  )

Check if Serial Flash is ready for the next read or write access.

When data is written to Serial Flash, the microcontroller must wait until the operation is finished, before the next one is attempted. This function allows the microcontroller to do something else while waiting for the operation to finish.

Return values
trueSerial Flash is ready for next read or write access.
falseSerial Flash is busy writing.

Definition at line 276 of file px_at25s.c.

◆ px_at25s_rd_status_reg1()

uint8_t px_at25s_rd_status_reg1 ( void  )

Read status register 1 of the Serial Flash.

The status register contains flags, e.g. PX_AT25S_STATUS_REG1_BSY to see if the device is ready or busy with an internal operation.

Returns
uint8_t Status register 1 value

Definition at line 300 of file px_at25s.c.

◆ px_at25s_rd_man_and_dev_id()

void px_at25s_rd_man_and_dev_id ( uint8_t *  buffer)

Read Manufacturer and Device ID.

Parameters
bufferBuffer with a size of 3 bytes to hold manufacturer and device ID

Definition at line 313 of file px_at25s.c.