Fix 'boot' command not re-enumerating USB

The "press button" path cleanly shuts down the USB stack
before going into the next stage.

"boot" does not; it missed the additional code added at the
end of the main routine.

Refactor the "boot" routine to be a function call now, so any
future improvements to the boot process are used by both paths.
This commit is contained in:
bunnie 2025-11-01 20:09:43 +08:00
parent 406e39a0d5
commit 3f60e48793
2 changed files with 24 additions and 1 deletions

View file

@ -273,6 +273,10 @@ pub unsafe extern "C" fn rust_entry() -> ! {
}
}
boot(&iox, oled, se0_port, se0_pin)
}
pub fn boot(iox: &Iox, mut oled: Option<Oled128x128>, se0_port: bao1x_api::IoxPort, se0_pin: u8) -> ! {
if let Some(ref mut sh1107) = oled {
marquee(sh1107, "Booting...");
}
@ -280,6 +284,7 @@ pub unsafe extern "C" fn rust_entry() -> ! {
// stop the USB subsystem so it can be re-init'd by the next stage.
// without this, USB init will hang later on.
glue::shutdown();
iox.set_gpio_dir(se0_port, se0_pin, bao1x_api::IoxDir::Output);
iox.set_gpio_pin(se0_port, se0_pin, bao1x_api::IoxValue::Low); // put the USB port into SE0, so we re-enumerate with the OS stack
// check that all pages in the SPI memory page cache have been written out

View file

@ -106,7 +106,25 @@ impl Repl {
rcurst.wo(utra::sysctrl::SFR_RCURST0, 0x55AA);
}
"boot" => {
crate::secboot::try_boot(true);
use bao1x_hal::iox::Iox;
let one_way = OneWayCounter::new();
let iox = Iox::new(utra::iox::HW_IOX_BASE as *mut u32);
let (port, pin) = match one_way.get_decoded::<bao1x_api::BoardTypeCoding>() {
// the default map is baosec in boot1
Ok(bao1x_api::BoardTypeCoding::Baosec) => bao1x_hal::board::setup_usb_pins(&iox),
// otherwise assume dabao mapping
_ => crate::setup_dabao_se0_pin(&iox),
};
// assert SE0 pin here. We add a delay even though crate:boot() calls this, because
// a button press initiated SE0 includes a certain minimum "low"; a direct serial command
// does not.
iox.set_gpio_pin(port, pin, IoxValue::Low);
crate::platform::delay(20); // minimum is 2.5ms
// note: the SE0 pin is now asserted & configured as an output as it goes to the next stage
// it us up to the next USB stack to de-assert this.
crate::boot(&iox, None, port, pin);
}
"uf2" => {
use base64::{Engine as _, engine::general_purpose};