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