px-fwlib 0.10.0
Cross-platform embedded library and documentation for 8/16/32-bit microcontrollers generated with Doxygen 1.9.2
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);
}
void px_board_init(void)
Initialise the board hardware.
Definition: px_board.c:168
void px_at25s_init(px_spi_handle_t *handle)
Initialise driver.
Definition: px_at25s.c:95
#define PX_AT25S_PAGE_SIZE
AT25S page size.
Definition: px_at25s.h:67
void px_at25s_rd_page(void *buf, uint16_t page)
Read a page from Serial Flash.
Definition: px_at25s.c:136
void px_at25s_wr_page(const void *buf, uint16_t page)
Write a page from Serial Flash.
Definition: px_at25s.c:149
#define PX_AT25S_SPI_DATA_ORDER
SPI Data order.
Definition: px_at25s.h:129
#define PX_AT25S_SPI_MODE
SPI Clock / Data phase.
Definition: px_at25s.h:127
#define PX_AT25S_MAX_SPI_CLOCK_HZ
Maximum SPI Clock rate.
Definition: px_at25s.h:125
void px_spi_init(void)
Initialise SPI driver.
Definition: px_spi.c:162
bool px_spi_open2(px_spi_handle_t *handle, px_spi_nr_t spi_nr, uint8_t cs_id, px_spi_baud_t baud, px_spi_mode_t mode, px_spi_dord_t data_order, uint8_t mo_dummy_byte)
Open SPI peripheral using specified parameters.
Definition: px_spi.c:252
Define SPI handle.
Definition: px_spi.h:126

Macros

#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 address. 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 *buf, uint32_t adr, uint16_t nr_of_bytes)
 Read data from Serial Flash. More...
 
void px_at25s_rd_page (void *buf, uint16_t page)
 Read a page from Serial Flash. More...
 
void px_at25s_rd_page_offset (void *buf, uint16_t page, uint8_t start_byte_in_page, uint16_t nr_of_bytes)
 Partial read of data in a page of Serial Flash. More...
 
void px_at25s_wr_page (const void *buf, uint16_t page)
 Write a page from Serial Flash. More...
 
void px_at25s_wr_page_offset (const void *buf, uint16_t page, uint8_t start_byte_in_page, uint16_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 *buf)
 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_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 address.

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

#define PX_AT25S_CFG_DEVICE   PX_CFG_DEV_AT25SF041

Specify device.

Definition at line 34 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 *  buf,
uint32_t  adr,
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
bufBuffer to store read data
adr0 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 *  buf,
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]bufBuffer to store read data
[in]page0 to (PX_AT25S_PAGES - 1)

Definition at line 136 of file px_at25s.c.

◆ px_at25s_rd_page_offset()

void px_at25s_rd_page_offset ( void *  buf,
uint16_t  page,
uint8_t  start_byte_in_page,
uint16_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]bufBuffer 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 141 of file px_at25s.c.

◆ px_at25s_wr_page()

void px_at25s_wr_page ( const void *  buf,
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]bufBuffer containing data to be written
[in]page0 to (PX_AT25S_PAGES - 1)

Definition at line 149 of file px_at25s.c.

◆ px_at25s_wr_page_offset()

void px_at25s_wr_page_offset ( const void *  buf,
uint16_t  page,
uint8_t  start_byte_in_page,
uint16_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]bufBuffer 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 168 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 190 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 254 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 278 of file px_at25s.c.

◆ px_at25s_rd_man_and_dev_id()

void px_at25s_rd_man_and_dev_id ( uint8_t *  buf)

Read Manufacturer and Device ID.

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

Definition at line 291 of file px_at25s.c.