AnsweredAssumed Answered

USB CDC with flow control

Question asked by aizenshtark.boaz on Feb 19, 2015
The example provided for Virtual COM over USB (STM32_USB-FS-Device_Lib_V4.0.0\Projects\Virtual_COM_Port) does not include UART flow control. The UART module is hard-coded to not use CTS/RTS, and when the UART-->USB buffer overflows, the head pointer is set to 0, running over previous data:

hw_config.c:
bool USART_Config(void)
{
     ...
     ...
     USART_BaudRate = linecoding.bitrate;
     USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None;
     USART_InitStructure.USART_Mode = USART_Mode_Rx | USART_Mode_Tx;
 
     /* Configure and enable the USART */
     STM_EVAL_COMInit(COM1, &USART_InitStructure);


     return (TRUE);
}

void USART_To_USB_Send_Data(void)
{
  
     ...
     USART_Rx_Buffer[USART_Rx_ptr_in] = USART_ReceiveData(EVAL_COM1);
     ...
  
     USART_Rx_ptr_in++;
  
     /* To avoid buffer overflow */
     if(USART_Rx_ptr_in == USART_RX_DATA_SIZE)
     {
         USART_Rx_ptr_in = 0;     // <-- no flow control
     }
}

Questions:
       
  • Is there a sample code which does implement UART flow control?
  •    
  • How should the example code be modified to support this?
  •    
  • Will switching to Cube's HAL help in this case?



Outcomes