← index #8290Issue #8949
Related · high · value 1.146
QUERY · ISSUE

ESP32: SDCard throws Errors

openby Narsskrarcopened 2022-02-10updated 2024-09-08
needs-info

Hi,

I try to access a SD card with MP V 1.18. The reader is connected to slot 2. The hardware seem to work (tested with an ESP32 with C code). It's a 8GB SDHC formatted with FAT32.

I do
sd = SDCard(slot=2)

Now
sd.info()
throws
OSError: (-265, 'ESP_ERR_INVALID_CRC')

and
os.mount(sd, "/sd")
throws
OSError: 16

16 seems to be EBUSY, although this errorcode isn't defined in errno.errorcode... and it doesn't help me either.

What can I do to investigate what goes wrong?

Thanks.

CANDIDATE · ISSUE

ESP32 machine.SDCard() Instantiation throws error on soft reboot: SPI bus already initialized; ESP_ERR_INVALID_STATE

closedby jamesquiltyopened 2022-07-23updated 2022-09-13
bugport-esp32

We're having trouble with microSD card access with MicroPython versions 1.16 through 1.19 on two different revisions of a single-board PCB based on the ESP32-WROVER-B (SPI RAM) with direct connections from the ESP32 pins to the pins of a MEM2075 microSD card connector (PDF). On first power-up, or after a hard reset, the card can be mounted on the REPL with the commands

from machine import SDCard

# PCB Revision A pin configuration:
sd = SDCard(slot=2, sck=13, miso=15, mosi=23, cs=12)

# PCB Revision B pin configuration:
sd = SDCard(slot=2, sck=13, miso=34, mosi=23, cs=12)

The cards can be accessed normally. Once a soft reboot is executed, the code to instantiate the SDCard() class results in an error. An example from a pristine MicroPython 1.19.1 (esp32spiram-20220618-v1.19.1.bin from https://micropython.org/download/esp32spiram/) on a Revision A board:

MicroPython v1.19.1 on 2022-06-18; ESP32 module (spiram) with ESP32
Type "help()" for more information.
>>> from machine import SDCard
>>> sd = SDCard(slot=2, sck=13, miso=15, mosi=23, cs=12)
>>>
MPY: soft reboot
MicroPython v1.19.1 on 2022-06-18; ESP32 module (spiram) with ESP32
Type "help()" for more information.
>>> from machine import SDCard
>>> sd = SDCard(slot=2, sck=13, miso=15, mosi=23, cs=12)
E (xxxxx) spi: spi_bus_initialize(462): SPI bus already initialized.
E (xxxxx) sdspi_host: spi_bus_initialize failed with rc=0x103
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
OSError: (-259, 'ESP_ERR_INVALID_STATE')

where we are not using sd.deinit() because the MicroPython documentation says sd.deinit() is only implemented on the cc3200 port.

This problem does not appear to affect re-instantiating SDCard() after wake from deep sleep, only soft reboot. That said, access to the microSD card is an integral part of remote operation of our device and we feel this problem blocks us from migrating to MicroPython 1.19.1, keeping us on version 1.14. This is, needless to say, a pretty serious problem for us.

We're aware that we're not using the slot 2 pins recommended in class SDCard - ESP32 but we're uncertain whether changing the pin connections on the PCB will resolve the problem. We're using every pin on the ESP32, so changing the microSD card connections will be a non-trivial task. We'll do it if we know it will resolve the SPI bus already initialized error.

We were using MicroPython 1.14 (esp32spiram-idf4-20210202-v1.14.bin) when the boards were developed and did not, and do not, see this error with microSD card access that we see with later versions. The issue causing the errors above appears to have been introduced in version 1.16 of the firmware. Hopefully this provides a clue to the change(s) causing the problem and the potential resolution?

Previous GitHub Issues and MicroPython Forum posts of similar errors on instantiating SDCard() after soft reboot coincide in time with the release of version 1.16:

Keyboard

j / / n
next pair
k / / p
previous pair
1 / / h
show query pane
2 / / l
show candidate pane
c
copy suggested comment
r
toggle reasoning
g i
go to index
?
show this help
esc
close overlays

press ? or esc to close

copied