aboutsummaryrefslogtreecommitdiffstats
path: root/os/hal/src/usb.c
diff options
context:
space:
mode:
Diffstat (limited to 'os/hal/src/usb.c')
-rw-r--r--os/hal/src/usb.c253
1 files changed, 160 insertions, 93 deletions
diff --git a/os/hal/src/usb.c b/os/hal/src/usb.c
index 602115fbd..ceb561957 100644
--- a/os/hal/src/usb.c
+++ b/os/hal/src/usb.c
@@ -29,7 +29,7 @@
#include "hal.h"
-#if HAL_USE_USB || defined(__DOXYGEN__)
+#if (HAL_USE_USB == TRUE) || defined(__DOXYGEN__)
/*===========================================================================*/
/* Driver local definitions. */
@@ -51,6 +51,14 @@ static const uint8_t halted_status[] = {0x01, 0x00};
/* Driver local functions. */
/*===========================================================================*/
+static uint16_t get_hword(uint8_t *p) {
+ uint16_t hw;
+
+ hw = (uint16_t)*p++;
+ hw |= (uint16_t)*p << 8U;
+ return hw;
+}
+
/**
* @brief SET ADDRESS transaction callback.
*
@@ -80,130 +88,154 @@ static bool default_handler(USBDriver *usbp) {
const USBDescriptor *dp;
/* Decoding the request.*/
- switch (((usbp->setup[0] & (USB_RTYPE_RECIPIENT_MASK |
- USB_RTYPE_TYPE_MASK)) |
- (usbp->setup[1] << 8))) {
- case USB_RTYPE_RECIPIENT_DEVICE | (USB_REQ_GET_STATUS << 8):
+ switch ((((uint32_t)usbp->setup[0] & (USB_RTYPE_RECIPIENT_MASK |
+ USB_RTYPE_TYPE_MASK)) |
+ ((uint32_t)usbp->setup[1] << 8U))) {
+ case (uint32_t)USB_RTYPE_RECIPIENT_DEVICE | ((uint32_t)USB_REQ_GET_STATUS << 8):
/* Just returns the current status word.*/
usbSetupTransfer(usbp, (uint8_t *)&usbp->status, 2, NULL);
return true;
- case USB_RTYPE_RECIPIENT_DEVICE | (USB_REQ_CLEAR_FEATURE << 8):
+ case (uint32_t)USB_RTYPE_RECIPIENT_DEVICE | ((uint32_t)USB_REQ_CLEAR_FEATURE << 8):
/* Only the DEVICE_REMOTE_WAKEUP is handled here, any other feature
number is handled as an error.*/
if (usbp->setup[2] == USB_FEATURE_DEVICE_REMOTE_WAKEUP) {
- usbp->status &= ~2;
+ usbp->status &= ~2U;
usbSetupTransfer(usbp, NULL, 0, NULL);
return true;
}
return false;
- case USB_RTYPE_RECIPIENT_DEVICE | (USB_REQ_SET_FEATURE << 8):
+ case (uint32_t)USB_RTYPE_RECIPIENT_DEVICE | ((uint32_t)USB_REQ_SET_FEATURE << 8):
/* Only the DEVICE_REMOTE_WAKEUP is handled here, any other feature
number is handled as an error.*/
if (usbp->setup[2] == USB_FEATURE_DEVICE_REMOTE_WAKEUP) {
- usbp->status |= 2;
+ usbp->status |= 2U;
usbSetupTransfer(usbp, NULL, 0, NULL);
return true;
}
return false;
- case USB_RTYPE_RECIPIENT_DEVICE | (USB_REQ_SET_ADDRESS << 8):
+ case (uint32_t)USB_RTYPE_RECIPIENT_DEVICE | ((uint32_t)USB_REQ_SET_ADDRESS << 8):
/* The SET_ADDRESS handling can be performed here or postponed after
the status packed depending on the USB_SET_ADDRESS_MODE low
driver setting.*/
#if USB_SET_ADDRESS_MODE == USB_EARLY_SET_ADDRESS
if ((usbp->setup[0] == USB_RTYPE_RECIPIENT_DEVICE) &&
- (usbp->setup[1] == USB_REQ_SET_ADDRESS))
+ (usbp->setup[1] == USB_REQ_SET_ADDRESS)) {
set_address(usbp);
+ }
usbSetupTransfer(usbp, NULL, 0, NULL);
#else
usbSetupTransfer(usbp, NULL, 0, set_address);
#endif
return true;
- case USB_RTYPE_RECIPIENT_DEVICE | (USB_REQ_GET_DESCRIPTOR << 8):
+ case (uint32_t)USB_RTYPE_RECIPIENT_DEVICE | ((uint32_t)USB_REQ_GET_DESCRIPTOR << 8):
/* Handling descriptor requests from the host.*/
- dp = usbp->config->get_descriptor_cb(
- usbp, usbp->setup[3], usbp->setup[2],
- usbFetchWord(&usbp->setup[4]));
- if (dp == NULL)
+ dp = usbp->config->get_descriptor_cb(usbp, usbp->setup[3],
+ usbp->setup[2],
+ get_hword(&usbp->setup[4]));
+ if (dp == NULL) {
return false;
+ }
+ /*lint -save -e9005 [11.8] Removing const is fine.*/
usbSetupTransfer(usbp, (uint8_t *)dp->ud_string, dp->ud_size, NULL);
+ /*lint -restore*/
return true;
- case USB_RTYPE_RECIPIENT_DEVICE | (USB_REQ_GET_CONFIGURATION << 8):
+ case (uint32_t)USB_RTYPE_RECIPIENT_DEVICE | ((uint32_t)USB_REQ_GET_CONFIGURATION << 8):
/* Returning the last selected configuration.*/
usbSetupTransfer(usbp, &usbp->configuration, 1, NULL);
return true;
- case USB_RTYPE_RECIPIENT_DEVICE | (USB_REQ_SET_CONFIGURATION << 8):
+ 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 == 0)
+ if (usbp->configuration == 0U) {
usbp->state = USB_SELECTED;
- else
+ }
+ else {
usbp->state = USB_ACTIVE;
+ }
_usb_isr_invoke_event_cb(usbp, USB_EVENT_CONFIGURED);
usbSetupTransfer(usbp, NULL, 0, NULL);
return true;
- case USB_RTYPE_RECIPIENT_INTERFACE | (USB_REQ_GET_STATUS << 8):
- case USB_RTYPE_RECIPIENT_ENDPOINT | (USB_REQ_SYNCH_FRAME << 8):
+ case (uint32_t)USB_RTYPE_RECIPIENT_INTERFACE | ((uint32_t)USB_REQ_GET_STATUS << 8):
+ case (uint32_t)USB_RTYPE_RECIPIENT_ENDPOINT | ((uint32_t)USB_REQ_SYNCH_FRAME << 8):
/* Just sending two zero bytes, the application can change the behavior
using a hook..*/
+ /*lint -save -e9005 [11.8] Removing const is fine.*/
usbSetupTransfer(usbp, (uint8_t *)zero_status, 2, NULL);
+ /*lint -restore*/
return true;
- case USB_RTYPE_RECIPIENT_ENDPOINT | (USB_REQ_GET_STATUS << 8):
+ case (uint32_t)USB_RTYPE_RECIPIENT_ENDPOINT | ((uint32_t)USB_REQ_GET_STATUS << 8):
/* Sending the EP status.*/
- if (usbp->setup[4] & 0x80) {
- switch (usb_lld_get_status_in(usbp, usbp->setup[4] & 0x0F)) {
+ if ((usbp->setup[4] & 0x80U) != 0U) {
+ switch (usb_lld_get_status_in(usbp, usbp->setup[4] & 0x0FU)) {
case EP_STATUS_STALLED:
+ /*lint -save -e9005 [11.8] Removing const is fine.*/
usbSetupTransfer(usbp, (uint8_t *)halted_status, 2, NULL);
+ /*lint -restore*/
return true;
case EP_STATUS_ACTIVE:
+ /*lint -save -e9005 [11.8] Removing const is fine.*/
usbSetupTransfer(usbp, (uint8_t *)active_status, 2, NULL);
+ /*lint -restore*/
return true;
+ case EP_STATUS_DISABLED:
default:
return false;
}
}
else {
- switch (usb_lld_get_status_out(usbp, usbp->setup[4] & 0x0F)) {
+ switch (usb_lld_get_status_out(usbp, usbp->setup[4] & 0x0FU)) {
case EP_STATUS_STALLED:
+ /*lint -save -e9005 [11.8] Removing const is fine.*/
usbSetupTransfer(usbp, (uint8_t *)halted_status, 2, NULL);
+ /*lint -restore*/
return true;
case EP_STATUS_ACTIVE:
+ /*lint -save -e9005 [11.8] Removing const is fine.*/
usbSetupTransfer(usbp, (uint8_t *)active_status, 2, NULL);
+ /*lint -restore*/
return true;
+ case EP_STATUS_DISABLED:
default:
return false;
}
}
- case USB_RTYPE_RECIPIENT_ENDPOINT | (USB_REQ_CLEAR_FEATURE << 8):
+ case (uint32_t)USB_RTYPE_RECIPIENT_ENDPOINT | ((uint32_t)USB_REQ_CLEAR_FEATURE << 8):
/* Only ENDPOINT_HALT is handled as feature.*/
- if (usbp->setup[2] != USB_FEATURE_ENDPOINT_HALT)
+ if (usbp->setup[2] != USB_FEATURE_ENDPOINT_HALT) {
return false;
+ }
/* Clearing the EP status, not valid for EP0, it is ignored in that case.*/
- if ((usbp->setup[4] & 0x0F) > 0) {
- if (usbp->setup[4] & 0x80)
- usb_lld_clear_in(usbp, usbp->setup[4] & 0x0F);
- else
- usb_lld_clear_out(usbp, usbp->setup[4] & 0x0F);
+ if ((usbp->setup[4] & 0x0FU) != 0U) {
+ if ((usbp->setup[4] & 0x80U) != 0U) {
+ usb_lld_clear_in(usbp, usbp->setup[4] & 0x0FU);
+ }
+ else {
+ usb_lld_clear_out(usbp, usbp->setup[4] & 0x0FU);
+ }
}
usbSetupTransfer(usbp, NULL, 0, NULL);
return true;
- case USB_RTYPE_RECIPIENT_ENDPOINT | (USB_REQ_SET_FEATURE << 8):
+ case (uint32_t)USB_RTYPE_RECIPIENT_ENDPOINT | ((uint32_t)USB_REQ_SET_FEATURE << 8):
/* Only ENDPOINT_HALT is handled as feature.*/
- if (usbp->setup[2] != USB_FEATURE_ENDPOINT_HALT)
+ if (usbp->setup[2] != USB_FEATURE_ENDPOINT_HALT) {
return false;
+ }
/* Stalling the EP, not valid for EP0, it is ignored in that case.*/
- if ((usbp->setup[4] & 0x0F) > 0) {
- if (usbp->setup[4] & 0x80)
- usb_lld_stall_in(usbp, usbp->setup[4] & 0x0F);
- else
- usb_lld_stall_out(usbp, usbp->setup[4] & 0x0F);
+ if ((usbp->setup[4] & 0x0FU) != 0U) {
+ if ((usbp->setup[4] & 0x80U) != 0U) {
+ usb_lld_stall_in(usbp, usbp->setup[4] & 0x0FU);
+ }
+ else {
+ usb_lld_stall_out(usbp, usbp->setup[4] & 0x0FU);
+ }
}
usbSetupTransfer(usbp, NULL, 0, NULL);
return true;
- case USB_RTYPE_RECIPIENT_DEVICE | (USB_REQ_SET_DESCRIPTOR << 8):
- case USB_RTYPE_RECIPIENT_INTERFACE | (USB_REQ_CLEAR_FEATURE << 8):
- case USB_RTYPE_RECIPIENT_INTERFACE | (USB_REQ_SET_FEATURE << 8):
- case USB_RTYPE_RECIPIENT_INTERFACE | (USB_REQ_GET_INTERFACE << 8):
- case USB_RTYPE_RECIPIENT_INTERFACE | (USB_REQ_SET_INTERFACE << 8):
+ case (uint32_t)USB_RTYPE_RECIPIENT_DEVICE | ((uint32_t)USB_REQ_SET_DESCRIPTOR << 8):
+ case (uint32_t)USB_RTYPE_RECIPIENT_INTERFACE | ((uint32_t)USB_REQ_CLEAR_FEATURE << 8):
+ case (uint32_t)USB_RTYPE_RECIPIENT_INTERFACE | ((uint32_t)USB_REQ_SET_FEATURE << 8):
+ case (uint32_t)USB_RTYPE_RECIPIENT_INTERFACE | ((uint32_t)USB_REQ_GET_INTERFACE << 8):
+ case (uint32_t)USB_RTYPE_RECIPIENT_INTERFACE | ((uint32_t)USB_REQ_SET_INTERFACE << 8):
/* All the above requests are not handled here, if you need them then
use the hook mechanism and provide handling.*/
default:
@@ -239,7 +271,7 @@ void usbObjectInit(USBDriver *usbp) {
usbp->state = USB_STOP;
usbp->config = NULL;
- for (i = 0; i < USB_MAX_ENDPOINTS; i++) {
+ for (i = 0; i < (unsigned)USB_MAX_ENDPOINTS; i++) {
usbp->in_params[i] = NULL;
usbp->out_params[i] = NULL;
}
@@ -264,8 +296,9 @@ void usbStart(USBDriver *usbp, const USBConfig *config) {
osalDbgAssert((usbp->state == USB_STOP) || (usbp->state == USB_READY),
"invalid state");
usbp->config = config;
- for (i = 0; i <= USB_MAX_ENDPOINTS; i++)
+ for (i = 0; i <= (unsigned)USB_MAX_ENDPOINTS; i++) {
usbp->epc[i] = NULL;
+ }
usb_lld_start(usbp);
usbp->state = USB_READY;
osalSysUnlock();
@@ -314,10 +347,12 @@ void usbInitEndpointI(USBDriver *usbp, usbep_t ep,
osalDbgAssert(usbp->epc[ep] == NULL, "already initialized");
/* Logically enabling the endpoint in the USBDriver structure.*/
- if (epcp->in_state != NULL)
+ if (epcp->in_state != NULL) {
memset(epcp->in_state, 0, sizeof(USBInEndpointState));
- if (epcp->out_state != NULL)
+ }
+ if (epcp->out_state != NULL) {
memset(epcp->out_state, 0, sizeof(USBOutEndpointState));
+ }
usbp->epc[ep] = epcp;
@@ -343,10 +378,11 @@ void usbDisableEndpointsI(USBDriver *usbp) {
osalDbgCheck(usbp != NULL);
osalDbgAssert(usbp->state == USB_SELECTED, "invalid state");
- usbp->transmitting &= ~1;
- usbp->receiving &= ~1;
- for (i = 1; i <= USB_MAX_ENDPOINTS; i++)
+ usbp->transmitting &= ~1U;
+ usbp->receiving &= ~1U;
+ for (i = 1; i <= (unsigned)USB_MAX_ENDPOINTS; i++) {
usbp->epc[i] = NULL;
+ }
/* Low level endpoints deactivation.*/
usb_lld_disable_endpoints(usbp);
@@ -475,10 +511,11 @@ bool usbStartReceiveI(USBDriver *usbp, usbep_t ep) {
osalDbgCheckClassI();
osalDbgCheck(usbp != NULL);
- if (usbGetReceiveStatusI(usbp, ep))
+ if (usbGetReceiveStatusI(usbp, ep)) {
return true;
+ }
- usbp->receiving |= (1 << ep);
+ usbp->receiving |= (uint16_t)((unsigned)1U << (unsigned)ep);
usb_lld_start_out(usbp, ep);
return false;
}
@@ -502,10 +539,11 @@ bool usbStartTransmitI(USBDriver *usbp, usbep_t ep) {
osalDbgCheckClassI();
osalDbgCheck(usbp != NULL);
- if (usbGetTransmitStatusI(usbp, ep))
+ if (usbGetTransmitStatusI(usbp, ep)) {
return true;
+ }
- usbp->transmitting |= (1 << ep);
+ usbp->transmitting |= (uint16_t)((unsigned)1U << (unsigned)ep);
usb_lld_start_in(usbp, ep);
return false;
}
@@ -527,8 +565,9 @@ bool usbStallReceiveI(USBDriver *usbp, usbep_t ep) {
osalDbgCheckClassI();
osalDbgCheck(usbp != NULL);
- if (usbGetReceiveStatusI(usbp, ep))
+ if (usbGetReceiveStatusI(usbp, ep)) {
return true;
+ }
usb_lld_stall_out(usbp, ep);
return false;
@@ -551,8 +590,9 @@ bool usbStallTransmitI(USBDriver *usbp, usbep_t ep) {
osalDbgCheckClassI();
osalDbgCheck(usbp != NULL);
- if (usbGetTransmitStatusI(usbp, ep))
+ if (usbGetTransmitStatusI(usbp, ep)) {
return true;
+ }
usb_lld_stall_in(usbp, ep);
return false;
@@ -578,8 +618,9 @@ void _usb_reset(USBDriver *usbp) {
usbp->receiving = 0;
/* Invalidates all endpoints into the USBDriver structure.*/
- for (i = 0; i <= USB_MAX_ENDPOINTS; i++)
+ for (i = 0; i <= (unsigned)USB_MAX_ENDPOINTS; i++) {
usbp->epc[i] = NULL;
+ }
/* EP0 state machine initialization.*/
usbp->ep0state = USB_EP0_WAITING_SETUP;
@@ -606,12 +647,16 @@ void _usb_ep0setup(USBDriver *usbp, usbep_t ep) {
/* First verify if the application has an handler installed for this
request.*/
- if (!(usbp->config->requests_hook_cb) ||
+ /*lint -save -e9007 [13.5] No side effects, it is intentional.*/
+ if ((usbp->config->requests_hook_cb == NULL) ||
!(usbp->config->requests_hook_cb(usbp))) {
+ /*lint -restore*/
/* Invoking the default handler, if this fails then stalls the
endpoint zero as error.*/
+ /*lint -save -e9007 [13.5] No side effects, it is intentional.*/
if (((usbp->setup[0] & USB_RTYPE_TYPE_MASK) != USB_RTYPE_TYPE_STD) ||
!default_handler(usbp)) {
+ /*lint -restore*/
/* Error response, the state machine goes into an error state, the low
level layer will have to reset it to USB_EP0_WAITING_SETUP after
receiving a SETUP packet.*/
@@ -631,18 +676,19 @@ void _usb_ep0setup(USBDriver *usbp, usbep_t ep) {
/* Transfer preparation. The request handler must have populated
correctly the fields ep0next, ep0n and ep0endcb using the macro
usbSetupTransfer().*/
- max = usbFetchWord(&usbp->setup[6]);
+ max = (size_t)get_hword(&usbp->setup[6]);
/* The transfer size cannot exceed the specified amount.*/
- if (usbp->ep0n > max)
+ if (usbp->ep0n > max) {
usbp->ep0n = max;
+ }
if ((usbp->setup[0] & USB_RTYPE_DIR_MASK) == USB_RTYPE_DIR_DEV2HOST) {
/* IN phase.*/
- if (usbp->ep0n > 0) {
+ if (usbp->ep0n != 0U) {
/* Starts the transmit phase.*/
usbp->ep0state = USB_EP0_TX;
usbPrepareTransmit(usbp, 0, usbp->ep0next, usbp->ep0n);
osalSysLockFromISR();
- usbStartTransmitI(usbp, 0);
+ (void) usbStartTransmitI(usbp, 0);
osalSysUnlockFromISR();
}
else {
@@ -652,7 +698,7 @@ void _usb_ep0setup(USBDriver *usbp, usbep_t ep) {
#if (USB_EP0_STATUS_STAGE == USB_EP0_STATUS_STAGE_SW)
usbPrepareReceive(usbp, 0, NULL, 0);
osalSysLockFromISR();
- usbStartReceiveI(usbp, 0);
+ (void) usbStartReceiveI(usbp, 0);
osalSysUnlockFromISR();
#else
usb_lld_end_setup(usbp, ep);
@@ -661,12 +707,12 @@ void _usb_ep0setup(USBDriver *usbp, usbep_t ep) {
}
else {
/* OUT phase.*/
- if (usbp->ep0n > 0) {
+ if (usbp->ep0n != 0U) {
/* Starts the receive phase.*/
usbp->ep0state = USB_EP0_RX;
usbPrepareReceive(usbp, 0, usbp->ep0next, usbp->ep0n);
osalSysLockFromISR();
- usbStartReceiveI(usbp, 0);
+ (void) usbStartReceiveI(usbp, 0);
osalSysUnlockFromISR();
}
else {
@@ -676,7 +722,7 @@ void _usb_ep0setup(USBDriver *usbp, usbep_t ep) {
#if (USB_EP0_STATUS_STAGE == USB_EP0_STATUS_STAGE_SW)
usbPrepareTransmit(usbp, 0, NULL, 0);
osalSysLockFromISR();
- usbStartTransmitI(usbp, 0);
+ (void) usbStartTransmitI(usbp, 0);
osalSysUnlockFromISR();
#else
usb_lld_end_setup(usbp, ep);
@@ -701,14 +747,15 @@ void _usb_ep0in(USBDriver *usbp, usbep_t ep) {
(void)ep;
switch (usbp->ep0state) {
case USB_EP0_TX:
- max = usbFetchWord(&usbp->setup[6]);
+ max = (size_t)get_hword(&usbp->setup[6]);
/* If the transmitted size is less than the requested size and it is a
multiple of the maximum packet size then a zero size packet must be
transmitted.*/
- if ((usbp->ep0n < max) && ((usbp->ep0n % usbp->epc[0]->in_maxsize) == 0)) {
+ if ((usbp->ep0n < max) &&
+ ((usbp->ep0n % usbp->epc[0]->in_maxsize) == 0U)) {
usbPrepareTransmit(usbp, 0, NULL, 0);
osalSysLockFromISR();
- usbStartTransmitI(usbp, 0);
+ (void) usbStartTransmitI(usbp, 0);
osalSysUnlockFromISR();
usbp->ep0state = USB_EP0_WAITING_TX0;
return;
@@ -720,7 +767,7 @@ void _usb_ep0in(USBDriver *usbp, usbep_t ep) {
#if (USB_EP0_STATUS_STAGE == USB_EP0_STATUS_STAGE_SW)
usbPrepareReceive(usbp, 0, NULL, 0);
osalSysLockFromISR();
- usbStartReceiveI(usbp, 0);
+ (void) usbStartReceiveI(usbp, 0);
osalSysUnlockFromISR();
#else
usb_lld_end_setup(usbp, ep);
@@ -728,20 +775,29 @@ void _usb_ep0in(USBDriver *usbp, usbep_t ep) {
return;
case USB_EP0_SENDING_STS:
/* Status packet sent, invoking the callback if defined.*/
- if (usbp->ep0endcb != NULL)
+ if (usbp->ep0endcb != NULL) {
usbp->ep0endcb(usbp);
+ }
usbp->ep0state = USB_EP0_WAITING_SETUP;
return;
+ case USB_EP0_WAITING_SETUP:
+ case USB_EP0_WAITING_STS:
+ case USB_EP0_RX:
+ /* All the above are invalid states in the IN phase.*/
+ osalDbgAssert(false, "EP0 state machine error");
+ /* Falling through is intentional.*/
+ case USB_EP0_ERROR:
+ /* Error response, the state machine goes into an error state, the low
+ level layer will have to reset it to USB_EP0_WAITING_SETUP after
+ receiving a SETUP packet.*/
+ usb_lld_stall_in(usbp, 0);
+ usb_lld_stall_out(usbp, 0);
+ _usb_isr_invoke_event_cb(usbp, USB_EVENT_STALLED);
+ usbp->ep0state = USB_EP0_ERROR;
+ return;
default:
- ;
+ osalDbgAssert(false, "EP0 state machine invalid state");
}
- /* Error response, the state machine goes into an error state, the low
- level layer will have to reset it to USB_EP0_WAITING_SETUP after
- receiving a SETUP packet.*/
- usb_lld_stall_in(usbp, 0);
- usb_lld_stall_out(usbp, 0);
- _usb_isr_invoke_event_cb(usbp, USB_EVENT_STALLED);
- usbp->ep0state = USB_EP0_ERROR;
}
/**
@@ -764,7 +820,7 @@ void _usb_ep0out(USBDriver *usbp, usbep_t ep) {
#if (USB_EP0_STATUS_STAGE == USB_EP0_STATUS_STAGE_SW)
usbPrepareTransmit(usbp, 0, NULL, 0);
osalSysLockFromISR();
- usbStartTransmitI(usbp, 0);
+ (void) usbStartTransmitI(usbp, 0);
osalSysUnlockFromISR();
#else
usb_lld_end_setup(usbp, ep);
@@ -774,25 +830,36 @@ void _usb_ep0out(USBDriver *usbp, usbep_t ep) {
/* Status packet received, it must be zero sized, invoking the callback
if defined.*/
#if (USB_EP0_STATUS_STAGE == USB_EP0_STATUS_STAGE_SW)
- if (usbGetReceiveTransactionSizeI(usbp, 0) != 0)
+ if (usbGetReceiveTransactionSizeI(usbp, 0) != 0U) {
break;
+ }
#endif
- if (usbp->ep0endcb != NULL)
+ if (usbp->ep0endcb != NULL) {
usbp->ep0endcb(usbp);
+ }
usbp->ep0state = USB_EP0_WAITING_SETUP;
return;
+ case USB_EP0_WAITING_SETUP:
+ case USB_EP0_TX:
+ case USB_EP0_WAITING_TX0:
+ case USB_EP0_SENDING_STS:
+ /* All the above are invalid states in the IN phase.*/
+ osalDbgAssert(false, "EP0 state machine error");
+ /* Falling through is intentional.*/
+ case USB_EP0_ERROR:
+ /* Error response, the state machine goes into an error state, the low
+ level layer will have to reset it to USB_EP0_WAITING_SETUP after
+ receiving a SETUP packet.*/
+ usb_lld_stall_in(usbp, 0);
+ usb_lld_stall_out(usbp, 0);
+ _usb_isr_invoke_event_cb(usbp, USB_EVENT_STALLED);
+ usbp->ep0state = USB_EP0_ERROR;
+ return;
default:
- ;
+ osalDbgAssert(false, "EP0 state machine invalid state");
}
- /* Error response, the state machine goes into an error state, the low
- level layer will have to reset it to USB_EP0_WAITING_SETUP after
- receiving a SETUP packet.*/
- usb_lld_stall_in(usbp, 0);
- usb_lld_stall_out(usbp, 0);
- _usb_isr_invoke_event_cb(usbp, USB_EVENT_STALLED);
- usbp->ep0state = USB_EP0_ERROR;
}
-#endif /* HAL_USE_USB */
+#endif /* HAL_USE_USB == TRUE */
/** @} */