-
Notifications
You must be signed in to change notification settings - Fork 6.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
drivers: serial: nrfx_uarte: Rework driver to support new features #78887
drivers: serial: nrfx_uarte: Rework driver to support new features #78887
Conversation
c140ae3
to
2bc614a
Compare
6279c82
to
863a6e2
Compare
…struct pointer Refactor RX asynchronous API function to use a pointer to the RX async data structure instead of top level data structure pointer. It improves readability with more concise code. Upstream PR: zephyrproject-rtos/zephyr#78887 Signed-off-by: Krzysztof Chruściński <[email protected]>
…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/zephyr#78887 Signed-off-by: Krzysztof Chruściński <[email protected]>
…eout Frame timeout is a hardware feature present in newer versions of UARTE (e.g. in NRF54X platforms) for detecting idle state on RX line and ending RX after configurable timeout. Upstream PR: zephyrproject-rtos/zephyr#78887 Signed-off-by: Krzysztof Chruściński <[email protected]>
…struct pointer Refactor RX asynchronous API function to use a pointer to the RX async data structure instead of top level data structure pointer. It improves readability with more concise code. Upstream PR: zephyrproject-rtos#78887 Signed-off-by: Krzysztof Chruściński <[email protected]>
…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]>
…eout Frame timeout is a hardware feature present in newer versions of UARTE (e.g. in NRF54X platforms) for detecting idle state on RX line and ending RX after configurable timeout. Upstream PR: zephyrproject-rtos#78887 Signed-off-by: Krzysztof Chruściński <[email protected]>
…struct pointer Refactor RX asynchronous API function to use a pointer to the RX async data structure instead of top level data structure pointer. It improves readability with more concise code. Upstream PR: zephyrproject-rtos/zephyr#78887 Signed-off-by: Krzysztof Chruściński <[email protected]>
…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/zephyr#78887 Signed-off-by: Krzysztof Chruściński <[email protected]>
…eout Frame timeout is a hardware feature present in newer versions of UARTE (e.g. in NRF54X platforms) for detecting idle state on RX line and ending RX after configurable timeout. Upstream PR: zephyrproject-rtos/zephyr#78887 Signed-off-by: Krzysztof Chruściński <[email protected]>
…struct pointer Refactor RX asynchronous API function to use a pointer to the RX async data structure instead of top level data structure pointer. It improves readability with more concise code. Upstream PR: zephyrproject-rtos/zephyr#78887 Signed-off-by: Krzysztof Chruściński <[email protected]>
…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/zephyr#78887 Signed-off-by: Krzysztof Chruściński <[email protected]>
…eout Frame timeout is a hardware feature present in newer versions of UARTE (e.g. in NRF54X platforms) for detecting idle state on RX line and ending RX after configurable timeout. Upstream PR: zephyrproject-rtos/zephyr#78887 Signed-off-by: Krzysztof Chruściński <[email protected]>
@masz-nordic can you take a look? |
drivers/serial/uart_nrfx_uarte.c
Outdated
uint32_t divisor = 1000000 / timeout; | ||
uint32_t bauds = baudrate / divisor; | ||
|
||
return MIN(bauds, UARTE_FRAMETIMEOUT_COUNTERTOP_Msk); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should be replaced with HAL define in next nrfx release.
@dcpleung can you take a look? |
Refactor RX asynchronous API function to use a pointer to the RX async data structure instead of top level data structure pointer. It improves readability with more concise code. Signed-off-by: Krzysztof Chruściński <[email protected]>
64e292f
6288a6a
to
812e4d8
Compare
@anangl can you take a look? I've applied your comments. |
@anangl What would you suggest? Increase tolerance in the test?
It is true when |
Regarding zephyr/drivers/serial/uart_nrfx_uarte.c Line 987 in 829c03b
but in the same function later on it is decremented by the slab: zephyr/drivers/serial/uart_nrfx_uarte.c Line 1032 in 829c03b
So as the result it triggers RX_RDY after 4 timeouts without new bytes. It added logging to
New bytes is detected 9ms after end of TX (first timeout) but in the same timeout it is decremented for the first time. RX_RDY is triggered 49.9ms after TX_DONE. |
I would add a comment that since it is not known when exactly the RXDRDY event was triggered and in the worst case it could have been right at the beginning of the checked timeout part, timeout needs to be triggered at
Right, I got confused with those partial timeout checks. |
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 (CONFIG_UART_NRFX_UARTE_ENHANCED_RX=y) 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. Signed-off-by: Krzysztof Chruściński <[email protected]>
Frame timeout is a hardware feature present in newer versions of UARTE (e.g. in NRF54X platforms) for detecting idle state on RX line and ending RX after configurable timeout. Signed-off-by: Krzysztof Chruściński <[email protected]>
812e4d8
to
f49a4b5
Compare
Comment added. |
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.
This PR is main part of #75462 which contains additional changes and significant changes in tests. It is created for ease of review as #75462 is overwhelming.
It also contains #78886.