Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Is it possible to switch the USB mode at runtime programmatically? #8277

Open
1 task done
sblantipodi opened this issue Jun 1, 2023 · 10 comments
Open
1 task done
Labels
Area: Peripherals API Relates to peripheral's APIs. Chip: ESP32-S3 Issue is related to support of ESP32-S3 Chip Type: Feature request Feature request for Arduino ESP32
Milestone

Comments

@sblantipodi
Copy link
Contributor

sblantipodi commented Jun 1, 2023

Board

Lolin ESP32-S3 mini

Device Description

ESP32-S3

Hardware Configuration

no gpio in use

Version

latest master (checkout manually)

IDE Name

CLION

Operating System

Windows 11

Flash frequency

80MHz

PSRAM enabled

yes

Upload speed

115200

Description

esptool.js does not work with TinyUSB devices like S2 and S3,
espressif/esptool-js#97
this means that you cannot flash this devices using a web tool when they are in TinyUSB mode.

as you can imagine TinyUSB is much better than CDC since CDC creates lags on S3, it consumes more memory and it's not as stable as TinyUSB.

is there a way to flash a CDC firmware using the esptool.js and then switch to TinyUSB at runtime using some lines of code inside our firmware?

Sketch

no sketch

Debug Message

no debug

Other Steps to Reproduce

No response

I have checked existing issues, online documentation and the Troubleshooting Guide

  • I confirm I have checked existing issues, online documentation and Troubleshooting guide.
@sblantipodi sblantipodi added the Status: Awaiting triage Issue is waiting for triage label Jun 1, 2023
@me-no-dev
Copy link
Member

you could manually boot into download mode, which will expose the CDC/JTAG interface and allow you to flash.

@sblantipodi
Copy link
Contributor Author

@me-no-dev this is not really a solution...
most open source projects are using web installers like esp-web-tools

to let users flash the firmware on their devices and then configure the wifi connection on the same webpage before accessing the web interface of the firmware itself.

if you set the device in CDC mode and then you flash a TinyUSB firmware, you can't setup the wifi connection as described before because the improv-wifi does not work since it tries to Serial.print() using the TinyUSB method on a CDC connection.

@me-no-dev
Copy link
Member

seems that you mention a few different problems. Getting TinyUSB's CDC to reboot into download, when attempted by esptool.js is not an issue. I made a couple small modifications and got it to work. The problems come afterwards:

  • The USB post changes, because now the CDC/JTAG controller is active
  • esptool.js needs to know that it needs to connect to that new port, but that is not implemented
  • In this mode (TinyUSB -> CDC/JTAG) download mode can not automatically reboot into the new firmware, so reset must be pressed
  • If you want to talk to the new firmware, you again need to connect to the new port

@sblantipodi
Copy link
Contributor Author

sblantipodi commented Jun 1, 2023

@me-no-dev thanks for the answer.

the idea is to

  • flash a CDC firmware with the esp-web-tools + improv-wifi,
  • let the user configure the wifi using improv-wifi,
  • once the wifi is set,
  • reboot the device in Tiny USB mode programmatically since we don't need the web tools features anymore.

it would be cool to have a function like the ESP.restart() that works like
ESP.restartInCdcMode()
or
ESP.restartInTinyUsbMode()

is it possible to do this? this could be really useful since the only method that works with web tools is CDC.

@sblantipodi sblantipodi changed the title Is it possible to switch the USB mode at runtime? Is it possible to switch the USB mode at runtime programmatically? Jun 1, 2023
@me-no-dev
Copy link
Member

Switching USB controllers is not all that straight-forward. We can and should look into this in the future, but as of now is not possible.

@sblantipodi
Copy link
Contributor Author

if you agree please leave this issue open as a reminder, this feature would be really really useful for a lot of use cases in addition to the one I explained before.

@me-no-dev me-no-dev added Type: Feature request Feature request for Arduino ESP32 Chip: ESP32-S3 Issue is related to support of ESP32-S3 Chip Area: Peripherals API Relates to peripheral's APIs. and removed Status: Awaiting triage Issue is waiting for triage labels Jun 1, 2023
@me-no-dev me-no-dev added this to the 3.0.0 milestone Jun 1, 2023
@me-no-dev
Copy link
Member

done :)

@sblantipodi
Copy link
Contributor Author

thank you very much, I appreciate it. :)

@0xBERNDOG
Copy link

0xBERNDOG commented Jan 17, 2024

Related to this, is it possible to change the device type programmatically before initialising? I would like to select either CDC or MSC (depending on a user input at boot), and it's okay to reboot in order to change between them

@VojtechBartoska VojtechBartoska modified the milestones: 3.0.0, 3.1.0 Feb 20, 2024
@VojtechBartoska
Copy link
Collaborator

Postponing to 3.1.0 milestone.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area: Peripherals API Relates to peripheral's APIs. Chip: ESP32-S3 Issue is related to support of ESP32-S3 Chip Type: Feature request Feature request for Arduino ESP32
Projects
Development

No branches or pull requests

4 participants