Microchip® Advanced Software Framework

 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
AT45dbx DataFlash component driver.

This is a driver for the AT45dbX series DataFlash memories.

It provides functions for initialization, read and write operations at byte or sector level. The DataFlash driver can be used either with SPI Master Service or USART_SPI Service. The SPI service configuration depends on AT45DBX_USES_SPI_MASTER_SERVICE or AT45DBX_USES_USART_SPI_SERVICE defined in conf_at45dbx.h.

Dependencies

This driver depends on the following modules:

Macros

#define AT45DBX_SECTOR_BITS   9
 Number of bits for addresses within logical sectors of file system. More...
 
#define AT45DBX_SECTOR_SIZE   (1 << AT45DBX_SECTOR_BITS)
 Logical sector size of file system in bytes. More...
 

Control Functions

static void at45dbx_chipselect_df (uint8_t memidx, bool bSelect)
 Selects or unselects a DF memory. More...
 
static void at45dbx_wait_ready (void)
 

Available AT45DBX Sizes

Number of address bits of available AT45DBX data flash memories.

Note
All memories from page sizes of 256 bytes to 1024 bytes are supported.
#define AT45DBX_500KB   19
 
#define AT45DBX_1MB   20
 
#define AT45DBX_2MB   21
 
#define AT45DBX_4MB   22
 
#define AT45DBX_8MB   23
 

Control Functions

bool at45dbx_init (void)
 Initializes the data flash controller and the SPI channel by which the DF is controlled. More...
 
bool at45dbx_mem_check (void)
 Performs a memory check on all DataFlash memories. More...
 
bool at45dbx_read_sector_open (uint32_t sector)
 Opens a DataFlash memory in read mode at a given sector. More...
 
bool at45dbx_read_byte_open (uint32_t ad)
 Opens a DataFlash memory in read mode at a given byte address. More...
 
void at45dbx_read_close (void)
 Unselects the current DataFlash memory. More...
 
bool at45dbx_write_sector_open (uint32_t sector)
 This function opens a DataFlash memory in write mode at a given sector. More...
 
bool at45dbx_write_byte_open (uint32_t ad)
 This function opens a DataFlash memory in write mode at a given address. More...
 
void at45dbx_write_close (void)
 Fills the end of the current logical sector and launches page programming. More...
 

Single-Byte Access Functions

uint8_t at45dbx_read_byte (void)
 Performs a single byte read from DataFlash memory. More...
 
bool at45dbx_write_byte (uint8_t b)
 Performs a single byte write to DataFlash memory. More...
 

Single-Sector Access Functions

bool at45dbx_read_sector_to_ram (void *ram)
 Reads one DataFlash sector to a RAM buffer. More...
 
bool at45dbx_write_sector_from_ram (const void *ram)
 Writes one DataFlash sector from a RAM buffer. More...
 

Functions to connect the DataFlash driver with the SPI Multiple-Sector Access Functions

void at45dbx_spi_init (void)
 Initialize SPI external resource for AT45dbx DataFlash driver. More...
 
void at45dbx_spi_select_device (uint8_t mem_id)
 Select one external DataFlash component. More...
 
void at45dbx_spi_deselect_device (uint8_t mem_id)
 Unselect one external DataFlash component. More...
 
void at45dbx_spi_write_byte (uint8_t data)
 Send one byte to the DataFlash. More...
 
void at45dbx_spi_read_byte (uint8_t *data)
 Get one byte (read) from the DataFlash. More...
 
void at45dbx_spi_read_packet (void const *data, size_t len)
 Receive a sequence of bytes from a DataFlash. More...
 
void at45dbx_spi_write_packet (void const *data, size_t len)
 Send a sequence of bytes to a DataFlash from. More...
 

#define AT45DBX_1MB   20
#define AT45DBX_2MB   21
#define AT45DBX_4MB   22
#define AT45DBX_500KB   19
#define AT45DBX_8MB   23
#define AT45DBX_SECTOR_BITS   9

Number of bits for addresses within logical sectors of file system.

Referenced by at45dbx_read_byte(), at45dbx_read_sector_open(), at45dbx_usb_read_10(), at45dbx_usb_write_10(), and at45dbx_write_sector_open().

#define AT45DBX_SECTOR_SIZE   (1 << AT45DBX_SECTOR_BITS)

Logical sector size of file system in bytes.

Referenced by at45dbx_usb_read_10(), at45dbx_usb_write_10(), and at45dbx_write_sector_from_ram().

static void at45dbx_chipselect_df ( uint8_t  memidx,
bool  bSelect 
)
static

Selects or unselects a DF memory.

Parameters
memidxMemory ID of DF to select or unselect.
bSelectBoolean indicating whether the DF memory has to be selected.

References at45dbx_spi_deselect_device(), and at45dbx_spi_select_device().

Referenced by at45dbx_mem_check(), at45dbx_read_byte(), at45dbx_read_byte_open(), at45dbx_read_close(), at45dbx_wait_ready(), at45dbx_write_byte(), at45dbx_write_byte_open(), at45dbx_write_close(), and at45dbx_write_sector_from_ram().

bool at45dbx_init ( void  )

Initializes the data flash controller and the SPI channel by which the DF is controlled.

Return values
trueSuccess.
falseFailure.
bool at45dbx_mem_check ( void  )

Performs a memory check on all DataFlash memories.

Return values
trueSuccess.
falseFailure.

References at45dbx_chipselect_df(), AT45DBX_CMDC_RD_STATUS_REG, AT45DBX_MSK_DENSITY, at45dbx_spi_read_byte(), at45dbx_spi_write_byte(), and status.

Referenced by at45dbx_test_unit_ready().

uint8_t at45dbx_read_byte ( void  )

Performs a single byte read from DataFlash memory.

Returns
The read byte.
Note
First call must be preceded by a call to the at45dbx_read_byte_open function.

References at45dbx_busy, AT45DBX_CHIP_UNSELECT, at45dbx_chipselect_df(), at45dbx_gl_ptr_mem, AT45DBX_MSK_PTR_BYTE, at45dbx_read_sector_open(), AT45DBX_SECTOR_BITS, at45dbx_spi_read_byte(), data, and Rd_bitfield.

bool at45dbx_read_byte_open ( uint32_t  ad)

Opens a DataFlash memory in read mode at a given byte address.

Parameters
adStart address.
Return values
trueSuccess.
falseFailure.

References addr, at45dbx_busy, at45dbx_check_address(), at45dbx_chipselect_df(), AT45DBX_CMDA_RD_PAGE, at45dbx_gl_ptr_mem, AT45DBX_MSK_PTR_BYTE, AT45DBX_MSK_PTR_PAGE, at45dbx_spi_write_byte(), at45dbx_wait_ready(), LSB0W, LSB1W, LSB2W, and Rd_bitfield.

Referenced by at45dbx_read_sector_open().

void at45dbx_read_close ( void  )

Unselects the current DataFlash memory.

References at45dbx_busy, AT45DBX_CHIP_UNSELECT, at45dbx_chipselect_df(), and at45dbx_gl_ptr_mem.

Referenced by at45dbx_df_2_ram(), and at45dbx_usb_read_10().

bool at45dbx_read_sector_open ( uint32_t  sector)

Opens a DataFlash memory in read mode at a given sector.

Parameters
sectorStart sector.
Return values
trueSuccess.
falseFailure.
Note
Sector may be page-unaligned (depending on the DataFlash page size).

References at45dbx_check_address(), at45dbx_read_byte_open(), and AT45DBX_SECTOR_BITS.

Referenced by at45dbx_df_2_ram(), at45dbx_read_byte(), and at45dbx_usb_read_10().

bool at45dbx_read_sector_to_ram ( void *  ram)

Reads one DataFlash sector to a RAM buffer.

Data flow is: DataFlash -> RAM.

Parameters
ramPointer to RAM buffer.
Return values
trueSuccess.
falseFailure.
Note
First call must be preceded by a call to the at45dbx_read_sector_open function.

Referenced by at45dbx_df_2_ram(), and at45dbx_usb_read_10().

void at45dbx_spi_deselect_device ( uint8_t  mem_id)
inline

Unselect one external DataFlash component.

Parameters
mem_idThe DataFlash index number.

References AT45DBX_DESELECT, and MREPEAT.

Referenced by at45dbx_chipselect_df().

void at45dbx_spi_init ( void  )
inline

Initialize SPI external resource for AT45dbx DataFlash driver.

This function initializes the DataFlash component as well as the SPI service the memory is connected to.

Precondition
The conf_at45dbx.h file should provide the following information
  • Selection of the SPI service the DataFlash is connected (AT45DBX_USES_SPI_MASTER_SERVICE or AT45DBX_USES_USART_SPI_SERVICE)
  • AT45DBX_MEM_SIZE: The DataFlash type the driver is connected to.
  • AT45DBX_MEM_CNT: The number of DataFlash components (number of chipselect)
  • AT45DBX_SPI_MODULE: The name of the SPI module used by the DataFlash driver
  • AT45DBX_SPI_MASTER_SPEED: The SPI bus speed.

References spi_enable(), spi_is_enabled(), spi_master_init(), and usart_spi_init().

void at45dbx_spi_read_byte ( uint8_t *  data)
inline

Get one byte (read) from the DataFlash.

Returns
The received byte.
Precondition
The DataFlash should be selected first using at45dbx_spi_select_device

References at45dbx_drv_read_packet.

Referenced by at45dbx_mem_check(), at45dbx_read_byte(), and at45dbx_wait_ready().

void at45dbx_spi_read_packet ( void const *  data,
size_t  len 
)
inline

Receive a sequence of bytes from a DataFlash.

Parameters
datadata buffer to read
lenLength of data
Precondition
The DataFlash should be selected first using at45dbx_spi_select_device

References at45dbx_drv_read_packet.

void at45dbx_spi_select_device ( uint8_t  mem_id)
inline

Select one external DataFlash component.

Parameters
mem_idThe DataFlash index number.

References AT45DBX_SELECT, and MREPEAT.

Referenced by at45dbx_chipselect_df().

void at45dbx_spi_write_byte ( uint8_t  data)
inline

Send one byte to the DataFlash.

Parameters
dataThe data byte to send.
Precondition
The DataFlash should be selected first using at45dbx_spi_select_device

References at45dbx_drv_write_packet.

Referenced by at45dbx_mem_check(), at45dbx_read_byte_open(), at45dbx_wait_ready(), at45dbx_write_byte(), at45dbx_write_byte_open(), and at45dbx_write_close().

void at45dbx_spi_write_packet ( void const *  data,
size_t  len 
)
inline

Send a sequence of bytes to a DataFlash from.

Parameters
datadata buffer to write
lenLength of data
Precondition
The DataFlash should be selected first using at45dbx_spi_select_device

References at45dbx_drv_write_packet.

Referenced by at45dbx_write_sector_from_ram().

bool at45dbx_write_byte ( uint8_t  b)

Performs a single byte write to DataFlash memory.

Parameters
bThe byte to write.
Return values
trueSuccess.
falseFailure.
Note
First call must be preceded by a call to the at45dbx_write_byte_open function.

References at45dbx_busy, AT45DBX_CHIP_UNSELECT, at45dbx_chipselect_df(), at45dbx_gl_ptr_mem, AT45DBX_MSK_PTR_BYTE, at45dbx_spi_write_byte(), at45dbx_write_byte_open(), and Rd_bitfield.

bool at45dbx_write_byte_open ( uint32_t  ad)
void at45dbx_write_close ( void  )

Fills the end of the current logical sector and launches page programming.

References at45dbx_busy, AT45DBX_CHIP_UNSELECT, at45dbx_chipselect_df(), at45dbx_gl_ptr_mem, AT45DBX_MSK_PTR_SECTOR, at45dbx_spi_write_byte(), and Rd_bitfield.

Referenced by at45dbx_ram_2_df(), and at45dbx_usb_write_10().

bool at45dbx_write_sector_from_ram ( const void *  ram)

Writes one DataFlash sector from a RAM buffer.

Data flow is: RAM -> DataFlash.

Parameters
ramPointer to RAM buffer.
Return values
trueSuccess.
falseFailure.
Note
First call must be preceded by a call to the at45dbx_write_sector_open function.

References at45dbx_busy, AT45DBX_CHIP_UNSELECT, at45dbx_chipselect_df(), at45dbx_gl_ptr_mem, AT45DBX_MSK_PTR_BYTE, AT45DBX_PAGE_SIZE, AT45DBX_SECTOR_SIZE, at45dbx_spi_write_packet(), at45dbx_write_byte_open(), and Rd_bitfield.

Referenced by at45dbx_ram_2_df(), and at45dbx_usb_write_10().

bool at45dbx_write_sector_open ( uint32_t  sector)

This function opens a DataFlash memory in write mode at a given sector.

Parameters
sectorStart sector.
Return values
trueSuccess.
falseFailure.
Note
Sector may be page-unaligned (depending on the DF page size).
If AT45DBX_PAGE_SIZE > AT45DBX_SECTOR_SIZE, page content is first loaded in buffer to then be partially updated by write byte or write sector functions.

References at45dbx_check_address(), AT45DBX_SECTOR_BITS, and at45dbx_write_byte_open().

Referenced by at45dbx_ram_2_df(), and at45dbx_usb_write_10().