Core2 for AWS IoT EduKit BSP 1.5.1
Core2ForAWS_SDcard_Mount
esp_err_t Core2ForAWS_SDcard_Mount(const char *mount_path, sdmmc_card_t **out_card);
esp_err_t Core2ForAWS_SDcard_Mount(const char *mount_path, sdmmc_card_t **out_card)
Initializes and mounts the SD-Card.
Definition: core2forAWS.c:102

Initializes and mounts the SD-Card.

Note
The SD Card must be mounted before use. The SD card and the screen uses the same SPI bus. In order to avoid conflicts with the screen, you must take the spi_mutex semaphore, then call spi_poll() before accessing the SD card. Once done, give/free the semaphore so the display can take it. The display task will then continue to update the display controller on the SPI bus.

Reading/writing to an inserted SD card can use the standard C functions fopen or fprintf to work with Espressif's virtual file drivers. Visit Espressif's virtual file system component docs for usage.

The example code below, mounts the SD card and then writes a file named hello.txt on the path /sdcard with the contents "Hello <<YOUR SD CARD'S PRODUCT NAME>>!":

Example:

#define MOUNT_POINT "/sdcard"
sdmmc_card_t* card;
esp_err_t err;
xSemaphoreTake(spi_mutex, portMAX_DELAY);
err = Core2ForAWS_Sdcard_Mount(MOUNT_POINT, &card);
FILE* f = fopen(MOUNT_POINT"/hello.txt", "w+")
fprintf(f, "Hello %s!\n", card->cid.name);
fclose(f);
xSemaphoreGive(spi_mutex);
void spi_poll()
Polls the SPI bus for a pending SPI transaction to complete.
Definition: disp_spi.c:34
SemaphoreHandle_t spi_mutex
Semaphore for the shared SPI bus.
Definition: disp_spi.c:21
Parameters
[in]mount_pathThe path where partition should be registered.
[out]out_cardThe pointer to the card information structure. Hold this handle and use it to unmount the card later if needed.
Returns
esp_err_t. 0 or ESP_OK if successful.