libopencm3-examples icon indicating copy to clipboard operation
libopencm3-examples copied to clipboard

STM32 F1 DFU example code

Open matswebjorn opened this issue 5 years ago • 0 comments

I have a question on libopencm3-examples\examples\stm32\f1\lisa-m-1\usb_hid\usbhid.c .

It defines

static enum usbd_request_return_codes dfu_control_request( usbd_device *dev, struct usb_setup_data *req, uint8_t **buf, uint16_t *len, void (**complete)(usbd_device *dev, struct usb_setup_data *req)) { (void)buf; (void)len; (void)dev; if ((req->bmRequestType != 0x21) || (req->bRequest != DFU_DETACH)) return USBD_REQ_NOTSUPP; /* Only accept class request. */ *complete = dfu_detach_complete; return USBD_REQ_HANDLED; }`

Which is registered in USBD using

usbd_register_control_callback( dev, USB_REQ_TYPE_CLASS | USB_REQ_TYPE_INTERFACE, USB_REQ_TYPE_TYPE | USB_REQ_TYPE_RECIPIENT, dfu_control_request);

My question is, why does dfu_control_request() check bmRequestType with

if ((req->bmRequestType != 0x21) ?

usb_control_request_dispatch() filters requests on the registered request-type using

if ((req->bmRequestType & cb[i].type_mask) == cb[i].type)

So the check in dfu_control_request() is redundant and just confusing for the reader.

It would be nice if the callback typedefs in libopencm3/include/libopencm3/usb/usbd.h Had the same kind of doxygen declaration as the other functions. This would most Likely eliminate these kind of misunderstandings of what the presumptions of the callback was.

matswebjorn avatar Jul 27 '20 07:07 matswebjorn