cancel
Showing results for 
Search instead for 
Did you mean: 

usb fs cdc communication port

yang hong
Associate II
Posted on July 09, 2018 at 22:12

I am using usb port nucleo f429zi. I know I need cdc library and I want to write some protocol (for example modbus) between usb and PC, so my program in PC can communicate with controller, is it possible to use IT to listen to usb port, and when message receiving on Usb and interrupt trigger and analyze the received data, also any way to get number of bytes controller received?  

1 REPLY 1
Posted on July 10, 2018 at 02:02

Look at the data at the End-Point level? Or how you are called back with the data, which provides a buffer and size?

/**

  * @brief  USBD_CDC_DataOut

  *         Data received on non-control Out endpoint

  * @param  pdev: device instance

  * @param  epnum: endpoint number

  * @retval status

  */

static uint8_t  USBD_CDC_DataOut (USBD_HandleTypeDef *pdev, uint8_t epnum)

{

  USBD_CDC_HandleTypeDef   *hcdc = (USBD_CDC_HandleTypeDef*) pdev->pClassData;

  /* Get the received data length */

  hcdc->RxLength = USBD_LL_GetRxDataSize (pdev, epnum);

  /* USB data will be immediately processed, this allow next USB traffic being

  NAKed till the end of the application Xfer */

  if(pdev->pClassData != NULL)

  {

    ((USBD_CDC_ItfTypeDef *)pdev->pUserData)->Receive(hcdc->RxBuffer, &hcdc->RxLength);

    return USBD_OK;

  }

  else

  {

    return USBD_FAIL;

  }

}
Tips, buy me a coffee, or three.. PayPal Venmo Up vote any posts that you find helpful, it shows what's working..