diff options
author | root <root@ka-ata-killa.ourano.james.local> | 2021-03-03 15:24:13 +0000 |
---|---|---|
committer | root <root@ka-ata-killa.ourano.james.local> | 2021-03-03 16:03:28 +0000 |
commit | 49148e76706e5e24c2ba7f6ccc1d7ec4736ab2f3 (patch) | |
tree | f65cb7440711ea1708c25fe78819e9986b2d8566 /app/dfu.c | |
parent | 129a103238d69bd90b4fe9a44bbed943b9488fc2 (diff) | |
download | serial_over_dp-49148e76706e5e24c2ba7f6ccc1d7ec4736ab2f3.tar.gz serial_over_dp-49148e76706e5e24c2ba7f6ccc1d7ec4736ab2f3.tar.bz2 serial_over_dp-49148e76706e5e24c2ba7f6ccc1d7ec4736ab2f3.zip |
support cheap chinese blue pill boards, make usb dfu compatible with dfuse
Diffstat (limited to 'app/dfu.c')
-rw-r--r-- | app/dfu.c | 28 |
1 files changed, 19 insertions, 9 deletions
@@ -1,13 +1,9 @@ #include "project.h" -#ifdef INCLUDE_DFU_INTERFACE - -extern uint32_t dfu_flag; - const struct usb_dfu_descriptor dfu_function = { .bLength = sizeof (struct usb_dfu_descriptor), .bDescriptorType = DFU_FUNCTIONAL, - .bmAttributes = USB_DFU_CAN_DOWNLOAD, + .bmAttributes = USB_DFU_CAN_DOWNLOAD | USB_DFU_WILL_DETACH, .wDetachTimeout = 255, .wTransferSize = 1024, .bcdDFUVersion = 0x011A, @@ -16,25 +12,37 @@ const struct usb_dfu_descriptor dfu_function = { const struct usb_interface_descriptor dfu_iface = { .bLength = USB_DT_INTERFACE_SIZE, .bDescriptorType = USB_DT_INTERFACE, - .bInterfaceNumber = 2, + .bInterfaceNumber = 1, .bAlternateSetting = 0, .bNumEndpoints = 0, .bInterfaceClass = 0xFE, .bInterfaceSubClass = 1, .bInterfaceProtocol = 1, .iInterface = 4, - .extra = &dfu_function, .extralen = sizeof (dfu_function), }; +const struct usb_iface_assoc_descriptor dfu_iface_assoc = { + .bLength = USB_DT_INTERFACE_ASSOCIATION_SIZE, + .bDescriptorType = USB_DT_INTERFACE_ASSOCIATION, + .bFirstInterface = 1, + .bInterfaceCount = 1, + .bFunctionClass = 0xfe, + .bFunctionSubClass = 1, + .bFunctionProtocol = 1, + .iFunction = 5, +}; + + static int dfu_detach_complete (usbd_device *usbd_dev, struct usb_setup_data *req) { (void) req; (void) usbd_dev; dfu_flag = 0xfee1dead; + scb_reset_core(); return 1; } @@ -48,7 +56,7 @@ dfu_control_request (usbd_device *usbd_dev, struct usb_setup_data *req, (void) len; (void) usbd_dev; - if ( (req->bmRequestType & 0x7F) != 0x21) { + if ((req->bmRequestType & 0x7F) != 0x21) { return 0; /* Only accept class request. */ } @@ -63,11 +71,13 @@ dfu_control_request (usbd_device *usbd_dev, struct usb_setup_data *req, *len = 6; return 1; } + case DFU_GETSTATE: /* Return state with no state transision. */ *buf[0] = STATE_APP_IDLE; *len = 1; return 1; + case DFU_DETACH: *complete = dfu_detach_complete; return 1; @@ -75,4 +85,4 @@ dfu_control_request (usbd_device *usbd_dev, struct usb_setup_data *req, return 0; } -#endif + |