AnsweredAssumed Answered

Broken usbd_cdc_if_template in USBlib v2.1?

Question asked by maurer.benjamin on May 12, 2014
Latest reply on May 13, 2014 by sung.chen_chung
Hello everyone.

I'm trying to get USB VCP communication to my STM32F107 working (using USB to communicate via minicom with my µc).
Looking at the example and the STM32_USB_Device_Library of the STM32_USB-Host-Device_Lib_V2.1.0 package, I saw the template but the code doesn't seem to make sense.

usbd_cdc_if_template.c:

/**
  * @brief  TEMPLATE_DataTx
  *         CDC received data to be send over USB IN endpoint are managed in
  *         this function.
  * @param  Buf: Buffer of data to be sent
  * @param  Len: Number of data to be sent (in bytes)
  * @retval Result of the opeartion: USBD_OK if all operations are OK else USBD_FAIL
  */
static uint16_t TEMPLATE_DataTx (uint8_t* Buf, uint32_t Len)
{
  /* Get the data to be sent */
  for (i = 0; i < Len; i++)
  {
    /* APP_Rx_Buffer[APP_Rx_ptr_in] = XXX_ReceiveData(XXX); */
  }
 
  /* Increment the in pointer */
  APP_Rx_ptr_in++;
   
  /* To avoid buffer overflow */
  if(APP_Rx_ptr_in == APP_RX_DATA_SIZE)
  {
    APP_Rx_ptr_in = 0;
  
   
  return USBD_OK;
}

So APP_Rx_ptr_in is incremented after the loop? And the first parameter, Buf, is never touched?
Shouldn't it be more like:
APP_Rx_Buffer[APP_Rx_ptr_in++] = XXX_ReceiveData(XXX);

And there might be more to be found. Just makes me question how reliable the code is. Or maybe I just don't understand the intention of this routine.

Would also be happy about any further resources about using the STM32F1XX's USB CDC capabilities.

Regards,
Ben

PS: Also, please STM, use less convoluted site layouts and create a modern, usable community and not this antiquated one-tiered
90ies forum, where information can hardly be found again.

Outcomes