feat(uart): add new API for RX internal pull and onewire UART#12744
feat(uart): add new API for RX internal pull and onewire UART#12744SuGlider wants to merge 2 commits into
Conversation
… setting onewire UART
There was a problem hiding this comment.
Merge request must include a release note, or it needs to be processed first.
Details
👋 Hello SuGlider, we appreciate your contribution to this project! 📘 Please review the project's Contributions Guide for key guidelines on code, documentation, testing, and more. 🖊️ Please also make sure you have read and signed the Contributor License Agreement for this project. Click to see more instructions ...
Review and merge process you can expect ...
|
There was a problem hiding this comment.
Pull request overview
Adds user-facing APIs and HAL support for (1) UART one-wire (shared RX/TX GPIO) and (2) configurable internal pull on the RX pin, including updates to Peripheral Manager handling, validation tests, examples, and documentation.
Changes:
- Added
HardwareSerial::enableOneWireMode()andHardwareSerial::enableRxInternalPull()APIs with HAL plumbing and pin validation. - Introduced
ESP32_BUS_TYPE_UART_RX_TXand updated UART pin attach/detach logic to support shared-pin operation. - Expanded UART validation tests plus added new Serial examples and updated Serial API docs.
Reviewed changes
Copilot reviewed 13 out of 13 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| tests/validation/uart/uart.ino | Extends validation coverage for one-wire mode, RX pull behavior, and periman interactions. |
| tests/validation/uart/README.md | Documents the updated UART validation suite behavior, ordering, and pin usage. |
| libraries/ESP32/examples/Serial/RxPull_Demo/RxPull_Demo.ino | New example demonstrating RX internal pull behavior (floating RX, inversion behavior, optional wired loopback). |
| libraries/ESP32/examples/Serial/RxPull_Demo/README.md | Usage notes and wiring instructions for RX pull demo. |
| libraries/ESP32/examples/Serial/OneWire_UART_Demo/OneWire_UART_Demo.ino | New example demonstrating one-wire UART on a single GPIO (self + optional peer loopback). |
| libraries/ESP32/examples/Serial/OneWire_UART_Demo/README.md | Usage notes, wiring, and electrical cautions for one-wire UART demo. |
| docs/en/api/serial.rst | Documents the new APIs, one-wire constraints, RX pull vs inversion, and periman implications. |
| cores/esp32/HardwareSerial.h | Adds public API declarations for RX pull and one-wire mode. |
| cores/esp32/HardwareSerial.cpp | Implements the new APIs and adjusts end()/registration behavior. |
| cores/esp32/esp32-hal-uart.h | Exposes HAL-level enable functions for RX pull and one-wire mode. |
| cores/esp32/esp32-hal-uart.c | Implements RX pull application, one-wire shared-pin attach/detach, and updated loopback behavior. |
| cores/esp32/esp32-hal-periman.h | Adds ESP32_BUS_TYPE_UART_RX_TX bus type. |
| cores/esp32/esp32-hal-periman.c | Adds name mapping for the new periman bus type. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| if (_uartRxPadInverted(uart)) { | ||
| esp_rom_gpio_connect_in_signal(GPIO_FUNC_IN_LOW, UART_PERIPH_SIGNAL(uart_num, SOC_UART_RX_PIN_IDX), false); | ||
| } else { | ||
| esp_rom_gpio_connect_in_signal(GPIO_FUNC_IN_HIGH, UART_PERIPH_SIGNAL(uart_num, SOC_UART_RX_PIN_IDX), false); | ||
| } | ||
| gpio_pullup_dis((gpio_num_t)rxPin); | ||
| gpio_pulldown_dis((gpio_num_t)rxPin); |
| bool oneWireRequest = (rxPin >= 0 && txPin >= 0 && rxPin == txPin); | ||
| bool sharedAttach = false; | ||
| if (oneWireRequest) { | ||
| peripheral_bus_type_t pinType = perimanGetPinBusType(rxPin); | ||
| sharedAttach = (pinType != ESP32_BUS_TYPE_UART_RX_TX || perimanGetPinBusNum(rxPin) != (int8_t)uart_num); | ||
| } | ||
|
|
|
Is there a specific reason for adding "enableOneWireMode()" instead of just having the Serial functionality automatically assume "OneWireMode" when the RX and TX pins are configured to the same GPIO pin? |
Test Results 148 files 148 suites 40m 28s ⏱️ Results for commit 410a9fd. |
|
Added all #12744 changes to my installed Arduino ESP32 v3.3.10. verbose output: #include <Arduino.h> #define SERIAL1_RPIN 18 // Connected to 19 HardwareSerial *pSerial1 = &Serial1; void set_rx_mode(int serialNb) { void set_tx_mode(int serialNb) { void setup() { void loop() { Serial.println("Serial1:write:1"); delay(1000); Serial.println("Serial2:write:2"); delay(1000); |
|
enableOneWireMode: Used a device sending continuously data at 125000 baud, 8N1. #include <Arduino.h> //#define STANDARD #define SERIAL2_RPIN 19 HardwareSerial *pSerial2 = &Serial2; void setup() { #ifdef STANDARD void loop() { while (pSerial2->available() > 0) { |

Description of Change
This pull request introduces support for UART one-wire mode and internal RX pull configuration, along with related improvements and fixes in the ESP32 hardware serial implementation. The changes add new APIs, update the internal UART state tracking, and enhance pin validation and attachment logic to support these features safely and flexibly.
The most important changes are:
UART one-wire mode support:
enableOneWireMode()toHardwareSerial, allowing RX and TX to share the same GPIO pin (one-wire UART) with proper validation and error handling. This includes new logic to handle pin attachment/detachment and Peripheral Manager integration for the shared pin. (HardwareSerial.cpp,HardwareSerial.h,esp32-hal-uart.c,esp32-hal-periman.h,esp32-hal-periman.c)Internal RX pull configuration:
enableRxInternalPull()toHardwareSerial, allowing users to enable or disable the internal pull resistor on the RX pin, with proper handling depending on UART mode and pin inversion. (HardwareSerial.cpp,HardwareSerial.h,esp32-hal-uart.c)Peripheral Manager and pin handling enhancements:
ESP32_BUS_TYPE_UART_RX_TXbus type for one-wire mode, and updated Peripheral Manager logic to support shared RX/TX pins. (esp32-hal-periman.h,esp32-hal-periman.c)esp32-hal-uart.c)Bug fixes and refactoring:
uart_register()andHardwareSerial::end()to ensure correct registration and cleanup of UART instances, especially with new one-wire and shared pin handling. (HardwareSerial.cpp)These changes provide more flexible UART configuration options for advanced use cases while maintaining safety and compatibility with existing features.
Test Scenarios
Tested with eht examples and also with uart.ino (validation test) using ESP32, S2, S3, C3 and C6
Related links
Closes #12729
Closes #12734