cancel
Showing results for 
Search instead for 
Did you mean: 

VCP with STM32

hisham23
Associate II
Posted on June 01, 2012 at 15:43

Hello,

I am working on virtual serial port to communicate between computer and device through usb.

So i downloaded ''STM32F105/7,STM32F2 and STM32F4 USB on-the-go Host and device library.''  from http://www.st.com/stonline/stappl/resourceSelector/app?page=resourceSelector&doctype=FIRMWARE&ClassID=1734

And i selected vcp from project lists, and start reading the code.

I found that the main application only contains initialization of the hardware and the interrupts.

So the code that is sending data is working in the interrupt, but i cannot find the portion that is responsible to send data... Please if any one can explain me the flow of the program.

Note that i read the manuals from ST concerning this project but i didn't get the point, because they wrote 2 papers only about this application.

Regards,

Hisham
12 REPLIES 12
hisham23
Associate II
Posted on June 06, 2012 at 14:36

While i am reading the data sheet of STM32F10xxx ''http://www.keil.com/dd/docs/DATASHTS/ST/STM32F10xxx.PDF'' i found that the NVIC of this series of microcontroller does not have interrupt vectors for OTG_HS_EP1_OUT_IRQHandler, and OTG_HS_EP1_IN_IRQHandler.

This is the interrupt that is enabled in vcp project:


void
USB_OTG_BSP_EnableInterrupt(USB_OTG_CORE_HANDLE *pdev)

{

NVIC_InitTypeDef NVIC_InitStructure; 


NVIC_PriorityGroupConfig(NVIC_PriorityGroup_1);

#ifdef USE_USB_OTG_HS 

NVIC_InitStructure.NVIC_IRQChannel = OTG_HS_IRQn;

#else

NVIC_InitStructure.NVIC_IRQChannel = OTG_FS_IRQn; 

#endif

NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 1;

NVIC_InitStructure.NVIC_IRQChannelSubPriority = 3;

NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;

NVIC_Init(&NVIC_InitStructure); 

#ifdef USB_OTG_HS_DEDICATED_EP1_ENABLED

NVIC_PriorityGroupConfig(NVIC_PriorityGroup_1);

NVIC_InitStructure.NVIC_IRQChannel = OTG_HS_EP1_OUT_IRQn;

NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 1;

NVIC_InitStructure.NVIC_IRQChannelSubPriority = 2;

NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;

NVIC_Init(&NVIC_InitStructure); 


NVIC_PriorityGroupConfig(NVIC_PriorityGroup_1);

NVIC_InitStructure.NVIC_IRQChannel = OTG_HS_EP1_IN_IRQn;

NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 1;

NVIC_InitStructure.NVIC_IRQChannelSubPriority = 1;

NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;

NVIC_Init(&NVIC_InitStructure); 

#endif

}

From line number 15 to line number 30 this code will not be excuted since i am using STM32F107 and it does not contain interrupt vector for OUT and IN endpoints which are enabled. So the only interrupt that can be enabled is

OTG_FS_IRQn

. So now i am back to zero point, i don't know how to get and send data through usb. Please share your ideas. Regards, Hisham
cordonnier
Associate II
Posted on September 16, 2013 at 21:23

I know the thread is old but I just wanted to document what I found by working with the library on this thread, because the example code is very misleading. Even though the DCD_EP_Tx() function is putting only one packet in the FIFO in the VCP example, this is an incorrect behaviour, because the function DCD_EP_Tx() can handle transfers bigger than one packet and is splitting the buffer given as parameter in several packets if the buffer size is greater than the max packet size.

The function DCD_EP_Tx() is used in this example code only with messages smaller than the packet size, and this has therefore no incidence in this example, but should not be used to develop other USB classes.

The ''DataIn'' callback is called by the OTG library at the end of a full transfer(several packets), and not at the end of each packet transmission. Unfortunately, in the code provided in the ST example the code in ''DataIn'' is checking the value of the ''in'' pointer set by the application, and some packets are therefore sent from the DataIn callback if the application initiated another bulk-in transfer during the current bulk-in transfer, and some others from DCD_EP_Tx(), which works but is clearly not logical.