fix[stm32][spi]: add usage_freq and compute transfer timeout by frequency#11240
fix[stm32][spi]: add usage_freq and compute transfer timeout by frequency#11240wdfk-prog wants to merge 1 commit intoRT-Thread:masterfrom
Conversation
|
👋 感谢您对 RT-Thread 的贡献!Thank you for your contribution to RT-Thread! 为确保代码符合 RT-Thread 的编码规范,请在你的仓库中执行以下步骤运行代码格式化工作流(如果格式化CI运行失败)。 🛠 操作步骤 | Steps
完成后,提交将自动更新至 如有问题欢迎联系我们,再次感谢您的贡献!💐 |
📌 Code Review Assignment🏷️ Tag: bsp_stm32Reviewers: Liang1795 hamburger-os wdfk-prog Changed Files (Click to expand)
🏷️ Tag: componentsReviewers: Maihuanyi Changed Files (Click to expand)
📊 Current Review Status (Last Updated: 2026-03-09 08:36 CST)
📝 Review Instructions
|
99c16be to
9033c82
Compare
2026-03-07T07:30:04.9015178Z packages/RTduino-latest/libraries/buildin/SPI/SPI.cpp: In member function 'void SPIClass::beginTransaction(SPISettings)':
2026-03-07T07:30:04.9016139Z packages/RTduino-latest/libraries/buildin/SPI/SPI.cpp:67:5: error: missing initializer for member 'rt_spi_configuration::usage_freq' [-Werror=missing-field-initializers]
2026-03-07T07:30:04.9016802Z 67 | };
2026-03-07T07:30:04.9016971Z | ^
2026-03-07T07:30:04.9017195Z CC build/packages/perf_counter-v2.2.4.1/perf_counter.o
2026-03-07T07:30:04.9017520Z cc1plus: all warnings being treated as errors
2026-03-07T07:30:04.9017904Z scons: *** [build/packages/RTduino-latest/libraries/buildin/SPI/SPI.o] Error 1
2026-03-07T07:30:04.9018293Z scons: building terminated because of errors.
2026-03-07T07:30:04.9018927Z �[1;32mscons -c�[0m
2026-03-07T07:30:04.9040078Z ##[error]build stm32/stm32g474-st-nucleo peripheral.arduino failed.
2026-03-07T07:31:35.1842835Z board/ports/drv_ov5640.c: In function 'ov5640_focus_init':
2026-03-07T07:31:35.1843468Z board/ports/drv_ov5640.c:265:20: warning: unsigned conversion from 'int' to 'rt_uint8_t' {aka 'unsigned char'} changes value from '-255' to '1' [-Woverflow]
2026-03-07T07:31:35.1844057Z 265 | return -RT_ERROR;
2026-03-07T07:31:35.1844287Z | ^
2026-03-07T07:31:35.1844563Z board/ports/drv_ov5640.c: In function 'ov5640_focus_constant':
2026-03-07T07:31:35.1845201Z board/ports/drv_ov5640.c:407:20: warning: unsigned conversion from 'int' to 'rt_uint8_t' {aka 'unsigned char'} changes value from '-255' to '1' [-Woverflow]
2026-03-07T07:31:35.1845789Z 407 | return -RT_ERROR;
2026-03-07T07:31:35.1846008Z | ^
2026-03-07T07:31:35.1846529Z board/ports/drv_ov5640.c:420:20: warning: unsigned conversion from 'int' to 'rt_uint8_t' {aka 'unsigned char'} changes value from '-255' to '1' [-Woverflow]
2026-03-07T07:31:35.1847100Z 420 | return -RT_ERROR;
2026-03-07T07:31:35.1847317Z | ^
2026-03-07T07:31:35.1847576Z board/ports/drv_ov5640.c: In function 'jpeg_data_process':
2026-03-07T07:31:35.1848229Z board/ports/drv_ov5640.c:483:14: warning: assignment to 'int *' from incompatible pointer type 'rt_int32_t *' {aka 'long int *'} [-Wincompatible-pointer-types]
2026-03-07T07:31:35.1849068Z 483 | pbuf = JPEG_DATA_BUF + jpeg_data_len;
2026-03-07T07:33:05.1335395Z packages/btstack-latest/rtt_adapter/rtt_btstack_adapter.c: In function 'uart_sample':
2026-03-07T07:33:05.1336164Z packages/btstack-latest/rtt_adapter/rtt_btstack_adapter.c:107:8: warning: missing terminating " character
2026-03-07T07:33:05.1336747Z 107 | #error "Please set the reset pin
2026-03-07T07:33:05.1337023Z | ^
2026-03-07T07:33:05.1337423Z packages/btstack-latest/port/posix-h4-bcm/btstack_main.c: In function 'bt_stack_main':
2026-03-07T07:33:05.1338180Z packages/btstack-latest/port/posix-h4-bcm/btstack_main.c:217:8: warning: missing terminating " character
2026-03-07T07:33:05.1339032Z 217 | #error "Please set the reset pin
2026-03-07T07:34:38.4700595Z CC /home/runner/work/rt-thread/rt-thread/bsp/stm32/libraries/HAL_Drivers/drivers/drv_gpio.o
2026-03-07T07:34:38.4701177Z CC /home/runner/work/rt-thread/rt-thread/bsp/stm32/libraries/HAL_Drivers/drivers/drv_usart.o
2026-03-07T07:34:38.4701584Z LINK rt-thread.elf
2026-03-07T07:34:38.4702464Z /opt/arm-gnu-toolchain-13.2.Rel1-x86_64-arm-none-eabi/bin/../lib/gcc/arm-none-eabi/13.2.1/../../../../arm-none-eabi/bin/ld:board/linker_scripts/link.lds:159: warning: memory region `RAM_SHARED' not declared
2026-03-07T07:34:38.4703285Z Memory region Used Size Region Size %age Used
2026-03-07T07:34:38.4703590Z ROM: 82976 B 1 MB 7.91%
2026-03-07T07:34:38.4703851Z RAM: 5356 B 192 KB 2.72%
2026-03-07T07:34:38.4704182Z *default*: 536876268 B 18446744073709551615 B 0.00%
2026-03-07T07:34:38.4704556Z arm-none-eabi-objcopy -O binary rt-thread.elf rtthread.bin
2026-03-07T07:34:38.4704877Z arm-none-eabi-size rt-thread.elf
2026-03-07T07:34:38.4705140Z text data bss dec hex filename
2026-03-07T07:34:38.4705517Z 82976 1104 4252 88332 1590c rt-thread.elf
2026-03-07T07:34:38.4706002Z arm-none-eabi-objcopy -O ihex rt-thread.elf rt-thread.hex
2026-03-07T07:34:38.4706435Z scons: done building targets.
2026-03-07T07:34:38.4718850Z �[1;32mscons -c�[0m
2026-03-07T07:34:38.4719464Z ##[endgroup]
2026-03-07T07:34:38.4759375Z ##[error]Process completed with exit code 4.
2026-03-07T07:34:38.4816447Z ##[group]Run curl -X POST -H "Authorization: token " \
2026-03-07T07:34:38.4816855Z �[36;1mcurl -X POST -H "Authorization: token " \�[0m
2026-03-07T07:34:38.4817563Z �[36;1m-d '{"body":"@wdfk-prog, Thank you for your contribution, but there was an error with the action. Could you please help check the BSP compilation issue? Thank you."}' \�[0m
2026-03-07T07:34:38.4818371Z �[36;1m"https://api.github.com/repos/RT-Thread/rt-thread/issues/11240/comments"�[0m
2026-03-07T07:34:38.4855783Z shell: /usr/bin/bash -e {0} |
为什么提交这份PR (why to submit this PR)
当前 STM32 SPI 驱动中,阻塞发送、接收、收发以及 DMA 等待完成时使用固定的 1000ms 超时。
当 SPI 传输数据量较大、配置频率较低,或者实际 SPI 工作频率低于预期时,固定超时可能过短,导致正常传输被误判为超时。
另外,驱动日志中计算 SPI 实际使用频率时使用了运行时表达式,结果不够直观,也不便于后续复用。
你的解决方案是什么 (what is your solution)
本 PR 对 STM32 SPI 驱动做了如下调整:
SPI_CLOCK重命名为spi_clock,使代码风格更符合规范;cfg->usage_freq;cfg->usage_freq;spixfer()中根据本次传输长度和实际 SPI 使用频率动态计算超时时间:usage_freq / 8计算理论字节传输速率;timeout_ms;HAL_SPI_TransmitReceive()、HAL_SPI_Transmit()、HAL_SPI_Receive()的固定 1000ms 超时替换为动态超时;rt_completion_wait()的固定超时替换为动态 tick 超时;HAL_SPI_STATE_READY的死等逻辑增加超时退出机制,避免异常情况下无限阻塞。这样可以让 SPI 超时与实际配置频率、传输长度相匹配,降低误超时风险,并提升驱动健壮性。
请提供验证的bsp和config (provide the config and bsp)
BSP:
.config:
action: