Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
purdeaandrei opened this issue Sep 26, 2024 · 0 comments

Comments

@purdeaandrei
Copy link

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant