本帖最后由 jasoji 于 2017-7-18 14:38 编辑
CDC_Receive_FS这样写,在大量数据环回还是有点问题的。
改成这样就没问题↓
static int8_t CDC_Receive_FS (uint8_t* Buf, uint32_t *Len)
{
/* USER CODE BEGIN 6 */
USBD_CDC_SetRxBuffer(&hUsbDeviceFS, &Buf[0]);
USBD_CDC_ReceivePacket(&hUsbDeviceFS);
if(UserTxBufPtrIn+*Len<=APP_TX_DATA_SIZE){ //UserTxBufferFS未满,续上len长度数据
memcpy((uint8_t*)(UserTxBufferFS+UserTxBufPtrIn),Buf,*Len);
UserTxBufPtrIn+=*Len;
} else { //满了,写完后面回前面继续写
uint16_t lenBack, lenFront;
lenBack = APP_RX_DATA_SIZE-UserTxBufPtrIn;//后面剩多少
lenFront = *Len-lenBack;//前面继续写多少
memcpy((uint8_t*)(UserTxBufferFS+UserTxBufPtrIn), Buf, lenBack);
memcpy((uint8_t*)(UserTxBufferFS), (uint8_t*)(Buf+lenBack), lenFront);
UserTxBufPtrIn=lenFront;
}
return (USBD_OK);
/* USER CODE END 6 */
}
然后main_loop那里改这个
if(UserTxBufPtrOut != UserTxBufPtrIn) {
if(UserTxBufPtrOut<UserTxBufPtrIn)
{
uint16_t len;
len = UserTxBufPtrIn-UserTxBufPtrOut;
CDC_Transmit_FS((uint8_t*)(UserTxBufferFS+UserTxBufPtrOut), len);
UserTxBufPtrOut+=len;
} else {
uint16_t lenBack, lenFront;
lenBack = APP_RX_DATA_len-UserTxBufPtrOut;
lenFront = UserTxBufPtrIn;
CDC_Transmit_FS((uint8_t*)(UserTxBufferFS+UserTxBufPtrOut), lenBack);
CDC_Transmit_FS((uint8_t*)(UserTxBufferFS), lenFront);
UserTxBufPtrOut=UserTxBufPtrIn;
}
}
|