本帖最后由 第109位梁山好汉 于 2018-7-20 15:05 编辑
测试基于CubeMX生成的模板,想把USB数据转存到SD,可是将USB和SD连接到一起的速度太太低了!!! 这是我做的一些测试。
测试条件: STM32 F407 , hal, SDIO(24M), DMA 闪迪 16G Class10 USBHS(USB3300)(MSC) WIN10,USB2.0/USB3.0
测试 一: SD卡,多扇区连续访问(200k) 写:6.9MB/S 读:10.85MB/S
测试 二: USB 写:10.6MB/S 读:14.4MB/S
测试 三:USB + SD 写:300KB/S 读:700KB/S
调试时,我把 STORAGE_Read_HS(uint8_t lun, uint8_t *buf,uint32_t blk_addr, uint16_t blk_len) STORAGE_Write_HS(uint8_t lun, uint8_t *buf,uint32_t blk_addr, uint16_t blk_len) blk_len 参数仿真查看,发现每次数据通讯都为 1 扇区,数据长度(512字节),怀疑是此处的时间开销,没有真正发挥 SDIO,DMA连续数据访问的优势。大家有遇到这种情况的吗? - <div class="blockcode"><blockquote>/**
- * @brief .
- * @param lun: .
- * @retval USBD_OK if all operations are OK else USBD_FAIL
- */
- int8_t STORAGE_Init_HS(uint8_t lun)
- {
- /* USER CODE BEGIN 9 */
- return (USBD_OK);
- /* USER CODE END 9 */
- }
- /**
- * @brief .
- * @param lun: .
- * @param block_num: .
- * @param block_size: .
- * @retval USBD_OK if all operations are OK else USBD_FAIL
- */
- int8_t STORAGE_GetCapacity_HS(uint8_t lun, uint32_t *block_num, uint16_t *block_size)
- {
- /* USER CODE BEGIN 10 */
-
- HAL_SD_CardInfoTypeDef pCardInfo;
-
- HAL_SD_GetCardInfo(&hsd, &pCardInfo);
-
- *block_num = pCardInfo.LogBlockNbr;
- *block_size = pCardInfo.LogBlockSize;
-
- return (USBD_OK);
- /* USER CODE END 10 */
- }
- /**
- * @brief .
- * @param lun: .
- * @retval USBD_OK if all operations are OK else USBD_FAIL
- */
- int8_t STORAGE_IsReady_HS(uint8_t lun)
- {
- /* USER CODE BEGIN 11 */
- if(HAL_SD_GetCardState(&hsd) == HAL_SD_CARD_TRANSFER)
- return (USBD_OK);
- else
- return (USBD_FAIL);
- /* USER CODE END 11 */
- }
- /**
- * @brief .
- * @param lun: .
- * @retval USBD_OK if all operations are OK else USBD_FAIL
- */
- int8_t STORAGE_IsWriteProtected_HS(uint8_t lun)
- {
- /* USER CODE BEGIN 12 */
- return (USBD_OK);
- /* USER CODE END 12 */
- }
- /**
- * @brief .
- * @param lun: .
- * @param buf: .
- * @param blk_addr: .
- * @param blk_len: .
- * @retval USBD_OK if all operations are OK else USBD_FAIL
- */
- int8_t STORAGE_Read_HS(uint8_t lun, uint8_t *buf, uint32_t blk_addr, uint16_t blk_len)
- {
- /* USER CODE BEGIN 13 */
-
- int8_t ret = USBD_FAIL;
- if( HAL_SD_ReadBlocks_DMA(&hsd, buf, blk_addr, blk_len) == HAL_OK )
- {
- ret = USBD_OK;
- }
-
- if( USBD_OK == ret )
- {
- while(HAL_SD_GetState(&hsd) == HAL_SD_STATE_BUSY){};
-
- while( HAL_SD_GetCardState(&hsd) != HAL_SD_CARD_TRANSFER ){};
- }
-
- return ret;
-
- /* USER CODE END 13 */
- }
- /**
- * @brief .
- * @param lun: .
- * @param buf: .
- * @param blk_addr: .
- * @param blk_len: .
- * @retval USBD_OK if all operations are OK else USBD_FAIL
- */
- int8_t STORAGE_Write_HS(uint8_t lun, uint8_t *buf, uint32_t blk_addr, uint16_t blk_len)
- {
- /* USER CODE BEGIN 14 */
-
- int8_t ret = USBD_FAIL;
- if( HAL_SD_WriteBlocks_DMA(&hsd, buf, blk_addr, blk_len) == HAL_OK )
- {
- ret = USBD_OK;
- }
-
- if( USBD_OK == ret )
- {
- while(HAL_SD_GetState(&hsd) == HAL_SD_STATE_BUSY){};
-
- while( HAL_SD_GetCardState(&hsd) != HAL_SD_CARD_TRANSFER ){};
- }
- return ret;
-
- /* USER CODE END 14 */
- }
- /**
- * @brief .
- * @param None
- * @retval .
- */
- int8_t STORAGE_GetMaxLun_HS(void)
- {
- /* USER CODE BEGIN 15 */
- return (STORAGE_LUN_NBR - 1);
- /* USER CODE END 15 */
- }
复制代码
|
工程配置修改:
测试环境:
测试环境:
WIN10 USB2.0/USB3.0
闪迪 class10 sdio(24M) dma USBFS(usb3300)
读取速度:7.8~8.0MB
写入速度:4.5~6.0MB
1 楼里面