px-fwlib 0.10.0
Cross-platform embedded library and documentation for 8/16/32-bit microcontrollers generated with Doxygen 1.9.2
px_at45d.h : Adesto AT45D DataFlash Driver

Description

Driver that communicates with an Adesto AT45D DataFlash using SPI.

File(s):

Reference:

Example:

#include "px_board.h"
#include "px_spi.h"
#include "px_at45d.h"
static uint8_t data[PX_AT45D_PAGE_SIZE];
static px_spi_handle_t px_at45d_spi_handle;
int main(void)
{
uint8_t status;
uint16_t i;
// Initialise modules
px_spi_open2(&px_at45d_spi_handle,
BOARD_SPI_CS_AT45D,
0x00);
px_at45d_init(&px_at45d_spi_handle);
#if PX_AT45D_POWER_OF_TWO_PAGE_SIZE
// Make sure page size is correct
{
// Set page size to a power of two.
// Device must be power cycled for setting to take effect
while(true) {;}
}
#endif
// Write a page of DataFlash
for(i = 0; i < PX_AT45D_PAGE_SIZE; i++)
{
data[i] = (uint8_t)(i & 0xff);
}
px_at45d_wr_page(data, 0);
// Read a page of DataFlash
px_at45d_rd_page(data, 0);
}
void px_board_init(void)
Initialise the board hardware.
Definition: px_board.c:168
#define PX_AT45D_SPI_DATA_ORDER
SPI Data order.
Definition: px_at45d.h:118
void px_at45d_wr_page(const void *buf, uint16_t page)
Write a page from DataFlash.
Definition: px_at45d.c:229
bool px_at45d_set_page_size_to_pwr_of_two(void)
Sets the page size of the DataFlash to a power of two.
Definition: px_at45d.c:366
#define PX_AT45D_MAX_SPI_CLOCK_HZ
Maximum SPI Clock rate.
Definition: px_at45d.h:114
#define PX_AT45D_SPI_MODE
SPI Clock / Data phase.
Definition: px_at45d.h:116
void px_at45d_init(px_spi_handle_t *handle)
Initialise driver.
Definition: px_at45d.c:99
bool px_at45d_page_size_is_pwr_of_two(void)
Check if page size of the DataFlash is a power of two.
Definition: px_at45d.c:350
void px_at45d_rd_page(void *buf, uint16_t page)
Read a page from DataFlash.
Definition: px_at45d.c:184
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_AT45D_FLASH_SIZE_BYTES   (PX_AT45D_PAGES * PX_AT45D_PAGE_SIZE)
 Flash size (in bytes) More...
 
#define PX_AT45D_ADR_MAX   (PX_AT45D_FLASH_SIZE_BYTES - 1)
 Maximum adress. More...
 
#define PX_AT45D_MAX_SPI_CLOCK_HZ   33000000
 Maximum SPI Clock rate. More...
 
#define PX_AT45D_SPI_MODE   PX_SPI_MODE0
 SPI Clock / Data phase. More...
 
#define PX_AT45D_SPI_DATA_ORDER   PX_SPI_DATA_ORDER_MSB
 SPI Data order. More...
 
#define PX_AT45D_CFG_DEVICE   PX_AT45DB041
 Specify device. More...
 
#define PX_AT45D_CFG_PWR_OF_TWO_PAGE_SIZE   0
 Select power of two page size. More...
 

Typedefs

typedef uint32_t px_at45d_adr_t
 Address size can be optimized, depending on maximum size of FLASH. More...
 

Functions

void px_at45d_init (px_spi_handle_t *handle)
 Initialise driver. More...
 
void px_at45d_deep_power_down (void)
 Power down device to minimise power consumption. More...
 
void px_at45d_resume_from_deep_power_down (void)
 Power up device to resume communication. More...
 
void px_at45d_ultra_deep_power_down (void)
 Power down device to minimise power consumption. More...
 
void px_at45d_resume_from_ultra_deep_power_down (void)
 Power up device to resume communication. More...
 
uint16_t px_at45d_rd (void *buf, px_at45d_adr_t adr, uint16_t nr_of_bytes)
 Read data from DataFlash. More...
 
void px_at45d_rd_page (void *buf, uint16_t page)
 Read a page from DataFlash. More...
 
void px_at45d_rd_page_offset (void *buf, uint16_t page, uint16_t start_byte_in_page, uint16_t nr_of_bytes)
 Partial read of data in a page of DataFlash. More...
 
void px_at45d_wr_page (const void *buf, uint16_t page)
 Write a page from DataFlash. More...
 
void px_at45d_wr_page_offset (const void *buf, uint16_t page, uint16_t start_byte_in_page, uint16_t nr_of_bytes)
 Partial write of data in a page of DataFlash. More...
 
void px_at45d_erase (uint16_t page)
 Erase a page of DataFlash. More...
 
bool px_at45d_ready (void)
 Check if DataFlash is ready for the next read or write access. More...
 
uint8_t px_at45d_get_status (void)
 Read the status register of the DataFlash. More...
 
bool px_at45d_page_size_is_pwr_of_two (void)
 Check if page size of the DataFlash is a power of two. More...
 
bool px_at45d_set_page_size_to_pwr_of_two (void)
 Sets the page size of the DataFlash to a power of two. More...
 

List AT45D devices

#define PX_AT45DB011   0
 1M bit, 2.7-Volt Minimum Serial-Interface Flash with One 264-Byte SRAM Buffer More...
 
#define PX_AT45DB021   1
 2M bit, 2.7-Volt Minimum Serial-Interface Flash with One 264-Byte SRAM Buffer More...
 
#define PX_AT45DB041   2
 4M bit 2.5-Volt or 2.7-Volt DataFlash More...
 
#define PX_AT45DB081   3
 8M bit, 2.5 or 2.7-Volt Only Serial-Interface Flash More...
 
#define PX_AT45DB161   4
 16M bit, 2.7-Volt Only Serial-Interface Flash with two SRAM Data Buffers More...
 
#define PX_AT45DB321   5
 32M bit, 2.7-Volt Only Serial Interface Flash More...
 
#define PX_AT45DB642   6
 64M bit, 2.7-Volt Dual-Interface Flash with two 1056-Byte SRAM More...
 

Status register

#define PX_AT45D_STATUS_READY   7
 Ready flag. More...
 
#define PX_AT45D_STATUS_COMP   6
 Compare flag. More...
 
#define PX_AT45D_STATUS_DENSITY_MASK   0x3C
 Density mask. More...
 
#define PX_AT45D_STATUS_PROTECT   1
 Protect flag. More...
 
#define PX_AT45D_STATUS_PAGE_SIZE   0
 Page size flag. More...
 

Macro Definition Documentation

◆ PX_AT45DB011

#define PX_AT45DB011   0

1M bit, 2.7-Volt Minimum Serial-Interface Flash with One 264-Byte SRAM Buffer

Definition at line 62 of file px_at45d.h.

◆ PX_AT45DB021

#define PX_AT45DB021   1

2M bit, 2.7-Volt Minimum Serial-Interface Flash with One 264-Byte SRAM Buffer

Definition at line 63 of file px_at45d.h.

◆ PX_AT45DB041

#define PX_AT45DB041   2

4M bit 2.5-Volt or 2.7-Volt DataFlash

Definition at line 64 of file px_at45d.h.

◆ PX_AT45DB081

#define PX_AT45DB081   3

8M bit, 2.5 or 2.7-Volt Only Serial-Interface Flash

Definition at line 65 of file px_at45d.h.

◆ PX_AT45DB161

#define PX_AT45DB161   4

16M bit, 2.7-Volt Only Serial-Interface Flash with two SRAM Data Buffers

Definition at line 66 of file px_at45d.h.

◆ PX_AT45DB321

#define PX_AT45DB321   5

32M bit, 2.7-Volt Only Serial Interface Flash

Definition at line 67 of file px_at45d.h.

◆ PX_AT45DB642

#define PX_AT45DB642   6

64M bit, 2.7-Volt Dual-Interface Flash with two 1056-Byte SRAM

Definition at line 68 of file px_at45d.h.

◆ PX_AT45D_FLASH_SIZE_BYTES

#define PX_AT45D_FLASH_SIZE_BYTES   (PX_AT45D_PAGES * PX_AT45D_PAGE_SIZE)

Flash size (in bytes)

Definition at line 99 of file px_at45d.h.

◆ PX_AT45D_ADR_MAX

#define PX_AT45D_ADR_MAX   (PX_AT45D_FLASH_SIZE_BYTES - 1)

Maximum adress.

Definition at line 102 of file px_at45d.h.

◆ PX_AT45D_STATUS_READY

#define PX_AT45D_STATUS_READY   7

Ready flag.

Definition at line 106 of file px_at45d.h.

◆ PX_AT45D_STATUS_COMP

#define PX_AT45D_STATUS_COMP   6

Compare flag.

Definition at line 107 of file px_at45d.h.

◆ PX_AT45D_STATUS_DENSITY_MASK

#define PX_AT45D_STATUS_DENSITY_MASK   0x3C

Density mask.

Definition at line 108 of file px_at45d.h.

◆ PX_AT45D_STATUS_PROTECT

#define PX_AT45D_STATUS_PROTECT   1

Protect flag.

Definition at line 109 of file px_at45d.h.

◆ PX_AT45D_STATUS_PAGE_SIZE

#define PX_AT45D_STATUS_PAGE_SIZE   0

Page size flag.

Definition at line 110 of file px_at45d.h.

◆ PX_AT45D_MAX_SPI_CLOCK_HZ

#define PX_AT45D_MAX_SPI_CLOCK_HZ   33000000

Maximum SPI Clock rate.

Definition at line 114 of file px_at45d.h.

◆ PX_AT45D_SPI_MODE

#define PX_AT45D_SPI_MODE   PX_SPI_MODE0

SPI Clock / Data phase.

Definition at line 116 of file px_at45d.h.

◆ PX_AT45D_SPI_DATA_ORDER

#define PX_AT45D_SPI_DATA_ORDER   PX_SPI_DATA_ORDER_MSB

SPI Data order.

Definition at line 118 of file px_at45d.h.

◆ PX_AT45D_CFG_DEVICE

#define PX_AT45D_CFG_DEVICE   PX_AT45DB041

Specify device.

Definition at line 34 of file px_at45d_cfg_template.h.

◆ PX_AT45D_CFG_PWR_OF_TWO_PAGE_SIZE

#define PX_AT45D_CFG_PWR_OF_TWO_PAGE_SIZE   0

Select power of two page size.

"Power of 2" binary page size Configuration Register is a user-programmable nonvolatile register that allows the page size of the main memory to be configured for binary page size or the DataFlash standard page size.

See px_at45d_set_page_size_to_pwr_of_two().

Definition at line 45 of file px_at45d_cfg_template.h.

Typedef Documentation

◆ px_at45d_adr_t

typedef uint32_t px_at45d_adr_t

Address size can be optimized, depending on maximum size of FLASH.

Definition at line 125 of file px_at45d.h.

Function Documentation

◆ px_at45d_init()

void px_at45d_init ( px_spi_handle_t handle)

Initialise driver.

Parameters
handleSPI handle to use for SPI slave device

Definition at line 99 of file px_at45d.c.

◆ px_at45d_deep_power_down()

void px_at45d_deep_power_down ( void  )

Power down device to minimise power consumption.

Definition at line 107 of file px_at45d.c.

◆ px_at45d_resume_from_deep_power_down()

void px_at45d_resume_from_deep_power_down ( void  )

Power up device to resume communication.

Definition at line 115 of file px_at45d.c.

◆ px_at45d_ultra_deep_power_down()

void px_at45d_ultra_deep_power_down ( void  )

Power down device to minimise power consumption.

Definition at line 123 of file px_at45d.c.

◆ px_at45d_resume_from_ultra_deep_power_down()

void px_at45d_resume_from_ultra_deep_power_down ( void  )

Power up device to resume communication.

After this function call, wait at least 120 us (see tXUDPD in datasheet) for DataFlash to wake up, otherwise it will will ignore the commands.

Definition at line 131 of file px_at45d.c.

◆ px_at45d_rd()

uint16_t px_at45d_rd ( void *  buf,
px_at45d_adr_t  adr,
uint16_t  nr_of_bytes 
)

Read data from DataFlash.

This function reads data from DataFlash and stores it in the specified buf.

Parameters
[out]bufBuffer to store read data
[in]adr0 to PX_AT45D_ADR_MAX
[in]nr_of_bytesNumber of bytes to read
Returns
uint16_t Number of bytes actually read

Definition at line 139 of file px_at45d.c.

◆ px_at45d_rd_page()

void px_at45d_rd_page ( void *  buf,
uint16_t  page 
)

Read a page from DataFlash.

This function reads a page of data from DataFlash and stores it in the specified buf. The buf must be at least PX_AT45D_PAGE_SIZE bytes in size to accomodate a full page.

The DataFlash has PX_AT45D_PAGES pages.

Parameters
[out]bufBuffer to store read data
[in]page0 to (PX_AT45D_PAGES - 1)

Definition at line 184 of file px_at45d.c.

◆ px_at45d_rd_page_offset()

void px_at45d_rd_page_offset ( void *  buf,
uint16_t  page,
uint16_t  start_byte_in_page,
uint16_t  nr_of_bytes 
)

Partial read of data in a page of DataFlash.

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

Note

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_AT45D_PAGES - 1)
[in]start_byte_in_pageIndex of first byte to read (0 to PX_AT45D_PAGE_SIZE - 1)
[in]nr_of_bytesNumber of bytes to read

Definition at line 205 of file px_at45d.c.

◆ px_at45d_wr_page()

void px_at45d_wr_page ( const void *  buf,
uint16_t  page 
)

Write a page from DataFlash.

This function writes a page of data to DataFlash using the specified buf as the source. The buf must contain at least PX_AT45D_PAGE_SIZE bytes of data.

The DataFlash has PX_AT45D_PAGES pages.

Parameters
[in]bufBuffer containing data to be written
[in]page0 to (PX_AT45D_PAGES - 1)

Definition at line 229 of file px_at45d.c.

◆ px_at45d_wr_page_offset()

void px_at45d_wr_page_offset ( const void *  buf,
uint16_t  page,
uint16_t  start_byte_in_page,
uint16_t  nr_of_bytes 
)

Partial write of data in a page of DataFlash.

This function writes a part of a page of data to DataFlash using the specified buf as source. The buf 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_AT45D_PAGES - 1)
[in]start_byte_in_pageIndex of first byte to write (0 to PX_AT45D_PAGE_SIZE - 1)
[in]nr_of_bytesNumber of bytes to write

Definition at line 246 of file px_at45d.c.

◆ px_at45d_erase()

void px_at45d_erase ( uint16_t  page)

Erase a page of DataFlash.

This function erases a page of DataFlash. The DataFlash has PX_AT45D_PAGES pages.

Parameters
[in]page0 to (PX_AT45D_PAGES - 1)

Definition at line 296 of file px_at45d.c.

◆ px_at45d_ready()

bool px_at45d_ready ( void  )

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

When data is written to DataFlash, 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
trueDataFlash is ready for next read or write access.
falseDataFlash is busy writing.

Definition at line 313 of file px_at45d.c.

◆ px_at45d_get_status()

uint8_t px_at45d_get_status ( void  )

Read the status register of the DataFlash.

The status register contains flags (e.g. PX_AT45D_STATUS_READY) and the density value (e.g. PX_AT45D_DENSITY). This function can be used to check that a valid and working DataFlash device is connected.

Returns
uint8_t Status register value

Definition at line 337 of file px_at45d.c.

◆ px_at45d_page_size_is_pwr_of_two()

bool px_at45d_page_size_is_pwr_of_two ( void  )

Check if page size of the DataFlash is a power of two.

The status register contains a flag PX_AT45D_STATUS_PAGE_SIZE that reports the page size: 1 = power of two, 0 = not a power of two.

Return values
truePage size is a power of two
falsePage size is not a power of two

Definition at line 350 of file px_at45d.c.

◆ px_at45d_set_page_size_to_pwr_of_two()

bool px_at45d_set_page_size_to_pwr_of_two ( void  )

Sets the page size of the DataFlash to a power of two.

A one-time programmable configuration register is written to configure the device for "power of 2" page size. Once it has been written, it can not be reconfigured again.

The device must be power cycled for this configuration bit to come into effect.

Return values
truepage size was set to a power of two
falsepage size was already set to a power of two

Definition at line 366 of file px_at45d.c.