File transfer over USB

jmadsenee
Posts: 30
Joined: Tue Apr 19, 2022 1:16 am

File transfer over USB

Postby jmadsenee » Wed Sep 28, 2022 12:12 am

I am using an ESP32-S3 module in a product that is going to take a number of pictures and other data, store it in jpg and txt files in FLASH memory. Eventually, the product will export the files over BLE to a smartphone. For now, though, I want to connect a PC to the USB port and export the files over USB. Can anyone point me in the right direction of how to best do this? Is there any example code that I can look at?

Thanks so much!

ESP_igrr
Posts: 2072
Joined: Tue Dec 01, 2015 8:37 am

Re: File transfer over USB

Postby ESP_igrr » Wed Sep 28, 2022 7:32 am

Hi jmadsenee,

We don't have an example of USB device MSC class yet, sorry about that.

I happen to have something similar in this personal project: https://github.com/igrr/esp32s2-wasm-de ... mware/main

If you ignore the WebAssembly parts of that application, essentially it allows using a partition in SPI Flash either from the PC (via USB MSC) or from the firmware. The example was made for the ESP32-S2, but should be easy to convert to S3.

jmadsenee
Posts: 30
Joined: Tue Apr 19, 2022 1:16 am

Re: File transfer over USB

Postby jmadsenee » Tue Oct 11, 2022 2:00 am

Hi ESP_igrr,

Thanks so much for your reply!

I'm not really looking to make it an MSC device. What I want to do is be able to talk to it in a command/response kind of way. Some examples are:
  • Request and receive a data file
  • Request and receive a jpg file
  • Set a parameter and receive a response
  • Send a command and receive a response

I suppose I can make the ESP32-S3 a CDC ACM device and make up a protocol and a custom program on my PC to talk to it (say using LabView), but that has a limited data rate.

I seems that there should be a better way to do it. Like put it into USB-OTG mode as a device using some class (I don't know what that is...).

Do you have any thoughts?

chegewara
Posts: 2376
Joined: Wed Jun 14, 2017 9:00 pm

Re: File transfer over USB

Postby chegewara » Tue Oct 11, 2022 11:53 pm

Why not build composite device, MSC + CDC-ACM?

Remyhx
Posts: 23
Joined: Thu Jun 17, 2021 8:22 pm

Re: File transfer over USB

Postby Remyhx » Tue Oct 25, 2022 1:57 pm

ESP_igrr wrote:
Wed Sep 28, 2022 7:32 am
Hi jmadsenee,

We don't have an example of USB device MSC class yet, sorry about that.

I happen to have something similar in this personal project: https://github.com/igrr/esp32s2-wasm-de ... mware/main

If you ignore the WebAssembly parts of that application, essentially it allows using a partition in SPI Flash either from the PC (via USB MSC) or from the firmware. The example was made for the ESP32-S2, but should be easy to convert to S3.
Does this also work with the tinyusb supplied within ESP-IDF 5.0?

ESP_igrr
Posts: 2072
Joined: Tue Dec 01, 2015 8:37 am

Re: File transfer over USB

Postby ESP_igrr » Tue Oct 25, 2022 4:49 pm

The example will probably need some adaptation to IDF v5.0 due to some breaking changes in that version. However it should work, overall. I'll revisit the example once the final v5.0 version is released.

Remyhx
Posts: 23
Joined: Thu Jun 17, 2021 8:22 pm

Re: File transfer over USB

Postby Remyhx » Wed Oct 26, 2022 4:55 pm

@ESP_igrr That would be awesome! Do you think it's possible to use an attached sd-mmc card or chip to redirect to USB? I'm looking for a nice solution to put data on a card or chip and read out by USB. Was also looking at a hardware solution like the MAX14500/14502, but it seems this chip is outdated and I didn't find a replacement yet. Also it adds to cost.

ESP_igrr
Posts: 2072
Joined: Tue Dec 01, 2015 8:37 am

Re: File transfer over USB

Postby ESP_igrr » Wed Oct 26, 2022 8:44 pm

Yes, it should be very similar to that example, except that you would call sdmmc_write_sectors instead of wear_levilling functions.

jmadsenee
Posts: 30
Joined: Tue Apr 19, 2022 1:16 am

Re: File transfer over USB

Postby jmadsenee » Thu Oct 27, 2022 2:07 am

Unfortunately, I am far from being a USB expert, so please forgive my ignorance. I am trying to understand the ESP32-S3 USB. I am using only the internal USB PHY. Depending on where I look, I get conflicting information. The API Guides>>USB OTG Console states:
By default, USB_SERIAL_JTAG module is connected to the internal PHY of the ESP32-S3, while USB_OTG peripheral can be used only if the external USB PHY is connected. Since CDC console is provided via USB_OTG peripheral, it cannot be used through the internal PHY in this configuration.
However, the TRF states:
These two USB controllers can utilize the integrated internal transceiver by time-division multiplexing...When only internal transceiver is used, it is shared by USB OTG and USB Serial/JTAG.
The TRF goes on to talk about fuses and flags (such as RTC_CNTL_SW _USB_PHY_SEL_CFG) for connection switching. If USB OTG and USB Serial/JTAG are TDMed, do I have to be setting/clearing flags to switch between them?

Where I'm going with this -
chegewara wrote:Why not build composite device, MSC + CDC-ACM?
USB Serial/JTAG is a CDC implementation, correct? I've implemented a console based on the examples>system>console examples (using esp_console_new_repl_usb_serial_jtag()). If I want to make a composite device, do I need to switch to USB OTG mode and use the tiny USB driver as in examples>peripherals>usb>tusb_console, then try to figure out ESP_iggr's project to make the MSC part? Or, can I keep my USB Serial/JTAG console and implement a USB OTG MSC device?

chegewara
Posts: 2376
Joined: Wed Jun 14, 2017 9:00 pm

Re: File transfer over USB

Postby chegewara » Sat Oct 29, 2022 1:29 am

Yes, for composite device you have to switch to tinyUSB.
This is quite old code, but i think you may find it useful:
https://github.com/espressif/esp-idf/pull/5355/files

https://github.com/espressif/esp-idf/pu ... c48d5bdd6e
https://github.com/espressif/esp-idf/pu ... abbe68fee1

Who is online

Users browsing this forum: No registered users and 98 guests