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
Code: Select all
from machine import SDCard
# Revision A board pin configuration use:
sd = SDCard(slot=2, sck=13, miso=15, mosi=23, cs=12)
# Revision B board pin configuration use:
sd = SDCard(slot=2, sck=13, miso=34, mosi=23, cs=12)
Code: Select all
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')
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 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 forum posts and GitHub Issues of similar errors on instantiating SDCard() after soft reboot coincide in time with the release of version 1.16:
- SD card not accessible from rshell. SD card not mounted after soft_reset
- Best practice for remounting sdcard and checking availability
- Oddities with SD
- micropython#7414 micropython 1.16 SD won't mount after umount
- micropython#7352 micropython 1.15 esp32 reboot at SD deinit, comment 863908895
- micropython#4722 sdcard esp32 does not work TTGO T8 V1.8
For example:
- Will reconfiguration of the pins connecting the ESP32 to the MEM2075 to the ESP32 Slot 2 recommended pins certainly resolve the error?
- Should we be doing something specific in our code to manually deinitialise the SPI port as a workaround?
- Is this, perhaps, a problem with the firmware introduced in 1.16 and thus should be raised as an Issue at https://github.com/micropython/micropython/