SD card not accessible from rshell. SD card not mounted after soft_reset

All ESP32 boards running MicroPython.
Target audience: MicroPython users with an ESP32 board.
Post Reply
User avatar
WZab
Posts: 25
Joined: Tue Jan 21, 2020 7:45 pm

SD card not accessible from rshell. SD card not mounted after soft_reset

Post by WZab » Sat Jul 24, 2021 9:28 am

I use MicroPython on a ESP32-based TTGO Lora32 V2 board https://pl.aliexpress.com/item/32846302183.html .
I mount the SD card with the following code:

Code: Select all

import machine
import uos
uos.mount(machine.SDCard(slot=2,width=1,sck=14,miso=2,mosi=15,cs=13,freq=20000000), "/sd") 
When I boot the board with minicom connected, the SD card is mounted correctly. However, when I do the soft_reset(), I gest the following errors:

Code: Select all

>>> machine.soft_reset()                                                     
MPY: soft reboot                                                  
E (877674) spi: spi_bus_initialize(462): SPI bus already initialized.
E (877674) sdspi_host: spi_bus_initialize failed with rc=0x103
Traceback (most recent call last):                                              
  File "main.py", line 5, in <module>                                           
OSError: (-259, 'ESP_ERR_INVALID_STATE')                                        
MicroPython v1.16 on 2021-06-23; ESP32 module with ESP32                        
Type "help()" for more information.  
I tried to put the code both into the /boot.py and into the /main.py, results are the same.

As the result, I can't access the SD card from rshell. When I connect the board and start the rshell, the SD card is not mounted.
When I enter the REPL, and issue the reset() command, I get:

Code: Select all

>>> import machine
>>> machine.reset()
ets Jun  8 2016 00:22:57

rst:0xc (SW_CPU_RESET),boot:0x13 (SPI_FAST_FLASH_BOOT)
configsip: 188777542, SPIWP:0xee
clk_drv:0x00,q_drv:0x00,d_drv:0x00,cs0_drv:0x00,hd_drv:0x00,wp_drv:0x00
mode:DIO, clock div:2
load:0x3fff0030,len:5640
load:0x40078000,len:12696
load:0x40080400,len:4292
entry 0x400806b0
MicroPython v1.16 on 2021-06-23; ESP32 module with ESP32
Type "help()" for more information.
>>> uos.listdir("/sd")
['test1.py', 'test2.py']
However, after I leave REPL with CTRL+X, the SD card is unavailable again.
I tried to deinitialize the SPI interface before initializing and mounting the SDCard in /boot.py:

Code: Select all

import machine
import uos
spi=machine.SPI(1,sck=machine.Pin(14),miso=machine.Pin(2),mosi=machine.Pin(15))
spi.deinit()
uos.mount(machine.SDCard(slot=2,width=1,sck=14,miso=2,mosi=15,cs=13,freq=20000000), "/sd") 
but it also leads to an error:

Code: Select all

E (468260) sdspi_host: Bus already initialized. Call `sdspi_host_init_dev` to attach an sdspi device to an initialized bus.
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
OSError: (-259, 'ESP_ERR_INVALID_STATE')
How should I handle the SPI and SDCard to ensure that they are properly handled during the soft_reset, and that rshell may access SD and transfer files to/from it?

Post Reply