使用usb host读写u盘无效,求助

发布于 2020-07-02 14:10:38

参考这里,但是没有效果,流程如下

打开 usb host

  • 打开 cubeMX,开启 USB_OTG, 使用 host 模式,生成代码,复制到项目
  • 复制 main.c 里面的时钟配置到 board.c
  • 修改 Kconfig,添加
config BSP_USING_USBD_FS
    bool "Enable OTGFS as USB host"
    select RT_USING_USB_HOST
    select BSP_USING_USBH
    default n
  • 位置
 Hardware Drivers Config --->
   On-chip Peripheral Drivers, 启用 usb otg

RT-Thread Components --->
    Device Drivers --->
      Using USB --->
        [*] Using USB host
        [*] Enable Udisk Drivers
        (/)   Udisk mount dir

打开文件系统

  • 位置
RT-Thread Components --->
  Device virtual file system --->
    [*]Using device virtual file system
  • 配置参数
[*]Enable elm-chan fatfs

复制驱动

  • 去 gitee 的 rt thread 的 master 分支里面找到 drv_usbh.c 和 drv_usbh.h, 放到项目的 libraries/HAL_Drivers 里面
  • 修改,添加 libraries/HAL_Drivers/SConscript
if GetDepend(['BSP_USING_USBH']):
    src += ['drv_usbh.c']

查看更多

关注者
0
被浏览
204
5 个回答
andychen
andychen 2020-07-02

这是问题描述?还是分享解决办法?

921742079
921742079 2020-07-02

sorry,怪我,求助,求助,不好意思

921742079
921742079 2020-07-02

board/Kconfig里面现在这个貌似并不会使 libraries/HAL_Drivers/drv_usbh.c 参与构建
的改成下面这个,烧录以后,直接卡死了

config BSP_USING_USBH
    bool "Enable USB host"
    select RT_USING_USB_HOST
    default n

调试发现,卡死是时钟问题,现在可以看到usb设备了

msh />list_device
device           type         ref count
-------- -------------------- ----------
usbh     USB Host Bus         0       
uart1    Character Device     2       
pin      Miscellaneous Device 0       
921742079
921742079 2020-07-02

现在问题是,u盘容量显示错误,导致无法mount
物理容量应该是32g,windows下显示28g,这里告诉我2047.1023GB
不知道应该怎么格式化,需要注意啥?
快速格式化和完全格式化都不行,给跪了

msh />reboot

 \ | /
- RT -     Thread Operating System
 / | \     4.0.2 build Jul  2 2020
 2006 - 2019 Copyright by rt-thread team
msh />usb connected
port 1 status 0x10201
reset port
start enumnation
ok
pipe transform remain size,: 8
nak
nak
ok
pipe transform remain size,: 0
ok
reset port
rt_usb_set_address
ok
pipe transform remain size,: 0
ok
get device descriptor length 18
ok
pipe transform remain size,: 18
ok
pipe transform remain size,: 0
ok
Vendor ID 0x951
Product ID 0x1666
ok
pipe transform remain size,: 18
ok
pipe transform remain size,: 0
ok
ok
pipe transform remain size,: 32
ok
pipe transform remain size,: 0
ok
ok
pipe transform remain size,: 0
ok
rt_usb_get_interface_descriptor: 0
interface class 0x8, subclass 0x6
rt_usb_get_endpoint_descriptor: 0
rt_usb_get_endpoint_descriptor: 1
subclass 6, protocal 80
rt_usbh_storage_run
rt_usb_get_endpoint_descriptor: 0
rt_usb_get_endpoint_descriptor: 1
rt_usbh_storage_reset
ok
pipe transform remain size,: 0
ok
rt_usbh_storage_get_max_lun
ok
pipe transform remain size,: 1
ok
pipe transform remain size,: 0
ok
rt_usbh_storage_inquiry
pipe transform remain size,: 31
nak
ok
pipe transform remain size,: 36
ok
pipe transform remain size,: 13
ok
rt_usbh_storage_test_unit_ready
pipe transform remain size,: 31
ok
pipe transform remain size,: 13
ok
rt_usbh_storage_get_capacity
pipe transform remain size,: 31
ok
pipe transform remain size,: 8
ok
pipe transform remain size,: 13
ok
capicity 60604416, block size 512
read partition table
rt_usbh_storage_read10
pipe transform remain size,: 31
ok
pipe transform remain size,: 512
nak
ok
pipe transform remain size,: 448
ok
pipe transform remain size,: 384
ok
pipe transform remain size,: 320
ok
pipe transform remain size,: 256
ok
pipe transform remain size,: 192
ok
pipe transform remain size,: 128
ok
pipe transform remain size,: 64
ok
pipe transform remain size,: 13
ok
finished reading partition
found part[0], begin: 512, size: 2047.1023GB
rt_usbh_storage_read10
pipe transform remain size,: 31
ok
pipe transform remain size,: 512
ok
pipe transform remain size,: 448
ok
pipe transform remain size,: 384
ok
pipe transform remain size,: 320
ok
pipe transform remain size,: 256
ok
pipe transform remain size,: 192
ok
pipe transform remain size,: 128
ok
pipe transform remain size,: 64
ok
pipe transform remain size,: 13
ok
rt_usbh_storage_read10
pipe transform remain size,: 31
ok
pipe transform remain size,: 512
ok
pipe transform remain size,: 448
ok
pipe transform remain size,: 384
ok
pipe transform remain size,: 320
ok
pipe transform remain size,: 256
ok
pipe transform remain size,: 192
ok
pipe transform remain size,: 128
ok
pipe transform remain size,: 64
ok
pipe transform remain size,: 13
ok
udisk part 0 mount failed
Ernest
Ernest 2020-07-03

有没有使用分区?

撰写答案

请登录后再发布答案,点击登录

发布
问题

分享
好友