forked from zephyrproject-rtos/zephyr
-
-
Notifications
You must be signed in to change notification settings - Fork 62
Pull forward a ton of nRF52 UART driver work to support async/DMA UARTs there. #47
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
Merged
petejohanson
merged 30 commits into
zmkfirmware:v3.5.0+zmk-fixes
from
petejohanson:v3.5.0+zmk-fixes-plus-uart
Jun 16, 2025
Merged
Pull forward a ton of nRF52 UART driver work to support async/DMA UARTs there. #47
petejohanson
merged 30 commits into
zmkfirmware:v3.5.0+zmk-fixes
from
petejohanson:v3.5.0+zmk-fixes-plus-uart
Jun 16, 2025
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
When rx_timeout is set to a sufficiently small value, rx_timeout_slab could potentially get set to a greater than necessary value that causes spurious UART_RX_RDY events. Fixes zephyrproject-rtos#62828 Signed-off-by: Jacob Preston <jacob.preston@synapse.com>
ISR function prototype requires const void *. Signed-off-by: Krzysztof Chruściński <krzysztof.chruscinski@nordicsemi.no>
Rework Kconfig to improve handling of multiple UART instances by using Kconfig template file. Signed-off-by: Krzysztof Chruściński <krzysztof.chruscinski@nordicsemi.no>
The ISR prototype used when building without the interrupt driven UART was not matching the signature for interrupt handlers, which results in build warnings. Let's fix it. Signed-off-by: Alberto Escolar Piedras <alberto.escolar.piedras@nordicsemi.no>
Instead of getting the hardcoded address from the DT structure use its symbolic name which will be resolved by the nRF HAL definitions to the same value. This allows the GPIO peripherals' addresses to be redefined for the simulated targets. Signed-off-by: Alberto Escolar Piedras <alberto.escolar.piedras@nordicsemi.no>
For simulation, we cannot get the UART regiter address for the pinctrl config structure from DT, as that cannot match the one allocated at build time. So let's override it at runtime with the correct address which is stored in the UART config structure. Signed-off-by: Alberto Escolar Piedras <alberto.escolar.piedras@nordicsemi.no>
While waiting for the UART to be ready in ISR mode, for simulation only, add a tiny delay per iteration of the busy wait loops to allow time to pass. This Z_SPIN_DELAY is an empty macro for any other target than simulation. Signed-off-by: Alberto Escolar Piedras <alberto.escolar.piedras@nordicsemi.no>
Increase the busy wait time granularity while runing in simulation for poll mode. In this mode, the driver spends a *lot* of time waiting for the UART to be done. The smallest frame time is ~10µs @ 1Mbps, so busywaiting in very small increments is very wastefull as we keep shuting down and turning on the simulated MCU. Let's increase the busy wait time increments of the driver to 3 micros, which should not change much the behaviour. Signed-off-by: Alberto Escolar Piedras <alberto.escolar.piedras@nordicsemi.no>
UART_RX_RDY event can be generated from UARTE interrupt or k_timer handler. When ENDRX event occurs then k_timer is stopped (it can be restarted if there is another buffer provided). However, if UARTE interrupt priority is higher than k_timer priority (RTC is used underneath) then k_timer handler may still be executed later. K_timer notifies new bytes based on RXDRDY HW event which is counter by the TIMER (using PPI). It may happen that RXDRDY event arrives due to byte received into RX FIFO but since there is not buffer provided it stays in that FIFO. Given all this, it was possible that RX_RDY event was reported from ENDRX UARTE event, timer was stopped but because UARTE interrupt had higher priority timer handler is executed after UARTE interrupt is handled. In timer handler TIMER counter reports more bytes and calls UART_RX_RDY event with null buffer and non-zero amount of bytes. Fixed by generating UART_RX_RDY event only if RX buffer is not null. Signed-off-by: Krzysztof Chruściński <krzysztof.chruscinski@nordicsemi.no>
- avoid to use undefined macros in #if expressions Signed-off-by: Hess Nathan <nhess@baumer.com>
Legacy shim takes less flash so it should be a first choice on cores with less code memory (like RISCV cores on nrf54h20). Adding new instances support to the legacy shim. Signed-off-by: Krzysztof Chruściński <krzysztof.chruscinski@nordicsemi.no>
When low power mode is enabled then whenever UARTE is not active, driver attempts to put the peripheral into the lowest power state by stopping and disabling UARTE. However, it did not put pins into sleep state which could lead to increased current consumption. Adding pins state handling to the low power mode. Pins are put into sleep state only if CONFIG_PM_DEVICE=y. Signed-off-by: Krzysztof Chruściński <krzysztof.chruscinski@nordicsemi.no>
This is needed to avoid warnings about uninitialized structure member, which was added in nrfx 3.6. Signed-off-by: Nikodem Kastelik <nikodem.kastelik@nordicsemi.no>
Some UARTE instances may be clocked at higher speeds than 16MHz, so the baudrate setting needs to be scaled accordingly. This patch parses the `clocks` property and obtains the clock-frequency property of the associated clock, assuming it is a fixed-clock. We should ideally have a proper clock control subsystem where frequency can be queried using an API, but we're far from there. Signed-off-by: Gerard Marull-Paretas <gerard@teslabs.com>
When runtime configuration is not enable then we can determine at compile time what are the hardware settings. Function which translates zephyr values to nRF register values is not needed as macros can do that at compile time. This optimization saves almost 400 bytes of code. Signed-off-by: Krzysztof Chruściński <krzysztof.chruscinski@nordicsemi.no>
Code size can significantly reduced (220 bytes per instance) if data structure (stored in RAM) is not initilized (can be moved to .bss). Data for asynchronous API had two fields which can easily be moved to the configuration structure (which is in ROM) because they do not change duing runtime. Signed-off-by: Krzysztof Chruściński <krzysztof.chruscinski@nordicsemi.no>
The initialization of the UARTE is attempting to handle potential improper handover from the bootloader. This handling is additional complexity which should be fixed in the bootloader or whatever component is failing to deinit the UART properly. This commit removes the handling of improper handover from the bootloader, while additionally clearing the ERROR flag when suspending the UARTE component. Signed-off-by: Bjarki Arge Andreasen <bjarki.andreasen@nordicsemi.no>
When interrupt driven instance is using only TX then low power mode is automatically enabled and then TXSTOPPED interrupt is disabled in idle so uarte_nrfx_irq_tx_ready_complete() was returning wrong value. Adding a dedicate flag which holds information is user enabled TX interrupt. Signed-off-by: Krzysztof Chruściński <krzysztof.chruscinski@nordicsemi.no>
When rx_flush() was called with NULL buffer it was an indication to drop data from the FIFO. However, it is still important to get the correct amount of dropped data because when PPI+TIMER are used to count bytes those flushed bytes are also counted (because each byte generates RXDRDY event). If those bytes are not counted then total amount of reported bytes is not correctly aligned with bytes counted by TIMER. Reworking rx_flush() to correctly count number of dropped bytes and then add this flushed bytes to the total amount of RX bytes reported to the user in RXTO event handler. Signed-off-by: Krzysztof Chruściński <krzysztof.chruscinski@nordicsemi.no>
we should be checking for config, not data. Fixes zephyrproject-rtos#78114 Signed-off-by: Anas Nashif <anas.nashif@intel.com>
Use short which is available on some devices. Signed-off-by: Krzysztof Chruściński <krzysztof.chruscinski@nordicsemi.no>
Split async control block structure into tx and rx structures. Signed-off-by: Krzysztof Chruściński <krzysztof.chruscinski@nordicsemi.no>
This is a leftover from pre-pinctrl era and no longer makes sense. Driver always manages gpio through pinctrl. Support removed from uart and uarte shims. Signed-off-by: Krzysztof Chruściński <krzysztof.chruscinski@nordicsemi.no>
Use nrfx_gppi as abstraction over (D)PPI. Signed-off-by: Krzysztof Chruściński <krzysztof.chruscinski@nordicsemi.no>
Update nrfx drivers with the minimum number of bytes that can be sent in a single call to `uart_fifo_fill`. Signed-off-by: Jordan Yates <jordan@embeint.com>
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 <krzysztof.chruscinski@nordicsemi.no>
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 <krzysztof.chruscinski@nordicsemi.no>
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 <krzysztof.chruscinski@nordicsemi.no>
Various API tweaks to account for cherry-pickes and Nordic HAL updates. Signed-off-by: Peter Johanson <peter@peterjohanson.com>
Signed-off-by: Peter Johanson <peter@peterjohanson.com>
628a0d8
into
zmkfirmware:v3.5.0+zmk-fixes
7 of 10 checks passed
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Needed for wired split to work well on nRF52 without impacting BLE timing critical work handling.