diff options
Diffstat (limited to 'os/hal/src/serial_usb.c')
-rw-r--r-- | os/hal/src/serial_usb.c | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/os/hal/src/serial_usb.c b/os/hal/src/serial_usb.c index 52be6e975..2b02ae02f 100644 --- a/os/hal/src/serial_usb.c +++ b/os/hal/src/serial_usb.c @@ -120,6 +120,11 @@ static void inotify(GenericQueue *qp) { size_t n, maxsize;
SerialUSBDriver *sdup = chQGetLink(qp);
+ /* If the USB driver is not in the appropriate state then transactions
+ must not be started.*/
+ if (usbGetDriverStateI(sdup->config->usbp) != USB_ACTIVE)
+ return;
+
/* If there is in the queue enough space to hold at least one packet and
a transaction is not yet started then a new transaction is started for
the available space.*/
@@ -145,6 +150,11 @@ static void onotify(GenericQueue *qp) { size_t n;
SerialUSBDriver *sdup = chQGetLink(qp);
+ /* If the USB driver is not in the appropriate state then transactions
+ must not be started.*/
+ if (usbGetDriverStateI(sdup->config->usbp) != USB_ACTIVE)
+ return;
+
/* If there is not an ongoing transaction and the output queue contains
data then a new transaction is started.*/
if (!usbGetTransmitStatusI(sdup->config->usbp, USB_CDC_DATA_REQUEST_EP) &&
@@ -239,6 +249,22 @@ void sduStop(SerialUSBDriver *sdup) { }
/**
+ * @brief USB device configured handler.
+ *
+ * @param[in] usbp pointer to the @p USBDriver object
+ *
+ * @iclass
+ */
+void sduConfigureHookI(USBDriver *usbp) {
+ SerialUSBDriver *sdup = usbp->param;
+
+ sdup->flags = CHN_NO_ERROR;
+ chIQResetI(&sdup->iqueue);
+ chOQResetI(&sdup->oqueue);
+ chnAddFlagsI(sdup, CHN_CONNECTED);
+}
+
+/**
* @brief Default requests hook.
* @details Applications wanting to use the Serial over USB driver can use
* this function as requests hook in the USB configuration.
|