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 #70

Open
benpeart opened this issue Jun 6, 2024 · 9 comments

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! Let me know if/how I can help.

@peterpolidoro
Copy link
Member

Hi! Which version of this library are you using? The last version update 9.1.1 should hopefully have fixed this issue. Were you using the latest version?

@benpeart
Copy link
Author

benpeart commented Jun 6, 2024

I'm using 9.1.1. Everything complies and 'runs' - it just never successfully communicates via UART. Using the Step/Dir/En pins works fine, just all serial communication/interfaces fail as if they aren't connected. I assumed forever that I just had the TX2/RX2 pins wired up wrong but after switching to the older board library they all work great. FWIW, this issue isn't unique to your library, the TMCStepper library I also looked at works with 2.x but not 3.0.

image

C:\src\TMC2209>git log
commit 60e32c02b829d14033bfc18786ff6206d2dd4954 (HEAD -> main, tag: 9.1.1, origin/main, origin/HEAD)
Author: Peter Polidoro <[email protected]>
Date:   Wed May 15 11:04:33 2024 -0400

    end(false) -> end() to work with esp32 3.x versions.

Here is how I have things wired up but given it is working with the 2.x version of the Espressif board package I'm pretty sure things are correct:
image

@LenStruttmann
Copy link

As an aside, I am working on a nearly identical set up and I am curious why you use two 22k resistors on the UART line rather than a single 1K resistor as shown on page 20 of the TMC2209 datasheet. Obviously, it works for you, but I am curious as to why this was chosen. Thanks

@benpeart
Copy link
Author

benpeart commented Jun 6, 2024

Sorry about the confusion there. I'm actually using a 1K resister on the TX line as specified on the datasheet. I was just being lazy and had never figured out how to choose the correct resister resistance in the Fritzing application (at some point I must have closed the Inspector window). I just googled it and fixed my laziness. :)

I had added a 10K pull down resister when trying to debug why UART communication wasn't working and observing via an oscilloscope that the line appears to be held high and I wasn't getting a big drop in voltage as the data was getting sent. I just removed the 10K pull down resister (now that I figured out that the issue was actually the 3.0 ESP32 board library) and it's still working correctly.

Here is an updated breadboard diagram with both issues fixed:

image

@LenStruttmann
Copy link

Thanks!

@peterpolidoro
Copy link
Member

So do you have any idea of what I need to change in this library in order to get it to work with 3.0?

@benpeart
Copy link
Author

I'm sorry but I really don't. I'd start by looking at the UART specific migration issues to see if you are doing any of the things they have listed in the "functional changes" as those are more insidious than API changes which typically generate compiler errors.

@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.

@peterpolidoro
Copy link
Member

Thank you! I will add this information to the documentation when I get a chance.

Can you confirm if it works when you call:

TMC2209 stepper_driver;
stepper_driver.setup(Serial2, 115200, TMC2209::SERIAL_ADDRESS_0, 16, 17);

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

3 participants