开发环境:RT-Thread stdio、源码4.1、使用的硬石YS-F4Pro开发板、芯片是stm32f407、U盘是USB2.0的。
问题:U盘可以正常挂载和枚举,文件系统挂载也正常,可以使用cat命令查看U盘内文件内容,但是echo命令写入失败(用命令与程序测试均尝试过),失败以后shell就是卡死无法输入。
请大家看下我的现象和分析,帮忙给点思路或者解决方法。
调试过程:
正常mount U盘如下:
\ | /
RT - Thread Operating System
/ | \ 4.1.0 build Jun 15 2022 16:43:48
2006 - 2022 Copyright by RT-Thread team
[I/SFUD] Find a Boya BY25Q128AS flash chip. Size is 16777216 bytes.
[I/SFUD] W25Q128 flash device is initialize succusb connected
port 1 status 0x10201
ess.
[I/SFUD] Probe SPI flash W25Q128 by SPI device spi10 success.
[D/FAL] (fal_flash_init:49) Flash device | onchip_flash_16k | addr: 0x08000000 | len: 0x00010000 | blk_size: 0x00004000 |initialized finish.
[D/FAL] (fal_flash_init:49) Flash device | onchip_flash_64k | addr: 0x08010000 | len: 0x00010000 | blk_size: 0x00010000 |initialized finish.
[D/FAL] (fal_flash_init:49) Flash device | onchip_flash_128k | addr: 0x08020000 | len: 0x000e0000 | blk_size: 0x00020000 |initialized finish.
[D/FAL] (fal_flash_init:49) Flash device | W25Q128 | addr: 0x00000000 | len: 0x01000000 | blk_size: 0x00001000 |initialized finish.
[I/FAL] ==================== FAL partition table ====================
[I/FAL] | name | flash_dev | offset | length |
[I/FAL] -------------------------------------------------------------
[I/FAL] | bootloader | onchip_flash_16k | 0x00000000 | 0x00010000 |
[I/FAL] | param | onchip_flash_64k | 0x00000000 | 0x00010000 |
[I/FAL] | app | onchip_flash_128k | 0x00000000 | 0x000e0000 |
[I/FAL] | easyflash | W25Q128 | 0x00000000 | 0x00100000 |
[I/FAL] | download | W25Q128 | 0x00100000 | 0x00100000 |
[I/FAL] =============================================================
[I/FAL] RT-Thread Flash Abstraction Layer initialize success.
[I/FAL] The FAL MTD NOR device (download) created successfully
[I/app.filesystem] mount to '/flash' success!
msh />reset port
start enumnation
ok
pipe transform remain size,: 8
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 0x1665
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 15356160, block size 512
read partition table
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
finished reading partition
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
Mount FAT on Udisk successful.
mount阶段有的时候偶尔会有nak,但是都可以挂载成功,没有影响,nak原因暂时未知。
正常读取1.txt文件如下:
Mount FAT on Udisk successful.
ls
Directory /:
dev
flash
udisk
msh />cd udisk
msh /udisk>ls
Directory /udisk:
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
System Volume Inform
1.txt 12
msh /udisk>cat 1.
msh /udisk>cat 1.txt
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
123123123123
msh /udisk>
写入失败情况如下:
msh /udisk>echo 2 2.txt
rt_usbh_storage_write10
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
可以看到直接就卡死了,经过调试发现,此时在drv_pipe_xfer函数中死循环,循环时通过HAL_HCD_HC_GetState(&stm32_hhcd_fs, pipe->pipe_index)函数获取状态发现状态为URB_IDLE与HC_IDLE,进一步跟踪发现HAL_HCD_HC_SubmitRequest函数(具体代码如下)中将这2个状态设置为IDLE。
hhcd->hc[ch_num].xfer_buff = pbuff;
hhcd->hc[ch_num].xfer_len = length;
hhcd->hc[ch_num].urb_state = URB_IDLE;
hhcd->hc[ch_num].xfer_count = 0U;
hhcd->hc[ch_num].ch_num = ch_num;
hhcd->hc[ch_num].state = HC_IDLE;
之后由于rt_completion_wait(&urb_completion, timeout);等不到完成量,完成量信号是在中断里面调用HAL_HCD_HC_NotifyURBChange_Callback发送出来的,但是一直没有中断发生,所以就以timeout(5S)时间一直循环,shell卡死应该就是没有对完成量的返回做处理。
手头没有USB协议分析仪,没办法分析协议,不知道到底是什么原因导致了这样的情况发送,请大神们给点思路,或者遇到相同情况的说说如何解决?
0
|
1个回答
|
|
|