aboutsummaryrefslogtreecommitdiffstats
path: root/demos/STM32/RT-STM32F103_INEMO_DISCOVERY
diff options
context:
space:
mode:
Diffstat (limited to 'demos/STM32/RT-STM32F103_INEMO_DISCOVERY')
-rw-r--r--demos/STM32/RT-STM32F103_INEMO_DISCOVERY/main.c14
-rw-r--r--demos/STM32/RT-STM32F103_INEMO_DISCOVERY/usbcfg.c24
-rw-r--r--demos/STM32/RT-STM32F103_INEMO_DISCOVERY/usbcfg.h1
3 files changed, 33 insertions, 6 deletions
diff --git a/demos/STM32/RT-STM32F103_INEMO_DISCOVERY/main.c b/demos/STM32/RT-STM32F103_INEMO_DISCOVERY/main.c
index bce8983bb..2515f18cb 100644
--- a/demos/STM32/RT-STM32F103_INEMO_DISCOVERY/main.c
+++ b/demos/STM32/RT-STM32F103_INEMO_DISCOVERY/main.c
@@ -26,9 +26,6 @@
#include "usbcfg.h"
-/* Virtual serial port over USB.*/
-SerialUSBDriver SDU1;
-
/*===========================================================================*/
/* Command line related. */
/*===========================================================================*/
@@ -87,6 +84,7 @@ static void cmd_test(BaseSequentialStream *chp, int argc, char *argv[]) {
chThdWait(tp);
}
+/* Can be measured using dd if=/dev/xxxx of=/dev/null bs=512 count=10000.*/
static void cmd_write(BaseSequentialStream *chp, int argc, char *argv[]) {
static uint8_t buf[] =
"0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef"
@@ -113,7 +111,15 @@ static void cmd_write(BaseSequentialStream *chp, int argc, char *argv[]) {
}
while (chnGetTimeout((BaseChannel *)chp, TIME_IMMEDIATE) == Q_TIMEOUT) {
- chSequentialStreamWrite(&SDU1, buf, sizeof buf - 1);
+#if 1
+ /* Writing in channel mode.*/
+ chnWrite(&SDU1, buf, sizeof buf - 1);
+#else
+ /* Writing in buffer mode.*/
+ (void) obqGetEmptyBufferTimeout(&SDU1.obqueue, TIME_INFINITE);
+ memcpy(SDU1.obqueue.ptr, buf, SERIAL_USB_BUFFERS_SIZE);
+ obqPostFullBuffer(&SDU1.obqueue, SERIAL_USB_BUFFERS_SIZE);
+#endif
}
chprintf(chp, "\r\n\nstopped\r\n");
}
diff --git a/demos/STM32/RT-STM32F103_INEMO_DISCOVERY/usbcfg.c b/demos/STM32/RT-STM32F103_INEMO_DISCOVERY/usbcfg.c
index f825ec239..07a492758 100644
--- a/demos/STM32/RT-STM32F103_INEMO_DISCOVERY/usbcfg.c
+++ b/demos/STM32/RT-STM32F103_INEMO_DISCOVERY/usbcfg.c
@@ -14,9 +14,11 @@
limitations under the License.
*/
-#include "ch.h"
#include "hal.h"
+/* Virtual serial port over USB.*/
+SerialUSBDriver SDU1;
+
/*
* Endpoints to be used for USBD1.
*/
@@ -284,6 +286,12 @@ static void usb_event(USBDriver *usbp, usbevent_t event) {
chSysUnlockFromISR();
return;
case USB_EVENT_SUSPEND:
+ chSysLockFromISR();
+
+ /* Disconnection event on suspend.*/
+ sduDisconnectI(&SDU1);
+
+ chSysUnlockFromISR();
return;
case USB_EVENT_WAKEUP:
return;
@@ -294,13 +302,25 @@ static void usb_event(USBDriver *usbp, usbevent_t event) {
}
/*
+ * Handles the USB driver global events.
+ */
+static void sof_handler(USBDriver *usbp) {
+
+ (void)usbp;
+
+ osalSysLockFromISR();
+ sduSOFHookI(&SDU1);
+ osalSysUnlockFromISR();
+}
+
+/*
* USB driver configuration.
*/
const USBConfig usbcfg = {
usb_event,
get_descriptor,
sduRequestsHook,
- NULL
+ sof_handler
};
/*
diff --git a/demos/STM32/RT-STM32F103_INEMO_DISCOVERY/usbcfg.h b/demos/STM32/RT-STM32F103_INEMO_DISCOVERY/usbcfg.h
index 2ffaa17f9..2da1c40a4 100644
--- a/demos/STM32/RT-STM32F103_INEMO_DISCOVERY/usbcfg.h
+++ b/demos/STM32/RT-STM32F103_INEMO_DISCOVERY/usbcfg.h
@@ -19,6 +19,7 @@
extern const USBConfig usbcfg;
extern SerialUSBConfig serusbcfg;
+extern SerialUSBDriver SDU1;
#endif /* _USBCFG_H_ */