ESP32-P4 OBC Firmware
ESP-IDF firmware for Plant-B CubeSat OBC
 
Loading...
Searching...
No Matches
SD Card Utilities

Functions

esp_err_t mount_sd_card (void)
 Mount the SD card with LittleFS.
 
void sd_card_log_info (const sdmmc_card_t *card)
 Log information about a mounted SD card.
 
esp_err_t unmount_sd_card (void)
 Unmount the SD card and release associated resources.
 

SD Card Macros

#define SD_PWR_CTRL_LDO_IO_ID   (4)
 GPIO controlling SD power via LDO.
 
#define GPIO_UNUSED   (-1)
 Placeholder for unused GPIO.
 
#define SD_CARD_MOUNT_PATH   ("/littlefs")
 Path where SD card is mounted with VFS.
 
#define SD_CARD_BUS_WIDTH   (4)
 SD card bus width.
 
#define BYTE_DIV   (8)
 Divider to convert bits to bytes.
 

Detailed Description

Useful ESP-IDF wrappers to initialize/deinitialize the file system on SD cards.

The OBC employs the fail-safe LittleFS file system. VFS is used to map standard POSIX calls to LittleFS functions.

Macro Definition Documentation

◆ BYTE_DIV

#define BYTE_DIV   (8)

Divider to convert bits to bytes.

◆ GPIO_UNUSED

#define GPIO_UNUSED   (-1)

Placeholder for unused GPIO.

◆ SD_CARD_BUS_WIDTH

#define SD_CARD_BUS_WIDTH   (4)

SD card bus width.

◆ SD_CARD_MOUNT_PATH

#define SD_CARD_MOUNT_PATH   ("/littlefs")

Path where SD card is mounted with VFS.

◆ SD_PWR_CTRL_LDO_IO_ID

#define SD_PWR_CTRL_LDO_IO_ID   (4)

GPIO controlling SD power via LDO.

Function Documentation

◆ mount_sd_card()

esp_err_t mount_sd_card ( void )

Mount the SD card with LittleFS.

The following steps are performed:

  • SDMMC host creation and SDMMC slot configuration.
  • Enabling on-chip LDO to power the SD card.
  • SD card initialization.
  • LittleFS configuration.
  • Mouting the SD card with LittleFS.
  • Cheking if the SD card has been mounted successfully.
Return values
ESP_OKOn success.
ESP_ERR_INVALID_ARGBad initialization for objects.
ESP_ERR_INVALID_STATEEither the SDMMC host has not been configured or the partition is already mounted / is encrypted.
ESP_ERR_NO_MEMFailed to allocate memory for objects.
ESP_ERR_NOT_FOUNDPartition for LittleFS was not found.
ESP_FAILMount or format failed.
Note
This function provides detailed information / error logs.
Warning
This function must run inside a critical section.

◆ sd_card_log_info()

void sd_card_log_info ( const sdmmc_card_t * card)

Log information about a mounted SD card.

The following information is loged:

  • Name.
  • Type (SDIO, MMC, SDSC, SDHC, SDXC).
  • Current speed and speed limit.
  • Size.
  • Version, sector size, capacity and read block lenght.
  • Bus width.
  • Specs specific to SD card types.
Parameters
[in]cardPointer to a SD card descriptor.
Warning
This function must run inside a critical section.

◆ unmount_sd_card()

esp_err_t unmount_sd_card ( void )

Unmount the SD card and release associated resources.

Safely unmounts the LittleFS file system and powers down the SD card.

Return values
ESP_OKOn success.
ESP_ERR_INVALID_ARGLDO instance is invalid.
ESP_ERR_INVALID_STATESDMMC host in not initialized or is unregistered.
Warning
This function must run inside a critical section.