8000 esp32/machine_pin.c: Fix the logic when to clear USB_SERIAL_JTAG_USB_PAD_ENABLE by garywill · Pull Request #16236 · micropython/micropython · GitHub
[go: up one dir, main page]

Skip to content

esp32/machine_pin.c: Fix the logic when to clear USB_SERIAL_JTAG_USB_PAD_ENABLE #16236

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

Merged
merged 2 commits into from
Mar 13, 2025

Conversation

garywill
Copy link
Contributor
@garywill garywill commented Nov 14, 2024

Summary

When we don't use USB JTAG, we want to use the two USB pins (D+/D-) as GPIO. So, do clear USB_SERIAL_JTAG_USB_PAD_ENABLE when USB SERIAL JTAG is not enabled

Testing

I was trying to build and use mpy v1.24.0 on ESP32-C3 (IDF 5.2.2).

The code below shows GPIO 18 19 shoud be usable when MICROPY_HW_ESP_USB_SERIAL_JTAG is false:

#if !MICROPY_HW_ESP_USB_SERIAL_JTAG
#define MICROPY_HW_ENABLE_GPIO18 (1)
#define MICROPY_HW_ENABLE_GPIO19 (1)
#endif

So I tried commenting out this:

// Enable stdio over USB Serial/JTAG peripheral
#ifndef MICROPY_HW_ESP_USB_SERIAL_JTAG
#define MICROPY_HW_ESP_USB_SERIAL_JTAG (SOC_USB_SERIAL_JTAG_SUPPORTED && !MICROPY_HW_USB_CDC)
#endif

to make sure MICROPY_HW_ESP_USB_SERIAL_JTAG is false.

Then the result is I could use Pin(18)/Pin(19) to get GPIO object, but could not do real GPIO output.

So I think we should apply this fix, which works for me on ESP32-C3

I don't have ESP32-C6 to test

@projectgus
Copy link
Contributor

Thanks @garywill for submitting this fix. I took a look at ESP32-C6 and it had a similar problem but had deviated from ESP32-C3 even more. Have pushed a commit here to make it the same behaviour as C3 (USB pins invalid if Serial/JTAG is enabled in the config, and can now be used otherwise).

I am currently working on some changes that will allow reconfiguring the USB pins for other uses on any SoC, without needing to make a custom build with USB disabled, provided that USB is not currently in use (related to #14217). However, that PR will not be ready for some time so this seems like a good fix to apply in the short term.

garywill and others added 2 commits March 13, 2025 13:06
When we don't use USB JTAG, we want to use the two USB pins (D+/D-) as
GPIO. So, do clear USB_SERIAL_JTAG_USB_PAD_ENABLE when USB SERIAL JTAG is
not enabled

Signed-off-by: Garry W <32130780+garywill@users.noreply.github.com>
Signed-off-by: Angus Gratton <angus@redyak.com.au>
Similar to parent commit, allow using USB Serial/JTAG pins for other
purposes but only if this feature is disabled in the build config.

Signed-off-by: Angus Gratton <angus@redyak.com.au>
@dpgeorge dpgeorge merged commit 1d5dc72 into micropython:master Mar 13, 2025
7 of 8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Disabling USB_SERIAL_JTAG on esp32c3 to free up the pins.
3 participants
0