-
-
Notifications
You must be signed in to change notification settings - Fork 8.2k
ESP32-S3 forcing use of USB OTG #14217
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
Comments
What hardware are you using? I'm guessing that you have a board that does not have a USB connector on GPIO19/20, and instead uses a UART REPL.
It looks like this config setting is always enabled if the MCU supports USB, which is ESP32-S2 and ESP32-S3. You cannot turn this option off. So MicroPython should probably not use this option to control whether |
If the only purpose for using the USB feature is to output repl data, which is what it looks like then this being set is what should e checked. CONFIG_ESP_CONSOLE_USB_CDC I also put into question the complexity of the code being used because if the user is wanting the repl data output to the USB then why not use
Which kind of makes no sense because of this...
In reality why would someone want to occupy 4 pins that have the purpose of doing the same thing essentially? The USB OTG should be exposed to the user in MicroPython if it is available and it is not being used for repl output. There are quite a few things it can be used for. Things like connecting a mouse, keyboard or joystick are a few examples. Just because a board has a second USB port doesn't mean that the USB should be locked to only being able to be used for the purposes of sending repl data. |
This comment was marked as outdated.
This comment was marked as outdated.
The board I am working with is a Sunton display board and no it doesn't have a second USB port. The waveshare board has a way of turning on and off the use of the second USB PORT by using an IO expander. |
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
I looked at this briefly as part of #15727 and agree it could use some cleanup. If I understand correctly, there's two related things here: Runtime USB pinsIt should be possible to reconfigure a USB pin for another purpose at runtime, at least if USB isn't currently enumerated. It's already possible to switch the UART0 pins to other functions, and the same should be possible for the USB pins as well. I think that would resolve the original issue report, while allowing us to keep shipping a single ESP32-S3 binary that works in as many places as possible. Compile time USB enable/disableThis is almost possible at the moment, but as discussed above it's fiddly. PR #15727 is a move towards making it easier as it defines two MicroPython board-level build macros to independently enable/disable native USB and USB Serial/JTAG. An additional fix is still needed to fully disable USB on IOs 19 and 20 though (I think unless USB has been permanently disabled on the chip via efuse, in that case it might work already.)
Historically (and currently) MicroPython esp32 port doesn't really use ESP-IDF stdio, except for (I think) ESP-IDF logging. The Python stdin/stdout functions all work directly with the various peripherals, as noted above. Maybe we could change this, although the current approach may actually make implementing these fixes easier (especially runtime reconfiguration). It'll probably be the only way after #15108 lands and MicroPython is no longer using ESP-IDF's TinyUSB. |
This comment was marked as outdated.
This comment was marked as outdated.
Never again on that chip. Burning the USB disable efuse would mean the two USB pins on that chip are permanently regular GPIO and can't be switched back to USB functions. I also haven't actually confirmed this allows those pins to work as normal IO in MicroPython, I just believe it would. It's absolutely not the proper fix for this issue. |
This comment was marked as outdated.
This comment was marked as outdated.
I can confirm that after #15727 was merged, I am able to disable // Disable USB CDC as the same pins are used by I2C0
#define MICROPY_HW_USB_CDC (0)
#define MICROPY_HW_I2C0_SCL (19)
#define MICROPY_HW_I2C0_SDA (20) After that, I can use pins >>> board.i2c().scan()
[72, 80, 81] |
This comment was marked as off-topic.
This comment was marked as off-topic.
This comment was marked as off-topic.
This comment was marked as off-topic.
This comment was marked as off-topic.
This comment was marked as off-topic.
On every S2 and S3 board I own, only USB CDC is wired up, UART pins are not connected to anything. Keep in mind most of this code is community contributed and under active development / change. I for one have been working on improving the consistency of repl / stdio interfaces across all the ports recently with the consolidation of stdio handling - this has all been done in my own personal time around my young family needs. This is what I do when there's features that don't work the way I want them to, I raise PR's. Regardless, the long term fix here is to use the dupterm interface/module for both CDC and UART repl, it's already designed to support dynamic attach/detach of streams to stdio so then users can decide at runtime. This is how it works currently on the stm port and I'm in progress making it possible on all others that use TinyUSB etc. |
This comment was marked as off-topic.
This comment was marked as off-topic.
This comment was marked as off-topic.
This comment was marked as off-topic.
I'm not sure what your comment is based on, but I think there are some inaccuracies. The REPL is available on both UART and CDC. Additionally, it might be worth considering: |
This comment was marked as off-topic.
This comment was marked as off-topic.
This comment was marked as off-topic.
This comment was marked as off-topic.
This comment was marked as off-topic.
This comment was marked as off-topic.
This comment was marked as off-topic.
This comment was marked as off-topic.
@kdschlosser when I read your messages they sound very heated to me, even if that's not your intention. I admit I can get frustrated by some of this too. Yes the Espressif Dev kit exposes both, as does the waveshare one - devkits often try to expose everything to let users decide what to use. The majority of other smaller esp32 boards I see on the market only expose USB, not UART. I always use esptool to flash my S3 boards via the native USB port. There were bugs in the silicon and some other platforms that have hurt the reliability of this in the early days, but that was never the intention of Espressif and PR's I've submitted both here and to esptool have resolved some of these issues. Regardless it's absolutely now a moot point because as @vshymanskyy said the port repl configuration can be enabled / disabled in board profile. The Dev kids with both ports wired should expose repl on both to avoid confusion, boards that only expose UART or USB can configure just that port. Unused port pins can be user configured for other goals. The ability to change these settings at runtime is well known to be desirable, I spoke to this in my last message, specifically that I am actually working on this already in my limited personal time! If that's too slow for you please feel free to help rather than repeat complaints that it's not already there. These things take effort and time. Keep in mind that runtime configurability comes at a cost in both flash and ram use. Sure, many esp boards come with "lots" of external flash and ram but not all, and certainly not so boards on other ports (what I'm working on is intended to do it properly for all ports, I don't just think about esp32). |
Well said, @andrewleech. As far as I'm concerned most of this issue discussion is generating far more heat than light. Time spent here is time not spent improving any code. Going back to the assessment I wrote in this comment then can re-summarise the status quo as follows: Compile time USB enable/disableThis is now possible on ESP32-C3, thanks @vshymanskyy for confirming and describing how: #14217 (comment) 🎉 🎉 I'm not actually sure the same strategy works on ESP32-S*, I think it does now but it'd be good to double check. If not now then I suspect will work after @andrewleech's PR #15108 is merged, which cleans up a bunch of the esp32 port USB implementation. Runtime USB pinsWhat I said in the comment linked above hasn't changed. It should be possible to reconfigure a USB pin at runtime and have it become a normal pin (maybe with a check that it's not currently being used as an enumerated USB device). However this is not currently possible. This needs someone to do the work, submit the PR, and would resolve the remaining part of this issue. There should be almost no behavioural difference between compile-time and runtime disabling of native USB (click for details).
Preventing the situation described in (1) and disabling the USB port at all times requires burning an efuse to permanently disable USB on that chip. There's nothing MicroPython can do to change this as it's ROM bootloader behaviour. Summary
EDIT: Fixed the assessment of compile time disabling, I missed this was on C3 only so far. I thought it was linking Andrew's big tinyusb PR. |
Any solutions for this problem? I am working on ESP32-S3 and I want to use GPIO19 20 for GPIO purpose. But I can't turn off the USB function |
As described above in #14217 (comment) / #14217 (comment)
|
Hello everyone, I designed a PCB and used ESP32C3 MIN 1U as a main MCU. I connected pins 18 and 19 as general GPIO without knowing this problem and after days of trying and trying I still cannot solve the issue. I have tried many times by changing mpconfigboard.h and recompiling the firmware like 20 times and still I get the invalid pin error. MY mpconfigboard.h is like this:
As you can see I disabled the USB_CDC and also enabled the UART because I am using a CP2102 as USB 'UART converter. If anyone knows how to solve it properly, I would be really happy. Thank you :) |
Checks
I agree to follow the MicroPython Code of Conduct to ensure a safe and respectful space for everyone.
I've searched for existing issues matching this bug, and didn't find any.
Port, board and/or hardware
ESP32-S3
MicroPython version
MicroPython: 1.22.2
board: ESP32_GENERIC_S3
board_variant: SPIRAM_OCT
Reproduction
compile for the ESP32-S3 and try and use the pins for I2C. Using them results in a timeout or if doing a scan it takes the scan more than a minute to complete and returns an empty list.
Expected behaviour
for I2C to work using pins 19 and 20
Observed behaviour
I2C attached to pins 19 and 20 does not work I believe this issue is caused by the forced use of USB OTG. I have tried to turn it off by setting
CONFIG_USB_OTG_SUPPORTED=n
in theports/esp32/boards/ESP32_GENERIC_S3/sdkconfig.board
file and also removingboards/sdkconfig.usb
from theports/esp32/boards/ESP32_GENERIC_S3/mpconfigboard.cmake
file. For whatever reasonCONFIG_USB_OTG_SUPPORTED
still gets set toy
when being compiled.Normally this wouldn't be an issue but because of this code in MicroPython
Pin 19 and 20 get forced into use for OTG instead of being something that user is able to selectively turn on. I believe that the ESP-IDF is overriding the setting
CONFIG_USB_OTG_SUPPORTED=n
which is why I am not able to turn it off and because MicroPython is coded in a manner that forces those pins into being used for USB OTG at runtime results in my inability to use those pins for anything else.I believe that this kind of a thing should be able to be turned on or off at the users discretion and it should be able to be done at runtime and not compile time. The
CONFIG_USB_OTG_SUPPORTED
is simply a setting that should be used to have code compiled and not be used to determine if it should run code. That macro as it implies if whether or not a board supports OTG not that it should be used.Additional Information
I have not managed to grasp why the OTG is having repl data sent to it.
The text was updated successfully, but these errors were encountered: