SD Card Peripheral

If your board has a SD card connected, use this API to initialize, mount and unmount the card, see functions periph_sdcard_init(), periph_sdcard_mount() and periph_sdcard_unmount(). The data reading / writing is implemented in a separate API described in FatFs Stream.

Application Examples

Implementation of this API is demonstrated in couple of examples:

API Reference

Header File

Functions

esp_periph_handle_t periph_sdcard_init(periph_sdcard_cfg_t *sdcard_config)

Create the sdcard peripheral handle for esp_peripherals.

Note

The handle was created by this function automatically destroy when esp_periph_destroy is called

Return

The esp peripheral handle

Parameters
  • sdcard_config: The sdcard configuration

bool periph_sdcard_is_mounted(esp_periph_handle_t periph)

Check the sdcard is mounted or not.

Return

SDCARD mounted state

Parameters
  • [in] periph: The periph

Structures

struct periph_sdcard_cfg_t

The SD Card Peripheral configuration.

Public Members

int card_detect_pin

Card detect gpio number

const char *root

Base path for vfs

periph_sdcard_mode_t mode

card mode

Enumerations

enum periph_sdcard_event_id_t

Peripheral sdcard event id.

Values:

SDCARD_STATUS_UNKNOWN

No event

SDCARD_STATUS_CARD_DETECT_CHANGE

Detect changes in the card_detect pin

SDCARD_STATUS_MOUNTED

SDCARD mounted successfully

SDCARD_STATUS_UNMOUNTED

SDCARD unmounted successfully

SDCARD_STATUS_MOUNT_ERROR

SDCARD mount error

SDCARD_STATUS_UNMOUNT_ERROR

SDCARD unmount error

enum periph_sdcard_mode_t

SD card mode, SPI, 1-line SD mode, 4-line SD mode.

Values:

SD_MODE_SPI = 0x0

sd_card SPI

SD_MODE_1_LINE = 0x1

sd_card 1-line SD mode

SD_MODE_4_LINE = 0x4

sd_card 4-line SD mode

SD_MODE_8_LINE = 0x8

sd_card 8-line SD mode

SD_MODE_MAX