2018-07-03 08:13 PM
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 #cdc2018-07-04 01:03 AM
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=false2018-07-04 03:36 AM
Thank you for responding. I did it as a presentation, but alas it does not work, that is takes one byte each.
2018-07-04 04:09 AM
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=false2018-07-05 06:34 PM
Then another question, where the length variable *Len is given?