STM32 USB HOST 驱动FT232 USB转串
2
闲来无事,测试了个HOST驱动FT232,暂时只测试了个回环
获取枚举信息,通过短接FT232 TX和RX ,开始数据回环测试。
/*** @brief Initialize the transmit and receive buffer and its parameter* @param None* @retval None*/
static void CDC_InitTxRxParam(void)
{/*Initialize the Transmit buffer and its parameter*/CDC_TxParam.CDCState = CDC_IDLE;CDC_TxParam.DataLength = 0;CDC_TxParam.pRxTxBuff = TxBuf;/*Initialize the Receive buffer and its parameter*/CDC_RxParam.CDCState = CDC_IDLE;CDC_RxParam.DataLength = 0;CDC_RxParam.pFillBuff = RxBuf; CDC_RxParam.pEmptyBuff = RxBuf;CDC_RxParam.BufferLen = sizeof(RxBuf);
}/*** @brief This is a call back function from cdc core layer to redirect the * received data on the user out put system* @param cdc_Data: type of USBH_CDCXfer_TypeDef* @retval None*/
static void CDC_ReceiveData(CDC_Xfer_TypeDef *cdc_Data)
{uint8_t *ptr; if(cdc_Data->pEmptyBuff < cdc_Data->pFillBuff){ptr = cdc_Data->pFillBuff;*ptr = 0x00;/* redirect the received data on the user out put system */UserCb.Receive(cdc_Data->pEmptyBuff, cdc_Data->DataLength);cdc_Data->pFillBuff = cdc_Data->pEmptyBuff ; cdc_Data->DataLength = 0; /*Reset the data length to zero*/}
}/*** @brief This function send data to the device.* @param fileName : name of the file * @retval the filestate will be returned * FS_SUCCESS : returned to the parent function when the file length become to zero*/
void CDC_SendData(uint8_t *data, uint16_t length)
{if(CDC_TxParam.CDCState == CDC_IDLE){CDC_TxParam.pRxTxBuff = data; CDC_TxParam.DataLength = length;CDC_TxParam.CDCState = CDC_SEND_DATA; }
}/*** @brief This function send data to the device.* @param fileName : name of the file * @retval the filestate will be returned * FS_SUCCESS : returned to the parent function when the file length become to zero*/
void CDC_StartReception( USB_OTG_CORE_HANDLE *pdev)
{RX_Enabled = 1;
}/*** @brief This function send data to the device.* @param fileName : name of the file * @retval the filestate will be returned * FS_SUCCESS : returned to the parent function when the file length become to zero*/
void CDC_StopReception( USB_OTG_CORE_HANDLE *pdev)
{RX_Enabled = 0; USB_OTG_HC_Halt(pdev, CDC_Machine.CDC_DataItf.hc_num_in);USBH_Free_Channel (pdev,CDC_Machine.CDC_DataItf.hc_num_in);
}