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

Hardware UART no longer working on ESP32 boards due to Espressif updating from 2.X to 3.0 #302

Open
benpeart opened this issue Jun 6, 2024 · 1 comment

Comments

@benpeart
Copy link

benpeart commented Jun 6, 2024

I recently started investigating using your library for a ESP32 based project I'm starting but could never get any of the UART based examples to work. After spending way more hours than I'd like to admit, I finally figured out why.

In November of 2023, the Arduino Espressif ESP32 boards package updated from 2.X to 3.0, and apparently the hardware UART code has changed as none of the examples run properly anymore. When I revert to version 2.0.17 of the boards library, they all work correctly.

All 3.0.0 version migration related issues are discussed here if you would like to look at them.

The UART specific migration issues are documented here

Thank you for all the work you have put into this library!

@benpeart
Copy link
Author

benpeart commented Sep 27, 2024

I now understand the cause of this issue and have a simple workaround. I thought I'd add it here in case someone else runs into the same problem.

The underlying change that caused the issue was listed in the 3.0.0 version migration related issues here.

Default pins for some SoCs have been changed to avoid conflicts with other peripherals: * ESP32’s UART1 RX and TX pins are now GPIO26 and GPIO27, respectively; * ESP32’s UART2 RX and TX pins are now GPIO4 and GPIO25, respectively; * ESP32-S2’s UART1 RX and TX pins are now GPIO4 and GPIO5, respectively.

This means that GPIO pins for Serial and Serial2 have changed and as a result, they no longer match all the existing HW designs and all the example code, pinout diagrams and documentation out there on the internet are now wrong. It is an interesting choice that Espressif made but at least they made it fairly easy to work around.

The simplest solution is to set the pins used for Serial and Serial2 to be the pins that were used before this breaking change. This can done by explicitly setting the pins used to their old/default values when you initialize the serial port:

    Serial2.begin(115200, SERIAL_8N1, 16, 17); // Initialize HW UART drivers with the legacy RX/TX pins of 16/17

In theory, if you are using a library that calls begin on your behalf you can also call setPins() to change back to the old default pins and the pin assignments should be preserved when the library calls begin - however, this has not worked for me in my testing.

    Serial2.setPins(16, 17); // Initialize HW UART drivers with the legacy RX/TX pins of 16/17

I hope this can save someone else some frustration when they attempt to update their design to use the new Espressif libraries.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant