Skip to content

Commit

Permalink
Merge pull request #170 from huming2207/master
Browse files Browse the repository at this point in the history
SD card (sdmmc driver) support
  • Loading branch information
BrianPugh authored Jan 15, 2024
2 parents 235e781 + ca0e139 commit 1083230
Show file tree
Hide file tree
Showing 7 changed files with 481 additions and 35 deletions.
8 changes: 6 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,14 +1,18 @@
cmake_minimum_required(VERSION 3.10)

file(GLOB SOURCES src/littlefs/*.c)
list(APPEND SOURCES src/esp_littlefs.c src/littlefs_api.c src/lfs_config.c)
list(APPEND SOURCES src/esp_littlefs.c src/littlefs_esp_part.c src/lfs_config.c)

if(CONFIG_LITTLEFS_SDMMC_SUPPORT)
list(APPEND SOURCES src/littlefs_sdmmc.c)
endif()

if(IDF_VERSION_MAJOR GREATER_EQUAL 5)
list(APPEND pub_requires esp_partition)
else()
list(APPEND pub_requires spi_flash)
endif()
list(APPEND priv_requires esptool_py spi_flash vfs)
list(APPEND priv_requires esptool_py spi_flash vfs sdmmc)

idf_component_register(
SRCS ${SOURCES}
Expand Down
7 changes: 7 additions & 0 deletions Kconfig
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
menu "LittleFS"

config LITTLEFS_SDMMC_SUPPORT
bool "SDMMC support (requires ESP-IDF v5+)"
default n
help
Toggle SD card support
This requires IDF v5+ as older ESP-IDF do not support SD card erase.

config LITTLEFS_MAX_PARTITIONS
int "Maximum Number of Partitions"
default 3
Expand Down
62 changes: 62 additions & 0 deletions include/esp_littlefs.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@
#include <stdbool.h>
#include "esp_partition.h"

#ifdef CONFIG_LITTLEFS_SDMMC_SUPPORT
#include <sdmmc_cmd.h>
#endif

#ifdef __cplusplus
extern "C" {
#endif
Expand All @@ -26,6 +30,11 @@ typedef struct {
const char *base_path; /**< Mounting point. */
const char *partition_label; /**< Label of partition to use. */
const esp_partition_t* partition; /**< partition to use if partition_label is NULL */

#ifdef CONFIG_LITTLEFS_SDMMC_SUPPORT
sdmmc_card_t *sdcard; /**< SD card handle to use if both esp_partition handle & partition label is NULL */
#endif

uint8_t format_if_mount_failed:1; /**< Format the file system if it fails to mount. */
uint8_t read_only : 1; /**< Mount the partition as read-only. */
uint8_t dont_mount:1; /**< Don't attempt to mount.*/
Expand Down Expand Up @@ -57,6 +66,19 @@ esp_err_t esp_vfs_littlefs_register(const esp_vfs_littlefs_conf_t * conf);
*/
esp_err_t esp_vfs_littlefs_unregister(const char* partition_label);

#ifdef CONFIG_LITTLEFS_SDMMC_SUPPORT
/**
* Unregister and unmount LittleFS from VFS for SD card
*
* @param sdcard SD card to unregister.
*
* @return
* - ESP_OK if successful
* - ESP_ERR_INVALID_STATE already unregistered
*/
esp_err_t esp_vfs_littlefs_unregister_sdmmc(sdmmc_card_t *sdcard);
#endif

/**
* Unregister and unmount littlefs from VFS
*
Expand Down Expand Up @@ -90,6 +112,19 @@ bool esp_littlefs_mounted(const char* partition_label);
*/
bool esp_littlefs_partition_mounted(const esp_partition_t* partition);

#ifdef CONFIG_LITTLEFS_SDMMC_SUPPORT
/**
* Check if littlefs is mounted
*
* @param sdcard SD card to check.
*
* @return
* - true if mounted
* - false if not mounted
*/
bool esp_littlefs_sdmmc_mounted(sdmmc_card_t *sdcard);
#endif

/**
* Format the littlefs partition
*
Expand All @@ -110,6 +145,18 @@ esp_err_t esp_littlefs_format(const char* partition_label);
*/
esp_err_t esp_littlefs_format_partition(const esp_partition_t* partition);

#ifdef CONFIG_LITTLEFS_SDMMC_SUPPORT
/**
* Format the LittleFS on a SD card
*
* @param sdcard SD card to format
* @return
* - ESP_OK if successful
* - ESP_FAIL on error
*/
esp_err_t esp_littlefs_format_sdmmc(sdmmc_card_t *sdcard);
#endif

/**
* Get information for littlefs
*
Expand All @@ -136,6 +183,21 @@ esp_err_t esp_littlefs_info(const char* partition_label, size_t* total_bytes, si
*/
esp_err_t esp_littlefs_partition_info(const esp_partition_t* partition, size_t *total_bytes, size_t *used_bytes);

#ifdef CONFIG_LITTLEFS_SDMMC_SUPPORT
/**
* Get information for littlefs on SD card
*
* @param[in] sdcard the SD card to get info for.
* @param[out] total_bytes Size of the file system
* @param[out] used_bytes Current used bytes in the file system
*
* @return
* - ESP_OK if success
* - ESP_ERR_INVALID_STATE if not mounted
*/
esp_err_t esp_littlefs_sdmmc_info(sdmmc_card_t *sdcard, size_t *total_bytes, size_t *used_bytes);
#endif

#ifdef __cplusplus
} // extern "C"
#endif
Expand Down
Loading

0 comments on commit 1083230

Please sign in to comment.