From b1056056af96239f48cd2f7c57b394c7a0c4ccbe Mon Sep 17 00:00:00 2001 From: arighi Date: Tue, 21 Sep 2010 10:37:55 +0000 Subject: [PATCH] STM32: USB: properly catch device's GET_DESCRIPTOR requests Getting descriptor for a device is a standard request (e.g., USB HID requires this). So, be sure to call the device's event handler when this request occurs. git-svn-id: https://src.develer.com/svnoss/bertos/trunk@4253 38d2e660-2303-0410-9eaa-f027e97ec537 --- bertos/cpu/cortex-m3/drv/usb_stm32.c | 29 +++++++++++++++------------- bertos/drv/usb.h | 3 ++- 2 files changed, 18 insertions(+), 14 deletions(-) diff --git a/bertos/cpu/cortex-m3/drv/usb_stm32.c b/bertos/cpu/cortex-m3/drv/usb_stm32.c index 6b0b28e1..89782fca 100644 --- a/bertos/cpu/cortex-m3/drv/usb_stm32.c +++ b/bertos/cpu/cortex-m3/drv/usb_stm32.c @@ -1381,6 +1381,17 @@ static void UsbGetDescriptor(void) } } +/* USB setup packet: class/vendor request handler */ +static void usb_event_handler(struct usb_device *dev) +{ + /* + * TODO: get the appropriate usb_dev in function of the endpoint + * address. + */ + if (dev->event_cb) + dev->event_cb(&setup_packet); +} + /* USB setup packet: GET_DESCRIPTOR handler */ static void UBS_GetDescriptorHandler(void) { @@ -1390,6 +1401,9 @@ static void UBS_GetDescriptorHandler(void) if ((setup_packet.mRequestType & USB_RECIP_MASK) == USB_RECIP_DEVICE) UsbGetDescriptor(); + /* Getting descriptor for a device is a standard request */ + else if ((setup_packet.mRequestType & USB_DIR_MASK) == USB_DIR_IN) + usb_event_handler(usb_dev); else ep_cnfg[CTRL_ENP_OUT].status = STALLED; } @@ -1555,17 +1569,6 @@ static void USB_StandardRequestHandler(void) } } -/* USB setup packet: class/vendor request handler */ -static void USB_EventHandler(void) -{ - /* - * TODO: get the appropriate usb_dev in function of the endpoint - * address. - */ - if (usb_dev->event_cb) - usb_dev->event_cb(&setup_packet); -} - /* USB setup packet handler */ static void USB_SetupHandler(void) { @@ -1581,13 +1584,13 @@ static void USB_SetupHandler(void) case USB_TYPE_CLASS: LOG_INFO("%s: bmRequestType=%02x (Class)\n", __func__, setup_packet.mRequestType); - USB_EventHandler(); + usb_event_handler(usb_dev); break; /* Vendor */ case USB_TYPE_VENDOR: LOG_INFO("%s: bmRequestType=%02x (Vendor)\n", __func__, setup_packet.mRequestType); - USB_EventHandler(); + usb_event_handler(usb_dev); break; case USB_TYPE_RESERVED: LOG_INFO("%s: bmRequestType=%02x (Reserved)\n", diff --git a/bertos/drv/usb.h b/bertos/drv/usb.h index 9909eb38..29dcb73c 100644 --- a/bertos/drv/usb.h +++ b/bertos/drv/usb.h @@ -89,6 +89,7 @@ enum usb_device_state { */ #define USB_DIR_OUT 0 /* to device */ #define USB_DIR_IN 0x80 /* to host */ +#define USB_DIR_MASK 0x80 /* * USB types, the second of three bRequestType fields @@ -310,7 +311,7 @@ typedef struct usb_endpoint_descriptor * Endpoints */ #define USB_ENDPOINT_NUMBER_MASK 0x0f /* in bEndpointAddress */ -#define USB_ENDPOINT_DIR_MASK 0x80 +#define USB_ENDPOINT_DIR_MASK USB_DIR_MASK #define USB_ENDPOINT_SYNCTYPE 0x0c #define USB_ENDPOINT_SYNC_NONE (0 << 2) -- 2.25.1