cancel
Showing results for 
Search instead for 
Did you mean: 

STM32L496VG USB CDC(VCP) Receive function

den2life
Associate II
Posted on July 04, 2018 at 05:13

Hello guys. I configure the CDC on CubeMX. But the function CDC_Receive_FS receive1 byte each. That is, if I transmit 12345678 then I receive only 8.

I have to modify the function like this:

uint8_t UserDataReceive[100];
uint16_t i = 0;
static int8_t CDC_Receive_FS(uint8_t* Buf, uint32_t *Len)
{
/* USER CODE BEGIN 6 */
USBD_CDC_SetRxBuffer(&hUsbDeviceFS, &Buf[0]);
memcpy(UserDataReceive + i, Buf, *Len);
++i;
// 
USBD_CDC_ReceivePacket(&hUsbDeviceFS);
return (USBD_OK);
/* USER CODE END 6 */
}�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?

In an array uint8_t UserRxBufferFS[APP_RX_DATA_SIZE] I receive such bytes when sending 12345678:

[0] - 0x38

[1] - 0x41

[2] - 0x6D.

Why? Please help!

I would like to take all of the transmitted packet, and not one byte processing. Can somewhere the settings for the life of the package are available?

#stm32l #vcp #cdc
4 REPLIES 4
Szymon PANECKI
Senior III
Posted on July 04, 2018 at 10:03

Hello,

I use such implementation to receive more than 1 byte:

static

int8_t

CDC_Receive_FS

(uint8_t*

Buf

, uint32_t *Len)

{

/* USER CODE BEGIN 6 */

USBD_CDC_SetRxBuffer

(&

hUsbDeviceFS

, &

Buf

[

0

]);

USBD_CDC_ReceivePacket

(&

hUsbDeviceFS

);

strlcpy

(

UserRxBuffer

,

Buf

, (*Len) +

1

);

return

(USBD_OK);

/* USER CODE END 6 */

}

For more information how to implement USB VCP on STM32L4 please refer to attached presentation.

Regards

Szymon

________________

Attachments :

STM32L4 USB VCP.pdf : https://st--c.eu10.content.force.com/sfc/dist/version/download/?oid=00Db0000000YtG6&ids=0680X000006HxS9&d=%2Fa%2F0X0000000ayC%2FR45mAnXpX78G1UNpKU_KM9.ALyNWymTWAWKRAR7aSps&asPdf=false
Posted on July 04, 2018 at 10:36

Thank you for responding. I did it as a presentation, but alas it does not work, that is takes one byte each.

Posted on July 04, 2018 at 11:09

And yet, I noticed that the program CubeMX does not generate the code correctly. The whole day was tormented, but theUSB did not start at all, the computer did not see the device. After a long search for errors, noticed that the program hangs on HAL_Delay (50), it turns out SysTick was not initialized. Added lines in SystemClock_Config and it worked, USB was defined.

Maybe the program

CubeMX

is not correctly generated, and I received only one byte and not the whole package in the array.

I attach the whole project to the message.

________________

Attachments :

USB Virtual Comport.rar : https://st--c.eu10.content.force.com/sfc/dist/version/download/?oid=00Db0000000YtG6&ids=0680X000006HxRu&d=%2Fa%2F0X0000000ayB%2FF1i8roxhhBc24tytSglChu2PSOMaIcsZjY0uDpiIU0U&asPdf=false
Posted on July 06, 2018 at 01:34

Then another question, where the length variable *Len is given?