Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

针对STM32F1系列的PMA自动分配计算方法有误 #19

Open
season-studio opened this issue Aug 3, 2021 · 4 comments
Open

针对STM32F1系列的PMA自动分配计算方法有误 #19

season-studio opened this issue Aug 3, 2021 · 4 comments

Comments

@season-studio
Copy link

(1)针对STM32F1系列处理器,一个端点的缓冲区配置表项里,每个成员之间有2个字节的填充占位,所以,每个端点的缓冲区配置表项大小应该为16字节。代码中tusb_dev_drv_setup_endpoint函数里面,bt_start的计算中,固定将端点数乘以8,显然是无法兼容F1系列处理器的。考虑到stm32_fs_platform.h中为不同处理器定义了不同的pma_ep_desc结构体来描述一个缓冲区配置表项。所以,bt_start的算式中将8修改为sizeof(pma_ep_desc)更合理。
(2)tusb_dev_drv_setup_endpoint函数里面采用的自动端点配置策略,是依据现行激活的Interface来按需配置端点的。在bt_start的计算中,引用到的局部变量max_ep_id是已激活的Interface中最大的端点编号。注意其中,当端点号为0,且is_reset为假时,端点0的pma项并不会得到更新。在代码中,默认的SetInterface处理代码调用了tusb_init_endpoint_by_config用于配置新Interface的端点,tusb_init_endpoint_by_config调用tusb_dev_drv_setup_endpoint时,is_reset参数传递了0。也就是说,SetInterface时是不会重新配置端点0的pma的。所以,如果我们实现的设备有两个Interface,且非默认的Interface(1)使用到了更大的端点编号时,当设备初启动的时候,端点0的pma并没有考虑给Interface(1)端点预留空间,当切换到Interface(1)时,端点0的pma也没有更新,那么端点0的缓冲就会和Interface(1)的端点pma配置项相互冲突。我采用了一个简单的修改,将bt_start计算时的缓冲区配置表项的保留数量,固定按照TUSB_MAX_EP_PAIR_COUNT来计算。

最终修改代码如下:
int tusb_dev_drv_setup_endpoint(...) { ... uint32_t bt_start = TUSB_MAX_EP_PAIR_COUNT * sizeof(pma_ep_desc); ... }

该问题在我实现UVC设备时发现。若不做以上修改,则要么UVC会发送出不可预期的数据,要么程序会陷入HardFault异常。经过以上修改后,UVC设备方可正常工作。

xtoolbox added a commit that referenced this issue Nov 7, 2021
…y way to dynamic setup EP in STM32 FS core.
@xtoolbox
Copy link
Owner

xtoolbox commented Nov 7, 2021

感谢反馈。已经做出相关修正。
关于第(2)点,如果要在运行时动态设置端点,可能需要遍历配置描述符的所有接口配置,然后找出最大的端点号。
但是这还会遇到多配置的情况。如果单靠代码来动态配置,最可靠的办法就是用你的这个办法,直接预留出最大端点。

@sass20
Copy link

sass20 commented Nov 30, 2023

Hi
I Have troble with stm32f103 with
uint32_t bt_start = TUSB_MAX_EP_PAIR_COUNT * sizeof(pma_ep_desc)
I have make HID, and dual CDC

The 1st cdc is work fine, but send wrong data ..
and found massege
Endpoint PMA buffer overflow, some ep will not init
in logs.
I change bt_start to bt_start =64*2 (EndPoint 0 size)
than dual cdc send good data...
I do not know why need bt_start = TUSB_MAX_EP_PAIR_COUNT * sizeof(pma_ep_desc); ??

@xtoolbox
Copy link
Owner

xtoolbox commented Dec 6, 2023

Hi I Have troble with stm32f103 with uint32_t bt_start = TUSB_MAX_EP_PAIR_COUNT * sizeof(pma_ep_desc) I have make HID, and dual CDC

The 1st cdc is work fine, but send wrong data .. and found massege Endpoint PMA buffer overflow, some ep will not init in logs. I change bt_start to bt_start =64*2 (EndPoint 0 size) than dual cdc send good data... I do not know why need bt_start = TUSB_MAX_EP_PAIR_COUNT * sizeof(pma_ep_desc); ??

Using [ TUSB_MAX_EP_PAIR_COUNT * sizeof(pma_ep_desc)] means reserving the description table for all endpoints, which leads to insufficient PMA memory and causes data transmission errors. Changing it to [64*2 (EndPoint 0 size)] means that some unused endpoints do not reserve description tables, allowing the PMA memory to meet the usage requirements.

@zhaoyang815678396
Copy link

Hi I Have troble with stm32f103 with uint32_t bt_start = TUSB_MAX_EP_PAIR_COUNT * sizeof(pma_ep_desc) I have make HID, and dual CDC
The 1st cdc is work fine, but send wrong data .. and found massege Endpoint PMA buffer overflow, some ep will not init in logs. I change bt_start to bt_start =64*2 (EndPoint 0 size) than dual cdc send good data... I do not know why need bt_start = TUSB_MAX_EP_PAIR_COUNT * sizeof(pma_ep_desc); ??

Using [ TUSB_MAX_EP_PAIR_COUNT * sizeof(pma_ep_desc)] means reserving the description table for all endpoints, which leads to insufficient PMA memory and causes data transmission errors. Changing it to [64*2 (EndPoint 0 size)] means that some unused endpoints do not reserve description tables, allowing the PMA memory to meet the usage requirements.

例程中的复合设备,composite工程,在STM32F1的芯片下,直接编译执行会报这个错误,并且PC不能完全识别,会每隔一段时间发送Device Reset命令,导致无法完全枚举,复合设备工程中修改为64*2依然不够,会报错,实测改到64能正常运行,设备枚举都正常了,通讯也正常了

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants