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

Parameters

sdcard_config – The sdcard configuration

Returns

The esp peripheral handle

bool periph_sdcard_is_mounted(esp_periph_handle_t periph)

Check the sdcard is mounted or not.

Parameters

periph[in] The periph

Returns

SDCARD mounted state

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:

enumerator SDCARD_STATUS_UNKNOWN

No event

enumerator SDCARD_STATUS_CARD_DETECT_CHANGE

Detect changes in the card_detect pin

enumerator SDCARD_STATUS_MOUNTED

SDCARD mounted successfully

enumerator SDCARD_STATUS_UNMOUNTED

SDCARD unmounted successfully

enumerator SDCARD_STATUS_MOUNT_ERROR

SDCARD mount error

enumerator 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:

enumerator SD_MODE_SPI

sd_card SPI

enumerator SD_MODE_1_LINE

sd_card 1-line SD mode

enumerator SD_MODE_4_LINE

sd_card 4-line SD mode

enumerator SD_MODE_8_LINE

sd_card 8-line SD mode

enumerator SD_MODE_MAX