mirror of
https://github.com/saymrwulf/xous-core.git
synced 2026-11-21 09:14:34 +00:00
try to improve the pmic detection code
we can now recover from an I2C timeout and get the PMIC data out, but mysteriously, when we leave the routine, the CPU hangs. I think fundamentally the I2C instability is due to something very wonky inside the chip itself, so the recovery only papers over an issue that is only fixed with a reboot...
This commit is contained in:
parent
f14cf1948c
commit
bb594a5c40
1 changed files with 76 additions and 26 deletions
|
|
@ -1,3 +1,4 @@
|
||||||
|
use cramium_hal::axp2101::Axp2101;
|
||||||
use cramium_hal::iox::{Iox, IoxDir, IoxEnable, IoxFunction, IoxPort};
|
use cramium_hal::iox::{Iox, IoxDir, IoxEnable, IoxFunction, IoxPort};
|
||||||
use cramium_hal::udma;
|
use cramium_hal::udma;
|
||||||
use cramium_hal::udma::PeriphId;
|
use cramium_hal::udma::PeriphId;
|
||||||
|
|
@ -74,6 +75,22 @@ pub const FLASH_BASE: usize = utralib::generated::HW_RERAM_MEM;
|
||||||
// exclusive of the signature block offset
|
// exclusive of the signature block offset
|
||||||
pub const KERNEL_OFFSET: usize = 0x5_0000;
|
pub const KERNEL_OFFSET: usize = 0x5_0000;
|
||||||
|
|
||||||
|
fn delay(quantum: usize) {
|
||||||
|
use utralib::{CSR, utra};
|
||||||
|
// abuse the d11ctime timer to create some time-out like thing
|
||||||
|
let mut d11c = CSR::new(utra::d11ctime::HW_D11CTIME_BASE as *mut u32);
|
||||||
|
d11c.wfo(utra::d11ctime::CONTROL_COUNT, 333_333); // 1.0ms per interval
|
||||||
|
let mut polarity = d11c.rf(utra::d11ctime::HEARTBEAT_BEAT);
|
||||||
|
for _ in 0..quantum {
|
||||||
|
while polarity == d11c.rf(utra::d11ctime::HEARTBEAT_BEAT) {}
|
||||||
|
polarity = d11c.rf(utra::d11ctime::HEARTBEAT_BEAT);
|
||||||
|
}
|
||||||
|
// we have to split this because we don't know where we caught the previous interval
|
||||||
|
if quantum == 1 {
|
||||||
|
while polarity == d11c.rf(utra::d11ctime::HEARTBEAT_BEAT) {}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#[cfg(feature = "cramium-soc")]
|
#[cfg(feature = "cramium-soc")]
|
||||||
pub fn early_init() -> u32 {
|
pub fn early_init() -> u32 {
|
||||||
// Set up the initial clocks. This is done as a "poke array" into a table of addresses.
|
// Set up the initial clocks. This is done as a "poke array" into a table of addresses.
|
||||||
|
|
@ -271,26 +288,67 @@ pub fn early_init() -> u32 {
|
||||||
};
|
};
|
||||||
let mut i2c = unsafe { cramium_hal::udma::I2c::new_with_ifram(i2c_channel, 400_000, perclk, i2c_ifram) };
|
let mut i2c = unsafe { cramium_hal::udma::I2c::new_with_ifram(i2c_channel, 400_000, perclk, i2c_ifram) };
|
||||||
// setup PMIC
|
// setup PMIC
|
||||||
let mut pmic = match cramium_hal::axp2101::Axp2101::new(&mut i2c) {
|
let mut pmic: Option<Axp2101> = None;
|
||||||
Ok(p) => p,
|
|
||||||
Err(_e) => {
|
for _ in 0..3 {
|
||||||
crate::println!("Couldn't init AXP2101, rebooting");
|
match cramium_hal::axp2101::Axp2101::new(&mut i2c) {
|
||||||
|
Ok(p) => {
|
||||||
|
pmic = Some(p);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
Err(e) => {
|
||||||
|
crate::println!("Error initializing pmic: {:?}, retrying", e);
|
||||||
|
|
||||||
|
// we have to reboot it appears if the I2C is unstable - a "soft recovery"
|
||||||
|
// just leads to CPU lock-up on exit from the init routine? what is going on??
|
||||||
|
// maybe some IFRAM instability? Maybe the I2C unit is locking up?
|
||||||
let mut rcurst = CSR::new(utra::sysctrl::HW_SYSCTRL_BASE as *mut u32);
|
let mut rcurst = CSR::new(utra::sysctrl::HW_SYSCTRL_BASE as *mut u32);
|
||||||
rcurst.wo(utra::sysctrl::SFR_RCURST0, 0x55AA);
|
rcurst.wo(utra::sysctrl::SFR_RCURST0, 0x55AA);
|
||||||
panic!("System should have reset");
|
rcurst.wo(utra::sysctrl::SFR_RCURST1, 0x55AA);
|
||||||
|
|
||||||
|
/*
|
||||||
|
unsafe {
|
||||||
|
let ifram0 = HW_IFRAM0_MEM as *mut u32;
|
||||||
|
for i in 0..HW_IFRAM0_MEM_LEN / size_of::<u32>() {
|
||||||
|
ifram0.add(i).write_volatile(0);
|
||||||
|
}
|
||||||
|
let ifram1 = HW_IFRAM1_MEM as *mut u32;
|
||||||
|
for i in 0..HW_IFRAM1_MEM_LEN / size_of::<u32>() {
|
||||||
|
ifram1.add(i).write_volatile(0);
|
||||||
|
}
|
||||||
|
}*/
|
||||||
|
|
||||||
|
delay(500);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
}
|
||||||
|
if let Some(mut pmic) = pmic {
|
||||||
pmic.set_ldo(&mut i2c, Some(2.5), cramium_hal::axp2101::WhichLdo::Aldo2).unwrap();
|
pmic.set_ldo(&mut i2c, Some(2.5), cramium_hal::axp2101::WhichLdo::Aldo2).unwrap();
|
||||||
pmic.set_dcdc(&mut i2c, Some((1.2, false)), cramium_hal::axp2101::WhichDcDc::Dcdc4).unwrap();
|
pmic.set_dcdc(&mut i2c, Some((1.2, false)), cramium_hal::axp2101::WhichDcDc::Dcdc4).unwrap();
|
||||||
crate::println!("AXP2101 configure: {:?}", pmic);
|
crate::println!("AXP2101 configure: {:?}", pmic);
|
||||||
|
|
||||||
// TEMPORARY: turn off SE0 on USB
|
// Make this true to have the system shut down by disconnecting its own battery while on battery power
|
||||||
|
// Note this does nothing if you have USB power plugged in.
|
||||||
|
if false {
|
||||||
|
crate::println!("shutting down...");
|
||||||
|
pmic.set_ldo(&mut i2c, Some(0.9), cramium_hal::axp2101::WhichLdo::Aldo3).ok();
|
||||||
|
crate::println!("system should be off");
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
crate::println!("Couldn't init AXP2101, rebooting");
|
||||||
|
let mut rcurst = CSR::new(utra::sysctrl::HW_SYSCTRL_BASE as *mut u32);
|
||||||
|
rcurst.wo(utra::sysctrl::SFR_RCURST0, 0x55AA);
|
||||||
|
rcurst.wo(utra::sysctrl::SFR_RCURST1, 0x55AA);
|
||||||
|
panic!("System should have reset");
|
||||||
|
}
|
||||||
|
|
||||||
|
// Turn off SE0 on USB
|
||||||
let _se0 = cramium_hal::board::baosec::setup_usb_pins(&iox);
|
let _se0 = cramium_hal::board::baosec::setup_usb_pins(&iox);
|
||||||
#[cfg(feature = "board-bringup")]
|
#[cfg(feature = "board-bringup")]
|
||||||
let iox_loop = iox.clone();
|
let iox_loop = iox.clone();
|
||||||
|
|
||||||
// show the boot logo
|
// show the boot logo
|
||||||
use cramium_hal::minigfx::FrameBuffer;
|
use cramium_hal::{ifram, minigfx::FrameBuffer};
|
||||||
|
|
||||||
let mut sh1107 = cramium_hal::sh1107::Oled128x128::new(perclk, &mut iox, &mut udma_global);
|
let mut sh1107 = cramium_hal::sh1107::Oled128x128::new(perclk, &mut iox, &mut udma_global);
|
||||||
sh1107.init();
|
sh1107.init();
|
||||||
|
|
@ -304,7 +362,7 @@ pub fn early_init() -> u32 {
|
||||||
#[cfg(feature = "board-bringup")]
|
#[cfg(feature = "board-bringup")]
|
||||||
{
|
{
|
||||||
use cramium_hal::minigfx::{Line, Point};
|
use cramium_hal::minigfx::{Line, Point};
|
||||||
use cramium_hal::{axp2101::WhichLdo, iox::IoxValue, minigfx::ColorNative, sh1107::Mono, udma::Udma};
|
use cramium_hal::{iox::IoxValue, minigfx::ColorNative, sh1107::Mono, udma::Udma};
|
||||||
|
|
||||||
use crate::platform::cramium::gfx;
|
use crate::platform::cramium::gfx;
|
||||||
//------------- test I2C ------------
|
//------------- test I2C ------------
|
||||||
|
|
@ -345,7 +403,7 @@ pub fn early_init() -> u32 {
|
||||||
crate::println!("LDO result - last value should be 0xe: {:x?}", ldo);
|
crate::println!("LDO result - last value should be 0xe: {:x?}", ldo);
|
||||||
|
|
||||||
//------------- test USB ---------------
|
//------------- test USB ---------------
|
||||||
#[cfg(feature = "usb")]
|
#[cfg(feature = "usb-test")]
|
||||||
{
|
{
|
||||||
crate::platform::cramium::usb::init_usb();
|
crate::platform::cramium::usb::init_usb();
|
||||||
// this does not return if USB is initialized correctly...
|
// this does not return if USB is initialized correctly...
|
||||||
|
|
@ -674,14 +732,6 @@ pub fn early_init() -> u32 {
|
||||||
frames += 1;
|
frames += 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Make this true to have the system shut down by disconnecting its own battery while on battery power
|
|
||||||
// Note this does nothing if you have USB power plugged in.
|
|
||||||
if false {
|
|
||||||
crate::println!("shutting down...");
|
|
||||||
pmic.set_ldo(&mut i2c, Some(0.9), WhichLdo::Aldo3).ok();
|
|
||||||
crate::println!("system should be off");
|
|
||||||
}
|
|
||||||
|
|
||||||
// ---------------- test TRNG -------------------
|
// ---------------- test TRNG -------------------
|
||||||
// configure the SCE clocks to enable the TRNG
|
// configure the SCE clocks to enable the TRNG
|
||||||
let mut sce = CSR::new(HW_SCE_GLBSFR_BASE as *mut u32);
|
let mut sce = CSR::new(HW_SCE_GLBSFR_BASE as *mut u32);
|
||||||
|
|
@ -1160,8 +1210,8 @@ pub fn early_init() -> u32 {
|
||||||
crate::println!("pmu_cr upd: {:x}", aoc_base.base().add(4).read_volatile());
|
crate::println!("pmu_cr upd: {:x}", aoc_base.base().add(4).read_volatile());
|
||||||
}
|
}
|
||||||
*/
|
*/
|
||||||
udma_uart.write("Press any key to continue...".as_bytes());
|
// udma_uart.write("Press any key to continue...".as_bytes());
|
||||||
getc();
|
// getc();
|
||||||
udma_uart.write(b"\n\rBooting!\n\r");
|
udma_uart.write(b"\n\rBooting!\n\r");
|
||||||
|
|
||||||
perclk
|
perclk
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue