Skip to content

Commit 1662a0b

Browse files
ccccmagicboydpgeorge
authored andcommitted
esp32/machine_sdcard: Add "freq" keyword arg to SDCard constructor.
To allow high speed access.
1 parent 2d1fef7 commit 1662a0b

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

docs/library/machine.SDCard.rst

+3-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ arguments that might need to be set in order to use either a non-standard slot
2323
or a non-standard pin assignment. The exact subset of arguments supported will
2424
vary from platform to platform.
2525

26-
.. class:: SDCard(slot=1, width=1, cd=None, wp=None, sck=None, miso=None, mosi=None, cs=None)
26+
.. class:: SDCard(slot=1, width=1, cd=None, wp=None, sck=None, miso=None, mosi=None, cs=None, freq=20000000)
2727

2828
This class provides access to SD or MMC storage cards using either
2929
a dedicated SD/MMC interface hardware or through an SPI channel.
@@ -50,6 +50,8 @@ vary from platform to platform.
5050
- *mosi* can be used to specify an SPI mosi pin.
5151

5252
- *cs* can be used to specify an SPI chip select pin.
53+
54+
- *freq* selects the SD/MMC interface frequency in Hz (only supported on the ESP32).
5355

5456
Implementation-specific details
5557
-------------------------------

ports/esp32/machine_sdcard.c

+6
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,7 @@ STATIC mp_obj_t machine_sdcard_make_new(const mp_obj_type_t *type, size_t n_args
126126
ARG_mosi,
127127
ARG_sck,
128128
ARG_cs,
129+
ARG_freq,
129130
};
130131
STATIC const mp_arg_t allowed_args[] = {
131132
{ MP_QSTR_slot, MP_ARG_KW_ONLY | MP_ARG_INT, {.u_int = 1} },
@@ -137,6 +138,8 @@ STATIC mp_obj_t machine_sdcard_make_new(const mp_obj_type_t *type, size_t n_args
137138
{ MP_QSTR_mosi, MP_ARG_KW_ONLY | MP_ARG_OBJ, {.u_obj = mp_const_none} },
138139
{ MP_QSTR_sck, MP_ARG_KW_ONLY | MP_ARG_OBJ, {.u_obj = mp_const_none} },
139140
{ MP_QSTR_cs, MP_ARG_KW_ONLY | MP_ARG_OBJ, {.u_obj = mp_const_none} },
141+
// freq is valid for both SPI and SDMMC interfaces
142+
{ MP_QSTR_freq, MP_ARG_KW_ONLY | MP_ARG_INT, {.u_int = 20000000} },
140143
};
141144
mp_arg_val_t arg_vals[MP_ARRAY_SIZE(allowed_args)];
142145
mp_map_t kw_args;
@@ -175,11 +178,14 @@ STATIC mp_obj_t machine_sdcard_make_new(const mp_obj_type_t *type, size_t n_args
175178
self->flags = 0;
176179
// Note that these defaults are macros that expand to structure
177180
// constants so we can't directly assign them to fields.
181+
int freq = arg_vals[ARG_freq].u_int;
178182
if (is_spi) {
179183
sdmmc_host_t _temp_host = SDSPI_HOST_DEFAULT();
184+
_temp_host.max_freq_khz = freq / 1000;
180185
self->host = _temp_host;
181186
} else {
182187
sdmmc_host_t _temp_host = SDMMC_HOST_DEFAULT();
188+
_temp_host.max_freq_khz = freq / 1000;
183189
self->host = _temp_host;
184190
}
185191

0 commit comments

Comments
 (0)