TB2026-YDS Firmware
Loading...
Searching...
No Matches
microSD card (FATFS over SPI)

Mount/unmount a FAT volume at "/sdcard" and read card presence. More...

Collaboration diagram for microSD card (FATFS over SPI):

Macros

#define SDCARD_MOUNT_POINT   "/sdcard"
 Mount point; prefix every path passed to fopen/fread/fwrite.

Functions

esp_err_t sdcard_mount (void)
 Initialize SPI3, attach the card via sdspi, and mount the FAT volume.
esp_err_t sdcard_unmount (void)
 Unmount the FAT volume and detach the sdspi device.
bool sdcard_present (void)
 Report whether a card is physically inserted (synchronous read of PIN_SD_DETECT).
int sdcard_freq_khz (void)
 Actual SPI clock negotiated with the card by the host, in kHz.

Detailed Description

Mount/unmount a FAT volume at "/sdcard" and read card presence.

Macro Definition Documentation

◆ SDCARD_MOUNT_POINT

#define SDCARD_MOUNT_POINT   "/sdcard"

Mount point; prefix every path passed to fopen/fread/fwrite.

Function Documentation

◆ sdcard_freq_khz()

int sdcard_freq_khz ( void )

Actual SPI clock negotiated with the card by the host, in kHz.

May be lower than the frequency requested at mount (the host rounds down to a reachable divider), so this is the value to trust when checking throughput.

Returns
Frequency in kHz while mounted, 0 otherwise.

◆ sdcard_mount()

esp_err_t sdcard_mount ( void )

Initialize SPI3, attach the card via sdspi, and mount the FAT volume.

Does not auto-format: if the card has no valid FAT, mounting fails and the card is left untouched. After this returns ESP_OK, files are accessible with the POSIX API under SDCARD_MOUNT_POINT.

Returns
ESP_OK on success; ESP_ERR_NOT_FOUND if no card is present; or the underlying SPI/sdspi/FATFS error.

◆ sdcard_present()

bool sdcard_present ( void )

Report whether a card is physically inserted (synchronous read of PIN_SD_DETECT).

Configures the detect GPIO on first call. Safe to call before mounting, e.g. to decide whether sdcard_mount() is worth attempting.

Returns
true if a card is inserted, false otherwise.

◆ sdcard_unmount()

esp_err_t sdcard_unmount ( void )

Unmount the FAT volume and detach the sdspi device.

Flushes FATFS. The SPI3 bus itself stays initialized: on the classic ESP32 both SPI hosts share one DMA clock bit, so freeing SPI3 would stall an in-flight display (SPI2) DMA transfer (see sdcard_mount()).

Returns
ESP_OK on success, or the underlying error.