|
2 | 2 | * Copyright (c) 2012-2014 Wind River Systems, Inc.
|
3 | 3 | * Copyright (c) 2020 Arm Limited
|
4 | 4 | * Copyright (c) 2021-2023 Nordic Semiconductor ASA
|
| 5 | + * Copyright (c) 2025 Aerlync Labs Inc. |
5 | 6 | *
|
6 | 7 | * Licensed under the Apache License, Version 2.0 (the "License");
|
7 | 8 | * you may not use this file except in compliance with the License.
|
@@ -479,6 +480,9 @@ int main(void)
|
479 | 480 | {
|
480 | 481 | struct boot_rsp rsp;
|
481 | 482 | int rc;
|
| 483 | +#if defined(CONFIG_BOOT_USB_DFU_GPIO) || defined(CONFIG_BOOT_USB_DFU_WAIT) |
| 484 | + bool usb_dfu_requested = false; |
| 485 | +#endif |
482 | 486 | FIH_DECLARE(fih_rc, FIH_FAILURE);
|
483 | 487 |
|
484 | 488 | MCUBOOT_WATCHDOG_SETUP();
|
@@ -518,35 +522,37 @@ int main(void)
|
518 | 522 |
|
519 | 523 | #if defined(CONFIG_BOOT_USB_DFU_GPIO)
|
520 | 524 | if (io_detect_pin()) {
|
| 525 | + usb_dfu_requested = true; |
| 526 | + |
521 | 527 | #ifdef CONFIG_MCUBOOT_INDICATION_LED
|
522 | 528 | io_led_set(1);
|
523 | 529 | #endif
|
524 | 530 |
|
525 | 531 | mcuboot_status_change(MCUBOOT_STATUS_USB_DFU_ENTERED);
|
| 532 | + } |
| 533 | +#elif defined(CONFIG_BOOT_USB_DFU_WAIT) |
| 534 | + usb_dfu_requested = true; |
| 535 | +#endif |
526 | 536 |
|
| 537 | +#if defined(CONFIG_BOOT_USB_DFU_GPIO) || defined(CONFIG_BOOT_USB_DFU_WAIT) |
| 538 | + if (usb_dfu_requested) { |
527 | 539 | rc = usb_enable(NULL);
|
528 | 540 | if (rc) {
|
529 |
| - BOOT_LOG_ERR("Cannot enable USB"); |
| 541 | + BOOT_LOG_ERR("Cannot enable USB: %d", rc); |
530 | 542 | } else {
|
531 | 543 | BOOT_LOG_INF("Waiting for USB DFU");
|
532 |
| - wait_for_usb_dfu(K_FOREVER); |
| 544 | + |
| 545 | +#if defined(CONFIG_BOOT_USB_DFU_WAIT) |
| 546 | + mcuboot_status_change(MCUBOOT_STATUS_USB_DFU_WAITING); |
| 547 | + wait_for_usb_dfu(K_MSEC(CONFIG_BOOT_USB_DFU_WAIT_DELAY_MS)); |
533 | 548 | BOOT_LOG_INF("USB DFU wait time elapsed");
|
| 549 | + mcuboot_status_change(MCUBOOT_STATUS_USB_DFU_TIMED_OUT); |
| 550 | +#else |
| 551 | + wait_for_usb_dfu(K_FOREVER); |
| 552 | + BOOT_LOG_INF("USB DFU wait terminated"); |
| 553 | +#endif |
534 | 554 | }
|
535 | 555 | }
|
536 |
| -#elif defined(CONFIG_BOOT_USB_DFU_WAIT) |
537 |
| - rc = usb_enable(NULL); |
538 |
| - if (rc) { |
539 |
| - BOOT_LOG_ERR("Cannot enable USB"); |
540 |
| - } else { |
541 |
| - BOOT_LOG_INF("Waiting for USB DFU"); |
542 |
| - |
543 |
| - mcuboot_status_change(MCUBOOT_STATUS_USB_DFU_WAITING); |
544 |
| - |
545 |
| - wait_for_usb_dfu(K_MSEC(CONFIG_BOOT_USB_DFU_WAIT_DELAY_MS)); |
546 |
| - BOOT_LOG_INF("USB DFU wait time elapsed"); |
547 |
| - |
548 |
| - mcuboot_status_change(MCUBOOT_STATUS_USB_DFU_TIMED_OUT); |
549 |
| - } |
550 | 556 | #endif
|
551 | 557 |
|
552 | 558 | #ifdef CONFIG_BOOT_SERIAL_WAIT_FOR_DFU
|
|
0 commit comments