cancel
Showing results for 
Search instead for 
Did you mean: 

Need help on USB device CDC VCP stack

mmensch
Associate II
Posted on June 24, 2016 at 10:52

Hello,

I built a small project to try USB device CDC VCP stack. I created the sources with CubeMX 4.15.1 for STM32L152, using the Nucleo board.

Code is running and I see the USB device with one IN, one OUT and one interrupt endpoint with Microsoft's usbview. Also I can send data using

 HAL_Delay (100);

CDC_Transmit_FS ((uint8_t*)(''123456 ''),7);

in the main while loop. It comes out on RealTerm correctly.

Now I want to receive data and get them out of the usb stack in CDC_Receive_FS in usb_cdc_if.c. I wrote a small function that copies Len data from Buf to an external fifo buffer from where they are sent to USART1. But output to RealTerm from USART1 is nonsense, has nothing to do with sent data. Now I stepped back through the various functions that finally call CDC_Receive_FS and found PCD_ReadPMA in stm32l1xx_hal_pcd.c. There the received data are copied from the buffer that is filled by usb hardware (called packet memory area) to a buffer called user memory area who's address is passed to the function. In the copying loop I inserted  copying to the mentioned fifo, so data from there is also send via USART1. And this is succesful. Data comes out at Realterm as sent.

Now I meanwhile tried for two days to find out how data are passed or buffer pointers are initialized but it is very complicated. At the moment it seems that the buffer used as user memory area in PCD_ReadPMA is not at the same address as the buffer set with USBD_CDC_SetRxBuffer which is done in CDC_Receive_FS.

Are there any USB experts online who can help me?

Thanks a lot

Martin

3 REPLIES 3
mmensch
Associate II
Posted on June 28, 2016 at 09:57

Hello,

I found the bug myself in my own code.

Sorry for posting this and thanks to all who took a look at it.

Martin

slimen
Senior
Posted on June 28, 2016 at 11:10

Hi Mr_M_from_G, 

I'm interested to know how you resolved this issue.

It may be helpful for other forum users.

 

Regards

mmensch
Associate II
Posted on June 29, 2016 at 16:28

Hello,

the Fifo I mentioned was not properly initialized. Filling data in and getting data out did not access the same memory adress area, so output had nothing to do with input. After adding initialization it worked fine.

Martin