Page 1 of 1

How can I edit file located on an SD card connected via SPI?

Posted: Tue May 26, 2020 1:45 pm
by WZab
Hi,

I'm using a simple STM32F411-based board with an SD card connected via SPI (I can't enable SDIO, as it blocks 3 SPI ports!),
To enable that I have copied the sdcard.py driver to the internal flash filesystem and have put the following into main.py:

Code: Select all

    import pyb
    import machine
    import sdcard
    import os
    import sys
    s1=pyb.SPI(1)
    sd1=sdcard.SDCard(s1,cs=machine.Pin('A4'))
    os.mount(sd1,"/sdcard")
    sys.path.append("/sdcard")
 
That allows me to import libraries from the SD card and import scripts. However, I can't easily access scripts on the SD card for editing.
I tried to copy them using the rshell, but rshell says that the /sdcard directory does not exist.
Is there any convenient way to modify the files on so mounted SD card without removing it physically and puting it into the card reader?

TIA & Regards,
Wojtek

Re: How can I edit file located on an SD card connected via SPI?

Posted: Tue May 26, 2020 2:42 pm
by dhylands
Try putting your sdcard initialisation in boot.py rather than main.py. When rshell is running it uses the raw repl and main.py doesn’t run in that scenario

Re: How can I edit file located on an SD card connected via SPI?

Posted: Tue May 26, 2020 3:41 pm
by WZab
Yes, it really helped!
Thanks a lot,
Wojtek