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

STM32 F1 DFU example code #209

Open
matswebjorn opened this issue Jul 27, 2020 · 0 comments
Open

STM32 F1 DFU example code #209

matswebjorn opened this issue Jul 27, 2020 · 0 comments

Comments

@matswebjorn
Copy link

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.

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