kywwilson11 opened a new pull request, #17416:
URL: https://github.com/apache/nuttx/pull/17416
## Summary
This change adds full RS-485 support to the STM32H5 serial driver, including
runtime configuration via `TIOCSRS485`/`TIOCGRS485`, proper DIR pin handling,
and optional unconfiguration of TX/RX/DIR pins on device close.
Upstream STM32H5 did not yet support the Linux-style `serial_rs485`
interface,
and RS-485 direction control was limited to static polarity and setup during
initialization. My patches introduce:
- A new `rs485_flags` field in the driver, compatible with `struct
serial_rs485`
- Dynamic DIR-pin switching during TX based on `SER_RS485_RTS_ON_SEND` /
`SER_RS485_RTS_AFTER_SEND`
- Runtime enable/disable of RS-485 mode through ioctl
- Optional per-USART *unconfiguration* of RX, TX, and DIR GPIOs on close via
new
Kconfig options (e.g., `CONFIG_USART2_UNCONFIG_DIR_ON_CLOSE`)
These updates bring the STM32H5 serial driver to feature parity with other
STM32 families and finally allow proper, hardware-controlled RS-485
operation.
## Impact
This change is fully backward-compatible:
- Existing UART/USART users are unaffected unless RS-485 mode is explicitly
enabled.
There are no changes to the build system, documentation requirements, or
security model. RS-485 support remains optional and off unless configured.
## Testing
I developed and validated the changes on:
- **Board:** Nucleo-H563ZI
- **Host:** Ubuntu 24.04
- **Toolchain:** `arm-none-eabi-gcc`
`gcc version 13.3.1 20240614 (Arm GNU Toolchain 13.3.Rel1 (Build
arm-13.24))`
- **Transceiver:** TI SN65HVD1781A connected to USART2 (PD5/PD6 + PD4 DIR)
- **PC connection:** USB-to-RS485 adapter
- **Board modifications:**
- Added DIR pin definition to `board.h` (PD4)
- Enabled RS-485 on USART2 in defconfig
- Used a small test application (`rs485test` inside the provided ZIP)
### Test Procedure
1. Built NuttX with the updated serial driver and board configuration.
2. Flashed onto Nucleo-H563ZI.
3. Ran the RS-485 test application (`rs485test`) which:
- Opens `/dev/ttyS1` (USART2)
- Sets RS-485 mode via `TIOCSRS485`
- Reads back mode via `TIOCGRS485`
- Performs multiple TX cycles and listens for host replies
4. Connected bidirectional link to a USB-RS485 dongle on the host PC and
monitored incoming messages.
### Observed Results
**NuttX console output:**
=== RS-485 Test Application ===
Opening device: /dev/ttyS1
Setting RS-485 mode via TIOCSRS485...
Reading back config via TIOCGRS485...
Returned flags: 0x00000003
Starting TX loop...
Wrote 35 bytes itr 1
Wrote 35 bytes itr 2
Wrote 35 bytes itr 3
Received 12 bytes: ... [Sending to n]
Wrote 35 bytes itr 4
Received 5 bytes: ... [ucleo]
Wrote 35 bytes itr 5
Wrote 35 bytes itr 6
Received 11 bytes: ... [Hello there]
Wrote 35 bytes itr 7
Received 1 bytes: 0x43 [C]
Quit command received. Closing port and exiting.
**PC-side serial output:**
Hello from RS-485 test app! Msg 1
Hello from RS-485 test app! Msg 2
Hello from RS-485 test app! Msg 3
Hello from RS-485 test app! Msg 4
Hello from RS-485 test app! Msg 5
Hello from RS-485 test app! Msg 6
Hello from RS-485 test app! Msg 7
### Validation Summary
- DIR pin polarity matched `TIOCSRS485` settings.
- RX-during-TX behaved correctly when enabled.
- GPIO unconfiguration on close worked as expected.
- No regressions observed in non-RS-485 serial operation.
These tests confirm that the new RS-485 implementation is functional,
stable, and integrates cleanly with the STM32H5 UART subsystem.
[rs485test.zip](https://github.com/user-attachments/files/23856726/rs485test.zip)
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]