mirror of
https://github.com/saymrwulf/xous-core.git
synced 2026-11-19 09:00:54 +00:00
add debug routines for spim
This commit is contained in:
parent
5a8c7c7aa3
commit
da623430c6
2 changed files with 103 additions and 0 deletions
|
|
@ -77,6 +77,7 @@ dabao-selftest = [
|
||||||
"xous-bio-bdma/bao1x",
|
"xous-bio-bdma/bao1x",
|
||||||
]
|
]
|
||||||
test-boot0-writeprotect = []
|
test-boot0-writeprotect = []
|
||||||
|
spim-tests = []
|
||||||
|
|
||||||
verilator-only = []
|
verilator-only = []
|
||||||
default = ["bao1x-usb", "dabao-selftest"]
|
default = ["bao1x-usb", "dabao-selftest"]
|
||||||
|
|
|
||||||
|
|
@ -167,6 +167,106 @@ impl Repl {
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
#[cfg(feature = "spim-tests")]
|
||||||
|
"qe" => {
|
||||||
|
use bao1x_hal::board::SPIM_FLASH_IFRAM_ADDR;
|
||||||
|
use bao1x_hal::iox::Iox;
|
||||||
|
use bao1x_hal::udma::{GlobalConfig, Spim, SpimClkPha, SpimClkPol, SpimCs};
|
||||||
|
|
||||||
|
let udma_global = GlobalConfig::new();
|
||||||
|
|
||||||
|
// setup the I/O pins
|
||||||
|
let iox = Iox::new(utralib::generated::HW_IOX_BASE as *mut u32);
|
||||||
|
let channel = bao1x_hal::board::setup_memory_pins(&iox);
|
||||||
|
udma_global.clock_on(PeriphId::from(channel));
|
||||||
|
|
||||||
|
// safety: this is safe because clocks have been set up
|
||||||
|
let mut flash_spim = unsafe {
|
||||||
|
Spim::new_with_ifram(
|
||||||
|
channel,
|
||||||
|
// has to be half the clock frequency reaching the block, but run it as fast
|
||||||
|
// as we can run perclk
|
||||||
|
100_000_000 / 4,
|
||||||
|
100_000_000 / 2,
|
||||||
|
SpimClkPol::LeadingEdgeRise,
|
||||||
|
SpimClkPha::CaptureOnLeading,
|
||||||
|
SpimCs::Cs0,
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
None,
|
||||||
|
16, // just enough space to send commands
|
||||||
|
4096,
|
||||||
|
Some(6),
|
||||||
|
None,
|
||||||
|
bao1x_hal::ifram::IframRange::from_raw_parts(
|
||||||
|
SPIM_FLASH_IFRAM_ADDR,
|
||||||
|
SPIM_FLASH_IFRAM_ADDR,
|
||||||
|
4096 * 2,
|
||||||
|
),
|
||||||
|
)
|
||||||
|
};
|
||||||
|
flash_spim.mem_qpi_mode(false);
|
||||||
|
let status = flash_spim.flash_read_status_register();
|
||||||
|
crate::println!("status register: {:x}", status);
|
||||||
|
flash_spim.flash_set_qe();
|
||||||
|
let status = flash_spim.flash_read_status_register();
|
||||||
|
crate::println!("status register after qe set: {:x}", status);
|
||||||
|
}
|
||||||
|
#[cfg(feature = "spim-tests")]
|
||||||
|
"check_qpi" => {
|
||||||
|
use bao1x_hal::board::SPIM_FLASH_IFRAM_ADDR;
|
||||||
|
use bao1x_hal::iox::Iox;
|
||||||
|
use bao1x_hal::udma::{GlobalConfig, Spim, SpimClkPha, SpimClkPol, SpimCs};
|
||||||
|
let udma_global = GlobalConfig::new();
|
||||||
|
|
||||||
|
// setup the I/O pins
|
||||||
|
let iox = Iox::new(utralib::generated::HW_IOX_BASE as *mut u32);
|
||||||
|
let channel = bao1x_hal::board::setup_memory_pins(&iox);
|
||||||
|
udma_global.clock_on(PeriphId::from(channel));
|
||||||
|
// safety: this is safe because clocks have been set up
|
||||||
|
let mut flash_spim = unsafe {
|
||||||
|
Spim::new_with_ifram(
|
||||||
|
channel,
|
||||||
|
// has to be half the clock frequency reaching the block, but run it as fast
|
||||||
|
// as we can run perclk
|
||||||
|
100_000_000 / 4,
|
||||||
|
100_000_000 / 2,
|
||||||
|
SpimClkPol::LeadingEdgeRise,
|
||||||
|
SpimClkPha::CaptureOnLeading,
|
||||||
|
SpimCs::Cs0,
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
None,
|
||||||
|
16, // just enough space to send commands
|
||||||
|
4096,
|
||||||
|
Some(6),
|
||||||
|
None,
|
||||||
|
bao1x_hal::ifram::IframRange::from_raw_parts(
|
||||||
|
SPIM_FLASH_IFRAM_ADDR,
|
||||||
|
SPIM_FLASH_IFRAM_ADDR,
|
||||||
|
4096 * 2,
|
||||||
|
),
|
||||||
|
)
|
||||||
|
};
|
||||||
|
flash_spim.mem_read_id_flash();
|
||||||
|
// turn off QPI mode, in case it was set from a reboot in a bad state
|
||||||
|
flash_spim.mem_qpi_mode(false);
|
||||||
|
|
||||||
|
// sanity check: read ID
|
||||||
|
let flash_id = flash_spim.mem_read_id_flash();
|
||||||
|
crate::println!("flash ID (init): {:x}", flash_id);
|
||||||
|
flash_spim.mem_qpi_mode(true);
|
||||||
|
|
||||||
|
// re-check the ID to confirm we entered QPI mode correctly
|
||||||
|
let flash_id = flash_spim.mem_read_id_flash();
|
||||||
|
crate::println!("QPI flash ID: {:x}", flash_id);
|
||||||
|
flash_spim.mem_qpi_mode(false);
|
||||||
|
let flash_id = flash_spim.mem_read_id_flash();
|
||||||
|
crate::println!("SPI flash ID: {:x}", flash_id);
|
||||||
|
flash_spim.mem_qpi_mode(true);
|
||||||
|
let flash_id = flash_spim.mem_read_id_flash();
|
||||||
|
crate::println!("QPI flash ID: {:x}", flash_id);
|
||||||
|
}
|
||||||
#[cfg(feature = "bao1x")]
|
#[cfg(feature = "bao1x")]
|
||||||
"rram" => {
|
"rram" => {
|
||||||
if args.len() == 2 || args.len() == 3 {
|
if args.len() == 2 || args.len() == 3 {
|
||||||
|
|
@ -1051,6 +1151,8 @@ impl Repl {
|
||||||
crate::print!(", trngro, trngav");
|
crate::print!(", trngro, trngav");
|
||||||
#[cfg(feature = "dabao-selftest")]
|
#[cfg(feature = "dabao-selftest")]
|
||||||
crate::print!(", dbtest");
|
crate::print!(", dbtest");
|
||||||
|
#[cfg(feature = "spim-tests")]
|
||||||
|
crate::print!(", qe, check_qpi");
|
||||||
crate::println!("");
|
crate::println!("");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue