From df9ae96263b82f1ae7220223ff5ab0e04f25a8d7 Mon Sep 17 00:00:00 2001 From: bunnie Date: Sun, 26 Oct 2025 19:27:54 +0800 Subject: [PATCH] fixup dabao demo apps - add boot delay on hello world - otherwise you might miss it because it prints before the console is enumerated - add preemption to the dabao environment - improve error handling --- apps-dabao/dabao-console/Cargo.toml | 2 ++ apps-dabao/dabao-console/src/main.rs | 5 +++++ apps-dabao/dabao-console/src/repl.rs | 16 ++++++++++++---- apps-dabao/helloworld/src/main.rs | 8 +++++++- 4 files changed, 26 insertions(+), 5 deletions(-) diff --git a/apps-dabao/dabao-console/Cargo.toml b/apps-dabao/dabao-console/Cargo.toml index 600aaa6f9..39d3561d9 100644 --- a/apps-dabao/dabao-console/Cargo.toml +++ b/apps-dabao/dabao-console/Cargo.toml @@ -19,6 +19,7 @@ bao1x-api = { path = "../../libs/bao1x-api" } bao1x-hal-service = { path = "../../services/bao1x-hal-service", optional = true } bao1x-emu = { path = "../../services/bao1x-emu", optional = true } usb-bao1x = { path = "../../services/usb-bao1x" } +bytemuck = "1.24.0" aes = { path = "../../services/aes", default-features = false, optional = true } @@ -31,6 +32,7 @@ bao1x = ["utralib/bao1x", "usb-bao1x/bao1x", "aes/bao1x"] board-dabao = [ "bao1x-hal-service", "bao1x-hal/board-dabao", + # "bao1x-hal/debug-print-duart", "usb-bao1x/board-dabao", ] ctap-bringup = [] diff --git a/apps-dabao/dabao-console/src/main.rs b/apps-dabao/dabao-console/src/main.rs index 36e225bb9..30270644e 100644 --- a/apps-dabao/dabao-console/src/main.rs +++ b/apps-dabao/dabao-console/src/main.rs @@ -4,6 +4,7 @@ mod ctap; mod repl; mod shell; use cmds::*; +#[cfg(feature = "usb")] use usb_bao1x::UsbHid; fn main() { @@ -12,6 +13,10 @@ fn main() { log::info!("my PID is {}", xous::process::id()); let tt = ticktimer::Ticktimer::new().unwrap(); + let hal = bao1x_hal_service::Hal::new(); + // allow preemption in the dabao console environment + hal.set_preemption(true); + #[cfg(feature = "usb")] { let usb = UsbHid::new(); diff --git a/apps-dabao/dabao-console/src/repl.rs b/apps-dabao/dabao-console/src/repl.rs index 4a0798df2..b2e19b0e2 100644 --- a/apps-dabao/dabao-console/src/repl.rs +++ b/apps-dabao/dabao-console/src/repl.rs @@ -83,13 +83,21 @@ impl Repl { // take the input and pass it on to the various command parsers, and attach result if let Some(local) = &mut self.input { println!("[console] {}", local); - if let Some(res) = self.env.dispatch(Some(local), None).expect("command dispatch failed") { - println!("{}\r", res); + match self.env.dispatch(Some(local), None) { + Ok(Some(res)) => println!("{}\r", res), + Ok(None) => println!("\r"), + Err(e) => { + println!("Command error: {:?}", e); + } } } else if let Some(msg) = &self.msg { log::trace!("processing callback msg: {:?}", msg); - if let Some(res) = self.env.dispatch(None, Some(msg)).expect("callback failed") { - println!("{}", res); + match self.env.dispatch(None, Some(msg)) { + Ok(Some(res)) => println!("{}\r", res), + Ok(None) => println!("\r"), + Err(e) => { + println!("Command error: {:?}", e); + } } } diff --git a/apps-dabao/helloworld/src/main.rs b/apps-dabao/helloworld/src/main.rs index e5cf5077e..a6f83ac5d 100644 --- a/apps-dabao/helloworld/src/main.rs +++ b/apps-dabao/helloworld/src/main.rs @@ -4,7 +4,13 @@ fn main() -> ! { log::set_max_level(log::LevelFilter::Info); log::info!("Hello world PID is {}", xous::process::id()); - println!("Hello world"); + // This delay of 5 seconds allows users watching over USB serial + // console a few seconds to connect the console and see the output. + // Otherwise, it will "print" to a console that's not listening. + std::thread::sleep(std::time::Duration::from_secs(5)); + + // This is the hello world! + println!("Hello world!"); // This ensures a graceful exit from the process. xous::terminate_process(0)