USB DFU Usage #64767
-
At Intercreate, we've found that in order to use the USB DFU system, via Here's the patch: diff --git a/subsys/usb/device/class/dfu/usb_dfu.c b/subsys/usb/device/class/dfu/usb_dfu.c
index 69a912ab9d..b816accd91 100644
--- a/subsys/usb/device/class/dfu/usb_dfu.c
+++ b/subsys/usb/device/class/dfu/usb_dfu.c
@@ -119,7 +119,7 @@ USBD_CLASS_DESCR_DEFINE(primary, 0) struct usb_dfu_config dfu_cfg = {
.bNumEndpoints = 0,
.bInterfaceClass = USB_BCC_APPLICATION,
.bInterfaceSubClass = DFU_SUBCLASS,
- .bInterfaceProtocol = DFU_RT_PROTOCOL,
+ .bInterfaceProtocol = DFU_MODE_PROTOCOL,
.iInterface = 0,
},
.dfu_descr = {
@@ -336,7 +336,7 @@ struct dfu_data_t {
static struct dfu_data_t dfu_data = {
- .state = appIDLE,
+ .state = dfuIDLE,
.status = statusOK,
.flash_area_id = DOWNLOAD_FLASH_AREA_ID,
.alt_setting = 0, With this patch, We have a few other fixes to submit for USB DFU and MCUBoot, but hoping to have a good discussion about the design goals and API first. We've run this on dev kits and custom boards with parts from ST and Nordic and never had success WITHOUT this patch. I think that it comes down to usage of CONFIG_USB_DFU_WILL_DETACH
What I don't understand is what "DFU_WILL_DETACH" means? Does it mean that the device will reset (wouldn't work) or something else? Open issues: Closed issues:
|
Beta Was this translation helpful? Give feedback.
Replies: 4 comments 7 replies
-
Hi @JPHutchins! We appreciate you submitting your first issue for our open-source project. 🌟 Even though I'm a bot, I can assure you that the whole community is genuinely grateful for your time and effort. 🤖💙 |
Beta Was this translation helpful? Give feedback.
-
Reconfiguration, switching from runtime to DFU mode is part of "four distinct phases" described in USB DFU specification. If it does not work, there is probably a problem with your host OS driver. TBH I am not sure if starting in runtime mode is necessary requirement form the spec but behavior of DFU implementation is not limited to your specific use case.
It does what is described in the option help, for more info see USB DFU spec and discussion in #49821. |
Beta Was this translation helpful? Give feedback.
-
@jfischer-no thank you! From these threads I see 2 areas to investigate:
Cheers, |
Beta Was this translation helpful? Give feedback.
-
@jfischer-no Going to continue taking notes here for reference. Initial results from within Windows, with the patch discussed in place
Windows dfu-util run:
Success! Now to test after removing the patch; that is, initialize USB DFU in Windows, dfu-util 0.11:
Hangs here forever. Attaching with debugger shows that Zephyr is still running without crash. Note the lines:
that were not present in the patched version. This makes sense and seems to show that the system is properly negotiating the detach/attach (AKA re-enumeration?) successfully. Before stepping through to see why it's not transferring I will test in WSL2. dfu-util 0.9 in Ubuntu 22.04:
Seems to have the same problem. Building with Didn't make a difference still stalls without transferring. Running At commit: dfu-util, Ubuntu, after west update, CONFIG_USB_DFU_WILL_DETACH=n:
dmesg:
Going to try with CONFIG_USB_DFU_WILL_DETACH=y since that's the desired setting anyway.
Now, dmesg reports nothing - probably asserted with that that Nordic mutex from interrupt bug. Progress though... Yep, it's the mutex_lock from usb_dc_detach in usb_dc_nrfx.c. Will cherry pick the fix real quick. Fix is here: #53414 OK, well the result is the same, except no assert. That is dmesg doesn't show any activity when
Stepping starting at the Trying at the work schedule call. Breakpoint is hit, timeout is set to 100 as expected from KConfigs. Perhaps I am misunderstanding the state setting, checking for break at the top of the work handler. Work handler is not called... Hmm, usb_work_q.h is interesting: #ifdef CONFIG_USB_WORKQUEUE
extern struct k_work_q z_usb_work_q;
#define USB_WORK_Q z_usb_work_q
#else
#define USB_WORK_Q k_sys_work_q
#endif So let's enable that and see if the delayable work works. dmesg does do the reset now! Since we're forwarding to WSL I'm adding dfu-util waits but still does not find the device. In dmesg we can see a problem: Device PID initially:
On reattach:
I will consider a PR to add a compile time assert to check that USB_DEVICE_DFU_PID != 0xffff since this is a silly time sink for engineers:
Will come back to this later with more notes. |
Beta Was this translation helpful? Give feedback.
Yeah. We are abandoning USB DFU entirely in favor of SMP over USB for FW updates for single slot and dual slot, from app or from MCUBoot.