|
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.
|
@@ -441,6 +442,9 @@ int main(void)
|
441 | 442 | {
|
442 | 443 | struct boot_rsp rsp;
|
443 | 444 | int rc;
|
| 445 | +#if defined(CONFIG_BOOT_USB_DFU_GPIO) || defined(CONFIG_BOOT_USB_DFU_WAIT) |
| 446 | + bool usb_dfu_requested = false; |
| 447 | +#endif |
444 | 448 | FIH_DECLARE(fih_rc, FIH_FAILURE);
|
445 | 449 |
|
446 | 450 | MCUBOOT_WATCHDOG_SETUP();
|
@@ -480,35 +484,37 @@ int main(void)
|
480 | 484 |
|
481 | 485 | #if defined(CONFIG_BOOT_USB_DFU_GPIO)
|
482 | 486 | if (io_detect_pin()) {
|
| 487 | + usb_dfu_requested = true; |
| 488 | + |
483 | 489 | #ifdef CONFIG_MCUBOOT_INDICATION_LED
|
484 | 490 | io_led_set(1);
|
485 | 491 | #endif
|
486 | 492 |
|
487 | 493 | mcuboot_status_change(MCUBOOT_STATUS_USB_DFU_ENTERED);
|
| 494 | + } |
| 495 | +#elif defined(CONFIG_BOOT_USB_DFU_WAIT) |
| 496 | + usb_dfu_requested = true; |
| 497 | +#endif |
488 | 498 |
|
| 499 | +#if defined(CONFIG_BOOT_USB_DFU_GPIO) || defined(CONFIG_BOOT_USB_DFU_WAIT) |
| 500 | + if (usb_dfu_requested) { |
489 | 501 | rc = usb_enable(NULL);
|
490 | 502 | if (rc) {
|
491 |
| - BOOT_LOG_ERR("Cannot enable USB"); |
| 503 | + BOOT_LOG_ERR("Cannot enable USB %d", rc); |
492 | 504 | } else {
|
493 | 505 | BOOT_LOG_INF("Waiting for USB DFU");
|
494 |
| - wait_for_usb_dfu(K_FOREVER); |
| 506 | + |
| 507 | +#if defined(CONFIG_BOOT_USB_DFU_WAIT) |
| 508 | + mcuboot_status_change(MCUBOOT_STATUS_USB_DFU_WAITING); |
| 509 | + wait_for_usb_dfu(K_MSEC(CONFIG_BOOT_USB_DFU_WAIT_DELAY_MS)); |
495 | 510 | BOOT_LOG_INF("USB DFU wait time elapsed");
|
| 511 | + mcuboot_status_change(MCUBOOT_STATUS_USB_DFU_TIMED_OUT); |
| 512 | +#else |
| 513 | + wait_for_usb_dfu(K_FOREVER); |
| 514 | + BOOT_LOG_INF("USB DFU wait terminated"); |
| 515 | +#endif |
496 | 516 | }
|
497 | 517 | }
|
498 |
| -#elif defined(CONFIG_BOOT_USB_DFU_WAIT) |
499 |
| - rc = usb_enable(NULL); |
500 |
| - if (rc) { |
501 |
| - BOOT_LOG_ERR("Cannot enable USB"); |
502 |
| - } else { |
503 |
| - BOOT_LOG_INF("Waiting for USB DFU"); |
504 |
| - |
505 |
| - mcuboot_status_change(MCUBOOT_STATUS_USB_DFU_WAITING); |
506 |
| - |
507 |
| - wait_for_usb_dfu(K_MSEC(CONFIG_BOOT_USB_DFU_WAIT_DELAY_MS)); |
508 |
| - BOOT_LOG_INF("USB DFU wait time elapsed"); |
509 |
| - |
510 |
| - mcuboot_status_change(MCUBOOT_STATUS_USB_DFU_TIMED_OUT); |
511 |
| - } |
512 | 518 | #endif
|
513 | 519 |
|
514 | 520 | #ifdef CONFIG_BOOT_SERIAL_WAIT_FOR_DFU
|
|
0 commit comments