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

Discussion about programs, libraries and tools that work with MicroPython. Mostly these are provided by a third party.
Target audience: All users and developers of MicroPython.
Post Reply
User avatar
WZab
Posts: 25
Joined: Tue Jan 21, 2020 7:45 pm

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

Post by WZab » Tue May 26, 2020 1:45 pm

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

User avatar
dhylands
Posts: 3821
Joined: Mon Jan 06, 2014 6:08 pm
Location: Peachland, BC, Canada
Contact:

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

Post by dhylands » Tue May 26, 2020 2:42 pm

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

User avatar
WZab
Posts: 25
Joined: Tue Jan 21, 2020 7:45 pm

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

Post by WZab » Tue May 26, 2020 3:41 pm

Yes, it really helped!
Thanks a lot,
Wojtek

Post Reply