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.
This commit is contained in:
bunnie 2025-10-18 01:16:42 +08:00
parent a40bb7c244
commit 11a95e13d1
6 changed files with 85 additions and 8 deletions

View file

@ -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"]

View file

@ -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;
}
}
}
}

View file

@ -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")]

View file

@ -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);

View file

@ -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"
);

View file

@ -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!("");
}
}