Skip to content

Commit

Permalink
drivers: serial: nrfx_uarte: Rework driver to support new features
Browse files Browse the repository at this point in the history
Rework driver to support new way of asynchronous RX handling.
Previously RX was handled in two modes: using RXDRDY interrupt for byte
counting or TIMER + PPI. Both modes had flaws. RXDRDY interrupt mode
could miscalculated amount of received bytes when interrupt was not
handled on time. Data was not lost but was not reported on time that
could lead to issues. PPI+TIMER mode requires additional resources
thus it was not the default mode. Often user was not aware of that
option and was expiriencing driver RX faults.

New RX mode is switching buffers when there is new data (RXDRDY event
not set for given amount of time). It does not require additional
resources to get precise byte counting. Additionally, this is in line
with new UARTE feature (RX frame timeout) which is present in nRF54X
devices. The behavior of the driver is the same for legacy devices
and new one. For legacy devices k_timer periodic interrupts are used
to check if there are any new bytes and it is not needed when RX frame
timeout is present.

Improved RX mode is enabled by default
(CONFIG_UART_NRFX_UARTE_ENHANCED_RX=y) but legacy modes are still
available though not recommended to be used.

Note that new RX mode behaves a bit different because timeout always
triggers switch of buffers which means that there will be no
UART_RX_RDY events with non-zero offset. It also means that every
UART_RX_RDY will be followed by UART_RX_BUF_RELEASED.

Driver structures are reworked and asynchronous data is split into two
structures: tx and rx data.

Additionally, support for DMM is added to asynchronous RX. For TX a
fixed size, statically allocated buffer is used. Same goes for single
byte buffers used for polling and interrupt driven mode (and RX FIFO
flush buffer).

After rework, driver is recommended to be used for all platforms as it
performs much better and takes much less code than the second UART shim
available for Nordic devices.

Signed-off-by: Krzysztof Chruściński <[email protected]>
  • Loading branch information
nordic-krch committed Jul 5, 2024
1 parent 46b37ce commit bb8c5e7
Show file tree
Hide file tree
Showing 3 changed files with 620 additions and 381 deletions.
17 changes: 13 additions & 4 deletions drivers/serial/Kconfig.nrfx
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,19 @@ config UART_NRFX_UARTE
config UART_NRFX_UARTE_LEGACY_SHIM
bool "Legacy UARTE shim"
depends on UART_NRFX_UARTE
# New shim takes more ROM. Until it is fixed use legacy shim.
depends on RISCV || !SOC_SERIES_NRF54HX
default y if !SOC_SERIES_NRF54LX
default n
default y

config UART_NRFX_UARTE_ENHANCED_RX
bool "Enhanced RX handling"
depends on UART_ASYNC_API
depends on UART_NRFX_UARTE_LEGACY_SHIM
default y if !(UART_0_NRF_HW_ASYNC || UART_1_NRF_HW_ASYNC || UART_2_NRF_HW_ASYNC)
help
Enable RX handling mode which is switching buffers on timeout. This is an
enhancement compared to other two modes (default and hardware assisted).
Default mode could miscount bytes when interrupt was not handled on time
and hardware assisted required TIMER peripheral instance and PPI channel
for accurate byte counting.

config UART_ASYNC_TX_CACHE_SIZE
int "TX cache buffer size"
Expand Down
1 change: 1 addition & 0 deletions drivers/serial/Kconfig.nrfx_uart_instance
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ config UART_$(nrfx_uart_num)_NRF_ASYNC_LOW_POWER
depends on HAS_HW_NRF_UARTE$(nrfx_uart_num)
depends on UART_ASYNC_API
depends on UART_NRFX_UARTE_LEGACY_SHIM
default y
help
When enabled, UARTE is enabled before each TX or RX usage and disabled
when not used. Disabling UARTE while in idle allows to achieve lowest
Expand Down
Loading

0 comments on commit bb8c5e7

Please sign in to comment.