aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--demos/AVR/RT-ARDUINOLEONARDO/usbcfg.c14
-rw-r--r--demos/AVR/RT-PRO_MICRO/usbcfg.c14
-rw-r--r--demos/AVR/RT-TEENSY2-USB/usbcfg.c14
-rw-r--r--demos/STM32/RT-STM32F103-MAPLEMINI/usbcfg.c14
-rw-r--r--demos/STM32/RT-STM32F103-STM3210E_EVAL-FATFS-USB/usbcfg.c14
-rw-r--r--demos/STM32/RT-STM32F103_INEMO_DISCOVERY/usbcfg.c14
-rw-r--r--demos/STM32/RT-STM32F407-OLIMEX_E407-LWIP-FATFS-USB/usbcfg.c14
-rw-r--r--demos/STM32/RT-STM32F429-DISCOVERY/usbcfg.c14
-rw-r--r--demos/STM32/RT-STM32F746G-DISCOVERY-LWIP-FATFS-USB/usbcfg.c14
-rw-r--r--demos/STM32/RT-STM32L053-DISCOVERY/usbcfg.c14
-rw-r--r--os/hal/include/hal_buffers.h56
-rw-r--r--os/hal/include/hal_serial_usb.h3
-rw-r--r--os/hal/src/hal_buffers.c144
-rw-r--r--os/hal/src/hal_serial_usb.c73
-rw-r--r--testex/STM32/STM32F3xx/I2C-LSM303DLHC/usbcfg.c14
-rw-r--r--testex/STM32/STM32F3xx/SPI-L3GD20/usbcfg.c14
-rw-r--r--testex/STM32/STM32F4xx/I2C-LSM303DLHC/usbcfg.c14
-rw-r--r--testex/STM32/STM32F4xx/SPI-L3GD20/usbcfg.c14
-rw-r--r--testex/STM32/STM32F4xx/SPI-LIS302DL/usbcfg.c14
-rw-r--r--testex/STM32/STM32F4xx/SPI-LIS3DSH/usbcfg.c14
-rw-r--r--testhal/STM32/STM32F0xx/USB_CDC/usbcfg.c14
-rw-r--r--testhal/STM32/STM32F1xx/USB_CDC/usbcfg.c14
-rw-r--r--testhal/STM32/STM32F2xx/USB_CDC/usbcfg.c14
-rw-r--r--testhal/STM32/STM32F37x/USB_CDC/usbcfg.c14
-rw-r--r--testhal/STM32/STM32F3xx/USB_CDC/usbcfg.c14
-rw-r--r--testhal/STM32/STM32F3xx/USB_CDC_IAD/usbcfg.c17
-rw-r--r--testhal/STM32/STM32F4xx/USB_CDC/usbcfg.c14
-rw-r--r--testhal/STM32/STM32F4xx/USB_CDC_IAD/usbcfg.c17
-rw-r--r--testhal/STM32/STM32F7xx/USB_CDC/usbcfg.c14
-rw-r--r--testhal/STM32/STM32L4xx/USB_CDC/usbcfg.c14
30 files changed, 428 insertions, 218 deletions
diff --git a/demos/AVR/RT-ARDUINOLEONARDO/usbcfg.c b/demos/AVR/RT-ARDUINOLEONARDO/usbcfg.c
index 09420baf7..3cb7b767e 100644
--- a/demos/AVR/RT-ARDUINOLEONARDO/usbcfg.c
+++ b/demos/AVR/RT-ARDUINOLEONARDO/usbcfg.c
@@ -283,8 +283,6 @@ static void usb_event(USBDriver *usbp, usbevent_t event) {
extern SerialUSBDriver SDU1;
switch (event) {
- case USB_EVENT_RESET:
- return;
case USB_EVENT_ADDRESS:
return;
case USB_EVENT_CONFIGURED:
@@ -302,17 +300,25 @@ static void usb_event(USBDriver *usbp, usbevent_t event) {
chSysUnlockFromISR();
return;
+ case USB_EVENT_RESET:
+ /* Falls into.*/
case USB_EVENT_UNCONFIGURED:
- return;
+ /* Falls into.*/
case USB_EVENT_SUSPEND:
chSysLockFromISR();
/* Disconnection event on suspend.*/
- sduDisconnectI(&SDU1);
+ sduSuspendHookI(&SDU1);
chSysUnlockFromISR();
return;
case USB_EVENT_WAKEUP:
+ chSysLockFromISR();
+
+ /* Disconnection event on suspend.*/
+ sduWakeupHookI(&SDU1);
+
+ chSysUnlockFromISR();
return;
case USB_EVENT_STALLED:
return;
diff --git a/demos/AVR/RT-PRO_MICRO/usbcfg.c b/demos/AVR/RT-PRO_MICRO/usbcfg.c
index 91b0207ab..851c576c4 100644
--- a/demos/AVR/RT-PRO_MICRO/usbcfg.c
+++ b/demos/AVR/RT-PRO_MICRO/usbcfg.c
@@ -282,8 +282,6 @@ static void usb_event(USBDriver *usbp, usbevent_t event) {
extern SerialUSBDriver SDU1;
switch (event) {
- case USB_EVENT_RESET:
- return;
case USB_EVENT_ADDRESS:
return;
case USB_EVENT_CONFIGURED:
@@ -301,17 +299,25 @@ static void usb_event(USBDriver *usbp, usbevent_t event) {
chSysUnlockFromISR();
return;
+ case USB_EVENT_RESET:
+ /* Falls into.*/
case USB_EVENT_UNCONFIGURED:
- return;
+ /* Falls into.*/
case USB_EVENT_SUSPEND:
chSysLockFromISR();
/* Disconnection event on suspend.*/
- sduDisconnectI(&SDU1);
+ sduSuspendHookI(&SDU1);
chSysUnlockFromISR();
return;
case USB_EVENT_WAKEUP:
+ chSysLockFromISR();
+
+ /* Disconnection event on suspend.*/
+ sduWakeupHookI(&SDU1);
+
+ chSysUnlockFromISR();
return;
case USB_EVENT_STALLED:
return;
diff --git a/demos/AVR/RT-TEENSY2-USB/usbcfg.c b/demos/AVR/RT-TEENSY2-USB/usbcfg.c
index 5c20ee7d9..979161ae5 100644
--- a/demos/AVR/RT-TEENSY2-USB/usbcfg.c
+++ b/demos/AVR/RT-TEENSY2-USB/usbcfg.c
@@ -248,8 +248,6 @@ static void usb_event(USBDriver *usbp, usbevent_t event) {
extern SerialUSBDriver SDU1;
switch (event) {
- case USB_EVENT_RESET:
- return;
case USB_EVENT_ADDRESS:
return;
case USB_EVENT_CONFIGURED:
@@ -267,17 +265,25 @@ static void usb_event(USBDriver *usbp, usbevent_t event) {
chSysUnlockFromISR();
return;
+ case USB_EVENT_RESET:
+ /* Falls into.*/
case USB_EVENT_UNCONFIGURED:
- return;
+ /* Falls into.*/
case USB_EVENT_SUSPEND:
chSysLockFromISR();
/* Disconnection event on suspend.*/
- sduDisconnectI(&SDU1);
+ sduSuspendHookI(&SDU1);
chSysUnlockFromISR();
return;
case USB_EVENT_WAKEUP:
+ chSysLockFromISR();
+
+ /* Disconnection event on suspend.*/
+ sduWakeupHookI(&SDU1);
+
+ chSysUnlockFromISR();
return;
case USB_EVENT_STALLED:
return;
diff --git a/demos/STM32/RT-STM32F103-MAPLEMINI/usbcfg.c b/demos/STM32/RT-STM32F103-MAPLEMINI/usbcfg.c
index 949321a59..db05bbd8a 100644
--- a/demos/STM32/RT-STM32F103-MAPLEMINI/usbcfg.c
+++ b/demos/STM32/RT-STM32F103-MAPLEMINI/usbcfg.c
@@ -267,8 +267,6 @@ static void usb_event(USBDriver *usbp, usbevent_t event) {
extern SerialUSBDriver SDU1;
switch (event) {
- case USB_EVENT_RESET:
- return;
case USB_EVENT_ADDRESS:
return;
case USB_EVENT_CONFIGURED:
@@ -285,17 +283,25 @@ static void usb_event(USBDriver *usbp, usbevent_t event) {
chSysUnlockFromISR();
return;
+ case USB_EVENT_RESET:
+ /* Falls into.*/
case USB_EVENT_UNCONFIGURED:
- return;
+ /* Falls into.*/
case USB_EVENT_SUSPEND:
chSysLockFromISR();
/* Disconnection event on suspend.*/
- sduDisconnectI(&SDU1);
+ sduSuspendHookI(&SDU1);
chSysUnlockFromISR();
return;
case USB_EVENT_WAKEUP:
+ chSysLockFromISR();
+
+ /* Disconnection event on suspend.*/
+ sduWakeupHookI(&SDU1);
+
+ chSysUnlockFromISR();
return;
case USB_EVENT_STALLED:
return;
diff --git a/demos/STM32/RT-STM32F103-STM3210E_EVAL-FATFS-USB/usbcfg.c b/demos/STM32/RT-STM32F103-STM3210E_EVAL-FATFS-USB/usbcfg.c
index 949321a59..db05bbd8a 100644
--- a/demos/STM32/RT-STM32F103-STM3210E_EVAL-FATFS-USB/usbcfg.c
+++ b/demos/STM32/RT-STM32F103-STM3210E_EVAL-FATFS-USB/usbcfg.c
@@ -267,8 +267,6 @@ static void usb_event(USBDriver *usbp, usbevent_t event) {
extern SerialUSBDriver SDU1;
switch (event) {
- case USB_EVENT_RESET:
- return;
case USB_EVENT_ADDRESS:
return;
case USB_EVENT_CONFIGURED:
@@ -285,17 +283,25 @@ static void usb_event(USBDriver *usbp, usbevent_t event) {
chSysUnlockFromISR();
return;
+ case USB_EVENT_RESET:
+ /* Falls into.*/
case USB_EVENT_UNCONFIGURED:
- return;
+ /* Falls into.*/
case USB_EVENT_SUSPEND:
chSysLockFromISR();
/* Disconnection event on suspend.*/
- sduDisconnectI(&SDU1);
+ sduSuspendHookI(&SDU1);
chSysUnlockFromISR();
return;
case USB_EVENT_WAKEUP:
+ chSysLockFromISR();
+
+ /* Disconnection event on suspend.*/
+ sduWakeupHookI(&SDU1);
+
+ chSysUnlockFromISR();
return;
case USB_EVENT_STALLED:
return;
diff --git a/demos/STM32/RT-STM32F103_INEMO_DISCOVERY/usbcfg.c b/demos/STM32/RT-STM32F103_INEMO_DISCOVERY/usbcfg.c
index 949321a59..db05bbd8a 100644
--- a/demos/STM32/RT-STM32F103_INEMO_DISCOVERY/usbcfg.c
+++ b/demos/STM32/RT-STM32F103_INEMO_DISCOVERY/usbcfg.c
@@ -267,8 +267,6 @@ static void usb_event(USBDriver *usbp, usbevent_t event) {
extern SerialUSBDriver SDU1;
switch (event) {
- case USB_EVENT_RESET:
- return;
case USB_EVENT_ADDRESS:
return;
case USB_EVENT_CONFIGURED:
@@ -285,17 +283,25 @@ static void usb_event(USBDriver *usbp, usbevent_t event) {
chSysUnlockFromISR();
return;
+ case USB_EVENT_RESET:
+ /* Falls into.*/
case USB_EVENT_UNCONFIGURED:
- return;
+ /* Falls into.*/
case USB_EVENT_SUSPEND:
chSysLockFromISR();
/* Disconnection event on suspend.*/
- sduDisconnectI(&SDU1);
+ sduSuspendHookI(&SDU1);
chSysUnlockFromISR();
return;
case USB_EVENT_WAKEUP:
+ chSysLockFromISR();
+
+ /* Disconnection event on suspend.*/
+ sduWakeupHookI(&SDU1);
+
+ chSysUnlockFromISR();
return;
case USB_EVENT_STALLED:
return;
diff --git a/demos/STM32/RT-STM32F407-OLIMEX_E407-LWIP-FATFS-USB/usbcfg.c b/demos/STM32/RT-STM32F407-OLIMEX_E407-LWIP-FATFS-USB/usbcfg.c
index 949321a59..db05bbd8a 100644
--- a/demos/STM32/RT-STM32F407-OLIMEX_E407-LWIP-FATFS-USB/usbcfg.c
+++ b/demos/STM32/RT-STM32F407-OLIMEX_E407-LWIP-FATFS-USB/usbcfg.c
@@ -267,8 +267,6 @@ static void usb_event(USBDriver *usbp, usbevent_t event) {
extern SerialUSBDriver SDU1;
switch (event) {
- case USB_EVENT_RESET:
- return;
case USB_EVENT_ADDRESS:
return;
case USB_EVENT_CONFIGURED:
@@ -285,17 +283,25 @@ static void usb_event(USBDriver *usbp, usbevent_t event) {
chSysUnlockFromISR();
return;
+ case USB_EVENT_RESET:
+ /* Falls into.*/
case USB_EVENT_UNCONFIGURED:
- return;
+ /* Falls into.*/
case USB_EVENT_SUSPEND:
chSysLockFromISR();
/* Disconnection event on suspend.*/
- sduDisconnectI(&SDU1);
+ sduSuspendHookI(&SDU1);
chSysUnlockFromISR();
return;
case USB_EVENT_WAKEUP:
+ chSysLockFromISR();
+
+ /* Disconnection event on suspend.*/
+ sduWakeupHookI(&SDU1);
+
+ chSysUnlockFromISR();
return;
case USB_EVENT_STALLED:
return;
diff --git a/demos/STM32/RT-STM32F429-DISCOVERY/usbcfg.c b/demos/STM32/RT-STM32F429-DISCOVERY/usbcfg.c
index 26ec6df67..5121b03aa 100644
--- a/demos/STM32/RT-STM32F429-DISCOVERY/usbcfg.c
+++ b/demos/STM32/RT-STM32F429-DISCOVERY/usbcfg.c
@@ -267,8 +267,6 @@ static void usb_event(USBDriver *usbp, usbevent_t event) {
extern SerialUSBDriver SDU1;
switch (event) {
- case USB_EVENT_RESET:
- return;
case USB_EVENT_ADDRESS:
return;
case USB_EVENT_CONFIGURED:
@@ -285,17 +283,25 @@ static void usb_event(USBDriver *usbp, usbevent_t event) {
chSysUnlockFromISR();
return;
+ case USB_EVENT_RESET:
+ /* Falls into.*/
case USB_EVENT_UNCONFIGURED:
- return;
+ /* Falls into.*/
case USB_EVENT_SUSPEND:
chSysLockFromISR();
/* Disconnection event on suspend.*/
- sduDisconnectI(&SDU1);
+ sduSuspendHookI(&SDU1);
chSysUnlockFromISR();
return;
case USB_EVENT_WAKEUP:
+ chSysLockFromISR();
+
+ /* Disconnection event on suspend.*/
+ sduWakeupHookI(&SDU1);
+
+ chSysUnlockFromISR();
return;
case USB_EVENT_STALLED:
return;
diff --git a/demos/STM32/RT-STM32F746G-DISCOVERY-LWIP-FATFS-USB/usbcfg.c b/demos/STM32/RT-STM32F746G-DISCOVERY-LWIP-FATFS-USB/usbcfg.c
index e0c0d853b..bb05f43c8 100644
--- a/demos/STM32/RT-STM32F746G-DISCOVERY-LWIP-FATFS-USB/usbcfg.c
+++ b/demos/STM32/RT-STM32F746G-DISCOVERY-LWIP-FATFS-USB/usbcfg.c
@@ -267,8 +267,6 @@ static void usb_event(USBDriver *usbp, usbevent_t event) {
extern SerialUSBDriver SDU2;
switch (event) {
- case USB_EVENT_RESET:
- return;
case USB_EVENT_ADDRESS:
return;
case USB_EVENT_CONFIGURED:
@@ -285,17 +283,25 @@ static void usb_event(USBDriver *usbp, usbevent_t event) {
chSysUnlockFromISR();
return;
+ case USB_EVENT_RESET:
+ /* Falls into.*/
case USB_EVENT_UNCONFIGURED:
- return;
+ /* Falls into.*/
case USB_EVENT_SUSPEND:
chSysLockFromISR();
/* Disconnection event on suspend.*/
- sduDisconnectI(&SDU2);
+ sduSuspendHookI(&SDU2);
chSysUnlockFromISR();
return;
case USB_EVENT_WAKEUP:
+ chSysLockFromISR();
+
+ /* Disconnection event on suspend.*/
+ sduWakeupHookI(&SDU2);
+
+ chSysUnlockFromISR();
return;
case USB_EVENT_STALLED:
return;
diff --git a/demos/STM32/RT-STM32L053-DISCOVERY/usbcfg.c b/demos/STM32/RT-STM32L053-DISCOVERY/usbcfg.c
index 949321a59..db05bbd8a 100644
--- a/demos/STM32/RT-STM32L053-DISCOVERY/usbcfg.c
+++ b/demos/STM32/RT-STM32L053-DISCOVERY/usbcfg.c
@@ -267,8 +267,6 @@ static void usb_event(USBDriver *usbp, usbevent_t event) {
extern SerialUSBDriver SDU1;
switch (event) {
- case USB_EVENT_RESET:
- return;
case USB_EVENT_ADDRESS:
return;
case USB_EVENT_CONFIGURED:
@@ -285,17 +283,25 @@ static void usb_event(USBDriver *usbp, usbevent_t event) {
chSysUnlockFromISR();
return;
+ case USB_EVENT_RESET:
+ /* Falls into.*/
case USB_EVENT_UNCONFIGURED:
- return;
+ /* Falls into.*/
case USB_EVENT_SUSPEND:
chSysLockFromISR();
/* Disconnection event on suspend.*/
- sduDisconnectI(&SDU1);
+ sduSuspendHookI(&SDU1);
chSysUnlockFromISR();
return;
case USB_EVENT_WAKEUP:
+ chSysLockFromISR();
+
+ /* Disconnection event on suspend.*/
+ sduWakeupHookI(&SDU1);
+
+ chSysUnlockFromISR();
return;
case USB_EVENT_STALLED:
return;
diff --git a/os/hal/include/hal_buffers.h b/os/hal/include/hal_buffers.h
index 21835b260..7d776f4a7 100644
--- a/os/hal/include/hal_buffers.h
+++ b/os/hal/include/hal_buffers.h
@@ -62,6 +62,10 @@ struct io_buffers_queue {
*/
threads_queue_t waiting;
/**
+ * @brief Queue suspended state flag.
+ */
+ bool suspended;
+ /**
* @brief Active buffers counter.
*/
volatile size_t bcounter;
@@ -171,6 +175,48 @@ typedef io_buffers_queue_t output_buffers_queue_t;
#define bqGetLinkX(bqp) ((bqp)->link)
/**
+ * @brief Return the suspended state of the queue.
+ *
+ * @param[in] bqp pointer to an @p io_buffers_queue_t structure
+ * @return The suspended state.
+ * @retval false if blocking access to the queue is enabled.
+ * @retval true if blocking access to the queue is suspended.
+ *
+ * @xclass
+ */
+#define bqIsSuspendedX(bqp) ((bqp)->suspended)
+
+/**
+ * @brief Puts the queue in suspended state.
+ * @details When the queue is put in suspended state all waiting threads are
+ * woken with message @p MSG_RESET and subsequent attempt at waiting
+ * on the queue will result in an immediate return with @p MSG_RESET
+ * message.
+ * @note The content of the queue is not altered, queues can be accessed
+ * is suspended state until a blocking operation is met then a
+ * @p MSG_RESET occurs.
+ *
+ * @param[in] bqp pointer to an @p io_buffers_queue_t structure
+ *
+ * @iclass
+ */
+#define bqSuspendI(bqp) { \
+ (bqp)->suspended = true; \
+ osalThreadDequeueAllI(&(bqp)->waiting, MSG_RESET); \
+}
+
+/**
+ * @brief Resumes normal queue operations.
+ *
+ * @param[in] bqp pointer to an @p io_buffers_queue_t structure
+ *
+ * @xclass
+ */
+#define bqResumeX(bqp) { \
+ (bqp)->suspended = false; \
+}
+
+/**
* @brief Evaluates to @p TRUE if the specified input buffers queue is empty.
*
* @param[in] ibqp pointer to an @p input_buffers_queue_t structure
@@ -232,9 +278,8 @@ typedef io_buffers_queue_t output_buffers_queue_t;
#ifdef __cplusplus
extern "C" {
#endif
- void ibqObjectInit(input_buffers_queue_t *ibqp, uint8_t *bp,
- size_t size, size_t n,
- bqnotify_t infy, void *link);
+ void ibqObjectInit(input_buffers_queue_t *ibqp, bool suspended, uint8_t *bp,
+ size_t size, size_t n, bqnotify_t infy, void *link);
void ibqResetI(input_buffers_queue_t *ibqp);
uint8_t *ibqGetEmptyBufferI(input_buffers_queue_t *ibqp);
void ibqPostFullBufferI(input_buffers_queue_t *ibqp, size_t size);
@@ -247,9 +292,8 @@ extern "C" {
msg_t ibqGetTimeout(input_buffers_queue_t *ibqp, systime_t timeout);
size_t ibqReadTimeout(input_buffers_queue_t *ibqp, uint8_t *bp,
size_t n, systime_t timeout);
- void obqObjectInit(output_buffers_queue_t *obqp, uint8_t *bp,
- size_t size, size_t n,
- bqnotify_t onfy, void *link);
+ void obqObjectInit(output_buffers_queue_t *obqp, bool suspended, uint8_t *bp,
+ size_t size, size_t n, bqnotify_t onfy, void *link);
void obqResetI(output_buffers_queue_t *obqp);
uint8_t *obqGetFullBufferI(output_buffers_queue_t *obqp,
size_t *sizep);
diff --git a/os/hal/include/hal_serial_usb.h b/os/hal/include/hal_serial_usb.h
index d0d3c6cd2..9d3e016b8 100644
--- a/os/hal/include/hal_serial_usb.h
+++ b/os/hal/include/hal_serial_usb.h
@@ -177,7 +177,8 @@ extern "C" {
void sduObjectInit(SerialUSBDriver *sdup);
void sduStart(SerialUSBDriver *sdup, const SerialUSBConfig *config);
void sduStop(SerialUSBDriver *sdup);
- void sduDisconnectI(SerialUSBDriver *sdup);
+ void sduSuspendHookI(SerialUSBDriver *sdup);
+ void sduWakeupHookI(SerialUSBDriver *sdup);
void sduConfigureHookI(SerialUSBDriver *sdup);
bool sduRequestsHook(USBDriver *usbp);
void sduSOFHookI(SerialUSBDriver *sdup);
diff --git a/os/hal/src/hal_buffers.c b/os/hal/src/hal_buffers.c
index 9cccbfd02..b56f79b60 100644
--- a/os/hal/src/hal_buffers.c
+++ b/os/hal/src/hal_buffers.c
@@ -64,6 +64,7 @@
* @brief Initializes an input buffers queue object.
*
* @param[out] ibqp pointer to the @p input_buffers_queue_t object
+ * @param[in] suspended initial state of the queue
* @param[in] bp pointer to a memory area allocated for buffers
* @param[in] size buffers size
* @param[in] n number of buffers
@@ -72,24 +73,24 @@
*
* @init
*/
-void ibqObjectInit(input_buffers_queue_t *ibqp, uint8_t *bp,
- size_t size, size_t n,
- bqnotify_t infy, void *link) {
+void ibqObjectInit(input_buffers_queue_t *ibqp, bool suspended, uint8_t *bp,
+ size_t size, size_t n, bqnotify_t infy, void *link) {
osalDbgCheck((ibqp != NULL) && (bp != NULL) && (size >= 2U));
osalThreadQueueObjectInit(&ibqp->waiting);
- ibqp->bcounter = 0;
- ibqp->brdptr = bp;
- ibqp->bwrptr = bp;
- ibqp->btop = bp + ((size + sizeof (size_t)) * n);
- ibqp->bsize = size + sizeof (size_t);
- ibqp->bn = n;
- ibqp->buffers = bp;
- ibqp->ptr = NULL;
- ibqp->top = NULL;
- ibqp->notify = infy;
- ibqp->link = link;
+ ibqp->suspended = suspended;
+ ibqp->bcounter = 0;
+ ibqp->brdptr = bp;
+ ibqp->bwrptr = bp;
+ ibqp->btop = bp + ((size + sizeof (size_t)) * n);
+ ibqp->bsize = size + sizeof (size_t);
+ ibqp->bn = n;
+ ibqp->buffers = bp;
+ ibqp->ptr = NULL;
+ ibqp->top = NULL;
+ ibqp->notify = infy;
+ ibqp->link = link;
}
/**
@@ -107,11 +108,11 @@ void ibqResetI(input_buffers_queue_t *ibqp) {
osalDbgCheckClassI();
- ibqp->bcounter = 0;
- ibqp->brdptr = ibqp->buffers;
- ibqp->bwrptr = ibqp->buffers;
- ibqp->ptr = NULL;
- ibqp->top = NULL;
+ ibqp->bcounter = 0;
+ ibqp->brdptr = ibqp->buffers;
+ ibqp->bwrptr = ibqp->buffers;
+ ibqp->ptr = NULL;
+ ibqp->top = NULL;
osalThreadDequeueAllI(&ibqp->waiting, MSG_RESET);
}
@@ -181,7 +182,8 @@ void ibqPostFullBufferI(input_buffers_queue_t *ibqp, size_t size) {
* @return The operation status.
* @retval MSG_OK if a buffer has been acquired.
* @retval MSG_TIMEOUT if the specified time expired.
- * @retval MSG_RESET if the queue has been reset.
+ * @retval MSG_RESET if the queue has been reset or has been put in
+ * suspended state.
*
* @api
*/
@@ -212,7 +214,8 @@ msg_t ibqGetFullBufferTimeout(input_buffers_queue_t *ibqp,
* @return The operation status.
* @retval MSG_OK if a buffer has been acquired.
* @retval MSG_TIMEOUT if the specified time expired.
- * @retval MSG_RESET if the queue has been reset.
+ * @retval MSG_RESET if the queue has been reset or has been put in
+ * suspended state.
*
* @sclass
*/
@@ -222,6 +225,9 @@ msg_t ibqGetFullBufferTimeout(input_buffers_queue_t *ibqp,
osalDbgCheckClassS();
while (ibqIsEmptyI(ibqp)) {
+ if (ibqp->suspended) {
+ return MSG_RESET;
+ }
msg_t msg = osalThreadEnqueueTimeoutS(&ibqp->waiting, timeout);
if (msg < MSG_OK) {
return msg;
@@ -295,7 +301,8 @@ void ibqReleaseEmptyBuffer(input_buffers_queue_t *ibqp) {
* .
* @return A byte value from the queue.
* @retval MSG_TIMEOUT if the specified time expired.
- * @retval MSG_RESET if the queue has been reset.
+ * @retval MSG_RESET if the queue has been reset or has been put in
+ * suspended state.
*
* @api
*/
@@ -432,6 +439,7 @@ size_t ibqReadTimeout(input_buffers_queue_t *ibqp, uint8_t *bp,
* @brief Initializes an output buffers queue object.
*
* @param[out] obqp pointer to the @p output_buffers_queue_t object
+ * @param[in] suspended initial state of the queue
* @param[in] bp pointer to a memory area allocated for buffers
* @param[in] size buffers size
* @param[in] n number of buffers
@@ -440,24 +448,24 @@ size_t ibqReadTimeout(input_buffers_queue_t *ibqp, uint8_t *bp,
*
* @init
*/
-void obqObjectInit(output_buffers_queue_t *obqp, uint8_t *bp,
- size_t size, size_t n,
- bqnotify_t onfy, void *link) {
+void obqObjectInit(output_buffers_queue_t *obqp, bool suspended, uint8_t *bp,
+ size_t size, size_t n, bqnotify_t onfy, void *link) {
osalDbgCheck((obqp != NULL) && (bp != NULL) && (size >= 2U));
osalThreadQueueObjectInit(&obqp->waiting);
- obqp->bcounter = n;
- obqp->brdptr = bp;
- obqp->bwrptr = bp;
- obqp->btop = bp + ((size + sizeof (size_t)) * n);
- obqp->bsize = size + sizeof (size_t);
- obqp->bn = n;
- obqp->buffers = bp;
- obqp->ptr = NULL;
- obqp->top = NULL;
- obqp->notify = onfy;
- obqp->link = link;
+ obqp->suspended = suspended;
+ obqp->bcounter = n;
+ obqp->brdptr = bp;
+ obqp->bwrptr = bp;
+ obqp->btop = bp + ((size + sizeof (size_t)) * n);
+ obqp->bsize = size + sizeof (size_t);
+ obqp->bn = n;
+ obqp->buffers = bp;
+ obqp->ptr = NULL;
+ obqp->top = NULL;
+ obqp->notify = onfy;
+ obqp->link = link;
}
/**
@@ -475,11 +483,11 @@ void obqResetI(output_buffers_queue_t *obqp) {
osalDbgCheckClassI();
- obqp->bcounter = bqSizeX(obqp);
- obqp->brdptr = obqp->buffers;
- obqp->bwrptr = obqp->buffers;
- obqp->ptr = NULL;
- obqp->top = NULL;
+ obqp->bcounter = bqSizeX(obqp);
+ obqp->brdptr = obqp->buffers;
+ obqp->bwrptr = obqp->buffers;
+ obqp->ptr = NULL;
+ obqp->top = NULL;
osalThreadDequeueAllI(&obqp->waiting, MSG_RESET);
}
@@ -548,7 +556,8 @@ void obqReleaseEmptyBufferI(output_buffers_queue_t *obqp) {
* @return The operation status.
* @retval MSG_OK if a buffer has been acquired.
* @retval MSG_TIMEOUT if the specified time expired.
- * @retval MSG_RESET if the queue has been reset.
+ * @retval MSG_RESET if the queue has been reset or has been put in
+ * suspended state.
*
* @api
*/
@@ -563,32 +572,36 @@ msg_t obqGetEmptyBufferTimeout(output_buffers_queue_t *obqp,
return msg;
}
- /**
- * @brief Gets the next empty buffer from the queue.
- * @note The function always acquires the same buffer if called repeatedly.
- * @post After calling the function the fields @p ptr and @p top are set
- * at beginning and end of the buffer data or @p NULL if the queue
- * is empty.
- *
- * @param[in] obqp pointer to the @p output_buffers_queue_t object
- * @param[in] timeout the number of ticks before the operation timeouts,
- * the following special values are allowed:
- * - @a TIME_IMMEDIATE immediate timeout.
- * - @a TIME_INFINITE no timeout.
- * .
- * @return The operation status.
- * @retval MSG_OK if a buffer has been acquired.
- * @retval MSG_TIMEOUT if the specified time expired.
- * @retval MSG_RESET if the queue has been reset.
- *
- * @sclass
- */
- msg_t obqGetEmptyBufferTimeoutS(output_buffers_queue_t *obqp,
- systime_t timeout) {
+/**
+ * @brief Gets the next empty buffer from the queue.
+ * @note The function always acquires the same buffer if called repeatedly.
+ * @post After calling the function the fields @p ptr and @p top are set
+ * at beginning and end of the buffer data or @p NULL if the queue
+ * is empty.
+ *
+ * @param[in] obqp pointer to the @p output_buffers_queue_t object
+ * @param[in] timeout the number of ticks before the operation timeouts,
+ * the following special values are allowed:
+ * - @a TIME_IMMEDIATE immediate timeout.
+ * - @a TIME_INFINITE no timeout.
+ * .
+ * @return The operation status.
+ * @retval MSG_OK if a buffer has been acquired.
+ * @retval MSG_TIMEOUT if the specified time expired.
+ * @retval MSG_RESET if the queue has been reset or has been put in
+ * suspended state.
+ *
+ * @sclass
+ */
+msg_t obqGetEmptyBufferTimeoutS(output_buffers_queue_t *obqp,
+ systime_t timeout) {
osalDbgCheckClassS();
while (obqIsFullI(obqp)) {
+ if (obqp->suspended) {
+ return MSG_RESET;
+ }
msg_t msg = osalThreadEnqueueTimeoutS(&obqp->waiting, timeout);
if (msg < MSG_OK) {
return msg;
@@ -669,7 +682,8 @@ void obqPostFullBufferS(output_buffers_queue_t *obqp, size_t size) {
* .
* @return A byte value from the queue.
* @retval MSG_TIMEOUT if the specified time expired.
- * @retval MSG_RESET if the queue has been reset.
+ * @retval MSG_RESET if the queue has been reset or has been put in
+ * suspended state.
*
* @api
*/
diff --git a/os/hal/src/hal_serial_usb.c b/os/hal/src/hal_serial_usb.c
index 480e4da4f..70f3c9179 100644
--- a/os/hal/src/hal_serial_usb.c
+++ b/os/hal/src/hal_serial_usb.c
@@ -84,75 +84,43 @@ static bool sdu_start_receive(SerialUSBDriver *sdup) {
static size_t write(void *ip, const uint8_t *bp, size_t n) {
- if (usbGetDriverStateI(((SerialUSBDriver *)ip)->config->usbp) != USB_ACTIVE) {
- return 0;
- }
-
return obqWriteTimeout(&((SerialUSBDriver *)ip)->obqueue, bp,
n, TIME_INFINITE);
}
static size_t read(void *ip, uint8_t *bp, size_t n) {
- if (usbGetDriverStateI(((SerialUSBDriver *)ip)->config->usbp) != USB_ACTIVE) {
- return 0;
- }
-
return ibqReadTimeout(&((SerialUSBDriver *)ip)->ibqueue, bp,
n, TIME_INFINITE);
}
static msg_t put(void *ip, uint8_t b) {
- if (usbGetDriverStateI(((SerialUSBDriver *)ip)->config->usbp) != USB_ACTIVE) {
- return MSG_RESET;
- }
-
return obqPutTimeout(&((SerialUSBDriver *)ip)->obqueue, b, TIME_INFINITE);
}
static msg_t get(void *ip) {
- if (usbGetDriverStateI(((SerialUSBDriver *)ip)->config->usbp) != USB_ACTIVE) {
- return MSG_RESET;
- }
-
return ibqGetTimeout(&((SerialUSBDriver *)ip)->ibqueue, TIME_INFINITE);
}
static msg_t putt(void *ip, uint8_t b, systime_t timeout) {
- if (usbGetDriverStateI(((SerialUSBDriver *)ip)->config->usbp) != USB_ACTIVE) {
- return MSG_RESET;
- }
-
return obqPutTimeout(&((SerialUSBDriver *)ip)->obqueue, b, timeout);
}
static msg_t gett(void *ip, systime_t timeout) {
- if (usbGetDriverStateI(((SerialUSBDriver *)ip)->config->usbp) != USB_ACTIVE) {
- return MSG_RESET;
- }
-
return ibqGetTimeout(&((SerialUSBDriver *)ip)->ibqueue, timeout);
}
static size_t writet(void *ip, const uint8_t *bp, size_t n, systime_t timeout) {
- if (usbGetDriverStateI(((SerialUSBDriver *)ip)->config->usbp) != USB_ACTIVE) {
- return 0;
- }
-
return obqWriteTimeout(&((SerialUSBDriver *)ip)->obqueue, bp, n, timeout);
}
static size_t readt(void *ip, uint8_t *bp, size_t n, systime_t timeout) {
- if (usbGetDriverStateI(((SerialUSBDriver *)ip)->config->usbp) != USB_ACTIVE) {
- return 0;
- }
-
return ibqReadTimeout(&((SerialUSBDriver *)ip)->ibqueue, bp, n, timeout);
}
@@ -226,10 +194,10 @@ void sduObjectInit(SerialUSBDriver *sdup) {
sdup->vmt = &vmt;
osalEventObjectInit(&sdup->event);
sdup->state = SDU_STOP;
- ibqObjectInit(&sdup->ibqueue, sdup->ib,
+ ibqObjectInit(&sdup->ibqueue, true, sdup->ib,
SERIAL_USB_BUFFERS_SIZE, SERIAL_USB_BUFFERS_NUMBER,
ibnotify, sdup);
- obqObjectInit(&sdup->obqueue, sdup->ob,
+ obqObjectInit(&sdup->obqueue, true, sdup->ob,
SERIAL_USB_BUFFERS_SIZE, SERIAL_USB_BUFFERS_NUMBER,
obnotify, sdup);
}
@@ -289,14 +257,19 @@ void sduStop(SerialUSBDriver *sdup) {
sdup->state = SDU_STOP;
/* Enforces a disconnection.*/
- sduDisconnectI(sdup);
+ chnAddFlagsI(sdup, CHN_DISCONNECTED);
+ ibqResetI(&sdup->ibqueue);
+ obqResetI(&sdup->obqueue);
osalOsRescheduleS();
osalSysUnlock();
}
/**
- * @brief USB device disconnection handler.
+ * @brief USB device suspend handler.
+ * @details Generates a @p CHN_DISCONNECT event and puts queues in
+ * non-blocking mode, this way the application cannot get stuck
+ * in the middle of an I/O operations.
* @note If this function is not called from an ISR then an explicit call
* to @p osalOsRescheduleS() in necessary afterward.
*
@@ -304,12 +277,30 @@ void sduStop(SerialUSBDriver *sdup) {
*
* @iclass
*/
-void sduDisconnectI(SerialUSBDriver *sdup) {
+void sduSuspendHookI(SerialUSBDriver *sdup) {
- /* Queues reset in order to signal the driver stop to the application.*/
chnAddFlagsI(sdup, CHN_DISCONNECTED);
- ibqResetI(&sdup->ibqueue);
- obqResetI(&sdup->obqueue);
+ bqSuspendI(&sdup->ibqueue);
+ bqSuspendI(&sdup->obqueue);
+}
+
+/**
+ * @brief USB device wakeup handler.
+ * @details Generates a @p CHN_CONNECT event and resumes normal queues
+ * operations.
+ *
+ * @note If this function is not called from an ISR then an explicit call
+ * to @p osalOsRescheduleS() in necessary afterward.
+ *
+ * @param[in] sdup pointer to a @p SerialUSBDriver object
+ *
+ * @iclass
+ */
+void sduWakeupHookI(SerialUSBDriver *sdup) {
+
+ chnAddFlagsI(sdup, CHN_CONNECTED);
+ bqResumeX(&sdup->ibqueue);
+ bqResumeX(&sdup->obqueue);
}
/**
@@ -322,7 +313,9 @@ void sduDisconnectI(SerialUSBDriver *sdup) {
void sduConfigureHookI(SerialUSBDriver *sdup) {
ibqResetI(&sdup->ibqueue);
+ bqResumeX(&sdup->ibqueue);
obqResetI(&sdup->obqueue);
+ bqResumeX(&sdup->obqueue);
chnAddFlagsI(sdup, CHN_CONNECTED);
(void) sdu_start_receive(sdup);
}
diff --git a/testex/STM32/STM32F3xx/I2C-LSM303DLHC/usbcfg.c b/testex/STM32/STM32F3xx/I2C-LSM303DLHC/usbcfg.c
index 949321a59..db05bbd8a 100644
--- a/testex/STM32/STM32F3xx/I2C-LSM303DLHC/usbcfg.c
+++ b/testex/STM32/STM32F3xx/I2C-LSM303DLHC/usbcfg.c
@@ -267,8 +267,6 @@ static void usb_event(USBDriver *usbp, usbevent_t event) {
extern SerialUSBDriver SDU1;
switch (event) {
- case USB_EVENT_RESET:
- return;
case USB_EVENT_ADDRESS:
return;
case USB_EVENT_CONFIGURED:
@@ -285,17 +283,25 @@ static void usb_event(USBDriver *usbp, usbevent_t event) {
chSysUnlockFromISR();
return;
+ case USB_EVENT_RESET:
+ /* Falls into.*/
case USB_EVENT_UNCONFIGURED:
- return;
+ /* Falls into.*/
case USB_EVENT_SUSPEND:
chSysLockFromISR();
/* Disconnection event on suspend.*/
- sduDisconnectI(&SDU1);
+ sduSuspendHookI(&SDU1);
chSysUnlockFromISR();
return;
case USB_EVENT_WAKEUP:
+ chSysLockFromISR();
+
+ /* Disconnection event on suspend.*/
+ sduWakeupHookI(&SDU1);
+
+ chSysUnlockFromISR();
return;
case USB_EVENT_STALLED:
return;
diff --git a/testex/STM32/STM32F3xx/SPI-L3GD20/usbcfg.c b/testex/STM32/STM32F3xx/SPI-L3GD20/usbcfg.c
index 949321a59..db05bbd8a 100644
--- a/testex/STM32/STM32F3xx/SPI-L3GD20/usbcfg.c
+++ b/testex/STM32/STM32F3xx/SPI-L3GD20/usbcfg.c
@@ -267,8 +267,6 @@ static void usb_event(USBDriver *usbp, usbevent_t event) {
extern SerialUSBDriver SDU1;
switch (event) {
- case USB_EVENT_RESET:
- return;
case USB_EVENT_ADDRESS:
return;
case USB_EVENT_CONFIGURED:
@@ -285,17 +283,25 @@ static void usb_event(USBDriver *usbp, usbevent_t event) {
chSysUnlockFromISR();
return;
+ case USB_EVENT_RESET:
+ /* Falls into.*/
case USB_EVENT_UNCONFIGURED:
- return;
+ /* Falls into.*/
case USB_EVENT_SUSPEND:
chSysLockFromISR();
/* Disconnection event on suspend.*/
- sduDisconnectI(&SDU1);
+ sduSuspendHookI(&SDU1);
chSysUnlockFromISR();
return;
case USB_EVENT_WAKEUP:
+ chSysLockFromISR();
+
+ /* Disconnection event on suspend.*/
+ sduWakeupHookI(&SDU1);
+
+ chSysUnlockFromISR();
return;
case USB_EVENT_STALLED:
return;
diff --git a/testex/STM32/STM32F4xx/I2C-LSM303DLHC/usbcfg.c b/testex/STM32/STM32F4xx/I2C-LSM303DLHC/usbcfg.c
index 949321a59..db05bbd8a 100644
--- a/testex/STM32/STM32F4xx/I2C-LSM303DLHC/usbcfg.c
+++ b/testex/STM32/STM32F4xx/I2C-LSM303DLHC/usbcfg.c
@@ -267,8 +267,6 @@ static void usb_event(USBDriver *usbp, usbevent_t event) {
extern SerialUSBDriver SDU1;
switch (event) {
- case USB_EVENT_RESET:
- return;
case USB_EVENT_ADDRESS:
return;
case USB_EVENT_CONFIGURED:
@@ -285,17 +283,25 @@ static void usb_event(USBDriver *usbp, usbevent_t event) {
chSysUnlockFromISR();
return;
+ case USB_EVENT_RESET:
+ /* Falls into.*/
case USB_EVENT_UNCONFIGURED:
- return;
+ /* Falls into.*/
case USB_EVENT_SUSPEND:
chSysLockFromISR();
/* Disconnection event on suspend.*/
- sduDisconnectI(&SDU1);
+ sduSuspendHookI(&SDU1);
chSysUnlockFromISR();
return;
case USB_EVENT_WAKEUP:
+ chSysLockFromISR();
+
+ /* Disconnection event on suspend.*/
+ sduWakeupHookI(&SDU1);
+
+ chSysUnlockFromISR();
return;
case USB_EVENT_STALLED:
return;
diff --git a/testex/STM32/STM32F4xx/SPI-L3GD20/usbcfg.c b/testex/STM32/STM32F4xx/SPI-L3GD20/usbcfg.c
index 949321a59..db05bbd8a 100644
--- a/testex/STM32/STM32F4xx/SPI-L3GD20/usbcfg.c
+++ b/testex/STM32/STM32F4xx/SPI-L3GD20/usbcfg.c
@@ -267,8 +267,6 @@ static void usb_event(USBDriver *usbp, usbevent_t event) {
extern SerialUSBDriver SDU1;
switch (event) {
- case USB_EVENT_RESET:
- return;
case USB_EVENT_ADDRESS:
return;
case USB_EVENT_CONFIGURED:
@@ -285,17 +283,25 @@ static void usb_event(USBDriver *usbp, usbevent_t event) {
chSysUnlockFromISR();
return;
+ case USB_EVENT_RESET:
+ /* Falls into.*/
case USB_EVENT_UNCONFIGURED:
- return;
+ /* Falls into.*/
case USB_EVENT_SUSPEND:
chSysLockFromISR();
/* Disconnection event on suspend.*/
- sduDisconnectI(&SDU1);
+ sduSuspendHookI(&SDU1);
chSysUnlockFromISR();
return;
case USB_EVENT_WAKEUP:
+ chSysLockFromISR();
+
+ /* Disconnection event on suspend.*/
+ sduWakeupHookI(&SDU1);
+
+ chSysUnlockFromISR();
return;
case USB_EVENT_STALLED:
return;
diff --git a/testex/STM32/STM32F4xx/SPI-LIS302DL/usbcfg.c b/testex/STM32/STM32F4xx/SPI-LIS302DL/usbcfg.c
index 949321a59..db05bbd8a 100644
--- a/testex/STM32/STM32F4xx/SPI-LIS302DL/usbcfg.c
+++ b/testex/STM32/STM32F4xx/SPI-LIS302DL/usbcfg.c
@@ -267,8 +267,6 @@ static void usb_event(USBDriver *usbp, usbevent_t event) {
extern SerialUSBDriver SDU1;
switch (event) {
- case USB_EVENT_RESET:
- return;
case USB_EVENT_ADDRESS:
return;
case USB_EVENT_CONFIGURED:
@@ -285,17 +283,25 @@ static void usb_event(USBDriver *usbp, usbevent_t event) {
chSysUnlockFromISR();
return;
+ case USB_EVENT_RESET:
+ /* Falls into.*/
case USB_EVENT_UNCONFIGURED:
- return;
+ /* Falls into.*/
case USB_EVENT_SUSPEND:
chSysLockFromISR();
/* Disconnection event on suspend.*/
- sduDisconnectI(&SDU1);
+ sduSuspendHookI(&SDU1);
chSysUnlockFromISR();
return;
case USB_EVENT_WAKEUP:
+ chSysLockFromISR();
+
+ /* Disconnection event on suspend.*/
+ sduWakeupHookI(&SDU1);
+
+ chSysUnlockFromISR();
return;
case USB_EVENT_STALLED:
return;
diff --git a/testex/STM32/STM32F4xx/SPI-LIS3DSH/usbcfg.c b/testex/STM32/STM32F4xx/SPI-LIS3DSH/usbcfg.c
index 949321a59..db05bbd8a 100644
--- a/testex/STM32/STM32F4xx/SPI-LIS3DSH/usbcfg.c
+++ b/testex/STM32/STM32F4xx/SPI-LIS3DSH/usbcfg.c
@@ -267,8 +267,6 @@ static void usb_event(USBDriver *usbp, usbevent_t event) {
extern SerialUSBDriver SDU1;
switch (event) {
- case USB_EVENT_RESET:
- return;
case USB_EVENT_ADDRESS:
return;
case USB_EVENT_CONFIGURED:
@@ -285,17 +283,25 @@ static void usb_event(USBDriver *usbp, usbevent_t event) {
chSysUnlockFromISR();
return;
+ case USB_EVENT_RESET:
+ /* Falls into.*/
case USB_EVENT_UNCONFIGURED:
- return;
+ /* Falls into.*/
case USB_EVENT_SUSPEND:
chSysLockFromISR();
/* Disconnection event on suspend.*/
- sduDisconnectI(&SDU1);
+ sduSuspendHookI(&SDU1);
chSysUnlockFromISR();
return;
case USB_EVENT_WAKEUP:
+ chSysLockFromISR();
+
+ /* Disconnection event on suspend.*/
+ sduWakeupHookI(&SDU1);
+
+ chSysUnlockFromISR();
return;
case USB_EVENT_STALLED:
return;
diff --git a/testhal/STM32/STM32F0xx/USB_CDC/usbcfg.c b/testhal/STM32/STM32F0xx/USB_CDC/usbcfg.c
index 1a46b170a..558334fb5 100644
--- a/testhal/STM32/STM32F0xx/USB_CDC/usbcfg.c
+++ b/testhal/STM32/STM32F0xx/USB_CDC/usbcfg.c
@@ -267,8 +267,6 @@ static void usb_event(USBDriver *usbp, usbevent_t event) {
extern SerialUSBDriver SDU1;
switch (event) {
- case USB_EVENT_RESET:
- return;
case USB_EVENT_ADDRESS:
return;
case USB_EVENT_CONFIGURED:
@@ -285,17 +283,25 @@ static void usb_event(USBDriver *usbp, usbevent_t event) {
chSysUnlockFromISR();
return;
+ case USB_EVENT_RESET:
+ /* Falls into.*/
case USB_EVENT_UNCONFIGURED:
- return;
+ /* Falls into.*/
case USB_EVENT_SUSPEND:
chSysLockFromISR();
/* Disconnection event on suspend.*/
- sduDisconnectI(&SDU1);
+ sduSuspendHookI(&SDU1);
chSysUnlockFromISR();
return;
case USB_EVENT_WAKEUP:
+ chSysLockFromISR();
+
+ /* Disconnection event on suspend.*/
+ sduWakeupHookI(&SDU1);
+
+ chSysUnlockFromISR();
return;
case USB_EVENT_STALLED:
return;
diff --git a/testhal/STM32/STM32F1xx/USB_CDC/usbcfg.c b/testhal/STM32/STM32F1xx/USB_CDC/usbcfg.c
index 949321a59..db05bbd8a 100644
--- a/testhal/STM32/STM32F1xx/USB_CDC/usbcfg.c
+++ b/testhal/STM32/STM32F1xx/USB_CDC/usbcfg.c
@@ -267,8 +267,6 @@ static void usb_event(USBDriver *usbp, usbevent_t event) {
extern SerialUSBDriver SDU1;
switch (event) {
- case USB_EVENT_RESET:
- return;
case USB_EVENT_ADDRESS:
return;
case USB_EVENT_CONFIGURED:
@@ -285,17 +283,25 @@ static void usb_event(USBDriver *usbp, usbevent_t event) {
chSysUnlockFromISR();
return;
+ case USB_EVENT_RESET:
+ /* Falls into.*/
case USB_EVENT_UNCONFIGURED:
- return;
+ /* Falls into.*/
case USB_EVENT_SUSPEND:
chSysLockFromISR();
/* Disconnection event on suspend.*/
- sduDisconnectI(&SDU1);
+ sduSuspendHookI(&SDU1);
chSysUnlockFromISR();
return;
case USB_EVENT_WAKEUP:
+ chSysLockFromISR();
+
+ /* Disconnection event on suspend.*/
+ sduWakeupHookI(&SDU1);
+
+ chSysUnlockFromISR();
return;
case USB_EVENT_STALLED:
return;
diff --git a/testhal/STM32/STM32F2xx/USB_CDC/usbcfg.c b/testhal/STM32/STM32F2xx/USB_CDC/usbcfg.c
index 949321a59..db05bbd8a 100644
--- a/testhal/STM32/STM32F2xx/USB_CDC/usbcfg.c
+++ b/testhal/STM32/STM32F2xx/USB_CDC/usbcfg.c
@@ -267,8 +267,6 @@ static void usb_event(USBDriver *usbp, usbevent_t event) {
extern SerialUSBDriver SDU1;
switch (event) {
- case USB_EVENT_RESET:
- return;
case USB_EVENT_ADDRESS:
return;
case USB_EVENT_CONFIGURED:
@@ -285,17 +283,25 @@ static void usb_event(USBDriver *usbp, usbevent_t event) {
chSysUnlockFromISR();
return;
+ case USB_EVENT_RESET:
+ /* Falls into.*/
case USB_EVENT_UNCONFIGURED:
- return;
+ /* Falls into.*/
case USB_EVENT_SUSPEND:
chSysLockFromISR();
/* Disconnection event on suspend.*/
- sduDisconnectI(&SDU1);
+ sduSuspendHookI(&SDU1);
chSysUnlockFromISR();
return;
case USB_EVENT_WAKEUP:
+ chSysLockFromISR();
+
+ /* Disconnection event on suspend.*/
+ sduWakeupHookI(&SDU1);
+
+ chSysUnlockFromISR();
return;
case USB_EVENT_STALLED:
return;
diff --git a/testhal/STM32/STM32F37x/USB_CDC/usbcfg.c b/testhal/STM32/STM32F37x/USB_CDC/usbcfg.c
index 949321a59..db05bbd8a 100644
--- a/testhal/STM32/STM32F37x/USB_CDC/usbcfg.c
+++ b/testhal/STM32/STM32F37x/USB_CDC/usbcfg.c
@@ -267,8 +267,6 @@ static void usb_event(USBDriver *usbp, usbevent_t event) {
extern SerialUSBDriver SDU1;
switch (event) {
- case USB_EVENT_RESET:
- return;
case USB_EVENT_ADDRESS:
return;
case USB_EVENT_CONFIGURED:
@@ -285,17 +283,25 @@ static void usb_event(USBDriver *usbp, usbevent_t event) {
chSysUnlockFromISR();
return;
+ case USB_EVENT_RESET:
+ /* Falls into.*/
case USB_EVENT_UNCONFIGURED:
- return;
+ /* Falls into.*/
case USB_EVENT_SUSPEND:
chSysLockFromISR();
/* Disconnection event on suspend.*/
- sduDisconnectI(&SDU1);
+ sduSuspendHookI(&SDU1);
chSysUnlockFromISR();
return;
case USB_EVENT_WAKEUP:
+ chSysLockFromISR();
+
+ /* Disconnection event on suspend.*/
+ sduWakeupHookI(&SDU1);
+
+ chSysUnlockFromISR();
return;
case USB_EVENT_STALLED:
return;
diff --git a/testhal/STM32/STM32F3xx/USB_CDC/usbcfg.c b/testhal/STM32/STM32F3xx/USB_CDC/usbcfg.c
index 949321a59..db05bbd8a 100644
--- a/testhal/STM32/STM32F3xx/USB_CDC/usbcfg.c
+++ b/testhal/STM32/STM32F3xx/USB_CDC/usbcfg.c
@@ -267,8 +267,6 @@ static void usb_event(USBDriver *usbp, usbevent_t event) {
extern SerialUSBDriver SDU1;
switch (event) {
- case USB_EVENT_RESET:
- return;
case USB_EVENT_ADDRESS:
return;
case USB_EVENT_CONFIGURED:
@@ -285,17 +283,25 @@ static void usb_event(USBDriver *usbp, usbevent_t event) {
chSysUnlockFromISR();
return;
+ case USB_EVENT_RESET:
+ /* Falls into.*/
case USB_EVENT_UNCONFIGURED:
- return;
+ /* Falls into.*/
case USB_EVENT_SUSPEND:
chSysLockFromISR();
/* Disconnection event on suspend.*/
- sduDisconnectI(&SDU1);
+ sduSuspendHookI(&SDU1);
chSysUnlockFromISR();
return;
case USB_EVENT_WAKEUP:
+ chSysLockFromISR();
+
+ /* Disconnection event on suspend.*/
+ sduWakeupHookI(&SDU1);
+
+ chSysUnlockFromISR();
return;
case USB_EVENT_STALLED:
return;
diff --git a/testhal/STM32/STM32F3xx/USB_CDC_IAD/usbcfg.c b/testhal/STM32/STM32F3xx/USB_CDC_IAD/usbcfg.c
index c265a9fd6..9559e1f43 100644
--- a/testhal/STM32/STM32F3xx/USB_CDC_IAD/usbcfg.c
+++ b/testhal/STM32/STM32F3xx/USB_CDC_IAD/usbcfg.c
@@ -373,8 +373,6 @@ static void usb_event(USBDriver *usbp, usbevent_t event) {
extern SerialUSBDriver SDU2;
switch (event) {
- case USB_EVENT_RESET:
- return;
case USB_EVENT_ADDRESS:
return;
case USB_EVENT_CONFIGURED:
@@ -399,18 +397,27 @@ static void usb_event(USBDriver *usbp, usbevent_t event) {
chSysUnlockFromISR();
return;
+ case USB_EVENT_RESET:
+ /* Falls into.*/
case USB_EVENT_UNCONFIGURED:
- return;
+ /* Falls into.*/
case USB_EVENT_SUSPEND:
chSysLockFromISR();
/* Disconnection event on suspend.*/
- sduDisconnectI(&SDU1);
- sduDisconnectI(&SDU2);
+ sduSuspendHookI(&SDU1);
+ sduSuspendHookI(&SDU2);
chSysUnlockFromISR();
return;
case USB_EVENT_WAKEUP:
+ chSysLockFromISR();
+
+ /* Disconnection event on suspend.*/
+ sduWakeupHookI(&SDU1);
+ sduWakeupHookI(&SDU2);
+
+ chSysUnlockFromISR();
return;
case USB_EVENT_STALLED:
return;
diff --git a/testhal/STM32/STM32F4xx/USB_CDC/usbcfg.c b/testhal/STM32/STM32F4xx/USB_CDC/usbcfg.c
index 949321a59..db05bbd8a 100644
--- a/testhal/STM32/STM32F4xx/USB_CDC/usbcfg.c
+++ b/testhal/STM32/STM32F4xx/USB_CDC/usbcfg.c
@@ -267,8 +267,6 @@ static void usb_event(USBDriver *usbp, usbevent_t event) {
extern SerialUSBDriver SDU1;
switch (event) {
- case USB_EVENT_RESET:
- return;
case USB_EVENT_ADDRESS:
return;
case USB_EVENT_CONFIGURED:
@@ -285,17 +283,25 @@ static void usb_event(USBDriver *usbp, usbevent_t event) {
chSysUnlockFromISR();
return;
+ case USB_EVENT_RESET:
+ /* Falls into.*/
case USB_EVENT_UNCONFIGURED:
- return;
+ /* Falls into.*/
case USB_EVENT_SUSPEND:
chSysLockFromISR();
/* Disconnection event on suspend.*/
- sduDisconnectI(&SDU1);
+ sduSuspendHookI(&SDU1);
chSysUnlockFromISR();
return;
case USB_EVENT_WAKEUP:
+ chSysLockFromISR();
+
+ /* Disconnection event on suspend.*/
+ sduWakeupHookI(&SDU1);
+
+ chSysUnlockFromISR();
return;
case USB_EVENT_STALLED:
return;
diff --git a/testhal/STM32/STM32F4xx/USB_CDC_IAD/usbcfg.c b/testhal/STM32/STM32F4xx/USB_CDC_IAD/usbcfg.c
index c6318049a..d1249b305 100644
--- a/testhal/STM32/STM32F4xx/USB_CDC_IAD/usbcfg.c
+++ b/testhal/STM32/STM32F4xx/USB_CDC_IAD/usbcfg.c
@@ -373,8 +373,6 @@ static void usb_event(USBDriver *usbp, usbevent_t event) {
extern SerialUSBDriver SDU2;
switch (event) {
- case USB_EVENT_RESET:
- return;
case USB_EVENT_ADDRESS:
return;
case USB_EVENT_CONFIGURED:
@@ -399,18 +397,27 @@ static void usb_event(USBDriver *usbp, usbevent_t event) {
chSysUnlockFromISR();
return;
+ case USB_EVENT_RESET:
+ /* Falls into.*/
case USB_EVENT_UNCONFIGURED:
- return;
+ /* Falls into.*/
case USB_EVENT_SUSPEND:
chSysLockFromISR();
/* Disconnection event on suspend.*/
- sduDisconnectI(&SDU1);
- sduDisconnectI(&SDU2);
+ sduSuspendHookI(&SDU1);
+ sduSuspendHookI(&SDU2);
chSysUnlockFromISR();
return;
case USB_EVENT_WAKEUP:
+ chSysLockFromISR();
+
+ /* Disconnection event on suspend.*/
+ sduWakeupHookI(&SDU1);
+ sduWakeupHookI(&SDU2);
+
+ chSysUnlockFromISR();
return;
case USB_EVENT_STALLED:
return;
diff --git a/testhal/STM32/STM32F7xx/USB_CDC/usbcfg.c b/testhal/STM32/STM32F7xx/USB_CDC/usbcfg.c
index e0c0d853b..bb05f43c8 100644
--- a/testhal/STM32/STM32F7xx/USB_CDC/usbcfg.c
+++ b/testhal/STM32/STM32F7xx/USB_CDC/usbcfg.c
@@ -267,8 +267,6 @@ static void usb_event(USBDriver *usbp, usbevent_t event) {
extern SerialUSBDriver SDU2;
switch (event) {
- case USB_EVENT_RESET:
- return;
case USB_EVENT_ADDRESS:
return;
case USB_EVENT_CONFIGURED:
@@ -285,17 +283,25 @@ static void usb_event(USBDriver *usbp, usbevent_t event) {
chSysUnlockFromISR();
return;
+ case USB_EVENT_RESET:
+ /* Falls into.*/
case USB_EVENT_UNCONFIGURED:
- return;
+ /* Falls into.*/
case USB_EVENT_SUSPEND:
chSysLockFromISR();
/* Disconnection event on suspend.*/
- sduDisconnectI(&SDU2);
+ sduSuspendHookI(&SDU2);
chSysUnlockFromISR();
return;
case USB_EVENT_WAKEUP:
+ chSysLockFromISR();
+
+ /* Disconnection event on suspend.*/
+ sduWakeupHookI(&SDU2);
+
+ chSysUnlockFromISR();
return;
case USB_EVENT_STALLED:
return;
diff --git a/testhal/STM32/STM32L4xx/USB_CDC/usbcfg.c b/testhal/STM32/STM32L4xx/USB_CDC/usbcfg.c
index 949321a59..db05bbd8a 100644
--- a/testhal/STM32/STM32L4xx/USB_CDC/usbcfg.c
+++ b/testhal/STM32/STM32L4xx/USB_CDC/usbcfg.c
@@ -267,8 +267,6 @@ static void usb_event(USBDriver *usbp, usbevent_t event) {
extern SerialUSBDriver SDU1;
switch (event) {
- case USB_EVENT_RESET:
- return;
case USB_EVENT_ADDRESS:
return;
case USB_EVENT_CONFIGURED:
@@ -285,17 +283,25 @@ static void usb_event(USBDriver *usbp, usbevent_t event) {
chSysUnlockFromISR();
return;
+ case USB_EVENT_RESET:
+ /* Falls into.*/
case USB_EVENT_UNCONFIGURED:
- return;
+ /* Falls into.*/
case USB_EVENT_SUSPEND:
chSysLockFromISR();
/* Disconnection event on suspend.*/
- sduDisconnectI(&SDU1);
+ sduSuspendHookI(&SDU1);
chSysUnlockFromISR();
return;
case USB_EVENT_WAKEUP:
+ chSysLockFromISR();
+
+ /* Disconnection event on suspend.*/
+ sduWakeupHookI(&SDU1);
+
+ chSysUnlockFromISR();
return;
case USB_EVENT_STALLED:
return;