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-STM32F429-DISCOVERY/main.c | 3 -- demos/STM32/RT-STM32F429-DISCOVERY/mcuconf.h | 4 +-- demos/STM32/RT-STM32F429-DISCOVERY/usbcfg.c | 50 +++++++++++++++++++--------- demos/STM32/RT-STM32F429-DISCOVERY/usbcfg.h | 1 + 4 files changed, 38 insertions(+), 20 deletions(-) (limited to 'demos/STM32/RT-STM32F429-DISCOVERY') diff --git a/demos/STM32/RT-STM32F429-DISCOVERY/main.c b/demos/STM32/RT-STM32F429-DISCOVERY/main.c index 4c23d280a..f423b233e 100644 --- a/demos/STM32/RT-STM32F429-DISCOVERY/main.c +++ b/demos/STM32/RT-STM32F429-DISCOVERY/main.c @@ -59,9 +59,6 @@ static THD_FUNCTION(Thread2, arg) { /* Command line related. */ /*===========================================================================*/ -/* Virtual serial port over USB.*/ -SerialUSBDriver SDU1; - #define SHELL_WA_SIZE THD_WORKING_AREA_SIZE(2048) #define TEST_WA_SIZE THD_WORKING_AREA_SIZE(256) diff --git a/demos/STM32/RT-STM32F429-DISCOVERY/mcuconf.h b/demos/STM32/RT-STM32F429-DISCOVERY/mcuconf.h index 06f802489..ae728ce6f 100644 --- a/demos/STM32/RT-STM32F429-DISCOVERY/mcuconf.h +++ b/demos/STM32/RT-STM32F429-DISCOVERY/mcuconf.h @@ -343,8 +343,8 @@ /* * USB driver system settings. */ -#define STM32_USB_USE_OTG1 FALSE -#define STM32_USB_USE_OTG2 TRUE +#define STM32_USB_USE_OTG1 TRUE +#define STM32_USB_USE_OTG2 FALSE #define STM32_USB_OTG1_IRQ_PRIORITY 14 #define STM32_USB_OTG2_IRQ_PRIORITY 14 #define STM32_USB_OTG1_RX_FIFO_SIZE 512 diff --git a/demos/STM32/RT-STM32F429-DISCOVERY/usbcfg.c b/demos/STM32/RT-STM32F429-DISCOVERY/usbcfg.c index 9f95a2a25..07a492758 100644 --- a/demos/STM32/RT-STM32F429-DISCOVERY/usbcfg.c +++ b/demos/STM32/RT-STM32F429-DISCOVERY/usbcfg.c @@ -14,15 +14,17 @@ limitations under the License. */ -#include "ch.h" #include "hal.h" +/* Virtual serial port over USB.*/ +SerialUSBDriver SDU1; + /* - * Endpoints to be used for USBD2. + * Endpoints to be used for USBD1. */ -#define USBD2_DATA_REQUEST_EP 1 -#define USBD2_DATA_AVAILABLE_EP 1 -#define USBD2_INTERRUPT_REQUEST_EP 2 +#define USBD1_DATA_REQUEST_EP 1 +#define USBD1_DATA_AVAILABLE_EP 1 +#define USBD1_INTERRUPT_REQUEST_EP 2 /* * USB Device Descriptor. @@ -100,7 +102,7 @@ static const uint8_t vcom_configuration_descriptor_data[67] = { USB_DESC_BYTE (0x01), /* bSlaveInterface0 (Data Class Interface). */ /* Endpoint 2 Descriptor.*/ - USB_DESC_ENDPOINT (USBD2_INTERRUPT_REQUEST_EP|0x80, + USB_DESC_ENDPOINT (USBD1_INTERRUPT_REQUEST_EP|0x80, 0x03, /* bmAttributes (Interrupt). */ 0x0008, /* wMaxPacketSize. */ 0xFF), /* bInterval. */ @@ -116,12 +118,12 @@ static const uint8_t vcom_configuration_descriptor_data[67] = { 4.7). */ 0x00), /* iInterface. */ /* Endpoint 3 Descriptor.*/ - USB_DESC_ENDPOINT (USBD2_DATA_AVAILABLE_EP, /* bEndpointAddress.*/ + USB_DESC_ENDPOINT (USBD1_DATA_AVAILABLE_EP, /* bEndpointAddress.*/ 0x02, /* bmAttributes (Bulk). */ 0x0040, /* wMaxPacketSize. */ 0x00), /* bInterval. */ /* Endpoint 1 Descriptor.*/ - USB_DESC_ENDPOINT (USBD2_DATA_REQUEST_EP|0x80, /* bEndpointAddress.*/ + USB_DESC_ENDPOINT (USBD1_DATA_REQUEST_EP|0x80, /* bEndpointAddress.*/ 0x02, /* bmAttributes (Bulk). */ 0x0040, /* wMaxPacketSize. */ 0x00) /* bInterval. */ @@ -275,8 +277,8 @@ static void usb_event(USBDriver *usbp, usbevent_t event) { /* Enables the endpoints specified into the configuration. Note, this callback is invoked from an ISR so I-Class functions must be used.*/ - usbInitEndpointI(usbp, USBD2_DATA_REQUEST_EP, &ep1config); - usbInitEndpointI(usbp, USBD2_INTERRUPT_REQUEST_EP, &ep2config); + usbInitEndpointI(usbp, USBD1_DATA_REQUEST_EP, &ep1config); + usbInitEndpointI(usbp, USBD1_INTERRUPT_REQUEST_EP, &ep2config); /* Resetting the state of the CDC subsystem.*/ sduConfigureHookI(&SDU1); @@ -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; @@ -293,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. */ @@ -300,15 +320,15 @@ const USBConfig usbcfg = { usb_event, get_descriptor, sduRequestsHook, - NULL + sof_handler }; /* * Serial over USB driver configuration. */ const SerialUSBConfig serusbcfg = { - &USBD2, - USBD2_DATA_REQUEST_EP, - USBD2_DATA_AVAILABLE_EP, - USBD2_INTERRUPT_REQUEST_EP + &USBD1, + USBD1_DATA_REQUEST_EP, + USBD1_DATA_AVAILABLE_EP, + USBD1_INTERRUPT_REQUEST_EP }; diff --git a/demos/STM32/RT-STM32F429-DISCOVERY/usbcfg.h b/demos/STM32/RT-STM32F429-DISCOVERY/usbcfg.h index 2ffaa17f9..2da1c40a4 100644 --- a/demos/STM32/RT-STM32F429-DISCOVERY/usbcfg.h +++ b/demos/STM32/RT-STM32F429-DISCOVERY/usbcfg.h @@ -19,6 +19,7 @@ extern const USBConfig usbcfg; extern SerialUSBConfig serusbcfg; +extern SerialUSBDriver SDU1; #endif /* _USBCFG_H_ */ -- cgit v1.2.3