Skip to main content
baranovay
Associate
Question

Multiple USB CDC (USB IAD). How?

Posted on June 10, 2010 at 07:46

Multiple USB CDC (USB IAD). How?

#iad #cdc #stm32f103 #dual-cdc-with-stm32l152 #usb-cdc-duart
This topic has been closed for replies.

24 replies

michele77
Associate II
Posted on July 27, 2012 at 11:06

Hello everyone,

I would also be interested to implement a FT2232 or FT4232 like functionality (DUART, QUART) with STM32.. an experienced developer told me he thinks it's impossible because there aren't enough endpoints.

Any comments from the official STM32 support forum?

Are there any pointers to source code and/or application notes that would suggest how to do this?

Best regards,

Michele

tsuneo
Associate II
Posted on July 27, 2012 at 16:39

> an experienced developer told me he thinks it's impossible because there aren't enough endpoints.

One CDC function requires 2 IN / 1 OUT endpoints (interrupt IN/ bulk IN/ bulk OUT), other than the default EP.

Available endpoints of each STM32F family are,

STM32F102/103

- FS Device core: 7 IN / 7 OUT

STM32F105/107

- OTG_FS: 3 IN / 3 OUT

STM32F2xx/4xx

- OTG_FS: 3 IN / 3 OUT

- OTG_HS: 5 IN / 5 OUT

STM32F102/103 - 3x CDC composite

STM32F105/107 - just one CDC

STM32F2xx/4xx - 2x CDC composite on OTG_HS

Starting from ST's example, it isn't so hard, to make them a CDC composite device,

if you would know where and how to touch on the source code :)

I can tell you where and how.

Do you want to make one with me?

Tsuneo

michele77
Associate II
Posted on July 27, 2012 at 18:06

Hello Tsuneo,

I could not hope for a better answer... I was reading your posts about Silabs and others and trying to understand what way to tackle the problem. The single CDC example works fine for me.

I would surely want to do this with you and I would also be willing to do this open source if you think it's appropriate.

I really need this functionality from my STM32F102/3xB.

The only problem I see is the significance of my contribution compared to yours!

I don't have much experience with STM32 and I use open source tools (CodeSourcery+Eclipse) to develop.. even though I am willing to spend a bit of money into a commercial suite if you think it's necessary.

Please let me know how we can proceed from here. My email address is michele.bavaro at gmail.

All the best,

Michele

Tesla DeLorean
Guru
Posted on July 27, 2012 at 19:35

I can tell you where and how. Do you want to make one with me?

It would be of general usefulness, I can see a couple of potential applications.

Tips, Buy me a coffee, or three.. PayPal Venmo (See Profile) Up vote any posts that you find helpful, it shows what's working..
tsuneo
Associate II
Posted on July 27, 2012 at 21:19

The original post was too long to process during our migration. Please click on the provided URL to read the original post. https://st--c.eu10.content.force.com/sfc/dist/version/download/?oid=00Db0000000YtG6&ids=0680X000006I6bc&d=%2Fa%2F0X0000000brf%2FPkDyba1OTBM8zIARSqdJmVQwC2E.uJnnFL8_iH25GXo&asPdf=false
tsuneo
Associate II
Posted on July 27, 2012 at 23:08

The original post was too long to process during our migration. Please click on the provided URL to read the original post. https://st--c.eu10.content.force.com/sfc/dist/version/download/?oid=00Db0000000YtG6&ids=0680X000006I6bh&d=%2Fa%2F0X0000000brg%2FgnytwOnLExb6NzIMfocAxqgEgXaBdii8kEmyairNx68&asPdf=false
Tesla DeLorean
Guru
Posted on July 27, 2012 at 23:34

I had to add :

#define CDC_V1_10 0x0110

#define USB_ENDPOINT_OUT(addr)                 ((addr) | 0x00)

#define USB_ENDPOINT_IN(addr)                  ((addr) | 0x80)

Keil is still choking on the following with a ''Error #146 Too many initializer values''

   IAD_CDC_IF_DESC_SET( USB_CDC_CIF_NUM0, USB_CDC_DIF_NUM0, USB_ENDPOINT_IN(1), USB_ENDPOINT_OUT(2), USB_ENDPOINT_IN(2) ),

Tips, Buy me a coffee, or three.. PayPal Venmo (See Profile) Up vote any posts that you find helpful, it shows what's working..
michele77
Associate II
Posted on July 28, 2012 at 11:31

The original post was too long to process during our migration. Please click on the provided URL to read the original post. https://st--c.eu10.content.force.com/sfc/dist/version/download/?oid=00Db0000000YtG6&ids=0680X000006I6bm&d=%2Fa%2F0X0000000brh%2FJ3lZIf6d6RgH7VoTomHlC3rMXe269v7CzBNws.utHOk&asPdf=false
tsuneo
Associate II
Posted on July 29, 2012 at 12:05

Hi clive1,

Thanks to your interest to our project!

mbavaro,

The modification code on my above post is not enough. I made more change on more source files. I attached current version of source code to this post.

The device appears as 3x CDC composite device on Windows successfully.

Current development state is,

- Descriptors and INF : finished

- Bulk IN/OUT endpoints : not touch yet

- Class requests and interrupt EPs: not touch yet

I'm testing this code on Olimex STM32-P I took STM3210B_EVAL option as the base setting. STM3210B_EVAL assigns PD9 for DISCONNECT port. Olimex STM32-P103 applies PC

To make this difference, platform_config.h was modified as follows,

platform_config.h

/* Define the STM32F10x hardware depending on the used evaluation board */

#ifdef USE_STM3210B_EVAL

#ifdef OLIMEX_STM32_P103

#define USB_DISCONNECT GPIOC

#define USB_DISCONNECT_PIN GPIO_Pin_11

#define RCC_APB2Periph_GPIO_DISCONNECT RCC_APB2Periph_GPIOC

#else

#define USB_DISCONNECT GPIOD

#define USB_DISCONNECT_PIN GPIO_Pin_9

#define RCC_APB2Periph_GPIO_DISCONNECT RCC_APB2Periph_GPIOD

#endif

#define EVAL_COM1_IRQHandler USART1_IRQHandler

Also, OLIMEX_STM32_P103 macro was added to Project > Options > C/C++ > Preprocessor Symbols: Define, over macros of original STM3210B_EVAL setting (I'm using Keil).

USE_STDPERIPH_DRIVER, STM32F10X_MD, USE_STM3210B_EVAL, OLIMEX_STM32_P103

To fit DISCONNECT port to your board, you'll need similar modification.

Tsuneo

________________

Attachments :

Virtual_COM_Port_x3_r1.zip : https://st--c.eu10.content.force.com/sfc/dist/version/download/?oid=00Db0000000YtG6&ids=0680X000006I15i&d=%2Fa%2F0X0000000biF%2F2lC9XEy6QTQfHdTP77j3PvDzqPmzkXh..r8E2F0tNwM&asPdf=false
michele77
Associate II
Posted on July 30, 2012 at 15:39

Hello Tsuneo,

Please call me Michele :) I modified a bit more the code.. 1) I duplicated the EP callbacks and I now have EP2_IN_Callback EP4_IN_Callback EP6_IN_Callback EP2_OUT_Callback EP4_OUT_Callback EP6_OUT_Callback defined like this:

void
EP2_IN_Callback (
void
) {
uint16_t USB_Tx_ptr;
uint16_t USB_Tx_length;
if
(CDC1_Tx_State == 1) {
if
(VCP1_Rx_length == 0) {
CDC1_Tx_State = 0;
} 
else
{
if
(VCP1_Rx_length > VIRTUAL_COM_PORT_DATA_SIZE) {
USB_Tx_ptr = VCP1_Rx_ptr_out;
USB_Tx_length = VIRTUAL_COM_PORT_DATA_SIZE;
VCP1_Rx_ptr_out += VIRTUAL_COM_PORT_DATA_SIZE;
VCP1_Rx_length -= VIRTUAL_COM_PORT_DATA_SIZE;
} 
else
{
USB_Tx_ptr = VCP1_Rx_ptr_out;
USB_Tx_length = VCP1_Rx_length;
VCP1_Rx_ptr_out += VCP1_Rx_length;
VCP1_Rx_length = 0;
}
UserToPMABufferCopy(&VCP1_Rx_Buffer[USB_Tx_ptr], ENDP2_TXADDR, USB_Tx_length);
SetEPTxCount(ENDP2, USB_Tx_length);
SetEPTxValid(ENDP2);
}
}
}

and

void
EP2_OUT_Callback(
void
) {
uint16_t USB_Rx_Cnt;
/* Get the received data buffer and update the counter */
USB_Rx_Cnt = USB_SIL_Read(EP2_OUT, USB_Rx_Buffer);
/* USB data will be immediately processed, this allow next USB traffic being 
NAKed till the end of the USART Xfer */
USB_To_VCP1_Send_Data(USB_Rx_Buffer, USB_Rx_Cnt);
/* Enable the receive of data on EP2 */
SetEPRxValid(ENDP2);
}

similarly I modified Handle_USBAsynchXfer()as follows:

void
Handle_USBAsynchXfer (
void
) {
uint16_t USB_Tx_ptr;
uint16_t USB_Tx_length;
// -------------------- VCP1
if
(CDC1_Tx_State != 1) {
if
(VCP1_Rx_ptr_out == VCP1_Rx_DATA_SIZE) {
VCP1_Rx_ptr_out = 0;
}
if
(VCP1_Rx_ptr_out == VCP1_Rx_ptr_in) {
CDC1_Tx_State = 0;
// return;
} 
else
{
if
(VCP1_Rx_ptr_out > VCP1_Rx_ptr_in) { 
/* rollback */
VCP1_Rx_length = VCP1_Rx_DATA_SIZE - VCP1_Rx_ptr_out;
} 
else
{
VCP1_Rx_length = VCP1_Rx_ptr_in - VCP1_Rx_ptr_out;
}
if
(VCP1_Rx_length > VIRTUAL_COM_PORT_DATA_SIZE) {
USB_Tx_ptr = VCP1_Rx_ptr_out;
USB_Tx_length = VIRTUAL_COM_PORT_DATA_SIZE;
VCP1_Rx_ptr_out += VIRTUAL_COM_PORT_DATA_SIZE;
VCP1_Rx_length -= VIRTUAL_COM_PORT_DATA_SIZE;
} 
else
{
USB_Tx_ptr = VCP1_Rx_ptr_out;
USB_Tx_length = VCP1_Rx_length;
VCP1_Rx_ptr_out += VCP1_Rx_length;
VCP1_Rx_length = 0;
}
CDC1_Tx_State = 1;
UserToPMABufferCopy(&VCP1_Rx_Buffer[USB_Tx_ptr], ENDP2_TXADDR, USB_Tx_length);
SetEPTxCount(ENDP2, USB_Tx_length);
SetEPTxValid(ENDP2);
}
}
// -------------------- VCP2
if
(CDC2_Tx_State != 1) {
if
(VCP2_Rx_ptr_out == VCP2_Rx_DATA_SIZE) {
VCP2_Rx_ptr_out = 0;
}
if
(VCP2_Rx_ptr_out == VCP2_Rx_ptr_in) {
CDC2_Tx_State = 0;
// return;
} 
else
{
if
(VCP2_Rx_ptr_out > VCP2_Rx_ptr_in) { 
/* rollback */
VCP2_Rx_length = VCP2_Rx_DATA_SIZE - VCP2_Rx_ptr_out;
} 
else
{
VCP2_Rx_length = VCP2_Rx_ptr_in - VCP2_Rx_ptr_out;
}
if
(VCP2_Rx_length > VIRTUAL_COM_PORT_DATA_SIZE) {
USB_Tx_ptr = VCP2_Rx_ptr_out;
USB_Tx_length = VIRTUAL_COM_PORT_DATA_SIZE;
VCP2_Rx_ptr_out += VIRTUAL_COM_PORT_DATA_SIZE;
VCP2_Rx_length -= VIRTUAL_COM_PORT_DATA_SIZE;
} 
else
{
USB_Tx_ptr = VCP2_Rx_ptr_out;
USB_Tx_length = VCP2_Rx_length;
VCP2_Rx_ptr_out += VCP2_Rx_length;
VCP2_Rx_length = 0;
}
CDC2_Tx_State = 1;
UserToPMABufferCopy(&VCP2_Rx_Buffer[USB_Tx_ptr], ENDP4_TXADDR, USB_Tx_length);
SetEPTxCount(ENDP4, USB_Tx_length);
SetEPTxValid(ENDP4);
}
}
// -------------------- VCP3
if
(CDC3_Tx_State != 1) {
if
(VCP3_Rx_ptr_out == VCP3_Rx_DATA_SIZE) {
VCP3_Rx_ptr_out = 0;
}
if
(VCP3_Rx_ptr_out == VCP3_Rx_ptr_in) {
CDC3_Tx_State = 0;
// return;
} 
else
{
if
(VCP3_Rx_ptr_out > VCP3_Rx_ptr_in) { 
/* rollback */
VCP3_Rx_length = VCP3_Rx_DATA_SIZE - VCP3_Rx_ptr_out;
} 
else
{
VCP3_Rx_length = VCP3_Rx_ptr_in - VCP3_Rx_ptr_out;
}
if
(VCP3_Rx_length > VIRTUAL_COM_PORT_DATA_SIZE) {
USB_Tx_ptr = VCP3_Rx_ptr_out;
USB_Tx_length = VIRTUAL_COM_PORT_DATA_SIZE;
VCP3_Rx_ptr_out += VIRTUAL_COM_PORT_DATA_SIZE;
VCP3_Rx_length -= VIRTUAL_COM_PORT_DATA_SIZE;
} 
else
{
USB_Tx_ptr = VCP3_Rx_ptr_out;
USB_Tx_length = VCP3_Rx_length;
VCP3_Rx_ptr_out += VCP3_Rx_length;
VCP3_Rx_length = 0;
}
CDC3_Tx_State = 1;
UserToPMABufferCopy(&VCP3_Rx_Buffer[USB_Tx_ptr], ENDP6_TXADDR, USB_Tx_length);
SetEPTxCount(ENDP6, USB_Tx_length);
SetEPTxValid(ENDP6);
}
}
}

There something else to modify I think... in fact I don't see where the interrupt endpoints are handled at all! It still does not work completely but on Windows7 64bit I can see this: 0690X000006051IQAQ.png Please note that I did not install any driver.. this comes up by default. I tried linking those serial ports to the ST VCP driver with no luck.. I guess Win7 64bit is picky. On Linux, when plugging my device I have the following:

[ 074217] usb 2-1.2: new full-speed USB device number 3 using ehci_hcd

[ 196449] cdc_acm 2-1.2:1.0: ttyACM0: USB ACM device [ 196945] cdc_acm 2-1.2:1.2: ttyACM1: USB ACM device [ 197586] cdc_acm 2-1.2:1.4: ttyACM2: USB ACM device [ 197992] usbcore: registered new interface driver cdc_acm [ 197997] cdc_acm: USB Abstract Control Model driver for USB modems and ISDN adapters and three virtual COM ports appear at ttyACM0, ttyACM1, ttyACM2. But nothing flows through them. Getting there? Cheers, Michele