mirror of
https://github.com/saymrwulf/xous-core.git
synced 2026-11-15 08:30:02 +00:00
add rram debug commands & duart-debug mode for the HAL in std
This commit is contained in:
parent
70a0b62014
commit
3a02dc125c
4 changed files with 158 additions and 1 deletions
|
|
@ -23,6 +23,7 @@ modals = { path = "../modals", default-features = false, optional = true }
|
|||
ux-api = { path = "../../libs/ux-api", optional = true }
|
||||
pddb = { path = "../pddb", optional = true }
|
||||
xous-swapper = { path = "../xous-swapper", optional = true }
|
||||
bytemuck = "1.24.0"
|
||||
|
||||
# pddb testing
|
||||
rand = { version = "0.8.5", features = ["getrandom"], optional = true }
|
||||
|
|
@ -69,4 +70,11 @@ modal-testing = ["ux-api", "modals/modal-testing"]
|
|||
test-scrollbars = []
|
||||
test-flash = []
|
||||
ctap-bringup = ["xous-usb-hid"]
|
||||
default = []
|
||||
rramtests = []
|
||||
|
||||
# Activating this makes this crate *try* to grab the DUART. To improve its odds
|
||||
# of winning the race, shift its position to first in the list in the PIDs to be
|
||||
# loaded and run.
|
||||
duart-debug-hal = ["bao1x-hal/debug-print-duart"]
|
||||
|
||||
default = ["rramtests"]
|
||||
|
|
|
|||
|
|
@ -99,6 +99,10 @@ mod i2cdetect;
|
|||
use i2cdetect::*;
|
||||
mod cute;
|
||||
use cute::*;
|
||||
#[cfg(feature = "rramtests")]
|
||||
mod rram;
|
||||
#[cfg(feature = "rramtests")]
|
||||
use rram::*;
|
||||
|
||||
pub struct CmdEnv {
|
||||
common_env: CommonEnv,
|
||||
|
|
@ -111,6 +115,8 @@ pub struct CmdEnv {
|
|||
pddb_cmd: PddbCmd,
|
||||
#[cfg(feature = "aestests")]
|
||||
aes_cmd: Aes,
|
||||
#[cfg(feature = "rramtests")]
|
||||
rram: Rram,
|
||||
}
|
||||
impl CmdEnv {
|
||||
pub fn new(xns: &xous_names::XousNames) -> CmdEnv {
|
||||
|
|
@ -125,6 +131,8 @@ impl CmdEnv {
|
|||
};
|
||||
#[cfg(feature = "aestests")]
|
||||
let aes_cmd = Aes::new(&xns, &mut _common);
|
||||
#[cfg(feature = "rramtests")]
|
||||
let rram = Rram::new(&xns, &mut _common);
|
||||
CmdEnv {
|
||||
common_env: _common,
|
||||
lastverb: String::new(),
|
||||
|
|
@ -139,6 +147,8 @@ impl CmdEnv {
|
|||
pddb_cmd: PddbCmd::new(),
|
||||
#[cfg(feature = "aestests")]
|
||||
aes_cmd,
|
||||
#[cfg(feature = "rramtests")]
|
||||
rram,
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -169,6 +179,8 @@ impl CmdEnv {
|
|||
&mut self.pddb_cmd,
|
||||
#[cfg(feature = "aestests")]
|
||||
&mut self.aes_cmd,
|
||||
#[cfg(feature = "rramtests")]
|
||||
&mut self.rram,
|
||||
];
|
||||
|
||||
if let Some(cmdline) = maybe_cmdline {
|
||||
|
|
|
|||
135
services/bao-console/src/cmds/rram.rs
Normal file
135
services/bao-console/src/cmds/rram.rs
Normal file
|
|
@ -0,0 +1,135 @@
|
|||
use String;
|
||||
use xous::MemoryFlags;
|
||||
|
||||
use crate::{CommonEnv, ShellCmdApi};
|
||||
|
||||
pub struct Rram {
|
||||
pub rram: bao1x_hal::rram::Reram,
|
||||
}
|
||||
|
||||
// offsets into RRAM array where we've mapped pages
|
||||
const RANGES: [usize; 4] = [0x30_0000, 0x30_8000, 0x30_4000, 0x30_7000];
|
||||
|
||||
impl Rram {
|
||||
pub fn new(_xns: &xous_names::XousNames, _env: &mut CommonEnv) -> Self {
|
||||
let mut rram = bao1x_hal::rram::Reram::new();
|
||||
for range in RANGES {
|
||||
let r = xous::map_memory(
|
||||
xous::MemoryAddress::new(range + utralib::HW_RERAM_MEM),
|
||||
None,
|
||||
4096,
|
||||
MemoryFlags::R | MemoryFlags::W,
|
||||
)
|
||||
.unwrap();
|
||||
rram.add_range(range, r);
|
||||
}
|
||||
Self { rram }
|
||||
}
|
||||
}
|
||||
impl<'a> ShellCmdApi<'a> for Rram {
|
||||
cmd_api!(rram);
|
||||
|
||||
// inserts boilerplate for command API
|
||||
|
||||
fn process(&mut self, args: String, _env: &mut CommonEnv) -> Result<Option<String>, xous::Error> {
|
||||
use core::fmt::Write;
|
||||
let mut ret = String::new();
|
||||
|
||||
#[allow(unused_variables)]
|
||||
let helpstring = "rram [read] [write] [mapped]";
|
||||
|
||||
let mut parts = args.split_whitespace();
|
||||
let cmd = parts.next().unwrap_or("").to_string();
|
||||
let args: Vec<String> = parts.map(|s| s.to_string()).collect();
|
||||
|
||||
match cmd.as_str() {
|
||||
"mapped" => {
|
||||
write!(ret, "Valid page offsets for access in this test: {:x?}", RANGES).ok();
|
||||
}
|
||||
"read" => {
|
||||
const COLUMNS: usize = 16;
|
||||
if args.len() == 1 || args.len() == 2 {
|
||||
let addr = usize::from_str_radix(&args[0], 16).map_err(|_| {
|
||||
write!(ret, "Read offset is in hex, no leading 0x").ok();
|
||||
xous::Error::BadAddress
|
||||
})?;
|
||||
|
||||
let count = if args.len() == 2 {
|
||||
if let Ok(count) = u32::from_str_radix(&args[1], 10) { count } else { 32 }
|
||||
} else {
|
||||
1
|
||||
};
|
||||
for offset in (0..count).step_by(32) {
|
||||
match self.rram.array(addr + offset as usize) {
|
||||
Ok(peek) => {
|
||||
for (i, &d) in peek.iter().enumerate() {
|
||||
if (i % COLUMNS) == 0 {
|
||||
print!("\n\r{:08x}: ", addr + i + offset as usize);
|
||||
}
|
||||
print!("{:02x} ", d);
|
||||
}
|
||||
}
|
||||
Err(e) => {
|
||||
write!(ret, "Couldn't read from rram array: {:?}", e).ok();
|
||||
}
|
||||
}
|
||||
}
|
||||
println!("");
|
||||
} else {
|
||||
write!(
|
||||
ret,
|
||||
"{}",
|
||||
"Help: read <offset> [count], offset into RRAM area is in hex, count in decimal"
|
||||
)
|
||||
.ok();
|
||||
}
|
||||
}
|
||||
"write" => {
|
||||
if args.len() == 2 || args.len() == 3 {
|
||||
let offset = u32::from_str_radix(&args[0], 16).map_err(|_| {
|
||||
write!(ret, "Write offset is in hex, no leading 0x").ok();
|
||||
xous::Error::BadAddress
|
||||
})?;
|
||||
|
||||
let value = u32::from_str_radix(&args[1], 16).map_err(|_| {
|
||||
write!(ret, "Write value is in hex, no leading 0x").ok();
|
||||
xous::Error::BadAddress
|
||||
})?;
|
||||
let count = if args.len() == 3 {
|
||||
if let Ok(count) = u32::from_str_radix(&args[2], 10) { count } else { 1 }
|
||||
} else {
|
||||
1
|
||||
};
|
||||
let mut poke = Vec::new();
|
||||
poke.resize(count as usize, value);
|
||||
let poke_u8: &[u8] = bytemuck::cast_slice(&poke);
|
||||
|
||||
match self.rram.write_slice(offset as usize, &poke_u8) {
|
||||
Ok(len) => {
|
||||
write!(
|
||||
ret,
|
||||
"Poked {:x} into {:x}, {} times",
|
||||
value,
|
||||
offset,
|
||||
len / size_of::<u32>()
|
||||
)
|
||||
.ok();
|
||||
}
|
||||
Err(e) => {
|
||||
write!(ret, "Couldn't write: {:?}", e).ok();
|
||||
}
|
||||
}
|
||||
} else {
|
||||
write!(ret, "{}",
|
||||
"Help: write <offset> <value> [count], offset into RRAM/value is in hex, count in decimal",
|
||||
).ok();
|
||||
}
|
||||
}
|
||||
_ => {
|
||||
write!(ret, "{}", helpstring).unwrap();
|
||||
}
|
||||
}
|
||||
|
||||
Ok(Some(ret))
|
||||
}
|
||||
}
|
||||
|
|
@ -9,6 +9,8 @@ fn main() {
|
|||
log_server::init_wait().unwrap();
|
||||
log::set_max_level(log::LevelFilter::Info);
|
||||
log::info!("my PID is {}", xous::process::id());
|
||||
#[cfg(feature = "duart-debug-hal")]
|
||||
bao1x_hal::claim_duart();
|
||||
|
||||
let tt = ticktimer::Ticktimer::new().unwrap();
|
||||
shell::start_shell();
|
||||
|
|
|
|||
Loading…
Reference in a new issue