From fafbe49123de3572c496e964fc3048b3ab2e28d8 Mon Sep 17 00:00:00 2001 From: Tilman Sauerbeck Date: Sun, 7 Jul 2019 20:29:48 +0200 Subject: [PATCH] bootloader: Only begin serial communication if PTE24 is held down. --- src/bootloader/main.rs | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/src/bootloader/main.rs b/src/bootloader/main.rs index 2e43b67..d81da15 100644 --- a/src/bootloader/main.rs +++ b/src/bootloader/main.rs @@ -42,6 +42,18 @@ extern { const APPLICATION_ADDR: u32 = 0x0; +fn bootloader_requested() -> bool { + let start_ticks = systick::now(); + + while !systick::has_timeout_ms(start_ticks, 3000) { + if (gpio::get(gpio::GPIOE) & (1 << 24)) == 0 { + return true; + } + } + + false +} + #[no_mangle] pub unsafe extern fn main() { clock::configure(); @@ -52,7 +64,7 @@ pub unsafe extern fn main() { port::set_af(port::PORTE, 24, 1); port::set_pull(port::PORTE, 24, port::Pull::Up); - if true { + if bootloader_requested() { usb_serial::init(0xf055, 0x635c); let mut b = bootloader::Bootloader::new(); @@ -61,5 +73,5 @@ pub unsafe extern fn main() { } } - jump_to_application(__application_addr); + jump_to_application(APPLICATION_ADDR); } -- 2.30.2