问答

汇集网友智慧,解决技术难题

21ic问答首页 - at32f415 rt-thread下识别U盘

AT32F415 U盘 RT-Thread 嵌入式 国产芯片 单片机

at32f415 rt-thread下识别U盘

jw__liu2024-06-17
第一次能顺利识别 拔出U盘来再次插入就不能识别了。
回答 +关注 0
1331人浏览 3人回答问题 分享 举报
3 个回答
  • 代码卡在了drv_usbotgh.c文件的第225行,原因是while循环中的条件retry--没有满足退出循环的条件。为了解决这个问题,可以尝试增加retry的初始值或者调整循环条件。

    可以尝试增加retry的初始值,例如将其从10改为20:

    ```c
    int retry = 20;
    while(retry --)
    {
        rt_completion_wait(&urb_completion, timeout);
        if(usbh_get_urb_status((&p_usbotg_instance->p_otg_core->host), pipe->pipe_index) == URB_NOTREADY)
        {
            if((pipe->ep.bEndpointAddress & 0x80) == 0)
            {
                goto __resend;
            }
        }
    }
    ```

    如果仍然无法解决问题,请检查循环体内的其他代码是否有逻辑错误或者死锁等问题。
  • AT32有测评活动吗?是不是要写个循环的端口扫描?
  • 本帖最后由 tyw 于 2024-6-17 09:28 编辑

    代码卡死在 drv_usbotgh.c 的 225 行的while循环里
        while(retry --)
        {
            rt_completion_wait(&urb_completion, timeout);
            if(usbh_get_urb_status((&p_usbotg_instance->p_otg_core->host), pipe->pipe_index) == URB_NOTREADY)
            {
                if((pipe->ep.bEndpointAddress & 0x80) == 0)
                {
                    goto __resend;
                }




您需要登录后才可以回复 登录 | 注册