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

Add four-byte alignment instructions for descriptors. #95

Closed Xy2019 closed 1 year ago

Xy2019 commented 1 year ago

第一次使用CherryUSB,我使用其中一个例程,在修改描述符后,USB在枚举时MCU就会HardFault,后来发现时描述符没有四字节对齐造成的。建议例程都应该加上四字节对齐指令。

sakumisu commented 1 year ago

不需要,代码里会copy到对齐的ram中

sakumisu commented 1 year ago

https://github.com/sakumisu/CherryUSB/blob/d7c0add7ef58cfa711cf152c088a7e1c65fa5886/core/usbd_core.c#L349

sakumisu commented 1 year ago

没有见过哪个mcu会异常,应该是你移植问题

sakumisu commented 1 year ago

使用cdc测试就知道了,hid大概定位到问题了

sakumisu commented 1 year ago

我猜测你是用的沁恒的,禁止使用const

Xy2019 commented 1 year ago

我猜测你是用的沁恒的,禁止使用const

我用的就是STM32F4 用的KeilV5.HID报告描述符不加四字节对齐就HardFault了

sakumisu commented 1 year ago

F4 测试没问题

sakumisu commented 1 year ago

FS PORT 还是HS PORT?

sakumisu commented 1 year ago

HS PORT 会检查对齐的

Xy2019 commented 1 year ago

FS PORT

是FS PORT,只是报告描述符会这样。其它描述符不用四字节对齐也可以。

sakumisu commented 1 year ago

那更不用了我觉得,貌似群里没人反馈这个

sakumisu commented 1 year ago

fifo模式都是字节写入的,不需要考虑对齐的

Xy2019 commented 1 year ago

那更不用了我觉得,貌似群里没人反馈这个

例程报告描述符是34字节我调试时首地址就是4的倍数,不用加对齐指令。我改成报告描述符后长度是25字节首地址不是4的倍数了就会HardFault。

sakumisu commented 1 year ago

更新了commit,你再试试

sakumisu commented 1 year ago

我还是觉得纯fifo,字节的,压根不需要考虑对齐

Xy2019 commented 1 year ago

更新了commit,你再试试 可以了。