From 2fdca55f58f29aa01be6a0b90728c902c20098ef Mon Sep 17 00:00:00 2001 From: Giovanni Di Sirio Date: Fri, 25 Dec 2015 12:45:23 +0000 Subject: Updated all USB demos. git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@8644 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- demos/STM32/RT-STM32F103-MAPLEMINI/main.c | 14 ++++++++---- demos/STM32/RT-STM32F103-MAPLEMINI/usbcfg.c | 34 ++++++++++++++++++++++++----- demos/STM32/RT-STM32F103-MAPLEMINI/usbcfg.h | 1 + 3 files changed, 39 insertions(+), 10 deletions(-) (limited to 'demos/STM32/RT-STM32F103-MAPLEMINI') diff --git a/demos/STM32/RT-STM32F103-MAPLEMINI/main.c b/demos/STM32/RT-STM32F103-MAPLEMINI/main.c index 44eddabd1..5ce15913b 100644 --- a/demos/STM32/RT-STM32F103-MAPLEMINI/main.c +++ b/demos/STM32/RT-STM32F103-MAPLEMINI/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-MAPLEMINI/usbcfg.c b/demos/STM32/RT-STM32F103-MAPLEMINI/usbcfg.c index a01c9dcb3..07a492758 100644 --- a/demos/STM32/RT-STM32F103-MAPLEMINI/usbcfg.c +++ b/demos/STM32/RT-STM32F103-MAPLEMINI/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. */ @@ -33,8 +35,8 @@ static const uint8_t vcom_device_descriptor_data[18] = { 0x00, /* bDeviceSubClass. */ 0x00, /* bDeviceProtocol. */ 0x40, /* bMaxPacketSize. */ - 0x1eaf, /* idVendor (LeafLabs). */ - 0x0004, /* idProduct. */ + 0x0483, /* idVendor (ST). */ + 0x5740, /* idProduct. */ 0x0200, /* bcdDevice. */ 1, /* iManufacturer. */ 2, /* iProduct. */ @@ -148,9 +150,11 @@ static const uint8_t vcom_string0[] = { * Vendor string. */ static const uint8_t vcom_string1[] = { - USB_DESC_BYTE(18), /* bLength. */ + USB_DESC_BYTE(38), /* bLength. */ USB_DESC_BYTE(USB_DESCRIPTOR_STRING), /* bDescriptorType. */ - 'L', 0, 'e', 0, 'a', 0, 'f', 0, 'L', 0, 'a', 0, 'b', 0, 's', 0, + 'S', 0, 'T', 0, 'M', 0, 'i', 0, 'c', 0, 'r', 0, 'o', 0, 'e', 0, + 'l', 0, 'e', 0, 'c', 0, 't', 0, 'r', 0, 'o', 0, 'n', 0, 'i', 0, + 'c', 0, 's', 0 }; /* @@ -282,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; @@ -291,6 +301,18 @@ static void usb_event(USBDriver *usbp, usbevent_t event) { return; } +/* + * Handles the USB driver global events. + */ +static void sof_handler(USBDriver *usbp) { + + (void)usbp; + + osalSysLockFromISR(); + sduSOFHookI(&SDU1); + osalSysUnlockFromISR(); +} + /* * USB driver configuration. */ @@ -298,7 +320,7 @@ const USBConfig usbcfg = { usb_event, get_descriptor, sduRequestsHook, - NULL + sof_handler }; /* diff --git a/demos/STM32/RT-STM32F103-MAPLEMINI/usbcfg.h b/demos/STM32/RT-STM32F103-MAPLEMINI/usbcfg.h index 2ffaa17f9..2da1c40a4 100644 --- a/demos/STM32/RT-STM32F103-MAPLEMINI/usbcfg.h +++ b/demos/STM32/RT-STM32F103-MAPLEMINI/usbcfg.h @@ -19,6 +19,7 @@ extern const USBConfig usbcfg; extern SerialUSBConfig serusbcfg; +extern SerialUSBDriver SDU1; #endif /* _USBCFG_H_ */ -- cgit v1.2.3