Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
pavel-kirienko committed Feb 21, 2019
1 parent 3958649 commit ad6e504
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 3 deletions.
18 changes: 17 additions & 1 deletion bootloader/src/usb_cdc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,22 @@ static const USBDescriptor *get_descriptor(USBDriver *usbp, uint8_t dtype, uint8
return NULL;
}

/*
* USB stack crash workaround.
* See http://www.chibios.com/forum/viewtopic.php?f=25&t=4568&p=32429
* This bug is fixed in ChibiOS 18+, so the workaround does not have to be here after the OS is updated.
*/
static void sduDataReceivedProxy(USBDriver* const usbp, const usbep_t ep)
{
if (auto sdup = static_cast<SerialUSBDriver*>(usbp->out_params[ep - 1U]))
{
if (usbGetReceiveTransactionSizeX(sdup->config->usbp, sdup->config->bulk_out) > 0)
{
sduDataReceived(usbp, ep);
}
}
}

/*
* USB endpoints
*/
Expand All @@ -267,7 +283,7 @@ static const USBEndpointConfig ep2config = ///< EP1 initialization structur
USB_EP_MODE_TYPE_BULK,
NULL,
sduDataTransmitted,
sduDataReceived,
sduDataReceivedProxy,
0x0040,
0x0040,
&ep2instate,
Expand Down
20 changes: 18 additions & 2 deletions firmware/src/usb_cdc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,22 @@ static const USBDescriptor *get_descriptor(USBDriver *usbp, uint8_t dtype, uint8
return NULL;
}

/*
* USB stack crash workaround.
* See http://www.chibios.com/forum/viewtopic.php?f=25&t=4568&p=32429
* This bug is fixed in ChibiOS 18+, so the workaround does not have to be here after the OS is updated.
*/
static void sduDataReceivedProxy(USBDriver* const usbp, const usbep_t ep)
{
if (auto sdup = static_cast<SerialUSBDriver*>(usbp->out_params[ep - 1U]))
{
if (usbGetReceiveTransactionSizeX(sdup->config->usbp, sdup->config->bulk_out) > 0)
{
sduDataReceived(usbp, ep);
}
}
}

/*
* USB endpoints
*/
Expand All @@ -265,7 +281,7 @@ static const USBEndpointConfig ep2config = ///< EP1 initialization structur
USB_EP_MODE_TYPE_BULK,
NULL,
sduDataTransmitted,
sduDataReceived,
sduDataReceivedProxy,
0x0040,
0x0040,
&ep2instate,
Expand Down Expand Up @@ -299,7 +315,7 @@ static void usb_event(USBDriver* usbp, usbevent_t event)
chSysLockFromISR();

/*
* Enables the endpoints specified into the configuration.
* Enables the endpoints specified in the configuration.
* Note, this callback is invoked from an ISR so I-Class functions
* must be used.
*/
Expand Down

0 comments on commit ad6e504

Please sign in to comment.