Flashing new Code to an ESP32s3 While it is Acting as a MSC

dhruvpareek_
Posts: 4
Joined: Fri Jul 19, 2024 11:27 pm

Flashing new Code to an ESP32s3 While it is Acting as a MSC

Postby dhruvpareek_ » Wed Sep 11, 2024 9:28 pm

Hi, I am working with an ESP32s3,
this Espressif MSC code - https://github.com/espressif/esp-idf/tr ... e/tusb_msc
and this Espressif Composite CDC+MSC code - https://github.com/espressif/esp-idf/tr ... rialdevice
(there is more documentation relating to this code here - https://docs.espressif.com/projects/esp ... evice.html).

I want to use my ESP32s3 as a mass storage device, where I can access the files written in the ESP32s3 via the USB port. Using this single USB port, I also want to be able to re-flash new programs onto the ESP32s3 (ideally without having to use the buttons on the ESP32s3). Basically, dual use of the USB port on the ESP32s3 (this same dual use of the UART port would be great too, although I don't think it's possible).

Right now, I am able to access the files written to the ESP32s3 as a part of the mass storage device. However, once I am able to do that after initially flashing the ESP32s3 as an MSC via the USB port, I am unable to flash a new program onto the ESP32s3 via the USB port again (I have to switch to the UART port to flash the device with new code & the USB port is basically only usable as a way to look at the files stored as an MSC).

ESP_Sprite
Posts: 9709
Joined: Thu Nov 26, 2015 4:08 am

Re: Flashing new Code to an ESP32s3 While it is Acting as a MSC

Postby ESP_Sprite » Thu Sep 12, 2024 1:39 am

Its possible in theory: you'd have to make a composite device with a MSC plus a CDC-ACM serial port, then hook up the DTR/RTS signals of the serial port to call something that resets the chip into bootloader mode. Not sure if anyone implemented that already, though.

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

Re: Flashing new Code to an ESP32s3 While it is Acting as a MSC

Postby chegewara » Thu Sep 12, 2024 2:34 am

Yes, it should be possible with composite USB device, and without hardware DTR/RTS.
As far as i remember espressif arduino team implemented this some time ago.
Espressif is using "special pattern" to switch esp32 into download mode. Its some mix of software DTR/RTS and uart speed set to 1200bps.
When software detects this pattern we can set some registers, dont know which one, and restart esp32. After restart esp32 will be in download mode.

I see its now implemented 2 different ways in arduino:
https://github.com/espressif/arduino-es ... #L195-L230
https://github.com/espressif/arduino-es ... #L252-L253

Switch to rom jtag mode before restart:
https://github.com/espressif/arduino-es ... usb.c#L481

dhruvpareek_
Posts: 4
Joined: Fri Jul 19, 2024 11:27 pm

Re: Flashing new Code to an ESP32s3 While it is Acting as a MSC

Postby dhruvpareek_ » Thu Sep 12, 2024 5:32 pm

Do you know if there is anything like those implementation done through the ESP-IDF? Or how to do something like that with ESP-IDF?

All of my work so far that I am integrating this MSC into is with ESP-IDF so unfortunately I can't use the Arduino code. I'm also new to the MSC and CDC stuff so I'm not fully sure how I would go about converting that code to work for the ESP-IDF.

username
Posts: 528
Joined: Thu May 03, 2018 1:18 pm

Re: Flashing new Code to an ESP32s3 While it is Acting as a MSC

Postby username » Fri Sep 13, 2024 1:56 pm

When you device is acting as an MSC and plugged into your PC why dont you just copy over you firmware's bin file to it and have it read that and flash itself?

Who is online

Users browsing this forum: No registered users and 281 guests