cancel
Showing results for 
Search instead for 
Did you mean: 

USB receive data

MBosc.2
Associate II

Hi all,

i have a problem to receive data from USB.

use STM32L476.

As for the transmission, everything works smoothly. but when i try to send a packet i can't find the arriving data, the byte length is correct, but i don't understand where the buffer is pointing to read my data. I am attaching the code I wrote:

static int8_t CDC_Receive_FS(uint8_t* Buf, uint32_t *Len)

{

 /* USER CODE BEGIN 6 */

uint32_t received_data_size;

   USBD_CDC_SetRxBuffer(&hUsbDeviceFS, &Buf[0]);

   USBD_CDC_ReceivePacket(&hUsbDeviceFS);

   received_data_size = *Len; // my

   memcpy(aRxBufferUSB, Buf, received_data_size); // my

   CDC_Transmit_FS(Buf, *Len);         // try echo

   return (USBD_OK);

 /* USER CODE END 6 */

}

aRxBufferUSB this is my external buffer.

can someone help

thanks

2 REPLIES 2
mBosc.11
Associate II

Please ​

LViei.1
Associate

Use callback function

static int8_t CDC_Receive_FS(uint8_t* Buf, uint32_t *Len)

{

 /* USER CODE BEGIN 6 */

 USBD_CDC_SetRxBuffer(&hUsbDeviceFS, Buf);

 USBD_CDC_ReceivePacket(&hUsbDeviceFS);

 CDC_ReceiveCallBack(Buf, Len[0]);

 return (USBD_OK);

 /* USER CODE END 6 */

}

in the main.c:

void CDC_ReceiveCallBack(uint8_t *buf, uint32_t len)

{

// your code

 }

when the data arrives, automatically callback is called.

I hope this helps