Skip to main content
den2life
Associate II
July 4, 2018
Question

STM32L496VG USB CDC(VCP) Receive function

  • July 4, 2018
  • 4 replies
  • 1249 views
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
This topic has been closed for replies.

4 replies

Szymon PANECKI
Senior III
July 4, 2018
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
den2life
den2lifeAuthor
Associate II
July 4, 2018
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.