ch32vct6高速usb模擬串口,數(shù)據(jù)傳輸比較慢

使用EVT\EXAM\USB\USBHS\DEVICE\SimulateCDC-HID這個(gè)例子來修改,上傳速度只能達(dá)到19MB/s,是不是我程序修改有問題?

/*********************************************************************
?*?@fn??????UART2_DataRx_Deal
?*
?*?@brief???Uart2?data?receiving?processing
?*
?*?@return??none
?*/
void?UART2_DataRx_Deal(?void?)
{
????uint16_t?temp16;
????uint32_t?remain_len;
????uint16_t?packlen;

//????/*?Serial?port?1?data?DMA?receive?processing?*/
//????NVIC_DisableIRQ(?USBHS_IRQn?);
//????NVIC_DisableIRQ(?USBHS_IRQn?);
//????UARTx_Rx_DMACurCount?=?DEF_UART2_RX_DMA_CH->CNTR;
//????if(?UARTx_Rx_DMALastCount?!=?UARTx_Rx_DMACurCount?)
//????{
//????????if(?UARTx_Rx_DMALastCount?>?UARTx_Rx_DMACurCount?)
//????????{
//????????????temp16?=?UARTx_Rx_DMALastCount?-?UARTx_Rx_DMACurCount;
//????????}
//????????else
//????????{
//????????????temp16?=?DEF_UARTx_RX_BUF_LEN?-?UARTx_Rx_DMACurCount;
//????????????temp16?+=?UARTx_Rx_DMALastCount;
//????????}
//????????UARTx_Rx_DMALastCount?=?UARTx_Rx_DMACurCount;
//????????if(?(?Uart.Rx_RemainLen?+?temp16?)?>?DEF_UARTx_RX_BUF_LEN?)
//????????{
//????????????/*?Overflow?handling?*/
//????????????/*?Save?frame?error?status?*/
//????????????DUG_PRINTF("U0_O:%08lx\n",(uint32_t)Uart.Rx_RemainLen);
//????????}
//????????else
//????????{
//????????????Uart.Rx_RemainLen?+=?temp16;
//????????}
//
//????????/*?Setting?reception?status?*/
//????????Uart.Rx_TimeOut?=?0x00;
//????}
//????NVIC_EnableIRQ(?USBHS_IRQn?);

????/*****************************************************************/
????/*?Serial?port?1?data?processing?via?USB?upload?and?reception?*/
//????if(?Uart.Rx_RemainLen?)
????{
????????if(?Uart.USB_Up_IngFlag?==?0?)
????????{
????????????/*?Calculate?the?length?of?this?upload?*/
????????????remain_len?=?Uart.Rx_RemainLen;
????????????packlen?=?0x00;
????????????if(?remain_len?>=?DEF_USBD_HS_PACK_SIZE?)
????????????{
????????????????packlen?=?DEF_USBD_HS_PACK_SIZE;
????????????}
????????????else
????????????{
????????????????if(?Uart.Rx_TimeOut?>=?Uart.Rx_TimeOutMax?)
????????????????{
????????????????????packlen?=?remain_len;
????????????????}
????????????}
????????????if(?packlen?>?(?DEF_UARTx_RX_BUF_LEN?-?Uart.Rx_DealPtr?)?)
????????????{
????????????????packlen?=?(?DEF_UARTx_RX_BUF_LEN?-?Uart.Rx_DealPtr?);
????????????}

????????????/*?Upload?serial?data?via?usb?*/
????????????if(?packlen=512?)//每次固定發(fā)送512字節(jié)
????????????{
????????????????NVIC_DisableIRQ(?USBHS_IRQn?);
????????????????NVIC_DisableIRQ(?USBHS_IRQn?);
????????????????Uart.USB_Up_IngFlag?=?0x01;
????????????????Uart.USB_Up_TimeOut?=?0x00;
????????????????USBHSD->UEP2_TX_DMA?=?(uint32_t)(uint8_t?*)&UART2_Rx_Buf[?0?];
????????????????USBHSD->UEP2_TX_LEN??=?packlen;
????????????????USBHSD->UEP2_TX_CTRL?&=?~USBHS_UEP_T_RES_MASK;
????????????????USBHSD->UEP2_TX_CTRL?|=?USBHS_UEP_T_RES_ACK;
????????????????NVIC_EnableIRQ(?USBHS_IRQn?);

????????????????/*?Calculate?the?variables?of?interest?*/
????????????????Uart.Rx_RemainLen?-=?packlen;
????????????????Uart.Rx_DealPtr?+=?packlen;
????????????????if(?Uart.Rx_DealPtr?>=?DEF_UARTx_RX_BUF_LEN?)
????????????????{
????????????????????Uart.Rx_DealPtr?=?0x00;
????????????????}

????????????????/*?Start?0-length?packet?timeout?timer?*/
????????????????if(?packlen?==?DEF_USBD_HS_PACK_SIZE?)
????????????????{
????????????????????Uart.USB_Up_Pack0_Flag?=?0x01;
????????????????}
????????????}
????????}
????????else
????????{
????????????/*?Set?the?upload?success?flag?directly?if?the?upload?is?not?successful?after?the?timeout?*/
????????????if(?Uart.USB_Up_TimeOut?>=?DEF_UARTx_USB_UP_TIMEOUT?)
????????????{
????????????????Uart.USB_Up_IngFlag?=?0x00;
????????????????USBHS_Endp_Busy[?DEF_UEP2?]?=?0;
????????????}
????????}
????}

????/*****************************************************************/
????/*?Determine?if?a?0-length?packet?needs?to?be?uploaded?(required?for?CDC?mode)?*/
//????if(?Uart.USB_Up_Pack0_Flag?)
//????{
//????????if(?Uart.USB_Up_IngFlag?==?0?)
//????????{
//????????????if(?Uart.USB_Up_TimeOut?>=?(?DEF_UARTx_RX_TIMEOUT?*?20?)?)
//????????????{
//????????????????NVIC_DisableIRQ(?USBHS_IRQn?);
//????????????????NVIC_DisableIRQ(?USBHS_IRQn?);
//????????????????Uart.USB_Up_IngFlag?=?0x01;
//????????????????Uart.USB_Up_TimeOut?=?0x00;
//????????????????USBHSD->UEP2_TX_LEN??=?0x00;
//????????????????USBHSD->UEP2_TX_CTRL?&=?~USBHS_UEP_T_RES_MASK;
//????????????????USBHSD->UEP2_TX_CTRL?|=?USBHS_UEP_T_RES_ACK;
//????????????????Uart.USB_Up_IngFlag?=?0;
//????????????????NVIC_EnableIRQ(?USBHS_IRQn?);
//????????????????Uart.USB_Up_Pack0_Flag?=?0x00;
//????????????}
//????????}
//????}
}


void?UART2_DataRx_Deal(?void?)
{
????uint16_t?temp16;
????uint32_t?remain_len;
????uint16_t?packlen;

//????/*?Serial?port?1?data?DMA?receive?processing?*/
//????NVIC_DisableIRQ(?USBHS_IRQn?);
//????NVIC_DisableIRQ(?USBHS_IRQn?);
//????UARTx_Rx_DMACurCount?=?DEF_UART2_RX_DMA_CH->CNTR;
//????if(?UARTx_Rx_DMALastCount?!=?UARTx_Rx_DMACurCount?)
//????{
//????????if(?UARTx_Rx_DMALastCount?>?UARTx_Rx_DMACurCount?)
//????????{
//????????????temp16?=?UARTx_Rx_DMALastCount?-?UARTx_Rx_DMACurCount;
//????????}
//????????else
//????????{
//????????????temp16?=?DEF_UARTx_RX_BUF_LEN?-?UARTx_Rx_DMACurCount;
//????????????temp16?+=?UARTx_Rx_DMALastCount;
//????????}
//????????UARTx_Rx_DMALastCount?=?UARTx_Rx_DMACurCount;
//????????if(?(?Uart.Rx_RemainLen?+?temp16?)?>?DEF_UARTx_RX_BUF_LEN?)
//????????{
//????????????/*?Overflow?handling?*/
//????????????/*?Save?frame?error?status?*/
//????????????DUG_PRINTF("U0_O:%08lx\n",(uint32_t)Uart.Rx_RemainLen);
//????????}
//????????else
//????????{
//????????????Uart.Rx_RemainLen?+=?temp16;
//????????}
//
//????????/*?Setting?reception?status?*/
//????????Uart.Rx_TimeOut?=?0x00;
//????}
//????NVIC_EnableIRQ(?USBHS_IRQn?);

????/*****************************************************************/
????/*?Serial?port?1?data?processing?via?USB?upload?and?reception?*/
//????if(?Uart.Rx_RemainLen?)
????{
????????if(?Uart.USB_Up_IngFlag?==?0?)
????????{
????????????/*?Calculate?the?length?of?this?upload?*/
????????????remain_len?=?Uart.Rx_RemainLen;
????????????packlen?=?0x00;
????????????if(?remain_len?>=?DEF_USBD_HS_PACK_SIZE?)
????????????{
????????????????packlen?=?DEF_USBD_HS_PACK_SIZE;
????????????}
????????????else
????????????{
????????????????if(?Uart.Rx_TimeOut?>=?Uart.Rx_TimeOutMax?)
????????????????{
????????????????????packlen?=?remain_len;
????????????????}
????????????}
????????????if(?packlen?>?(?DEF_UARTx_RX_BUF_LEN?-?Uart.Rx_DealPtr?)?)
????????????{
????????????????packlen?=?(?DEF_UARTx_RX_BUF_LEN?-?Uart.Rx_DealPtr?);
????????????}

????????????/*?Upload?serial?data?via?usb?*/
????????????if(?packlen=512?)//每次固定發(fā)送512字節(jié)
????????????{
????????????????NVIC_DisableIRQ(?USBHS_IRQn?);
????????????????NVIC_DisableIRQ(?USBHS_IRQn?);
????????????????Uart.USB_Up_IngFlag?=?0x01;
????????????????Uart.USB_Up_TimeOut?=?0x00;
????????????????USBHSD->UEP2_TX_DMA?=?(uint32_t)(uint8_t?*)&UART2_Rx_Buf[?0?];
????????????????USBHSD->UEP2_TX_LEN??=?packlen;
????????????????USBHSD->UEP2_TX_CTRL?&=?~USBHS_UEP_T_RES_MASK;
????????????????USBHSD->UEP2_TX_CTRL?|=?USBHS_UEP_T_RES_ACK;
????????????????NVIC_EnableIRQ(?USBHS_IRQn?);

????????????????/*?Calculate?the?variables?of?interest?*/
????????????????Uart.Rx_RemainLen?-=?packlen;
????????????????Uart.Rx_DealPtr?+=?packlen;
????????????????if(?Uart.Rx_DealPtr?>=?DEF_UARTx_RX_BUF_LEN?)
????????????????{
????????????????????Uart.Rx_DealPtr?=?0x00;
????????????????}

????????????????/*?Start?0-length?packet?timeout?timer?*/
????????????????if(?packlen?==?DEF_USBD_HS_PACK_SIZE?)
????????????????{
????????????????????Uart.USB_Up_Pack0_Flag?=?0x01;
????????????????}
????????????}
????????}
????????else
????????{
????????????/*?Set?the?upload?success?flag?directly?if?the?upload?is?not?successful?after?the?timeout?*/
????????????if(?Uart.USB_Up_TimeOut?>=?DEF_UARTx_USB_UP_TIMEOUT?)
????????????{
????????????????Uart.USB_Up_IngFlag?=?0x00;
????????????????USBHS_Endp_Busy[?DEF_UEP2?]?=?0;
????????????}
????????}
????}

????/*****************************************************************/
????/*?Determine?if?a?0-length?packet?needs?to?be?uploaded?(required?for?CDC?mode)?*/
//????if(?Uart.USB_Up_Pack0_Flag?)
//????{
//????????if(?Uart.USB_Up_IngFlag?==?0?)
//????????{
//????????????if(?Uart.USB_Up_TimeOut?>=?(?DEF_UARTx_RX_TIMEOUT?*?20?)?)
//????????????{
//????????????????NVIC_DisableIRQ(?USBHS_IRQn?);
//????????????????NVIC_DisableIRQ(?USBHS_IRQn?);
//????????????????Uart.USB_Up_IngFlag?=?0x01;
//????????????????Uart.USB_Up_TimeOut?=?0x00;
//????????????????USBHSD->UEP2_TX_LEN??=?0x00;
//????????????????USBHSD->UEP2_TX_CTRL?&=?~USBHS_UEP_T_RES_MASK;
//????????????????USBHSD->UEP2_TX_CTRL?|=?USBHS_UEP_T_RES_ACK;
//????????????????Uart.USB_Up_IngFlag?=?0;
//????????????????NVIC_EnableIRQ(?USBHS_IRQn?);
//????????????????Uart.USB_Up_Pack0_Flag?=?0x00;
//????????????}
//????????}
//????}
}



您好,CDC設(shè)備向PC發(fā)送數(shù)據(jù)只需要置len長度、要發(fā)送的數(shù)據(jù)以及端點(diǎn)狀態(tài)即可。測試過程中盡量避免出現(xiàn)數(shù)據(jù)拷貝/搬運(yùn)/打印的過程,建議創(chuàng)建一個(gè)固定的buff,每次發(fā)送字節(jié)數(shù)按USB端點(diǎn)最大字節(jié)數(shù)。數(shù)據(jù)發(fā)送期間不要有其他中斷或其他程序影響。其次上位機(jī)或驅(qū)動獲取IN包的時(shí)間間隔也是影響測試速率的一大因素。


張工你好我用的臺式機(jī)測試換過幾根USB數(shù)據(jù)線,上傳數(shù)據(jù)最大只能到 22.5MB/s 跟論壇里的45MB/s相差還是比較大,修改的程序:

int?main(void)
{
????SystemCoreClockUpdate();
????Delay_Init();
????USART_Printf_Init(115200);
????	
????printf("SystemClk:%d\r\n",SystemCoreClock);
????printf(?"ChipID:%08x\r\n",?DBGMCU_GetCHIPID()?);
????printf(?"Simulate?USB-CDC/HID?Device?running?on?USBHS?Controller\r\n"?);
????RCC_Configuration(?);

????/*?Tim2?init?*/
//????TIM2_Init(?);

????/*?Usart1?init?*/
????UART2_Init(?1,?DEF_UARTx_BAUDRATE,?DEF_UARTx_STOPBIT,?DEF_UARTx_PARITY?);

????/*?USB20?device?init?*/
????USBHS_RCC_Init(?);
????USBHS_Device_Init(?ENABLE?);

????while(1)
????{
????????UART2_DataRx_Deal(?);
//????????UART2_DataTx_Deal(?);
????}
}
void?UART2_DataRx_Deal(?void?)
{

????if(?Uart.USB_Up_IngFlag?==?0?)
????{


????????Uart.USB_Up_IngFlag?=?0x01;
????????Uart.USB_Up_TimeOut?=?0x00;
????????USBHSD->UEP2_TX_DMA?=?(uint32_t)(uint8_t?*)&UART2_Rx_Buf[0];//(uint32_t)(uint8_t?*)&UART2_Rx_Buf[?Uart.Rx_DealPtr?];
????????USBHSD->UEP2_TX_LEN??=?512;
????????USBHSD->UEP2_TX_CTRL?&=?~USBHS_UEP_T_RES_MASK;
????????USBHSD->UEP2_TX_CTRL?|=?USBHS_UEP_T_RES_ACK;


????}

}

這個(gè)程序只用來測試上傳了,沒有其他功能,是不是還要修改其他地方?

image.png






你好,電腦發(fā)送OUT包是固定時(shí)間間隔,當(dāng)MCU代碼運(yùn)行速度不夠快時(shí),會回復(fù)NAK,從而浪費(fèi)一次傳輸時(shí)間,而且還需要回復(fù)一包PING,如下所示image.png

所以會出現(xiàn)速度差了一半的情況,正常跑滿的抓包如下

image.png

解決辦法是提高M(jìn)CU主頻到144M,提高代碼優(yōu)化等級(MRS默認(rèn)是高的),目的是加快代碼的運(yùn)行速度,清除USB相關(guān)標(biāo)志位,回復(fù)ACK。

如果仍有問題,可以將代碼和測試軟件發(fā)到郵箱zc@wch.cn


只有登錄才能回復(fù),可以選擇微信賬號登錄

国产91精品新入口,国产成人综合网在线播放,九热这里只有精品,本道在线观看,美女视频a美女视频,韩国美女激情视频,日本美女pvp视频