From 371d3c186a84809e49a943fb61f998ebe7b5db48 Mon Sep 17 00:00:00 2001 From: Giovanni Di Sirio Date: Fri, 17 Jun 2016 09:46:53 +0000 Subject: git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@9636 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/hal/src/hal_usb.c | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) (limited to 'os/hal') diff --git a/os/hal/src/hal_usb.c b/os/hal/src/hal_usb.c index c10bf0d56..261ff6822 100644 --- a/os/hal/src/hal_usb.c +++ b/os/hal/src/hal_usb.c @@ -141,19 +141,23 @@ static bool default_handler(USBDriver *usbp) { usbSetupTransfer(usbp, &usbp->configuration, 1, NULL); return true; case (uint32_t)USB_RTYPE_RECIPIENT_DEVICE | ((uint32_t)USB_REQ_SET_CONFIGURATION << 8): - /* Handling configuration selection from the host.*/ - usbp->configuration = usbp->setup[2]; - if (usbp->configuration == 0U) { + /* Handling configuration selection from the host only if it is different + from the current configuration.*/ + if (usbp->configuration != usbp->setup[2]) { + /* If the USB device is already active then we have to perform the clear + procedure on the current configuration.*/ if (usbp->state == USB_ACTIVE) { + /* Current configuration cleared.*/ chSysLockFromISR (); usbDisableEndpointsI(usbp); chSysUnlockFromISR (); + usbp->configuration = 0U; usbp->state = USB_SELECTED; _usb_isr_invoke_event_cb(usbp, USB_EVENT_UNCONFIGURED); } - } - else { - if (usbp->state != USB_ACTIVE) { + if (usbp->setup[2] != 0U) { + /* New configuration.*/ + usbp->configuration = usbp->setup[2]; usbp->state = USB_ACTIVE; _usb_isr_invoke_event_cb(usbp, USB_EVENT_CONFIGURED); } -- cgit v1.2.3