Skip to content

Commit

Permalink
[nrf fromlist] drivers: serial: nrfx_uarte: Rework driver to support …
Browse files Browse the repository at this point in the history
…new features

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.

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.

Upstream PR: zephyrproject-rtos#78887

Signed-off-by: Krzysztof Chruściński <[email protected]>
  • Loading branch information
nordic-krch committed Oct 8, 2024
1 parent bc67230 commit 971a934
Show file tree
Hide file tree
Showing 3 changed files with 375 additions and 229 deletions.
12 changes: 12 additions & 0 deletions drivers/serial/Kconfig.nrfx
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,18 @@ config UART_NRFX_UARTE_LEGACY_SHIM
# New shim takes more ROM. Until it is fixed use legacy shim.
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"
depends on UART_ASYNC_API
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 971a934

Please sign in to comment.