Skip to content
This repository was archived by the owner on Mar 26, 2026. It is now read-only.
This repository was archived by the owner on Mar 26, 2026. It is now read-only.

USBDFU should be updated to not use deprecated SETUP_EP0_BUF(0); call. #21

Description

@purdeaandrei

After PR #18 is merged, the USBDFU code should be updated as well.
Exactly how I'm not sure, since it's not trivial.

The simplest non-functional change would be:

diff --git a/firmware/library/usbdfu.c b/firmware/library/usbdfu.c
index 38ca144..2fc9178 100644
--- a/firmware/library/usbdfu.c
+++ b/firmware/library/usbdfu.c
@@ -93,14 +93,16 @@ bool usb_dfu_setup(usb_dfu_iface_state_t *dfu, __xdata struct usb_req_setup *req
         dfu->length   = req->wLength;
         dfu->pending  = true;
         dfu->sync     = false;
-        SETUP_EP0_BUF(0);
+        SETUP_EP0_OUT_BUF();
+        ACK_EP0(); // TODO: this should probably be refactored to ack the buffer only after it's been processed?
         return true;
       } else if(dfu->state == USB_DFU_STATE_dfuDNLOAD_IDLE && req->wLength > 0) {
         dfu->state    = USB_DFU_STATE_dfuDNLOAD_SYNC;
         dfu->length   = req->wLength;
         dfu->pending  = true;
         dfu->sync     = false;
-        SETUP_EP0_BUF(0);
+        SETUP_EP0_OUT_BUF();
+        ACK_EP0(); // TODO: this should probably be refactored to ack the buffer only after it's been processed?
         return true;
       } else if(dfu->state == USB_DFU_STATE_dfuDNLOAD_IDLE) {
         dfu->state    = USB_DFU_STATE_dfuMANIFEST_SYNC;

However reading the code, it seems like USB_DFU_STATE_dfuDNLOAD_SYNC state exists specifically to work around the problem introduced by SETUP_EP0_BUF(0);, so I think the right implementation is to remove the USB_DFU_STATE_dfuDNLOAD_SYNC state completely.

Since the correct solution is not necessarily trivial, I'm not submitting a PR for this.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions