From 8dc000a0f757e99c2fa6ee8c97ca74625486a56f Mon Sep 17 00:00:00 2001 From: Giovanni Di Sirio Date: Fri, 6 Feb 2015 09:30:13 +0000 Subject: STM32F4 CDC_IAD demo, to be tested. git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@7663 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- testhal/STM32/STM32F4xx/USB_CDC_IAD/.cproject | 2 +- testhal/STM32/STM32F4xx/USB_CDC_IAD/.project | 2 +- testhal/STM32/STM32F4xx/USB_CDC_IAD/Makefile | 2 +- ...4xx-USB_CDC_IAD (OpenOCD, Flash and Run).launch | 6 +- .../USB_CDC_IAD/driver/ChibiOS Virtual COM.inf | 54 ++++++++++ testhal/STM32/STM32F4xx/USB_CDC_IAD/main.c | 4 +- testhal/STM32/STM32F4xx/USB_CDC_IAD/mcuconf.h | 4 +- testhal/STM32/STM32F4xx/USB_CDC_IAD/readme.txt | 6 +- testhal/STM32/STM32F4xx/USB_CDC_IAD/usbcfg.c | 109 +++++++++++++-------- 9 files changed, 134 insertions(+), 55 deletions(-) create mode 100644 testhal/STM32/STM32F4xx/USB_CDC_IAD/driver/ChibiOS Virtual COM.inf (limited to 'testhal/STM32') diff --git a/testhal/STM32/STM32F4xx/USB_CDC_IAD/.cproject b/testhal/STM32/STM32F4xx/USB_CDC_IAD/.cproject index c203ca26c..3b33d55e0 100644 --- a/testhal/STM32/STM32F4xx/USB_CDC_IAD/.cproject +++ b/testhal/STM32/STM32F4xx/USB_CDC_IAD/.cproject @@ -37,7 +37,7 @@ - + diff --git a/testhal/STM32/STM32F4xx/USB_CDC_IAD/.project b/testhal/STM32/STM32F4xx/USB_CDC_IAD/.project index dab0e915e..4fb3e660d 100644 --- a/testhal/STM32/STM32F4xx/USB_CDC_IAD/.project +++ b/testhal/STM32/STM32F4xx/USB_CDC_IAD/.project @@ -1,6 +1,6 @@ - STM32F4xx-USB_CDC_DUAL + STM32F4xx-USB_CDC_IAD diff --git a/testhal/STM32/STM32F4xx/USB_CDC_IAD/Makefile b/testhal/STM32/STM32F4xx/USB_CDC_IAD/Makefile index bcceec615..486617f6e 100644 --- a/testhal/STM32/STM32F4xx/USB_CDC_IAD/Makefile +++ b/testhal/STM32/STM32F4xx/USB_CDC_IAD/Makefile @@ -82,7 +82,7 @@ PROJECT = ch # Imported source files and paths CHIBIOS = ../../../.. include $(CHIBIOS)/os/hal/hal.mk -include $(CHIBIOS)/os/hal/boards/ST_STM32F4_DISCOVERY/board.mk +include $(CHIBIOS)/os/hal/boards/OLIMEX_STM32_E407/board.mk include $(CHIBIOS)/os/hal/ports/STM32/STM32F4xx/platform.mk include $(CHIBIOS)/os/hal/osal/rt/osal.mk include $(CHIBIOS)/os/rt/rt.mk diff --git a/testhal/STM32/STM32F4xx/USB_CDC_IAD/debug/STM32F4xx-USB_CDC_IAD (OpenOCD, Flash and Run).launch b/testhal/STM32/STM32F4xx/USB_CDC_IAD/debug/STM32F4xx-USB_CDC_IAD (OpenOCD, Flash and Run).launch index 3a4979a6d..0e8bffdae 100644 --- a/testhal/STM32/STM32F4xx/USB_CDC_IAD/debug/STM32F4xx-USB_CDC_IAD (OpenOCD, Flash and Run).launch +++ b/testhal/STM32/STM32F4xx/USB_CDC_IAD/debug/STM32F4xx-USB_CDC_IAD (OpenOCD, Flash and Run).launch @@ -1,6 +1,6 @@ - + @@ -37,11 +37,11 @@ - + - + diff --git a/testhal/STM32/STM32F4xx/USB_CDC_IAD/driver/ChibiOS Virtual COM.inf b/testhal/STM32/STM32F4xx/USB_CDC_IAD/driver/ChibiOS Virtual COM.inf new file mode 100644 index 000000000..7e6908513 --- /dev/null +++ b/testhal/STM32/STM32F4xx/USB_CDC_IAD/driver/ChibiOS Virtual COM.inf @@ -0,0 +1,54 @@ +[Version] +Signature="$Windows NT$" +Class=Ports +ClassGuid={4D36E978-E325-11CE-BFC1-08002BE10318} +Provider=%PRVDR% +CatalogFile=stmcdc.cat +DriverVer=02/06/2015,1.0.0 + +[SourceDisksNames] + +[SourceDisksFiles] + +[Manufacturer] +%MFGNAME%=DeviceList,NT,NTamd64 + +[DestinationDirs] +DefaultDestDir = 12 + +[DeviceList.NT] +%DESCRIPTION1%=DriverInstall,USB\VID_F055&PID_E063&MI_00 +%DESCRIPTION2%=DriverInstall,USB\VID_F055&PID_E063&MI_02 + +[DeviceList.NTamd64] +%DESCRIPTION1%=DriverInstall,USB\VID_F055&PID_E063&MI_00 +%DESCRIPTION2%=DriverInstall,USB\VID_F055&PID_E063&MI_02 + +[DriverInstall.NT] +Include=mdmcpq.inf +CopyFiles=FakeModemCopyFileSection +AddReg=DriverInstall.NT.AddReg + +[DriverInstall.NT.AddReg] +HKR,,DevLoader,,*ntkern +HKR,,NTMPDriver,,usbser.sys +HKR,,EnumPropPages32,,"MsPorts.dll,SerialPortPropPageProvider" + +[DriverInstall.NT.Services] +AddService=usbser, 0x00000002, DriverServiceInst + +[DriverServiceInst] +DisplayName=%SERVICE% +ServiceType = 1 ; SERVICE_KERNEL_DRIVER +StartType = 3 ; SERVICE_DEMAND_START +ErrorControl = 1 ; SERVICE_ERROR_NORMAL +ServiceBinary= %12%\usbser.sys +LoadOrderGroup = Base + +[Strings] +PRVDR = "www.chibios.org" +MFGNAME = "ChibiOS." +DESCRIPTION1 = "ChibiOS Virtual COM Port 1" +DESCRIPTION2 = "ChibiOS Virtual COM Port 2" +SERVICE = "ChibiOS Virtual COM Port" +DriversDisk = "ChibiOS Drivers Disk" diff --git a/testhal/STM32/STM32F4xx/USB_CDC_IAD/main.c b/testhal/STM32/STM32F4xx/USB_CDC_IAD/main.c index 04d5148bc..b8a75106a 100644 --- a/testhal/STM32/STM32F4xx/USB_CDC_IAD/main.c +++ b/testhal/STM32/STM32F4xx/USB_CDC_IAD/main.c @@ -155,9 +155,9 @@ static msg_t Thread1(void *arg) { systime_t time; time = serusbcfg1.usbp->state == USB_ACTIVE ? 250 : 500; - palClearPad(GPIOD, GPIOD_LED4); + palClearPad(GPIOC, GPIOC_LED); chThdSleepMilliseconds(time); - palSetPad(GPIOD, GPIOD_LED4); + palSetPad(GPIOC, GPIOC_LED); chThdSleepMilliseconds(time); } } diff --git a/testhal/STM32/STM32F4xx/USB_CDC_IAD/mcuconf.h b/testhal/STM32/STM32F4xx/USB_CDC_IAD/mcuconf.h index 77cf4d44e..c92679905 100644 --- a/testhal/STM32/STM32F4xx/USB_CDC_IAD/mcuconf.h +++ b/testhal/STM32/STM32F4xx/USB_CDC_IAD/mcuconf.h @@ -41,7 +41,7 @@ #define STM32_CLOCK48_REQUIRED TRUE #define STM32_SW STM32_SW_PLL #define STM32_PLLSRC STM32_PLLSRC_HSE -#define STM32_PLLM_VALUE 8 +#define STM32_PLLM_VALUE 12 #define STM32_PLLN_VALUE 336 #define STM32_PLLP_VALUE 2 #define STM32_PLLQ_VALUE 7 @@ -294,7 +294,7 @@ * USB driver system settings. */ #define STM32_USB_USE_OTG1 TRUE -#define STM32_USB_USE_OTG2 FALSE +#define STM32_USB_USE_OTG2 TRUE #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/testhal/STM32/STM32F4xx/USB_CDC_IAD/readme.txt b/testhal/STM32/STM32F4xx/USB_CDC_IAD/readme.txt index bb7c368db..9ed9ec449 100644 --- a/testhal/STM32/STM32F4xx/USB_CDC_IAD/readme.txt +++ b/testhal/STM32/STM32F4xx/USB_CDC_IAD/readme.txt @@ -1,14 +1,14 @@ ***************************************************************************** -** ChibiOS/HAL - USB-CDC driver demo for STM32. ** +** ChibiOS/HAL - USB-CDC (IAD descriptors) driver demo for STM32F4xx. ** ***************************************************************************** ** TARGET ** -The demo runs on an STMicroelectronics STM32F4-Discovery board. +The demo runs on an Olimex STM32-E407 board. ** The Demo ** -The application demonstrates the use of the STM32 USB (OTG) driver. +The application demonstrates the use of the STM32F4xx USB driver. ** Build Procedure ** diff --git a/testhal/STM32/STM32F4xx/USB_CDC_IAD/usbcfg.c b/testhal/STM32/STM32F4xx/USB_CDC_IAD/usbcfg.c index b1d2b307b..5abf0f520 100644 --- a/testhal/STM32/STM32F4xx/USB_CDC_IAD/usbcfg.c +++ b/testhal/STM32/STM32F4xx/USB_CDC_IAD/usbcfg.c @@ -16,6 +16,9 @@ #include "hal.h" +#define USB_DEVICE_VID 0xF055 /* You MUST change this.*/ +#define USB_DEVICE_PID 0xE063 /* You MUST change this.*/ + /* * Endpoints. */ @@ -26,6 +29,9 @@ #define USB_DATA_AVAILABLE_EP_B 4 #define USB_DATA_REQUEST_EP_B 4 +#define USB_INTERRUPT_REQUEST_SIZE 0x10 +#define USB_DATA_SIZE 0x40 + /* * Interfaces */ @@ -38,15 +44,15 @@ /* * USB Device Descriptor. */ -static const uint8_t vcom_device_descriptor_data[18] = { +static const uint8_t vcom_device_descriptor_data[] = { USB_DESC_DEVICE( - 0x0110, /* bcdUSB (1.1). */ + 0x0200, /* bcdUSB (1.1). */ 0xEF, /* bDeviceClass (misc). */ 0x02, /* bDeviceSubClass (common). */ 0x01, /* bDeviceProtocol (IAD). */ - 0x40, /* bMaxPacketSize. */ - 0x0483, /* idVendor (ST). */ - 0x5740, /* idProduct. */ + USB_DATA_SIZE, /* bMaxPacketSize. */ + USB_DEVICE_VID, /* idVendor. */ + USB_DEVICE_PID, /* idProduct. */ 0x0200, /* bcdDevice. */ 1, /* iManufacturer. */ 2, /* iProduct. */ @@ -64,12 +70,12 @@ static const USBDescriptor vcom_device_descriptor = { #define CDC_IF_DESC_SET_SIZE \ (USB_DESC_INTERFACE_SIZE + 5 + 5 + 4 + 5 + USB_DESC_ENDPOINT_SIZE + \ - USB_DESC_INTERFACE_SIZE + (USB_DESC_ENDPOINT_SIZE *2)) + USB_DESC_INTERFACE_SIZE + (USB_DESC_ENDPOINT_SIZE * 2)) #define CDC_IF_DESC_SET(comIfNum, datIfNum, comInEp, datOutEp, datInEp) \ /* Interface Descriptor.*/ \ USB_DESC_INTERFACE( \ - 0x00, /* bInterfaceNumber. */ \ + comIfNum, /* bInterfaceNumber. */ \ 0x00, /* bAlternateSetting. */ \ 0x01, /* bNumEndpoints. */ \ CDC_COMMUNICATION_INTERFACE_CLASS, /* bInterfaceClass. */ \ @@ -104,8 +110,8 @@ static const USBDescriptor vcom_device_descriptor = { USB_DESC_ENDPOINT ( \ comInEp, \ USB_EP_MODE_TYPE_INTR, /* bmAttributes. */ \ - 0x0010, /* wMaxPacketSize. */ \ - 0x01), /*******/ /* bInterval. */ \ + USB_INTERRUPT_REQUEST_SIZE, /* wMaxPacketSize. */ \ + 0x01), /* bInterval. */ \ \ /* CDC Data Interface Descriptor.*/ \ USB_DESC_INTERFACE( \ @@ -122,30 +128,30 @@ static const USBDescriptor vcom_device_descriptor = { USB_DESC_ENDPOINT( \ datOutEp, /* bEndpointAddress. */ \ USB_EP_MODE_TYPE_BULK, /* bmAttributes. */ \ - 0x0040, /*ZZZZZ*/ /* wMaxPacketSize. */ \ + USB_DATA_SIZE, /* wMaxPacketSize. */ \ 0x00), /* bInterval. */ \ /* Endpoint, Bulk IN.*/ \ USB_DESC_ENDPOINT( \ datInEp, /* bEndpointAddress. */ \ USB_EP_MODE_TYPE_BULK, /* bmAttributes. */ \ - 0x0040, /*ZZZZZ*/ /* wMaxPacketSize. */ \ + USB_DATA_SIZE, /* wMaxPacketSize. */ \ 0x00) /* bInterval. */ -#define IAD_CDC_IF_DESC_SET_SIZE (8 + CDC_IF_DESC_SET_SIZE) +#define IAD_CDC_IF_DESC_SET_SIZE \ + (USB_DESC_INTERFACE_ASSOCIATION_SIZE + CDC_IF_DESC_SET_SIZE) #define IAD_CDC_IF_DESC_SET(comIfNum, datIfNum, comInEp, datOutEp, datInEp) \ /* Interface Association Descriptor.*/ \ - USB_DESC_BYTE (0x08), /* bLength. */ \ - USB_DESC_BYTE (0x0B), /* bDescriptorType. */ \ - USB_DESC_BYTE (comIfNum), /* bFirstInterface. */ \ - USB_DESC_BYTE (0x02), /* bInterfaceCount. */ \ - USB_DESC_BYTE (CDC_COMMUNICATION_INTERFACE_CLASS), \ - USB_DESC_BYTE (CDC_ABSTRACT_CONTROL_MODEL), \ - USB_DESC_BYTE (0x01), /* bFunctionProcotol. */ \ - USB_DESC_BYTE (0x00), /* iInterface.*/ \ + USB_DESC_INTERFACE_ASSOCIATION( \ + comIfNum, /* bFirstInterface. */ \ + 2, /* bInterfaceCount. */ \ + CDC_COMMUNICATION_INTERFACE_CLASS, /* bFunctionClass. */ \ + CDC_ABSTRACT_CONTROL_MODEL, /* bFunctionSubClass. */ \ + 1, /* bFunctionProcotol. */ \ + 0 /* iInterface. */ \ + ), \ /* CDC Interface descriptor set */ \ - CDC_IF_DESC_SET(comIfNum, datIfNum, comInEp, datOutEp, datInEp) - + CDC_IF_DESC_SET(comIfNum, datIfNum, comInEp, datOutEp, datInEp) /* Configuration Descriptor tree for a CDC.*/ static const uint8_t vcom_configuration_descriptor_data[] = { @@ -272,7 +278,7 @@ static const USBEndpointConfig ep1config = { NULL, sduInterruptTransmitted, NULL, - 0x0010, + USB_INTERRUPT_REQUEST_SIZE, 0x0000, &ep1instate, NULL, @@ -298,8 +304,8 @@ static const USBEndpointConfig ep2config = { NULL, sduDataTransmitted, sduDataReceived, - 0x0040, - 0x0040, + USB_DATA_SIZE, + USB_DATA_SIZE, &ep2instate, &ep2outstate, 2, @@ -319,7 +325,7 @@ static const USBEndpointConfig ep3config = { NULL, sduInterruptTransmitted, NULL, - 0x0010, + USB_INTERRUPT_REQUEST_SIZE, 0x0000, &ep3instate, NULL, @@ -345,8 +351,8 @@ static const USBEndpointConfig ep4config = { NULL, sduDataTransmitted, sduDataReceived, - 0x0040, - 0x0040, + USB_DATA_SIZE, + USB_DATA_SIZE, &ep4instate, &ep4outstate, 2, @@ -368,17 +374,22 @@ static void usb_event(USBDriver *usbp, usbevent_t event) { case USB_EVENT_CONFIGURED: chSysLockFromISR(); - /* Enables the endpoints specified into the configuration. - Note, this callback is invoked from an ISR so I-Class functions - must be used.*/ - usbInitEndpointI(usbp, USB_DATA_REQUEST_EP_A, &ep1config); - usbInitEndpointI(usbp, USB_INTERRUPT_REQUEST_EP_A, &ep2config); - usbInitEndpointI(usbp, USB_DATA_REQUEST_EP_B, &ep3config); - usbInitEndpointI(usbp, USB_INTERRUPT_REQUEST_EP_B, &ep4config); - - /* Resetting the state of the CDC subsystem.*/ - sduConfigureHookI(&SDU1); - sduConfigureHookI(&SDU2); + if (usbp->state == USB_ACTIVE) { + /* Enables the endpoints specified into the configuration. + Note, this callback is invoked from an ISR so I-Class functions + must be used.*/ + usbInitEndpointI(usbp, USB_INTERRUPT_REQUEST_EP_A, &ep1config); + usbInitEndpointI(usbp, USB_DATA_REQUEST_EP_A, &ep2config); + usbInitEndpointI(usbp, USB_INTERRUPT_REQUEST_EP_B, &ep3config); + usbInitEndpointI(usbp, USB_DATA_REQUEST_EP_B, &ep4config); + + /* Resetting the state of the CDC subsystem.*/ + sduConfigureHookI(&SDU1); + sduConfigureHookI(&SDU2); + } + else if (usbp->state == USB_SELECTED) { + usbDisableEndpointsI(usbp); + } chSysUnlockFromISR(); return; @@ -392,13 +403,27 @@ static void usb_event(USBDriver *usbp, usbevent_t event) { return; } +/* + * Handling messages not implemented in the default handler nor in the + * SerialUSB handler. + */ +static bool requests_hook(USBDriver *usbp) { + + if (((usbp->setup[0] & USB_RTYPE_RECIPIENT_MASK) == USB_RTYPE_RECIPIENT_INTERFACE) && + (usbp->setup[1] == USB_REQ_SET_INTERFACE)) { + usbSetupTransfer(usbp, NULL, 0, NULL); + return true; + } + return sduRequestsHook(usbp); +} + /* * USB driver configuration. */ const USBConfig usbcfg = { usb_event, get_descriptor, - sduRequestsHook, + requests_hook, NULL }; @@ -406,7 +431,7 @@ const USBConfig usbcfg = { * Serial over USB driver configuration 1. */ const SerialUSBConfig serusbcfg1 = { - &USBD1, + &USBD2, USB_DATA_REQUEST_EP_A, USB_DATA_AVAILABLE_EP_A, USB_INTERRUPT_REQUEST_EP_A @@ -416,7 +441,7 @@ const SerialUSBConfig serusbcfg1 = { * Serial over USB driver configuration 2. */ const SerialUSBConfig serusbcfg2 = { - &USBD1, + &USBD2, USB_DATA_REQUEST_EP_B, USB_DATA_AVAILABLE_EP_B, USB_INTERRUPT_REQUEST_EP_B -- cgit v1.2.3