I am trying to format an SD card with an ESP32 connected to an SD card as a SDMMC host. I would like to figure out how to format it as FAT32 within the Arduino framework. Does anyone know if this is possible to do within the Arduino framework? I can create, read, write and delete files, but I cannot figure out how to format an SD Card.
I believe it's possible using Espressif's ESPIDF, but I cannot figue out how to get this working in Arduino. the following page describes the basics of working with an SD Card wired up as an SDMMC host:
This does not cover how to format an SD card wired up this way. I wish I could offer more details on this but I am a loss for where to start. Any and all help is appreciated.
Someone suggested that this might work in espidf:
#include "esp_vfs_fat.h"
#include "driver/sdmmc_host.h"
#include "sdmmc_cmd.h"
#include "SD.h"
void setup() {
Serial.begin(115200);
// Initialize SDMMC host driver
sdmmc_host_t host = SDMMC_HOST_DEFAULT();
sdmmc_slot_config_t slot_config = SDMMC_SLOT_CONFIG_DEFAULT();
esp_vfs_fat_sdmmc_mount_config_t mount_config = {
.format_if_mount_failed = true,
.max_files = 5,
.allocation_unit_size = 16 * 1024
};
sdmmc_card_t* card;
esp_err_t err = esp_vfs_fat_sdmmc_mount("/sdcard", &host, &slot_config, &mount_config, &card);
if (err != ESP_OK) {
Serial.printf("Failed to mount SD card (%s)\n", esp_err_to_name(err));
return;
}
Serial.println("SD card mounted successfully");
// List files in root directory
File root = SD.open("/");
File file = root.openNextFile();
while (file) {
Serial.println(file.name());
file = root.openNextFile();
}
}
void loop() {
}