add println_d! macro to bao1x-hal

this allows forcing prints to go to the duart

this is useful for debugging early boot issues
This commit is contained in:
bunnie 2025-12-19 03:30:20 +08:00
parent e5790d76a3
commit 5195d46d7b

View file

@ -139,3 +139,56 @@ macro_rules! println
$crate::print!(concat!($fmt, "\r\n"), $($args)+)
});
}
// ==== DUART-only debug print ====
// Used for forcing the use of DUART in debugging
pub struct Duart {}
impl Duart {
/// Print a character
pub fn putc(&self, c: u8) {
let base = utra::duart::HW_DUART_BASE as *mut u32;
let mut uart = CSR::new(base);
if uart.rf(utra::duart::SFR_CR_SFR_CR) == 0 {
uart.wfo(utra::duart::SFR_CR_SFR_CR, 1);
}
while uart.r(utra::duart::SFR_SR) != 0 {}
uart.wo(utra::duart::SFR_TXD, c as u32);
}
}
impl Write for Duart {
fn write_str(&mut self, s: &str) -> Result<(), Error> {
for c in s.bytes() {
self.putc(c);
}
Ok(())
}
}
#[macro_use]
/// Hardware debug print module
pub mod debug_print_duart {
#[macro_export]
macro_rules! print_d
{
($($args:tt)+) => ({
use core::fmt::Write;
let _ = write!(crate::debug::Duart {}, $($args)+);
});
}
}
#[macro_export]
macro_rules! println_d
{
() => ({
$crate::print_d!("\r\n")
});
($fmt:expr) => ({
$crate::print_d!(concat!($fmt, "\r\n"))
});
($fmt:expr, $($args:tt)+) => ({
$crate::print_d!(concat!($fmt, "\r\n"), $($args)+)
});
}