cherry-embedded / CherryUSB

CherryUSB is a tiny, beautiful and portable USB host and device stack for embedded system with USB IP
https://cherryusb.readthedocs.io/
Apache License 2.0
1.21k stars 256 forks source link

STM32H743 开启数据高速缓存后,USB DMA功能失效,会导致USB无法枚举 #105

Closed chengshuihang closed 1 year ago

chengshuihang commented 1 year ago

问题如题目所示。 原因如下 1683532077686

b489501170c08cb44cf983c57570856

g_dwc2_udc未添加 USB_NOCACHE_RAM_SECTION宏,导致其被高速缓存命中,导致DMA枚举失败

sakumisu commented 1 year ago

开了dma,这片内存不允许使用cache

chengshuihang commented 1 year ago

是的,开了dma,这片内存不允许使用cache。但是当前usb_dc_dwc2.c文件中变量g_dwc2_udc没有使用宏USB_NOCACHE_RAM_SECTION修饰,需要手动在g_dwc2_udc变量上添加宏USB_NOCACHE_RAM_SECTION

sakumisu commented 1 year ago

嗯嗯,可能之前写漏了,晚点我改下

chengshuihang commented 1 year ago

将dwc2_reset函数 uint32_t count = 0U; 修改为 __IO uint32_t count = 0U; 修复在GCC环境下,因优化问题,未调用HAL库USB初始化,使用自定义的USB初始化函数,导致USB复位失败的bug。

sakumisu commented 1 year ago

将dwc2_reset函数 uint32_t count = 0U; 修改为 __IO uint32_t count = 0U; 修复在GCC环境下,因优化问题,未调用HAL库USB初始化,使用自定义的USB初始化函数,导致USB复位失败的bug。

没看懂这个是什么意思。本来就不应该调用 hal库的usb代码,我都自己重写了,为什么还要调用他们的代码

chengshuihang commented 1 year ago

就是不调用hal库的usb初始化代码,现在的dwc2_reset函数中uint32_t count = 0U,经过优化后,循环会立马跳出,导致USB复位失败,需要增加volatile关键字修饰count,保证不被优化,能够正确的完成USB复位动作

sakumisu commented 1 year ago

建议使用armcc和clang

sakumisu commented 1 year ago

好吧,会被优化成2000

sakumisu commented 1 year ago

已经 fix,有新问题可以 reopen or 开新 issue,thanks