USB stall error
Posted: Wed Apr 27, 2022 2:26 pm
Hello!
If a USB stall error occurs is there any common procedure to clear/solve it?
If a USB stall error occurs is there any common procedure to clear/solve it?
Giovanni wrote:Hi,
It depends on the cause of the stall, if it is an unimplemented command then you need to implement the command handler (not all CDC commands are implemented by default).
Giovanni
Giovanni wrote:Find all instances of "usb_lld_stall" in hal_usb.c, those are all the possible causes, mainly are unimplemented EP0 commands.
Giovanni
Code: Select all
bool requestsHook(USBDriver *usbp) {
// (void) usbp;
if ((usbp->setup[0] & USB_RTYPE_DIR_MASK) == USB_RTYPE_DIR_HOST2DEV)
{
if (usbp->setup[1] == USB_REQ_SET_ADDRESS)
{
set_address(usbp);
usbSetupTransfer(usbp, NULL, 0, NULL);
return true;
}
else if (usbp->setup[1] == USB_REQ_SET_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.*/
osalSysLockFromISR ();
usbDisableEndpointsI(usbp);
osalSysUnlockFromISR ();
usbp->configuration = 0U;
usbp->state = USB_SELECTED;
_usb_isr_invoke_event_cb(usbp, USB_EVENT_UNCONFIGURED);
}
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);
}
}
usbSetupTransfer(usbp, NULL, 0, NULL);
return true;
}
}
else if ((usbp->setup[0] & USB_RTYPE_DIR_MASK) == USB_RTYPE_DIR_DEV2HOST)
{
if (usbp->setup[1] == USB_REQ_GET_DESCRIPTOR)
{
const USBDescriptor *dp = usbp->config->get_descriptor_cb(usbp, usbp->setup[3],
usbp->setup[2],
get_hword(&usbp->setup[4]));
if (dp == NULL)
{
return false;
}
usbSetupTransfer(usbp, (uint8_t *)dp->ud_string, dp->ud_size, NULL);
return true;
}
}
return FALSE;
}
I noticed that bool requestsHook(USBDriver *usbp) receives
* USB_REQ_SET_ADDRESS
* USB_REQ_SET_CONFIGURATION
* USB_REQ_GET_DESCRIPTOR