Arduino FatFS
Loading...
Searching...
No Matches
Public Member Functions | Public Attributes | Protected Attributes | List of all members
fatfs::Esp32SdmmcIO Class Reference
Main » IO

Accessing an SD card via the ESP32 SDMMC interface using low-level API. More...

#include <Esp32SdmmcIO.h>

Inheritance diagram for fatfs::Esp32SdmmcIO:
Inheritance graph
[legend]
Collaboration diagram for fatfs::Esp32SdmmcIO:
Collaboration graph
[legend]

Public Member Functions

 Esp32SdmmcIO ()
 Default constructor - card must be initialized with begin()
 
 Esp32SdmmcIO (bool mode1bit, int max_freq_khz=SDMMC_FREQ_DEFAULT)
 Constructor with bus mode and frequency.
 
 Esp32SdmmcIO (bool mode1bit, int max_freq_khz, const sdmmc_host_t &host_cfg, const sdmmc_slot_config_t &slot_cfg)
 Constructor with custom host and slot configuration.
 
 ~Esp32SdmmcIO ()
 Destructor - cleanup resources.
 
bool begin (bool mode1bit=false, int max_freq_khz=SDMMC_FREQ_DEFAULT)
 Initialize the SDMMC interface and mount the SD card.
 
bool begin (bool mode1bit, int max_freq_khz, sdmmc_host_t host_cfg, sdmmc_slot_config_t slot_cfg)
 Initialize with custom host and slot configuration.
 
void end ()
 End SDMMC interface and unmount SD card.
 
DSTATUS disk_initialize (BYTE drv) override
 Initialize disk drive.
 
DSTATUS disk_status (BYTE drv) override
 Get disk status.
 
DRESULT disk_read (BYTE drv, BYTE *buff, LBA_t sector, UINT count) override
 Read sector(s)
 
DRESULT disk_write (BYTE drv, const BYTE *buff, LBA_t sector, UINT count) override
 Write sector(s)
 
DRESULT disk_ioctl (BYTE drv, ioctl_cmd_t cmd, void *buff) override
 Miscellaneous drive controls.
 
uint64_t cardSize () const
 Get the card size in bytes.
 
uint8_t cardType () const
 Get the card type flags.
 
uint64_t totalSectors () const
 Get the total number of sectors.
 
sdmmc_card_t * getCard ()
 Get pointer to the card structure (for advanced use)
 
bool isMMC () const
 Check if card is MMC.
 
uint32_t getFreqKHz () const
 Get card frequency in kHz.
 
virtual FRESULT mount (FatFs &fs)
 mount the file system - implementation at end of header to avoid recursive include
 
virtual FRESULT un_mount (FatFs &fs)
 unmount the file system - implementation at end of header to avoid recursive include
 

Public Attributes

FATFS fatfs
 

Protected Attributes

volatile DSTATUS stat = STA_NOINIT
 Physical drive status.
 
BYTE CardType = 0
 Card type flags.
 
sdmmc_card_t * card
 Pointer to card structure.
 
sdmmc_host_t host_config
 Host configuration.
 
sdmmc_slot_config_t slot_config
 Slot configuration.
 
bool auto_init
 Whether to auto-init on first use.
 
bool init_mode1bit
 Stored 1-bit mode setting.
 
int init_max_freq_khz
 Stored max frequency setting.
 

Detailed Description

Accessing an SD card via the ESP32 SDMMC interface using low-level API.

This driver uses the ESP32's built-in SDMMC controller for high-speed SD card access via the ESP-IDF low-level driver API. It supports both 1-bit and 4-bit bus modes with custom pin configuration.

Example usage:

#include "fatfs.h"
using namespace fatfs;
// Method 1: Default constructor + begin()
Esp32SdmmcIO driver1;
FatFs fs1;
void setup() {
if (!driver1.begin(false, SDMMC_FREQ_DEFAULT)) {
Serial.println("Card Mount Failed");
return;
}
driver1.mount(fs1);
}
// Method 2: Constructor with config (auto-init on mount)
Esp32SdmmcIO driver2(false, SDMMC_FREQ_DEFAULT); // 4-bit, 20MHz
FatFs fs2;
void setup() {
// Card initializes automatically when mounting
driver2.mount(fs2);
}
Accessing an SD card via the ESP32 SDMMC interface using low-level API.
Definition Esp32SdmmcIO.h:60
bool begin(bool mode1bit=false, int max_freq_khz=SDMMC_FREQ_DEFAULT)
Initialize the SDMMC interface and mount the SD card.
Definition Esp32SdmmcIO.h:117
API for FatFS See http://elm-chan.org/fsw/ff/00index_e.html.
Definition ff.h:34
virtual FRESULT mount(FatFs &fs)
mount the file system - implementation at end of header to avoid recursive include
Definition IO.h:100

Constructor & Destructor Documentation

◆ Esp32SdmmcIO() [1/2]

fatfs::Esp32SdmmcIO::Esp32SdmmcIO ( bool  mode1bit,
int  max_freq_khz = SDMMC_FREQ_DEFAULT 
)
inline

Constructor with bus mode and frequency.

Parameters
mode1bitUse 1-bit mode (true) or 4-bit mode (false, default)
max_freq_khzMaximum frequency in kHz (default: SDMMC_FREQ_DEFAULT)

Note: Card initialization is deferred until disk_initialize() is called, or you can call begin() explicitly.

◆ Esp32SdmmcIO() [2/2]

fatfs::Esp32SdmmcIO::Esp32SdmmcIO ( bool  mode1bit,
int  max_freq_khz,
const sdmmc_host_t &  host_cfg,
const sdmmc_slot_config_t &  slot_cfg 
)
inline

Constructor with custom host and slot configuration.

Parameters
mode1bitUse 1-bit mode (true) or 4-bit mode (false)
max_freq_khzMaximum frequency in kHz
host_cfgHost configuration (from SDMMC_HOST_DEFAULT())
slot_cfgSlot configuration (from SDMMC_SLOT_CONFIG_DEFAULT())

Note: Card initialization is deferred until disk_initialize() is called, or you can call begin() explicitly.

Member Function Documentation

◆ begin() [1/2]

bool fatfs::Esp32SdmmcIO::begin ( bool  mode1bit,
int  max_freq_khz,
sdmmc_host_t  host_cfg,
sdmmc_slot_config_t  slot_cfg 
)
inline

Initialize with custom host and slot configuration.

Parameters
mode1bitUse 1-bit mode (true) or 4-bit mode (false)
max_freq_khzMaximum frequency in kHz
host_cfgHost configuration (from SDMMC_HOST_DEFAULT())
slot_cfgSlot configuration (from SDMMC_SLOT_CONFIG_DEFAULT())
Returns
true if initialization succeeded, false otherwise

◆ begin() [2/2]

bool fatfs::Esp32SdmmcIO::begin ( bool  mode1bit = false,
int  max_freq_khz = SDMMC_FREQ_DEFAULT 
)
inline

Initialize the SDMMC interface and mount the SD card.

Parameters
mode1bitUse 1-bit mode (true) or 4-bit mode (false, default)
max_freq_khzMaximum frequency in kHz (default: SDMMC_FREQ_DEFAULT)
Returns
true if initialization succeeded, false otherwise

◆ cardSize()

uint64_t fatfs::Esp32SdmmcIO::cardSize ( ) const
inline

Get the card size in bytes.

Returns
Card size in bytes

◆ cardType()

uint8_t fatfs::Esp32SdmmcIO::cardType ( ) const
inline

Get the card type flags.

Returns
Card type flags (CT_MMC, CT_SD1, CT_SD2, CT_BLOCK)

◆ disk_initialize()

DSTATUS fatfs::Esp32SdmmcIO::disk_initialize ( BYTE  drv)
inlineoverridevirtual

Initialize disk drive.

Parameters
drvPhysical drive number (0)
Returns
Disk status

Reimplemented from fatfs::BaseIO.

◆ disk_ioctl()

DRESULT fatfs::Esp32SdmmcIO::disk_ioctl ( BYTE  drv,
ioctl_cmd_t  cmd,
void *  buff 
)
inlineoverridevirtual

Miscellaneous drive controls.

Parameters
drvPhysical drive number (0)
cmdControl command code
buffPointer to the control data
Returns
Result code

Reimplemented from fatfs::BaseIO.

◆ disk_read()

DRESULT fatfs::Esp32SdmmcIO::disk_read ( BYTE  drv,
BYTE *  buff,
LBA_t  sector,
UINT  count 
)
inlineoverridevirtual

Read sector(s)

Parameters
drvPhysical drive number (0)
buffPointer to the data buffer to store read data
sectorStart sector number (LBA)
countNumber of sectors to read (1..128)
Returns
Result code

Reimplemented from fatfs::BaseIO.

◆ disk_status()

DSTATUS fatfs::Esp32SdmmcIO::disk_status ( BYTE  drv)
inlineoverridevirtual

Get disk status.

Parameters
drvPhysical drive number (0)
Returns
Disk status

Reimplemented from fatfs::BaseIO.

◆ disk_write()

DRESULT fatfs::Esp32SdmmcIO::disk_write ( BYTE  drv,
const BYTE *  buff,
LBA_t  sector,
UINT  count 
)
inlineoverridevirtual

Write sector(s)

Parameters
drvPhysical drive number (0)
buffPointer to the data to write
sectorStart sector number (LBA)
countNumber of sectors to write (1..128)
Returns
Result code

Reimplemented from fatfs::BaseIO.

◆ getCard()

sdmmc_card_t * fatfs::Esp32SdmmcIO::getCard ( )
inline

Get pointer to the card structure (for advanced use)

Returns
Pointer to sdmmc_card_t or nullptr if not initialized

◆ getFreqKHz()

uint32_t fatfs::Esp32SdmmcIO::getFreqKHz ( ) const
inline

Get card frequency in kHz.

Returns
Card operating frequency in kHz

◆ isMMC()

bool fatfs::Esp32SdmmcIO::isMMC ( ) const
inline

Check if card is MMC.

Returns
true if MMC card, false if SD card

◆ mount()

FRESULT fatfs::IO::mount ( FatFs fs)
inlinevirtualinherited

mount the file system - implementation at end of header to avoid recursive include

Reimplemented in fatfs::MultiIO, and fatfs::RamIO.

◆ totalSectors()

uint64_t fatfs::Esp32SdmmcIO::totalSectors ( ) const
inline

Get the total number of sectors.

Returns
Total sectors (0 if not initialized)

◆ un_mount()

FRESULT fatfs::IO::un_mount ( FatFs fs)
inlinevirtualinherited

unmount the file system - implementation at end of header to avoid recursive include

Reimplemented in fatfs::MultiIO.


The documentation for this class was generated from the following file: