STM32f407芯片
flash芯片 w25q128
usb device接口,用的是PB14和PB15 HS_OTG
- #define BSP_USING_USBDEVICE
- #define EP_MPS_64 0U
- #define BSP_USBD_TYPE_HS
- #define BSP_USBD_SPEED_HSINFS 1
hal初始化
- void HAL_PCD_MspInit(PCD_HandleTypeDef* pcdHandle)
- {
- GPIO_InitTypeDef GPIO_InitStruct = {0};
- if(pcdHandle->Instance==USB_OTG_FS)
- {
- /* USER CODE BEGIN USB_OTG_FS_MspInit 0 */
- /* USER CODE END USB_OTG_FS_MspInit 0 */
- __HAL_RCC_GPIOA_CLK_ENABLE();
- /**USB_OTG_FS GPIO Configuration
- PA11 ------> USB_OTG_FS_DM
- PA12 ------> USB_OTG_FS_DP
- */
- GPIO_InitStruct.Pin = GPIO_PIN_11|GPIO_PIN_12;
- GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
- GPIO_InitStruct.Pull = GPIO_NOPULL;
- GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH;
- GPIO_InitStruct.Alternate = GPIO_AF10_OTG_FS;
- HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
- /* USB_OTG_FS clock enable */
- __HAL_RCC_USB_OTG_FS_CLK_ENABLE();
- /* USER CODE BEGIN USB_OTG_FS_MspInit 1 */
- /* USER CODE END USB_OTG_FS_MspInit 1 */
- }
- else if(pcdHandle->Instance==USB_OTG_HS)
- {
- /* USER CODE BEGIN USB_OTG_HS_MspInit 0 */
- /* USER CODE END USB_OTG_HS_MspInit 0 */
- __HAL_RCC_GPIOB_CLK_ENABLE();
- /**USB_OTG_HS GPIO Configuration
- PB14 ------> USB_OTG_HS_DM
- PB15 ------> USB_OTG_HS_DP
- */
- GPIO_InitStruct.Pin = GPIO_PIN_14|GPIO_PIN_15;
- GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
- GPIO_InitStruct.Pull = GPIO_NOPULL;
- GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH;
- GPIO_InitStruct.Alternate = GPIO_AF12_OTG_HS_FS;
- HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);
- /* USB_OTG_HS clock enable */
- __HAL_RCC_USB_OTG_HS_CLK_ENABLE();
- /* USER CODE BEGIN USB_OTG_HS_MspInit 1 */
- /* USER CODE END USB_OTG_HS_MspInit 1 */
- }
- }
配置启用的虚拟串口和存储,设备名时w25,这个是spi通过sfud挂载的flashw25q128
- int spi_flash_init(void)
- {
- extern rt_err_t rt_hw_spi_device_attach(const char *bus_name, const char *device_name, GPIO_TypeDef* cs_gpiox, uint16_t cs_gpio_pin);
- rt_hw_spi_device_attach("spi1","spi10",GPIOG,GPIO_PIN_8);
- rt_sfud_flash_probe("w25","spi10"); // 获取 sfud_dev
- return RT_EOK;
- }
- INIT_DEVICE_EXPORT(spi_flash_init);

启动后电脑可以识别u盘,也可以拷贝文件,但是向u盘拷贝文件时大概十几秒进度条会动一下然后再卡十几秒,不能连续写入
将存储设备换成sdio挂载的tf卡也是一样的
但是从u盘向外拷贝文件则不会卡,会连续走进度条
请大神分享问题是什么,谢谢!