1
0
mirror of https://github.com/RIOT-OS/RIOT.git synced 2025-01-18 12:52:44 +01:00

cpu/sam0_common: UART: implement inverted RX & TX

The UART TX and TX lines on SAMD5x and SAML1x can be inverted.
However, the flags don't do exactly what one would expect.

See errata 2.18.5: SERCOM-UART: TXINV and RXINV Bits Reference:

> The TXINV and RXINV bits in the CTRLA register have inverted functionality.
>
> Workaround:
> In software interpret the TXINV bit as a functionality of RXINV, and conversely,
> interpret the RXINV bit as a functionality of TXINV.
This commit is contained in:
Benjamin Valentin 2020-06-16 19:53:00 +02:00 committed by Benjamin Valentin
parent 56962f86fb
commit 585dc15f99
2 changed files with 14 additions and 0 deletions

View File

@ -168,6 +168,8 @@ typedef enum {
UART_FLAG_NONE = 0x0, /**< No flags set */
UART_FLAG_RUN_STANDBY = 0x1, /**< run SERCOM in standby mode */
UART_FLAG_WAKEUP = 0x2, /**< wake from sleep on receive */
UART_FLAG_RXINV = 0x4, /**< invert RX signal */
UART_FLAG_TXINV = 0x8, /**< invert TX signal */
} uart_flag_t;
#ifndef DOXYGEN

View File

@ -114,6 +114,18 @@ int uart_init(uart_t uart, uint32_t baudrate, uart_rx_cb_t rx_cb, void *arg)
if (uart_config[uart].flags & UART_FLAG_RUN_STANDBY) {
dev(uart)->CTRLA.reg |= SERCOM_USART_CTRLA_RUNSTDBY;
}
#ifdef SERCOM_USART_CTRLA_RXINV
/* COM100-61: The TXINV and RXINV bits in the CTRLA register have inverted functionality. */
if (uart_config[uart].flags & UART_FLAG_TXINV) {
dev(uart)->CTRLA.reg |= SERCOM_USART_CTRLA_RXINV;
}
#endif
#ifdef SERCOM_USART_CTRLA_TXINV
/* COM100-61: The TXINV and RXINV bits in the CTRLA register have inverted functionality. */
if (uart_config[uart].flags & UART_FLAG_RXINV) {
dev(uart)->CTRLA.reg |= SERCOM_USART_CTRLA_TXINV;
}
#endif
/* calculate and set baudrate */
uint32_t baud = (((sam0_gclk_freq(uart_config[uart].gclk_src) * 8) / baudrate) / 16);