How to access the micro-SD card on F1 starter kit?
-
I tried to access the micro-SD card with the following script:
import machine from machine import Pin sd = machine.SDCard(slot=1, width=4, sck=Pin(42), cmd=Pin(40), data=(Pin(41), Pin(18), Pin(17), Pin(16)), freq=20000000)But that gives the following error:
>>> sd = machine.SDCard(slot=1, width=4, sck=Pin(42), cmd=Pin(40), data=(Pin(41), Pin(18), Pin(17), Pin(16)), freq=20000000) Traceback (most recent call last): File "<stdin>", line 1, in <module> TypeError: extra keyword arguments given`Also this does not work:
>>> sd = machine.SDCard(slot=1, width=4, sck=42, cmd=40, data=(41, 18, 17, 16), freq=20000000) Traceback (most recent call last): File "<stdin>", line 1, in <module> TypeError: extra keyword arguments givenFrom the schematic, I can see that the micro-SD card reader is connected as follows:
CLK >> GPIO42
CMD >> GPIO40
DAT0 >> GPIO41
DAT1 >> GPIO18
DAT2 >> GPIO17
DAT3 >> GPIO16Is that correct?
From the explanation on link text I learned that for ESP32-S3 and using SD/MMC mode, slot 1 allows for the use of 4 data pins (width=4). Correct? -
Hello @jandls,
Please see the following from the MicroPython documentation:

Please note that on the Starter Kit, only 1 of the data pins is connected to the ESP32-S3 as anything else would require a hardware license from the SD Association. You would have to populate R506, R508 and R510 with 0Ohm resistors to connect the GPIO pins and if necessary R500-R502 for the pull-ups.

On the starter kit, you can mount a FAT formatted SD Card like this:
import machine sd = machine.SDCard() os.mount(sd, '/sd') os.listdir('/sd')The pins are hard coded but can be changed here: https://github.com/sg-wireless/sg-sdk/blob/main/src/platforms/F1/mpy-hooks/patches/machine_sdcard.c.patch on custom designs.
-
It would be good if the documentation provided some more information on this hard coding that is done for the F1 starter kit, but that does not apply when the F1 is put on a custom board. There must still be other things that are hardcoded to make the F1 starter kit work, because when I try the following, it doesn’t work:
>>> import machine, os >>> sd = machine.SDCard(slot=3, sck=42, miso=41, mosi=40) >>> os.mount(sd, '/sd') Traceback (most recent call last): File "<stdin>", line 1, in <module> OSError: 16The code that you gave works fine:
>>> import machine >>> sd = machine.SDCard() >>> os.mount(sd, '/sd') >>> os.listdir('/sd') ['System Volume Information', 'rain.csv', 'sensor.csv', 'waterlevel.csv'] -
These are the defaults when using SPI mode according to the MicroPython source code ext/micropython/ports/esp32/machine_sdcard.c
if (is_spi) { // SPI interface #if CONFIG_IDF_TARGET_ESP32S3 STATIC const sdspi_slot_config_t slot_defaults[2] = { { .gpio_miso = GPIO_NUM_36, .gpio_mosi = GPIO_NUM_35, .gpio_sck = GPIO_NUM_37, .gpio_cs = GPIO_NUM_34, .gpio_cd = SDSPI_SLOT_NO_CD, .gpio_wp = SDSPI_SLOT_NO_WP, .dma_channel = 2 }, SDSPI_SLOT_CONFIG_DEFAULT() };