Skip to content

Add UART line inversion support#5522

Merged
deadprogram merged 2 commits into
tinygo-org:devfrom
helvionics:de_uart_inversion
Jul 17, 2026
Merged

Add UART line inversion support#5522
deadprogram merged 2 commits into
tinygo-org:devfrom
helvionics:de_uart_inversion

Conversation

@digitalentity

Copy link
Copy Markdown
Contributor

Add InvertTX and InvertRX to UARTConfig to allow enabling hardware line inversion on supported targets. Added hardware implementation for RP2 (RP2040, RP2350), STM32 (newer families), SAM (SAMD51, SAME5x), and ESP (ESP32, ESP32-C3, ESP32-C6).

Fixes #5383

Add InvertTX and InvertRX to UARTConfig to allow enabling hardware
line inversion on supported targets. Added hardware implementation for
RP2 (RP2040, RP2350), STM32 (newer families), SAM (SAMD51, SAME5x),
and ESP (ESP32, ESP32-C3, ESP32-C6).
Comment thread src/machine/machine_rp2_uart.go Outdated
if config.TX != NoPin {
config.TX.Configure(PinConfig{Mode: PinUART})
if config.InvertTX {
config.TX.ioCtrl().ReplaceBits(rp.IO_BANK0_GPIO0_CTRL_OUTOVER_INVERT<<rp.IO_BANK0_GPIO0_CTRL_OUTOVER_Pos, rp.IO_BANK0_GPIO0_CTRL_OUTOVER_Msk, 0)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this could be something like:

config.TX.ioCtrl().SetGPIO0_CTRL_OUTOVER(rp.IO_BANK0_GPIO0_CTRL_OUTOVER_INVERT)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Easier to say than do unfortunately. I changed the code to use the wrapper, which is confined to gpio implementation,but still uses ReplaceBits under the hood (like other GPIO-related functions on RP2).

@deadprogram

Copy link
Copy Markdown
Member

General comment: we should try to use the generated wrapper functions whenever possible, if you please.

RP2: Extract setOutOver/setInOver methods on Pin, removing inline
IO control register manipulation from UART configure.

SAM: Switch to SetCTRLA_TXINV/SetCTRLA_RXINV methods, dropping
the unused device/sam import and raw SetBits/ClearBits calls.
@deadprogram

Copy link
Copy Markdown
Member

Anyone else have any feedback on this before merge?

@deadprogram

Copy link
Copy Markdown
Member

Now squash/merging. Thanks for adding this feature @digitalentity !

@deadprogram
deadprogram merged commit ea003da into tinygo-org:dev Jul 17, 2026
20 checks passed
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

Successfully merging this pull request may close these issues.

Feature request: UART inversion

2 participants