Core2 for AWS IoT EduKit BSP 1.5.1

The SD Card functions wraps Espressif's virtual file drivers for the SD card slot. Reading/writing to an inserted SD card can use the standard C functions fopen or fprintf. The SD Card must be unmounted before removing if the device is on to avoid data corruption. Visit Espressif's virtual file system component docs for usage. Maximum supported SD is 16GB and requires the use of a FAT/FAT32 partition table and the feature's symbol must be enabled.

Circuit Block Diagram for the SD card slot

To enable this feature using KConfig, use the command pio run --environment core2foraws --target menuconfig from within the root of the project directoy in your PlatformIO terminal window and go to the menu Component Config --> Core2 for AWS features to set the features you want to enable.

This feature requires the ILI9342 display to be enabled.

The SD card and the screen share the same SPI bus. In order to avoid conflicts with the screen, you must take the spi_mutex semaphore, and then call spi_poll() before accessing the SD card. Once done, give the semaphore so that the display can go back to using it.


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

#include "esp_log.h"
#include "core2forAWS.h"
static const char *TAG = "EXAMPLE";
#define MOUNT_POINT "/sdcard"
void app_main(void){
sdmmc_card_t* card;
esp_err_t err;
char file_path[] = MOUNT_POINT"/hello.txt";
xSemaphoreTake(spi_mutex, portMAX_DELAY);
err = Core2ForAWS_SDcard_Mount(MOUNT_POINT, &card);
if(err == ESP_OK){
ESP_LOGI(TAG, "SD Card mounted");
ESP_LOGI(TAG, "SD Card mount error code: %d", err);
FILE* f = fopen(file_path, "w+");
if (f == NULL) {
ESP_LOGE(TAG, "Failed to open file for writing");
fprintf(f, "Hello %s!\n", card->;
ESP_LOGI(TAG, "Reading file %s", file_path);
f = fopen(file_path, "r");
if (f == NULL) {
ESP_LOGE(TAG, "Failed to open file for reading");
char line[64];
fgets(line, sizeof(line), f);
ESP_LOGI(TAG, "Read <- %s", line);
err = Core2ForAWS_SDcard_Unmount(MOUNT_POINT, card);
if(err == ESP_OK){
ESP_LOGI(TAG, "Ejected the SDCard");
ESP_LOGI(TAG, "SDCard eject error code: %d", err);
void Core2ForAWS_Init(void)
Initializes the power chip with default values, enables battery charging, and initializes all enabled...
Definition: core2forAWS.c:32
esp_err_t Core2ForAWS_SDcard_Unmount(const char *mount_path, sdmmc_card_t *out_card)
Removes the FAT partition and unmounts the SD-Card.
Definition: core2forAWS.c:132
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
Functions to initialize and access Core2 for AWS IoT EduKit hardware features.
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
#define TAG
Definition: i2c_device.c:10