Quellcode durchsuchen

Jump to app if bootloader entry not requested

Brian Starkey vor 1 Jahr
Ursprung
Commit
6347c8e02c
1 geänderte Dateien mit 23 neuen und 0 gelöschten Zeilen
  1. 23
    0
      main.c

+ 23
- 0
main.c Datei anzeigen

@@ -552,10 +552,33 @@ struct comm_command reboot_cmd = {
552 552
 	.handle = &handle_reboot,
553 553
 };
554 554
 
555
+static bool should_stay_in_bootloader()
556
+{
557
+	bool wd_says_so = (watchdog_hw->scratch[5] == BOOTLOADER_ENTRY_MAGIC) &&
558
+		(watchdog_hw->scratch[6] == ~BOOTLOADER_ENTRY_MAGIC);
559
+
560
+	return !gpio_get(BOOTLOADER_ENTRY_PIN) || wd_says_so;
561
+}
562
+
555 563
 int main()
556 564
 {
557 565
 	err_t err;
558 566
 
567
+	gpio_init(BOOTLOADER_ENTRY_PIN);
568
+	gpio_pull_up(BOOTLOADER_ENTRY_PIN);
569
+	gpio_set_dir(BOOTLOADER_ENTRY_PIN, 0);
570
+
571
+	sleep_ms(10);
572
+
573
+	struct image_header *hdr = (struct image_header *)(XIP_BASE + IMAGE_HEADER_OFFSET);
574
+
575
+	if (!should_stay_in_bootloader() && image_header_ok(hdr)) {
576
+		uint32_t vtor = *((uint32_t *)(XIP_BASE + IMAGE_HEADER_OFFSET));
577
+		disable_interrupts();
578
+		reset_peripherals();
579
+		jump_to_vtor(vtor);
580
+	}
581
+
559 582
 	DBG_PRINTF_INIT();
560 583
 
561 584
 	queue_init(&event_queue, sizeof(struct event), EVENT_QUEUE_LENGTH);

Laden…
Abbrechen
Speichern