adafruit / circuitpython

CircuitPython - a Python implementation for teaching coding with microcontrollers
https://circuitpython.org
Other
4.02k stars 1.19k forks source link

ESP32-S2 mounted SD not accessible from PC? #3477

Open emard opened 3 years ago

emard commented 3 years ago

Recent ESP32-S2 release can mount SD card, after setting pinout and SPI, this works storage.mount(vfs, "/sd") os.listdir("/sd") lists files stored on the SD card. ['KERNEL.SYS', 'COMMAND.COM', 'INVADERS.COM', etc..

Now I want to copy a file from PC to the mounted SD card but linux PC usb-storage interface doesn't "see" mounted "/sd" directory

cp README.md /media/guest/CIRCUITPY/sd/ cp: cannot create regular file '/media/guest/CIRCUITPY/sd/': Not a directory

tannewt commented 3 years ago

We don't support the SD card over USB. The USB Mass Storage protocol works on the blocks below the filesystem. So, we'd need to expose the SD card as a second drive (logical unit in USB parlance). It would have the same read/write constraints as the internal flash.

emard commented 3 years ago

OK, let SD-over-USB be a feature request, it's ok for me to appear as another drive.

Intuitively, I have expected this to "just work".

Now I need to first upload file from USB to internal flash, write my own copy.py application, upload it too, then enter python prompt and finally copy this file from flash to SD.

On 9/28/20, Scott Shawcroft notifications@github.com wrote:

We don't support the SD card over USB. The USB Mass Storage protocol works on the blocks below the filesystem. So, we'd need to expose the SD card as a second drive (logical unit in USB parlance). It would have the same read/write constraints as the internal flash.

-- You are receiving this because you authored the thread. Reply to this email directly or view it on GitHub: https://github.com/adafruit/circuitpython/issues/3477#issuecomment-699738273

emard commented 3 years ago

Can you provide some boot or commandline option for usb-storage to be directed towards SD card instead of internal flash?

tannewt commented 3 years ago

Can you provide some boot or commandline option for usb-storage to be directed towards SD card instead of internal flash?

It's not a high priority for us and it's not simple. The native sdcard support is a good start though.

calcut commented 3 years ago

@tannewt I asked about this yesterday in the deep dive chat.

From the discussion here https://github.com/adafruit/circuitpython/issues/2206 with @dhalbert I thought the new CP7 USB endpoint customisation might make this easier.

But sounds like there is another subtlety that makes it tricky. Appreciate it isn't high priority just now.

dhalbert commented 3 years ago

From the discussion here #2206 with @dhalbert I thought the new CP7 USB endpoint customisation might make this easier.

It doesn't really help that much, though the internal structure makes it a bit easier to add another MSC device. But there still has to be code behind that to make the SD card visible, and that's not easy.

Paul-iKarma commented 3 years ago

Newbie question. Was hoping to connect this like a USB memory stick, write jpeg files from the PC and have those changes trigger the posting of file names and sizes to a remote server. Is this possible? Perhaps with some onboard program that might, for example, switch connection of the SD card back and forth between the unit and the PC so the card could take a peek at the new files? Or completely impossible given the current specs? Thanks.

dhalbert commented 3 years ago

See #2206 and #1764 for why this is hard.

lesamouraipourpre commented 3 years ago

For transferring text files to and from the SD card, you can use Thonny (and maybe other editors, eg Mu, but I haven't tried)

Once code.py has run and mounted the SD card, the /sd/ directory shows up when you try to read or write a file to the CircuitPython device. I don't understand how it actually works but it does.

I don't think this can be used for transferring binary files but someone might be able to figure out something.

rgbpcb commented 2 years ago

See #2206 and #1764 for why this is hard.

A newer comment in #2206 says:

This is not an issue with endpoint count. USB MSC can have multiple drives over the same endpoints by using a logical unit (LUN) index.

Is implementing this the hard part? If so, could you please add the option to show the SD card instead of the usual CIRCUITPY filesystem?

For example, boot.py could mount the SD card and read some file from it that says whether the SD card should be shown to the computer instead of the usual CIRCUITPY.

Giving the computer easy access to the SD card (which is by far the largest storage of the device) seems kind of important. :) Thanks!

dhalbert commented 2 years ago

We are working on making multiple drives available. There are some issues about making it work properly on all operating systems, which we're working through.

rgbpcb commented 2 years ago

That's great, thank you! Looking forward to the Windows solution :sweat_smile:

hathach commented 2 years ago

just submit an PR for this #6555