bootloader: Import bootloader-final.ld.
[gps-watch.git] / src / bootloader / main.rs
index 2e43b67eb9dc3762f3301d39d07ecdc79090fe45..0d2954909572a02f26432aef8147c5894dfaff47 100644 (file)
@@ -40,8 +40,24 @@ extern {
     fn jump_to_application(address: u32);
 }
 
+#[cfg(bootloader_type = "intermediate")]
 const APPLICATION_ADDR: u32 = 0x0;
 
+#[cfg(bootloader_type = "final")]
+const APPLICATION_ADDR: u32 = 0x8000;
+
+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 +68,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 +77,5 @@ pub unsafe extern fn main() {
         }
     }
 
-    jump_to_application(__application_addr);
+    jump_to_application(APPLICATION_ADDR);
 }