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
This commit is contained in:
parent
d4397ff8ef
commit
8dc000a0f7
|
@ -37,7 +37,7 @@
|
|||
</cconfiguration>
|
||||
</storageModule>
|
||||
<storageModule moduleId="cdtBuildSystem" version="4.0.0">
|
||||
<project id="STM32F4xx-USB_CDC_DUAL.null.1373754647" name="STM32F4xx-USB_CDC_DUAL"/>
|
||||
<project id="STM32F4xx-USB_CDC_IAD.null.1373754647" name="STM32F4xx-USB_CDC_IAD"/>
|
||||
</storageModule>
|
||||
<storageModule moduleId="scannerConfiguration">
|
||||
<autodiscovery enabled="true" problemReportingEnabled="true" selectedProfileId=""/>
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<projectDescription>
|
||||
<name>STM32F4xx-USB_CDC_DUAL</name>
|
||||
<name>STM32F4xx-USB_CDC_IAD</name>
|
||||
<comment></comment>
|
||||
<projects>
|
||||
</projects>
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
||||
<launchConfiguration type="org.eclipse.cdt.debug.gdbjtag.launchConfigurationType">
|
||||
<stringAttribute key="bad_container_name" value="\STM32F4xx-USB_CDC_DUAL\debug"/>
|
||||
<stringAttribute key="bad_container_name" value="\STM32F4xx-USB_CDC_IAD\debug"/>
|
||||
<intAttribute key="org.eclipse.cdt.debug.gdbjtag.core.delay" value="1"/>
|
||||
<booleanAttribute key="org.eclipse.cdt.debug.gdbjtag.core.doHalt" value="true"/>
|
||||
<booleanAttribute key="org.eclipse.cdt.debug.gdbjtag.core.doReset" value="true"/>
|
||||
|
@ -37,11 +37,11 @@
|
|||
<stringAttribute key="org.eclipse.cdt.launch.GLOBAL_VARIABLES" value="<?xml version="1.0" encoding="UTF-8" standalone="no"?> <globalVariableList/> "/>
|
||||
<stringAttribute key="org.eclipse.cdt.launch.MEMORY_BLOCKS" value="<?xml version="1.0" encoding="UTF-8" standalone="no"?> <memoryBlockExpressionList/> "/>
|
||||
<stringAttribute key="org.eclipse.cdt.launch.PROGRAM_NAME" value="./build/ch.elf"/>
|
||||
<stringAttribute key="org.eclipse.cdt.launch.PROJECT_ATTR" value="STM32F4xx-USB_CDC_DUAL"/>
|
||||
<stringAttribute key="org.eclipse.cdt.launch.PROJECT_ATTR" value="STM32F4xx-USB_CDC_IAD"/>
|
||||
<booleanAttribute key="org.eclipse.cdt.launch.PROJECT_BUILD_CONFIG_AUTO_ATTR" value="true"/>
|
||||
<stringAttribute key="org.eclipse.cdt.launch.PROJECT_BUILD_CONFIG_ID_ATTR" value="0.588576619"/>
|
||||
<listAttribute key="org.eclipse.debug.core.MAPPED_RESOURCE_PATHS">
|
||||
<listEntry value="/STM32F4xx-USB_CDC_DUAL"/>
|
||||
<listEntry value="/STM32F4xx-USB_CDC_IAD"/>
|
||||
</listAttribute>
|
||||
<listAttribute key="org.eclipse.debug.core.MAPPED_RESOURCE_TYPES">
|
||||
<listEntry value="4"/>
|
||||
|
|
|
@ -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"
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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 **
|
||||
|
||||
|
|
|
@ -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,31 +128,31 @@ 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)
|
||||
|
||||
|
||||
/* Configuration Descriptor tree for a CDC.*/
|
||||
static const uint8_t vcom_configuration_descriptor_data[] = {
|
||||
/* Configuration Descriptor.*/
|
||||
|
@ -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();
|
||||
|
||||
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_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);
|
||||
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
|
||||
|
|
Loading…
Reference in New Issue