From 464d26e7b0a1e15d0fa8aef3434663d368241bde Mon Sep 17 00:00:00 2001 From: bunnie Date: Sat, 18 Oct 2025 01:15:52 +0800 Subject: [PATCH 1/3] adjust default voltages & freqs to be in-line with validation numbers --- bao1x-boot/boot0/src/platform/bao1x/bao1x.rs | 6 +++--- bao1x-boot/boot0/src/version.rs | 1 + bao1x-boot/boot1/src/platform/bao1x/bao1x.rs | 6 +++--- bao1x-boot/boot1/src/version.rs | 1 + 4 files changed, 8 insertions(+), 6 deletions(-) create mode 100644 bao1x-boot/boot0/src/version.rs create mode 100644 bao1x-boot/boot1/src/version.rs diff --git a/bao1x-boot/boot0/src/platform/bao1x/bao1x.rs b/bao1x-boot/boot0/src/platform/bao1x/bao1x.rs index df45b95a9..fb4609713 100644 --- a/bao1x-boot/boot0/src/platform/bao1x/bao1x.rs +++ b/bao1x-boot/boot0/src/platform/bao1x/bao1x.rs @@ -318,7 +318,7 @@ pub unsafe fn init_clock_asic(freq_hz: u32) -> u32 { // commit dividers daric_cgu.add(utra::sysctrl::SFR_CGUSET.offset()).write_volatile(0x32); - if freq_hz >= 600_000_000 { + if freq_hz > 700_000_000 { crate::println!("setting vdd85 to 0.893v"); let mut ao_sysctrl = CSR::new(utralib::HW_AO_SYSCTRL_BASE as *mut u32); ao_sysctrl.wo(utra::ao_sysctrl::SFR_PMUTRM0CSR, 0x08421FF1); @@ -326,9 +326,9 @@ pub unsafe fn init_clock_asic(freq_hz: u32) -> u32 { cgu.wo(sysctrl::SFR_IPCARIPFLOW, 0x57); crate::platform::delay_at_sysfreq(20, 48_000_000); } else { - crate::println!("setting vdd85 to 0.80v"); + crate::println!("setting vdd85 to 0.81v"); let mut ao_sysctrl = CSR::new(utralib::HW_AO_SYSCTRL_BASE as *mut u32); - ao_sysctrl.wo(utra::ao_sysctrl::SFR_PMUTRM0CSR, 0x08421080); + ao_sysctrl.wo(utra::ao_sysctrl::SFR_PMUTRM0CSR, 0x08421290); ao_sysctrl.wo(utra::ao_sysctrl::SFR_PMUTRM1CSR, 0x2); cgu.wo(sysctrl::SFR_IPCARIPFLOW, 0x57); crate::platform::delay_at_sysfreq(20, 48_000_000); diff --git a/bao1x-boot/boot0/src/version.rs b/bao1x-boot/boot0/src/version.rs new file mode 100644 index 000000000..cb070b3ca --- /dev/null +++ b/bao1x-boot/boot0/src/version.rs @@ -0,0 +1 @@ +pub const SEMVER: &'static str = "v0.9.16-1847-g0efcd0af9"; diff --git a/bao1x-boot/boot1/src/platform/bao1x/bao1x.rs b/bao1x-boot/boot1/src/platform/bao1x/bao1x.rs index f2907275d..a1103ad66 100644 --- a/bao1x-boot/boot1/src/platform/bao1x/bao1x.rs +++ b/bao1x-boot/boot1/src/platform/bao1x/bao1x.rs @@ -440,7 +440,7 @@ pub unsafe fn init_clock_asic(freq_hz: u32) -> u32 { // commit dividers daric_cgu.add(utra::sysctrl::SFR_CGUSET.offset()).write_volatile(0x32); - if freq_hz >= 600_000_000 { + if freq_hz > 700_000_000 { crate::println!("setting vdd85 to 0.893v"); let mut ao_sysctrl = CSR::new(utralib::HW_AO_SYSCTRL_BASE as *mut u32); ao_sysctrl.wo(utra::ao_sysctrl::SFR_PMUTRM0CSR, 0x08421FF1); @@ -448,9 +448,9 @@ pub unsafe fn init_clock_asic(freq_hz: u32) -> u32 { cgu.wo(sysctrl::SFR_IPCARIPFLOW, 0x57); crate::platform::delay_at_sysfreq(20, 48_000_000); } else { - crate::println!("setting vdd85 to 0.80v"); + crate::println!("setting vdd85 to 0.81v"); let mut ao_sysctrl = CSR::new(utralib::HW_AO_SYSCTRL_BASE as *mut u32); - ao_sysctrl.wo(utra::ao_sysctrl::SFR_PMUTRM0CSR, 0x08421080); + ao_sysctrl.wo(utra::ao_sysctrl::SFR_PMUTRM0CSR, 0x08421290); ao_sysctrl.wo(utra::ao_sysctrl::SFR_PMUTRM1CSR, 0x2); cgu.wo(sysctrl::SFR_IPCARIPFLOW, 0x57); crate::platform::delay_at_sysfreq(20, 48_000_000); diff --git a/bao1x-boot/boot1/src/version.rs b/bao1x-boot/boot1/src/version.rs new file mode 100644 index 000000000..cb070b3ca --- /dev/null +++ b/bao1x-boot/boot1/src/version.rs @@ -0,0 +1 @@ +pub const SEMVER: &'static str = "v0.9.16-1847-g0efcd0af9"; From a40bb7c2447ce75d8a8ac787d2ebe1bf8f659e51 Mon Sep 17 00:00:00 2001 From: bunnie Date: Sat, 18 Oct 2025 01:16:16 +0800 Subject: [PATCH 2/3] other half of the adjustment --- libs/bao1x-api/src/offsets/baosec.rs | 4 ++-- libs/bao1x-api/src/offsets/dabao.rs | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/libs/bao1x-api/src/offsets/baosec.rs b/libs/bao1x-api/src/offsets/baosec.rs index c19c665b7..35f9d5942 100644 --- a/libs/bao1x-api/src/offsets/baosec.rs +++ b/libs/bao1x-api/src/offsets/baosec.rs @@ -38,5 +38,5 @@ pub const APP_RRAM_OFFSET: usize = 0; pub const APP_RRAM_LEN: usize = 0; // Regulator voltage target at boot -pub const CPU_VDD_LDO_BOOT_MV: u32 = 900; -pub const DEFAULT_FCLK_FREQUENCY: u32 = 800_000_000; +pub const CPU_VDD_LDO_BOOT_MV: u32 = 810; +pub const DEFAULT_FCLK_FREQUENCY: u32 = 700_000_000; diff --git a/libs/bao1x-api/src/offsets/dabao.rs b/libs/bao1x-api/src/offsets/dabao.rs index 96cbff1de..76b1c556a 100644 --- a/libs/bao1x-api/src/offsets/dabao.rs +++ b/libs/bao1x-api/src/offsets/dabao.rs @@ -25,5 +25,5 @@ pub const APP_RRAM_START: usize = 0x6000_0000 + APP_RRAM_OFFSET - crate::signatu pub const APP_RRAM_LEN: usize = 0xD_A000 + crate::signatures::SIGBLOCK_LEN; // Regulator voltage target at boot -pub const CPU_VDD_LDO_BOOT_MV: u32 = 900; -pub const DEFAULT_FCLK_FREQUENCY: u32 = 800_000_000; +pub const CPU_VDD_LDO_BOOT_MV: u32 = 810; +pub const DEFAULT_FCLK_FREQUENCY: u32 = 700_000_000; From 11a95e13d125d4cc74a12126dcbb07cccb62ae40 Mon Sep 17 00:00:00 2001 From: bunnie Date: Sat, 18 Oct 2025 01:16:42 +0800 Subject: [PATCH 3/3] add a small self-test routine to baremetal when enabled as a feature, runs through all the I/Os available on a dabao board. This will be the default firmware loaded on a doabao board. --- baremetal/Cargo.toml | 9 ++-- baremetal/src/main.rs | 12 +++++ baremetal/src/platform/bao1x.rs | 2 + baremetal/src/platform/bao1x/bao1x.rs | 11 ++-- .../src/platform/bao1x/dabao_selftest.rs | 53 +++++++++++++++++++ baremetal/src/repl.rs | 6 +++ 6 files changed, 85 insertions(+), 8 deletions(-) create mode 100644 baremetal/src/platform/bao1x/dabao_selftest.rs diff --git a/baremetal/Cargo.toml b/baremetal/Cargo.toml index 460692e37..3e6daf46f 100644 --- a/baremetal/Cargo.toml +++ b/baremetal/Cargo.toml @@ -39,14 +39,12 @@ artybio = [ artyvexii = ["utralib/artyvexii", "linked_list_allocator"] # Baochip feature tree below -v0p9 = [] # selects RAM timings for VDD core = 0.9V bao1x = [ "utralib/bao1x", "linked_list_allocator", "bao1x-hal/loader-baosec", # "bao1x-hal/debug-print-usb", "bao1x-api", - "v0p9", "digest", "sha2-bao1x", ] @@ -73,6 +71,11 @@ bao1x-trng = [ ] trng-debug = [] verbose-debug = [] +dabao-selftest = [ + "xous-bio-bdma/bio-mul", + "xous-bio-bdma/baremetal", + "xous-bio-bdma/bao1x", +] verilator-only = [] -default = ["bao1x-usb", "bao1x-trng", "bao1x-bio"] +default = ["bao1x-usb", "dabao-selftest"] diff --git a/baremetal/src/main.rs b/baremetal/src/main.rs index 8d49f26a1..007ea2bee 100644 --- a/baremetal/src/main.rs +++ b/baremetal/src/main.rs @@ -7,6 +7,7 @@ mod asm; mod platform; mod repl; + use alloc::collections::VecDeque; use core::cell::RefCell; #[cfg(feature = "bao1x-usb")] @@ -95,6 +96,10 @@ pub unsafe extern "C" fn rust_entry() -> ! { USB_CONNECTED.load(Ordering::SeqCst), crate::platform::usb::TX_IDLE.load(Ordering::SeqCst) ); + + #[cfg(feature = "dabao-selftest")] + let mut self_test_ran = false; + #[cfg(feature = "bao1x-usb")] // do the main loop through either USB interface or serial port loop { @@ -107,6 +112,13 @@ pub unsafe extern "C" fn rust_entry() -> ! { crate::println!("USB is connected!"); last_usb_state = new_usb_state; USB_CONNECTED.store(true, core::sync::atomic::Ordering::SeqCst); + #[cfg(feature = "dabao-selftest")] + { + if !self_test_ran { + crate::dabao_selftest::dabao_selftest(); + self_test_ran = true; + } + } } } diff --git a/baremetal/src/platform/bao1x.rs b/baremetal/src/platform/bao1x.rs index e3e5883b4..03ed3b200 100644 --- a/baremetal/src/platform/bao1x.rs +++ b/baremetal/src/platform/bao1x.rs @@ -4,6 +4,8 @@ pub use bao1x::*; pub mod avtrng; #[cfg(feature = "bao1x-bio")] pub mod bio; +#[cfg(feature = "dabao-selftest")] +pub mod dabao_selftest; pub mod debug; pub mod irq; #[cfg(feature = "bao1x-usb")] diff --git a/baremetal/src/platform/bao1x/bao1x.rs b/baremetal/src/platform/bao1x/bao1x.rs index 7b7d9de8f..94037efe2 100644 --- a/baremetal/src/platform/bao1x/bao1x.rs +++ b/baremetal/src/platform/bao1x/bao1x.rs @@ -28,7 +28,7 @@ pub const SCRATCH_PAGE: usize = HEAP_START + HEAP_LEN + 4096; pub const UART_IFRAM_ADDR: usize = bao1x_hal::board::UART_DMA_TX_BUF_PHYS; -pub const SYSTEM_CLOCK_FREQUENCY: u32 = 800_000_000; +pub const SYSTEM_CLOCK_FREQUENCY: u32 = 700_000_000; pub const SYSTEM_TICK_INTERVAL_MS: u32 = 1; pub fn early_init() { @@ -40,7 +40,8 @@ pub fn early_init() { // Ensure SRAM timings are set for 900mV operation before setting fast clock frequency. We will // be running at full tilt on baosec. - let trim_table = bao1x_hal::sram_trim::get_sram_trim_for_voltage(900); + let trim_table = + bao1x_hal::sram_trim::get_sram_trim_for_voltage(bao1x_api::offsets::dabao::CPU_VDD_LDO_BOOT_MV); let mut rbist = CSR::new(utra::rbist_wrp::HW_RBIST_WRP_BASE as *mut u32); for item in trim_table { rbist.wo(utra::rbist_wrp::SFRCR_TRM, item.raw_value()); @@ -296,7 +297,7 @@ pub unsafe fn init_clock_asic(freq_hz: u32) -> u32 { // commit dividers daric_cgu.add(utra::sysctrl::SFR_CGUSET.offset()).write_volatile(0x32); - if freq_hz >= 600_000_000 { + if freq_hz > 700_000_000 { crate::println!("setting vdd85 to 0.893v"); let mut ao_sysctrl = CSR::new(utralib::HW_AO_SYSCTRL_BASE as *mut u32); ao_sysctrl.wo(utra::ao_sysctrl::SFR_PMUTRM0CSR, 0x08421FF1); @@ -304,9 +305,9 @@ pub unsafe fn init_clock_asic(freq_hz: u32) -> u32 { cgu.wo(sysctrl::SFR_IPCARIPFLOW, 0x57); crate::platform::delay_at_sysfreq(20, 48_000_000); } else { - crate::println!("setting vdd85 to 0.80v"); + crate::println!("setting vdd85 to 0.81v"); let mut ao_sysctrl = CSR::new(utralib::HW_AO_SYSCTRL_BASE as *mut u32); - ao_sysctrl.wo(utra::ao_sysctrl::SFR_PMUTRM0CSR, 0x08421080); + ao_sysctrl.wo(utra::ao_sysctrl::SFR_PMUTRM0CSR, 0x08421290); ao_sysctrl.wo(utra::ao_sysctrl::SFR_PMUTRM1CSR, 0x2); cgu.wo(sysctrl::SFR_IPCARIPFLOW, 0x57); crate::platform::delay_at_sysfreq(20, 48_000_000); diff --git a/baremetal/src/platform/bao1x/dabao_selftest.rs b/baremetal/src/platform/bao1x/dabao_selftest.rs new file mode 100644 index 000000000..66fac4b5f --- /dev/null +++ b/baremetal/src/platform/bao1x/dabao_selftest.rs @@ -0,0 +1,53 @@ +use utralib::*; +use xous_bio_bdma::*; + +// pinmask 29 is not mapped out. This is tested by pushing the button to allow boot +const DABAO_PINMASK: u32 = 0b0001_1111_1000_1111_0111_1000_011_1110; // 0x1F8F783E; + +pub fn dabao_selftest() { + let mut bio_ss = BioSharedState::new(); + let iox = bao1x_hal::iox::Iox::new(utra::iox::HW_IOX_BASE as *mut u32); + iox.set_ports_from_pio_bitmask(DABAO_PINMASK); + bio_ss.init(); + bio_ss.load_code(db_pin_test_code(), 0, BioCore::Core0); + bio_ss.bio.wo(utra::bio_bdma::SFR_QDIV0, 0x1_0001); + bio_ss.set_core_run_states([true, false, false, false]); + + let pin_ordering: [u32; 19] = [28, 27, 26, 25, 24, 23, 19, 18, 17, 16, 14, 13, 12, 11, 1, 2, 3, 4, 5]; + + crate::println!( + "Starting dabao mini self-test: sets each pin sequentially, in a counter-clockwise order." + ); + crate::usb::flush(); + crate::delay(100); + const TOTAL_ITERS: usize = 4; + for i in 0..TOTAL_ITERS { + crate::println!("Iter {}/{}", i + 1, TOTAL_ITERS); + crate::usb::flush(); + for pin in pin_ordering { + crate::print!("{} ", pin); + crate::usb::flush(); + bio_ss.bio.wo(utra::bio_bdma::SFR_TXF0, 1u32 << pin); + crate::delay(100); + } + crate::println!(""); + } + crate::println!("Done; pin state reverted"); + crate::usb::flush(); + iox.set_ports_from_pio_bitmask(0x0); +} + +#[rustfmt::skip] +bio_code!(db_pin_test_code, BM_PIN_TEST_START, BM_PIN_TEST_END, + // set all pins as inputs + "li a0, -1", + "mv x26, a0", // mask + "mv x25, a0", // inputs + "li a1, 0x3F8F783E", // connected pin mask + "mv x24, a1", // select pins as outputs + // receive data from the FIFO, update it to the pins +"10:", + "mv t0, x16", // wait for input + "mv x21, t0", // pass to output pins + "j 10b" +); diff --git a/baremetal/src/repl.rs b/baremetal/src/repl.rs index be4a640a8..5206bd34e 100644 --- a/baremetal/src/repl.rs +++ b/baremetal/src/repl.rs @@ -1005,6 +1005,10 @@ impl Repl { crate::println!("Sha512 failed: {:x?}", digest); } } + #[cfg(feature = "dabao-selftest")] + "dbtest" => { + crate::dabao_selftest::dabao_selftest(); + } "echo" => { for word in args { crate::print!("{} ", word); @@ -1026,6 +1030,8 @@ impl Repl { crate::print!(", usb"); #[cfg(feature = "bao1x-trng")] crate::print!(", trngro, trngav"); + #[cfg(feature = "dabao-selftest")] + crate::print!(", dbtest"); crate::println!(""); } }