[uart] Revert UART0 default pin workarounds (fixed in ESP-IDF 5.5.2)#14363
[uart] Revert UART0 default pin workarounds (fixed in ESP-IDF 5.5.2)#14363
Conversation
|
To use the changes from this PR as an external component, add the following to your ESPHome configuration YAML file: external_components:
- source: github://pr#14363
components: [uart]
refresh: 1h(Added by the PR bot) |
|
👋 Hi there! This PR modifies 1 file(s) with codeowners. @esphome/core - As codeowner(s) of the affected files, your review would be appreciated! 🙏 Note: Automatic review request may have failed, but you're still welcome to review. |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## dev #14363 +/- ##
=======================================
Coverage 74.28% 74.28%
=======================================
Files 55 55
Lines 11597 11597
Branches 1583 1583
=======================================
Hits 8615 8615
Misses 2578 2578
Partials 404 404 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
Pull request overview
This PR fixes a regression on ESP32 ESP-IDF when using UART0 default pins (notably ESP32-C3 GPIO20 RX) by preserving the pull-up state established by gpio_reset_pin() while still re-enabling the RX input buffer required for UART0 IOMUX pins.
Changes:
- Adjust UART0-default pin post-reset handling to avoid
pin->setup()when no explicit pull/open-drain flags are configured. - Use
gpio_input_enable()to re-enable the input buffer without modifying pull resistor configuration. - Keep
pin->setup()for cases where users explicitly set pull-up/pull-down/open-drain in YAML.
Memory Impact AnalysisComponents:
📊 Component Memory Breakdown
🔍 Symbol-Level Changes (click to expand)Changed Symbols
Removed Symbols (top 15)
This analysis runs automatically when components change. Memory usage is measured from a representative test configuration. |
|
#14364 will fix the unit tests |
|
need to check the TX pin as well |
|
actually we don't need gpio_input_enable at all |
422e2fd to
188be9a
Compare
|
gpio_hal_iomux_in and gpio_hal_iomux_out should already do the right thing |
This reverts commit 1897551.
188be9a to
0efa547
Compare
|
ld2450,ld2412,ld2410 still ok |
|
Thanks 🤞 that this is finally sorted out |
What does this implement/fix?
Reverts PR #14130 and PR #12519 which added
gpio_reset_pin()andpin->setup()workarounds for default UART0 pins on ESP-IDF.Background
Issue #10132 reported that LD2410 sensors stopped working on default UART0 pins. PR #12519 attributed the root cause to espressif/esp-idf#17459 (commit espressif/esp-idf@9ed617fb17 removing
gpio_func_sel()fromuart_set_pin()) and addedgpio_reset_pin()calls as a workaround. However,gpio_reset_pin()disables the input buffer, which broke UART RX. PR #14130 then addedpin->setup()to re-enable it — but that introduced a new regression (#14178) wheregpio_config()removes the pullup set bygpio_reset_pin(), causing floating lines on RS-485/modbus devices.Why the workaround was misattributed
The commit espressif/esp-idf@9ed617fb17 only removed
gpio_func_sel()from the GPIO matrix fallback path — the code path for non-default pins. Default UART0 pins use the IOMUX path viauart_try_set_iomux_pin(), which returns false only when the pin doesn't match the default (upin->default_gpio != io_num). For default UART0 pins it returns true, so the GPIO matrix fallback block (wheregpio_func_selwas removed) is never entered.The IOMUX path has handled default UART0 pins correctly since
uart_try_set_iomux_pinwas introduced in 2021, including on ESP-IDF 5.4.2 where the issue was reported:RX path:
uart_set_pin()→uart_try_set_iomux_pin()→gpio_iomux_in()→gpio_ll_iomux_in()which callsPIN_INPUT_ENABLE()(re-enables input buffer)TX path:
uart_set_pin()→uart_try_set_iomux_pin()→gpio_iomux_out()→gpio_ll_iomux_out()which callsgpio_ll_func_sel()(sets IOMUX function)Upstream ESP-IDF fix
The true root cause was an ESP-IDF bootloader bug: when the console was switched away from UART0 (e.g., to USB Serial JTAG or a different UART), the bootloader did not properly release the default UART0 TX pin. The TX output remained active, causing issues when user code later reconfigured those pins for a different UART purpose.
Espressif fixed this in
bootloader_console.cby adding arelease_default_console_io()function that:gpio_ll_output_disable())gpio_ll_func_sel(..., PIN_FUNC_GPIO))esp_rom_gpio_connect_in_signal(GPIO_MATRIX_CONST_ONE_INPUT, ...))This fix closes both espressif/esp-idf#16764 and espressif/esp-idf#17459.
The fix is included in ESP-IDF v5.5.2+ (not in v5.5.1). ESPHome currently uses ESP-IDF v5.5.3, so the workarounds are no longer needed.
fb20e147(in v5.5.2+)aef9061d(not yet released, will be in v5.4.4)c4c932adTypes of changes
Related issue or feature (if applicable):
Pull request in esphome-docs with documentation (if applicable):
Test Environment
Example entry for
config.yaml:Checklist:
tests/folder).If user exposed functionality or configuration variables are added/changed: