Skip to content

Commit 6ab17fb

Browse files
committed
SDMMC enable max open files arg
1 parent e5071e0 commit 6ab17fb

File tree

2 files changed

+15
-4
lines changed

2 files changed

+15
-4
lines changed

libraries/SD_MMC/src/SD_MMC.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ SDMMCFS::SDMMCFS(FSImplPtr impl)
3636
: FS(impl), _card(NULL)
3737
{}
3838

39-
bool SDMMCFS::begin(const char * mountpoint, bool mode1bit, bool format_if_mount_failed)
39+
bool SDMMCFS::begin(const char * mountpoint, bool mode1bit, bool format_if_mount_failed, int sdmmc_frequency, int maxOpenFiles)
4040
{
4141
if(_card) {
4242
return true;
@@ -59,7 +59,7 @@ bool SDMMCFS::begin(const char * mountpoint, bool mode1bit, bool format_if_mount
5959
.io_int_wait = &sdmmc_host_io_int_wait,
6060
.command_timeout_ms = 0
6161
};
62-
host.max_freq_khz = SDMMC_FREQ_HIGHSPEED;
62+
host.max_freq_khz = sdmmc_frequency;
6363
#ifdef BOARD_HAS_1BIT_SDMMC
6464
mode1bit = true;
6565
#endif
@@ -70,7 +70,7 @@ bool SDMMCFS::begin(const char * mountpoint, bool mode1bit, bool format_if_mount
7070

7171
esp_vfs_fat_sdmmc_mount_config_t mount_config = {
7272
.format_if_mount_failed = format_if_mount_failed,
73-
.max_files = 5,
73+
.max_files = maxOpenFiles,
7474
.allocation_unit_size = 0
7575
};
7676

libraries/SD_MMC/src/SD_MMC.h

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,17 @@
1818
#include "driver/sdmmc_types.h"
1919
#include "sd_defines.h"
2020

21+
// If reading/writing to the SD card is unstable,
22+
// you can define BOARD_MAX_SDMMC_FREQ with lower value (Ex. SDMMC_FREQ_DEFAULT)
23+
// in pins_arduino.h for your board variant.
24+
#ifndef BOARD_MAX_SDMMC_FREQ
25+
#define BOARD_MAX_SDMMC_FREQ SDMMC_FREQ_HIGHSPEED
26+
#endif
27+
28+
#ifndef SDMMC_HOST_MAX_FILES_DEFAULT
29+
#define SDMMC_HOST_MAX_FILES_DEFAULT 10
30+
#endif
31+
2132
namespace fs
2233
{
2334

@@ -28,7 +39,7 @@ class SDMMCFS : public FS
2839

2940
public:
3041
SDMMCFS(FSImplPtr impl);
31-
bool begin(const char * mountpoint="/sdcard", bool mode1bit=false, bool format_if_mount_failed=false);
42+
bool begin(const char *mountpoint = "/sdcard", bool mode1bit = false, bool format_if_mount_failed = false, int sdmmc_frequency = BOARD_MAX_SDMMC_FREQ, int maxOpenFiles = SDMMC_HOST_MAX_FILES_DEFAULT);
3243
void end();
3344
sdcard_type_t cardType();
3445
uint64_t cardSize();

0 commit comments

Comments
 (0)