machine.SDCard(slot=3) defaults

All ESP32 boards running MicroPython.
Target audience: MicroPython users with an ESP32 board.
Post Reply
Online
User avatar
RobH
Posts: 56
Joined: Fri Mar 23, 2018 3:37 pm
Location: Netherlands
Contact:

machine.SDCard(slot=3) defaults

Post by RobH » Thu Dec 17, 2020 9:53 am

I'm trying to access an SD card to an ESP32 (nodemcu, currently with firmware 1.13-254) with the following code:

Code: Select all

import machine
sd = machine.SDCard(slot=2)
print(sd.info())
This works fine, no need to specify pins when using the defaults.

However to get this working for slot=3 I need to specify mosi, miso and cs, even when using the default pins (13, 12, 15 as documented in the table of https://docs.micropython.org/en/latest/ ... DCard.html).
Without miso I get: OSError: (-264, 'ESP_ERR_INVALID_RESPONSE')
Without mosi I get: OSError: (110, 'ESP_ERR_TIMEOUT')

Strangely enough the sck pin needs not be specified.

It looks to me that machine.SDCard does not have implemented the (correct) defaults for slot=3 (except for sck).

User avatar
jimmo
Posts: 2262
Joined: Tue Aug 08, 2017 1:57 am
Location: Sydney, Australia
Contact:

Re: machine.SDCard(slot=3) defaults

Post by jimmo » Sun Jan 10, 2021 11:40 pm

I think the defaults used for slot=3 are

#define SDSPI_SLOT_CONFIG_DEFAULT() {\
.gpio_miso = GPIO_NUM_2, \
.gpio_mosi = GPIO_NUM_15, \
.gpio_sck = GPIO_NUM_14, \
.gpio_cs = GPIO_NUM_13, \
.gpio_cd = SDSPI_SLOT_NO_CD, \
.gpio_wp = SDSPI_SLOT_NO_WP, \
.gpio_int = GPIO_NUM_NC, \
.dma_channel = 1 \
}
RobH wrote:
Thu Dec 17, 2020 9:53 am
It looks to me that machine.SDCard does not have implemented the (correct) defaults for slot=3 (except for sck).
Looks like there's a typo in the documentation -- miso should be 2, not 12.


Online
User avatar
RobH
Posts: 56
Joined: Fri Mar 23, 2018 3:37 pm
Location: Netherlands
Contact:

Re: machine.SDCard(slot=3) defaults

Post by RobH » Mon Jan 11, 2021 10:56 am

@Jimmo,
Confirmed! Just received a new ESP module with onboard micro SD card connector (TTGO-T8 V1.7). Its pinout picture shows the same numbers for its SPI interface as you mention above. And indeed I can access the SD card by just specifying:

Code: Select all

machine.SDCard(slot=3)
Thanks

Online
User avatar
RobH
Posts: 56
Joined: Fri Mar 23, 2018 3:37 pm
Location: Netherlands
Contact:

Re: machine.SDCard(slot=3) defaults

Post by RobH » Tue Jan 12, 2021 3:06 pm

@jimmo: May I conclude that the default pins for the Hardware SPI bus, esp. for HSPI (id=1) as documented in the Quick Reference for ESP32 are incorrect too?

User avatar
jimmo
Posts: 2262
Joined: Tue Aug 08, 2017 1:57 am
Location: Sydney, Australia
Contact:

Re: machine.SDCard(slot=3) defaults

Post by jimmo » Tue Jan 12, 2021 11:08 pm

RobH wrote:
Tue Jan 12, 2021 3:06 pm
@jimmo: May I conclude that the default pins for the Hardware SPI bus, esp. for HSPI (id=1) as documented in the Quick Reference for ESP32 are incorrect too?
from spi_caps.h in ESP-IDF

Code: Select all

#define HSPI_IOMUX_PIN_NUM_MISO 12
#define HSPI_IOMUX_PIN_NUM_MOSI 13
#define HSPI_IOMUX_PIN_NUM_CLK  14
#define HSPI_IOMUX_PIN_NUM_CS   15
#define HSPI_IOMUX_PIN_NUM_WP   2
#define HSPI_IOMUX_PIN_NUM_HD   4

#define VSPI_IOMUX_PIN_NUM_MISO 19
#define VSPI_IOMUX_PIN_NUM_MOSI 23
#define VSPI_IOMUX_PIN_NUM_CLK  18
#define VSPI_IOMUX_PIN_NUM_CS   5
#define VSPI_IOMUX_PIN_NUM_WP   22
#define VSPI_IOMUX_PIN_NUM_HD   21
Seems fine to me? What are you seeing?

Online
User avatar
RobH
Posts: 56
Joined: Fri Mar 23, 2018 3:37 pm
Location: Netherlands
Contact:

Re: machine.SDCard(slot=3) defaults

Post by RobH » Wed Jan 13, 2021 9:13 am

@jimmo
Well, this pins seems to match the quick ref and the datasheet Table 1 of the ESP32. I'm surprised/confused/would-like-to-understand why machine.SDCard(slot=3) uses different default pins for mosi and miso than machine.SPI(id=1). I expected that these would use the same SPI hardware (HSPI). I'm probably missing knowledge of the ESP32 architecture.

Post Reply