Generic UART driver based on Device Trees#72
Open
xarantolus wants to merge 3 commits into
Open
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
This PR introduces a device-tree-driven, generic UART stack (codegen + HAL + kernel driver + uAPI) for STM32L4, and switches the kernel console UART selection from an environment variable to chosen.osiris,console in the DTS. It also integrates UART interrupts with the dynamic IRQ registration system.
Changes:
- Extend
dtgento emit a UART registry/query API from DT pinctrl + interrupts, and resolve the console UART fromchosen.osiris,console. - Add a kernel UART driver (blocking + NB + waiter/callback wakeups) and expose it via
src/uapi::uart. - Replace the previous “debug UART via OSIRIS_DEBUG_UART” path with a DT-driven console UART, updating Cortex-M init/print and presets accordingly.
Reviewed changes
Copilot reviewed 16 out of 16 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
| xtasks/crates/dtgen/src/codegen.rs | Adds UART DT registry/query codegen, shared STM32 pinmux decode helper, console resolution via chosen.osiris,console. |
| src/uapi/uart.rs | Adds uAPI re-export and open() wrapper for UART devices. |
| src/uapi.rs | Exposes the new uapi::uart module. |
| src/sched.rs | Adds kick_by_uid and exports an ISR-safe kick_thread C-ABI symbol. |
| src/drivers/uart/wait.rs | Implements IRQ-driven waiter lists/callback dispatch and dynamic IRQ registration for UART slots. |
| src/drivers/uart/mod.rs | Adds UART Device abstraction with blocking/NB read/write and timeout handling. |
| src/drivers.rs | Registers the UART driver module in the kernel drivers tree. |
| presets/stm32l4r5zi_def.toml | Removes OSIRIS_DEBUG_UART preset setting (console now selected via DTS). |
| machine/cortex-m/st/stm32l4/interface/uart.h | Introduces new STM32L4 UART interface API (IT-driven rings + console mode). |
| machine/cortex-m/st/stm32l4/interface/uart.c | Implements multi-UART slot management, ring buffers, and HAL callbacks for STM32L4. |
| machine/cortex-m/st/stm32l4/interface/export.h | Switches exported UART interface to uart.h instead of debug-uart-only symbols. |
| machine/cortex-m/src/stub/uart.rs | Adds stub UART HAL for non-hardware builds. |
| machine/cortex-m/src/stub.rs | Exposes the new stub UART module. |
| machine/cortex-m/src/native/uart.rs | Adds native UART HAL glue: DT registry lookup, C FFI calls, console init/write. |
| machine/cortex-m/src/native.rs | Initializes console UART from DT and routes Machine::print through it. |
| machine/cortex-m/build.rs | Errors out if OSIRIS_DEBUG_UART is set; continues DT generation and vector table generation. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
+1457
to
+1460
| let base = pin_ctrl | ||
| .reg | ||
| .and_then(|(b, _)| usize::try_from(b).ok()) | ||
| .unwrap_or(0); |
Comment on lines
+1554
to
+1561
| "cargo::warning=dtgen: skipping UART node `{}` — no `tx` pin in pinctrl-0", | ||
| node.name | ||
| ); | ||
| continue; | ||
| }; | ||
| let Some(rx) = rx else { | ||
| eprintln!( | ||
| "cargo::warning=dtgen: skipping UART node `{}` — no `rx` pin in pinctrl-0", |
Comment on lines
+196
to
+199
| // IPSR = NVIC line + 16 on Cortex-M. | ||
| let vector = dev.irqn() as usize + 16; | ||
| unsafe { | ||
| crate::irq::register_irq(vector, vector_dispatch, Some(slot as usize)) |
Comment on lines
+281
to
+282
| if (HAL_UART_Receive_IT(&slot->huart, (uint8_t *)&slot->rx_byte, 1) != HAL_OK) | ||
| return UART_ERR_IO; |
gkuznik
reviewed
May 12, 2026
| } | ||
| } | ||
|
|
||
| fn duration_to_ticks(d: Duration) -> u64 { |
Member
There was a problem hiding this comment.
we should maybe put that directly in the time module
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
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.
Imagine #41, except that you can now define UART pins in the device tree definition.
Also uses the new dynamic IRQ system.
Mostly tested via debug UART.