Skip to content

Generic UART driver based on Device Trees#72

Open
xarantolus wants to merge 3 commits into
mainfrom
feature/generic-uart
Open

Generic UART driver based on Device Trees#72
xarantolus wants to merge 3 commits into
mainfrom
feature/generic-uart

Conversation

@xarantolus
Copy link
Copy Markdown
Contributor

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.

Copilot AI review requested due to automatic review settings May 10, 2026 21:04
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 dtgen to emit a UART registry/query API from DT pinctrl + interrupts, and resolve the console UART from chosen.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 thread src/drivers/uart/wait.rs
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;
Comment thread src/drivers/uart/mod.rs
}
}

fn duration_to_ticks(d: Duration) -> u64 {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we should maybe put that directly in the time module

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants