Skip to main content
Visitor II
March 2, 2021
Question

USB receive data

  • March 2, 2021
  • 2 replies
  • 1421 views

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

    This topic has been closed for replies.

    2 replies

    Visitor II
    March 3, 2021

    Please ​

    Visitor II
    March 8, 2021

    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