Block Device Drivers for Littlefs
SPI Flash Block Device Driver

General Description

Note:

Macros

#define LFS_SPI_FLASH_BD_TRACE(...)
 Enable trace for this driver by defining this macro. More...
 

Functions

void lfs_spi_flash_bd_configure_memory (const struct lfs_config *lfs_cfg, uint32_t address, uint32_t region_size)
 Configures the memory region used by littlefs. More...
 
cy_rslt_t lfs_spi_flash_bd_create (struct lfs_config *lfs_cfg, mtb_serial_memory_t *serial_memory_obj)
 Initializes the SPI flash and populates the lfs_config structure with the default values. More...
 
void lfs_spi_flash_bd_destroy (const struct lfs_config *lfs_cfg)
 De-initializes the SPI flash and frees the resources. More...
 
int lfs_spi_flash_bd_read (const struct lfs_config *lfs_cfg, lfs_block_t block, lfs_off_t off, void *buffer, lfs_size_t size)
 Reads the data starting from a given block and offset. More...
 
int lfs_spi_flash_bd_prog (const struct lfs_config *lfs_cfg, lfs_block_t block, lfs_off_t off, const void *buffer, lfs_size_t size)
 Programs or writes the data starting from a given block and offset. More...
 
int lfs_spi_flash_bd_erase (const struct lfs_config *lfs_cfg, lfs_block_t block)
 Erases a given block. More...
 
int lfs_spi_flash_bd_sync (const struct lfs_config *lfs_cfg)
 Flushes the write cache when present. More...
 
int lfs_spi_flash_bd_lock (const struct lfs_config *lfs_cfg)
 Locks or gets the mutex associated with this block device. More...
 
int lfs_spi_flash_bd_unlock (const struct lfs_config *lfs_cfg)
 Unlocks or sets the mutex associated with this block device. More...
 

Macro Definition Documentation

◆ LFS_SPI_FLASH_BD_TRACE

#define LFS_SPI_FLASH_BD_TRACE (   ...)

Enable trace for this driver by defining this macro.

You must also define the global trace enable macro LFS_YES_TRACE.

Function Documentation

◆ lfs_spi_flash_bd_configure_memory()

void lfs_spi_flash_bd_configure_memory ( const struct lfs_config *  lfs_cfg,
uint32_t  address,
uint32_t  region_size 
)

Configures the memory region used by littlefs.

If this function is not called, the littlefs will use the whole size of the memory module. The function must be called before lfs_spi_flash_bd_create(). After de-initialization of littlefs, the settings configured by this function are lost.

Parameters
lfs_cfgThe pointer to the block device configuration structure
addressThe start of a memory region available for littlefs.
region_sizeThe size of a memory region available for littlefs.

◆ lfs_spi_flash_bd_create()

cy_rslt_t lfs_spi_flash_bd_create ( struct lfs_config *  lfs_cfg,
mtb_serial_memory_t *  serial_memory_obj 
)

Initializes the SPI flash and populates the lfs_config structure with the default values.

Parameters
lfs_cfgPointer to the lfs_config structure that will be initialized with the default values.
serial_memory_objPointer to the serial memory object.
Returns
CY_RSLT_SUCCESS if the initialization was successful; an error code otherwise.

◆ lfs_spi_flash_bd_destroy()

void lfs_spi_flash_bd_destroy ( const struct lfs_config *  lfs_cfg)

De-initializes the SPI flash and frees the resources.

Parameters
lfs_cfgPointer to the lfs_config structure.

◆ lfs_spi_flash_bd_read()

int lfs_spi_flash_bd_read ( const struct lfs_config *  lfs_cfg,
lfs_block_t  block,
lfs_off_t  off,
void *  buffer,
lfs_size_t  size 
)

Reads the data starting from a given block and offset.

Calls the non-blocking read API from serial-flash and waits on a semaphore until read completes if COMPONENTS=RTOS_AWARE is added in the makefile. Otherwise, calls the blocking read function.

Parameters
lfs_cfgPointer to the lfs_config structure.
blockBlock number from which read should begin.
offOffset in the block from which read should begin.
bufferPointer to the buffer to store the data read from the memory.
sizeNumber of bytes to read.
Returns
0 if the read was successful; -1 otherwise.

◆ lfs_spi_flash_bd_prog()

int lfs_spi_flash_bd_prog ( const struct lfs_config *  lfs_cfg,
lfs_block_t  block,
lfs_off_t  off,
const void *  buffer,
lfs_size_t  size 
)

Programs or writes the data starting from a given block and offset.

The block must have been previously erased. This is a blocking function.

Parameters
lfs_cfgPointer to the lfs_config structure.
blockBlock number from which write should begin.
offOffset in the block from which write should begin.
bufferPointer to the buffer that contains the data to be written.
sizeNumber of bytes to write.
Returns
0 if the write was successful; -1 otherwise.

◆ lfs_spi_flash_bd_erase()

int lfs_spi_flash_bd_erase ( const struct lfs_config *  lfs_cfg,
lfs_block_t  block 
)

Erases a given block.

A block must be erased before being programmed. This is a blocking function.

Parameters
lfs_cfgPointer to the lfs_config structure.
blockBlock number to be erased.
Returns
0 if the write was successful; -1 otherwise.

◆ lfs_spi_flash_bd_sync()

int lfs_spi_flash_bd_sync ( const struct lfs_config *  lfs_cfg)

Flushes the write cache when present.

Simply returns zero because QSPI block does not have any write cache in MMIO mode.

Parameters
lfs_cfgPointer to the lfs_config structure.
Returns
Always 0.

◆ lfs_spi_flash_bd_lock()

int lfs_spi_flash_bd_lock ( const struct lfs_config *  lfs_cfg)

Locks or gets the mutex associated with this block device.

This function is internally called by the littlefs APIs when LFS_THREADSAFE is defined. User should call this function directly only if the other block device functions are directly called and thread-safety is required in that case.

Parameters
lfs_cfgPointer to the lfs_config structure.
Returns
0 if locking was successful; -1 otherwise.

◆ lfs_spi_flash_bd_unlock()

int lfs_spi_flash_bd_unlock ( const struct lfs_config *  lfs_cfg)

Unlocks or sets the mutex associated with this block device.

This function is internally called by the littlefs APIs when LFS_THREADSAFE is defined. User should call this function directly only if the other block device functions are directly called and thread-safety is required in that case.

Parameters
lfs_cfgPointer to the lfs_config structure.
Returns
0 if unlocking was successful; -1 otherwise.