How to view changes to micro-SD card in real-time in Windows File Explorer

The official PYBD running MicroPython, and its accessories.
Target audience: Users with a PYBD
Post Reply
kbrenner
Posts: 46
Joined: Mon Jan 20, 2020 8:05 pm

How to view changes to micro-SD card in real-time in Windows File Explorer

Post by kbrenner » Wed Jan 19, 2022 5:05 pm

I currently have the micro-SD on the SF6W exposed in Windows File Explorer by calling the following line in boot.py:

Code: Select all

pyb.usb_mode('VCP+MSC',msc=(pyb.Flash(), pyb.SDCard()))
However, when I make a modification to one or more of the contents of the SD card, it is not immediately reflected in File Explorer. I can view the changes in the REPL prompt. The only way I can view these changes in File Explorer is by unplugging the Pyboard from the PC and then plugging it back in.

Is there an alternative solution than this method? I ask because the act of unplugging/replugging the Pyboard requires opening up a new REPL prompt each time.

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

Re: How to view changes to micro-SD card in real-time in Windows File Explorer

Post by dhylands » Wed Jan 19, 2022 7:45 pm

Yeah - Windows thinks that it's the exclusive owner of the SD card when you use MSC and it will be blissfully unaware of writes made by micropython.

You should disable MSC if you want MicroPython to write to the SD, otherwise you run the risk of corrupting it.

You can use something like rshell or mpremote to see things from MicroPython's point of view.

kbrenner
Posts: 46
Joined: Mon Jan 20, 2020 8:05 pm

Re: How to view changes to micro-SD card in real-time in Windows File Explorer

Post by kbrenner » Wed Jan 19, 2022 11:49 pm

Thanks, Dave. So does that mean that there really isn't a way to give the Pyboard permission to write to the SD card while still viewing the contents of the SD card in File Explorer without running the risk of corruption?

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

Re: How to view changes to micro-SD card in real-time in Windows File Explorer

Post by dhylands » Thu Jan 20, 2022 12:08 am

That's correct. Having MicroPython write to a volume shared via MSC is basically an invitation for corruption.

Windows will happily overwrite any changes made by MicroPython because it has no way of knowing that the changes occurred.

Even having MicroPython read from a volume shared via MSC may look like corruption as the Windows side may not have flushed out all of its changes yet. For example, when copying files from the host via MSC, quite often a reset is required of the MicroPython board before the changes are seen on the MicroPython board.

Post Reply