| 上位机写入测试代码: 
 MCU代码:// winusb_demo.cpp : 此文件包含 "main" 函数。程序执行将在此处开始并结束。
//
#include <iostream>
#include <chrono>
#include <format>
#include <thread>
#include "CWinUSBProxy.h"
#define BUF_SIZE            1024
int main()
{
    std::cout << "Hello AT32!\n";
    CWinUSBProxy winUSBDevice("{13EB360B-BC1E-46CB-AC8B-EF3DA47B4062}");
    winUSBDevice.InitWinUsbDevicePath();
    winUSBDevice.OpenWinUsb();
    winUSBDevice.GetUSBDeviceSpeed();
    winUSBDevice.QueryDeviceEndpoints();
    while (true)
    {
        int readCount = 0;
        auto startTime = std::chrono::steady_clock::now();
        /** 进行数据发包统计,发送1MB数据包,统计速率 */
        for (int i = 0; i < 1024; i++)
        {
#if 0
            BOOL status = winUSBDevice.ReadFromBulkEndpoint(BUF_SIZE);
#else
            BOOL status = winUSBDevice.WriteToBulkEndpoint(BUF_SIZE);
#endif
            /** 正确发包计数 */
            if (status)
                readCount++;
        }
        auto entTime = std::chrono::steady_clock::now();
        /** 计算速率 */
        auto dr_s = std::chrono::duration<double, std::milli>(entTime - startTime).count();
        auto  speed = floor(readCount * 1000 / dr_s) ;
        /** 输出统计信息 */
        std::cout << std::format("transter speed:{} KB/S",speed) << std::endl;
        /** 等待1秒 */
        std::this_thread::sleep_for(std::chrono::milliseconds(1000));
    }
    
    system("pause");
}
 /**
  **************************************************************************
  * [url=home.php?mod=space&uid=288409]@file[/url]     main.c
  * @brief    main program
  **************************************************************************
  *                       Copyright notice & Disclaimer
  *
  * The software Board Support Package (BSP) that is made available to
  * download from Artery official website is the copyrighted work of Artery.
  * Artery authorizes customers to use, copy, and distribute the BSP
  * software and its related documentation for the purpose of design and
  * development in conjunction with Artery microcontrollers. Use of the
  * software is governed by this copyright notice and the following disclaimer.
  *
  * THIS SOFTWARE IS PROVIDED ON "AS IS" BASIS WITHOUT WARRANTIES,
  * GUARANTEES OR REPRESENTATIONS OF ANY KIND. ARTERY EXPRESSLY DISCLAIMS,
  * TO THE FULLEST EXTENT PERMITTED BY LAW, ALL EXPRESS, IMPLIED OR
  * STATUTORY OR OTHER WARRANTIES, GUARANTEES OR REPRESENTATIONS,
  * INCLUDING BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY,
  * FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT.
  *
  **************************************************************************
  */
#include "at32f402_405_board.h"
#include "at32f402_405_clock.h"
#include "usb_conf.h"
#include "usb_core.h"
#include "usbd_int.h"
#include "winusb_class.h"
#include "winusb_desc.h"
/** @addtogroup AT32F405_periph_examples
  * @{
  */
/** @addtogroup 405_USB_device_custom_hid USB_device_custom_hid
  * @{
  */
/* usb global struct define */
otg_core_type otg_core_struct;
#if defined ( __ICCARM__ ) /* iar compiler */
  #pragma data_alignment=4
#endif
#define BUF_SIZE                                                512
uint8_t usb_buffer[BUF_SIZE];
void usb_clock48m_select(usb_clk48_s clk_s);
void usb_gpio_config(void);
void usb_low_power_wakeup_config(void);
void button_exint_init(void);
void init_buffer();
/**
  * @brief  main function.
  * @param  none
  * @retval none
  */
int main(void)
{
        uint16_t data_len;
        uint8_t send_zero_packet = 0;
        
  nvic_priority_group_config(NVIC_PRIORITY_GROUP_4);
  system_clock_config();
  at32_board_init();
    /* usb gpio config */
  usb_gpio_config();
#ifdef USB_LOW_POWER_WAKUP
  crm_periph_clock_enable(CRM_PWC_PERIPH_CLOCK, TRUE);
  button_exint_init();
  usb_low_power_wakeup_config();
#endif
  /* enable otg clock */
  crm_periph_clock_enable(OTG_CLOCK, TRUE);
  /* select usb 48m clcok source */
  usb_clock48m_select(USB_CLK_HEXT);
  /* enable otg irq */
  nvic_irq_enable(OTG_IRQ, 0, 0);
        
        /* Initialization buffer */
        init_buffer();
  /* init usb */
        usbd_init(&otg_core_struct,
                                                USB_HIGH_SPEED_CORE_ID,
                                                USB_ID,
                                                &winusb_class_handler,
                                                &winusb_desc_handler);
                                                
        
                
  while(1)
  {
                if(usbd_connect_state_get(&otg_core_struct.dev) == USB_CONN_STATE_CONFIGURED)
                {
                #if 0
                        usb_winusb_send_data(&otg_core_struct.dev,usb_buffer,BUF_SIZE);
                #else
                        uint32_t count = usb_winusb_get_rxdata(&otg_core_struct.dev,usb_buffer);
                        //printf("count:%d\r\n",count);
                #endif
                }
  }
}
测试结果:
 
   
 这个写入速度15MB/S,这个速度是在注释掉了usb_winusb_get_rxdata里的内存复制过程,代码如下
 
 开启内存复制,大概速度在8-9MB/S左右。/**
  * @brief  usb device class rx data process
  * @param  udev: to the structure of usbd_core_type
  * @param  recv_data: receive buffer
  * @retval receive data len
  */
uint16_t usb_winusb_get_rxdata(void *udev, uint8_t *recv_data)
{
  uint16_t i_index = 0;
  uint16_t tmp_len = 0;
  usbd_core_type *pudev = (usbd_core_type *)udev;
  winusb_struct_type *p_winusb = (winusb_struct_type *)pudev->class_handler->pdata;
  if(p_winusb->g_rx_completed == 0)
  {
    return 0;
  }
  p_winusb->g_rx_completed = 0;
  tmp_len = p_winusb->g_rxlen;
//  for(i_index = 0; i_index < p_winusb->g_rxlen; i_index ++)
//  {
//    recv_data[i_index] = p_winusb->g_rx_buff[i_index];
//  }
  usbd_ept_recv(pudev, USBD_WINUSB_BULK_OUT_EPT, p_winusb->g_rx_buff, p_winusb->maxpacket);
  return tmp_len;
}
 
 以上测试结果和官方的测试结果有点出入。总体来说好于官方数据。
 
 
 
 |