SPI Flash Fileystem API

SPI Flash when enabled is mounted on VFS path /sf with LittleFS filesystem.

Chip Select Selection

On 4G modules, when hardware chipselect is used for SPI flash, it is recommended to provide gpio_cs as -1 or GPIO_PIN_MAX. In other cases a GPIO number can be provided for chipselect.

On 2G modules, only GPIO number is allowed as a valid parameter for chipselect. Even when hardware chipselect line is used, the corresponding GPIO number must provided for gpio_cs.

Example Usage

#include <spifs.h>

/* Enable and mount SPIFS */
/* On RDA8910 based module when hardware CS line is used */
spifs_enable(SPI_PORT_0, -1, 10000000U, SPI_MODE0);

/* On 4G/2G module with GPIO line as chipselect */
spifs_enable(SPI_PORT_0, GPIO_1, 10000000U, SPI_MODE0);

/* Disable and unmount */
spifs_disable();

API Reference

Header File

Source: include/spifs.h

#include <spifs.h>

Functions

int spifs_enable(int port, int gpio_cs, unsigned long speed_hz, int mode)

Enable SPI Flash and mount LFS filesystem

Parameters:
  • port – [in] SPI Port to use

  • gpio_cs – [in] GPIO number connected to SPI chip select

  • speed_hz – [in] SPI Speed in Hz (max 10MHz)

  • mode – [in] SPI mode

Returns:

0 on success, negative value on failure

int spifs_disable(void)

Disable SPI Flash and unmount LFS filesystem

Returns:

0 on success, negative value on failure

int spifs_getstatus(void)

Get status of SPI Flash

Returns:

SPI Flash status see sfstat_e

Enumerations

enum sfstat_e

SPI Flash status

Values:

enumerator SF_STAT_NOTENABLED

SPI Flash not enabled (Either not found or Initialization error)

enumerator SF_STAT_ENABLED

SPI Flash enabled but not mounted (Filesystem mount issue, Try spifs_enable() again

enumerator SF_STAT_MOUNTED

SPI Flash enabled and filesystem is mounted successfully