Repository navigation
[bsp][esp32-c6] compile SPI when it is selected - #11846
Conversation
Selecting BSP_USING_SPI on C6 links the IDF SPI master. The default image still leaves SPI off, and the peripheral table stays unsupported.
|
👋 感谢您对 RT-Thread 的贡献!Thank you for your contribution to RT-Thread! 为确保代码符合 RT-Thread 的编码规范,请在你的仓库中执行以下步骤运行代码格式化工作流(如果格式化CI运行失败)。 🛠 操作步骤 | Steps
完成后,提交将自动更新至 如有问题欢迎联系我们,再次感谢您的贡献!💐 |
cppcheck follows spi_configure(NULL, NULL) into a dereference. clang-format also wants the macro backslashes left-aligned and a single space around the enum equals.
| memcpys the low byte of each 32-bit data_buf word to the start of the | ||
| buffer -- its length is (len + 7) / 8, which is 1 for an 8-bit word -- and | ||
| that is what fills the staging array above. */ | ||
| err = spi_bus_initialize(SPI2_HOST, &buscfg, SPI_DMA_DISABLED); |
There was a problem hiding this comment.
AI给的建议:关闭 DMA 后,IDF 将单次传输上限设为 64 字节,忽略配置中的 4092。但 spixfer() 仍整包提交,65 字节消息就会返回 ESP_ERR_INVALID_ARG,随后触发 ESP_ERROR_CHECK 中止。应分段传输并保持正确片选时序,至少应返回错误而非终止系统。
There was a problem hiding this comment.
感谢指出。ai说的没错,关闭dma以后单次传输确实会收到限制;我目前的想法是在驱动里边,把超过64字节的分段循环发送;如果分段发送的过程中有bug直接弹错误码。改完以后我会做一轮验证
| with open(gdma, 'wb') as f: | ||
| f.write(fixed) | ||
|
|
||
| _adapt_idf_gdma_to_c6_ll() |
There was a problem hiding this comment.
当 C3/C6 共用 bsp/ESP/libraries/ESP-IDF-latest 时,构建 C6 会永久把 gdma.c 改成四参数调用,即使未启用 SPI 也会执行。之后构建 C3,其 HAL 仍是三参数接口,会报 too many arguments。应使用 C6 独立副本,或通过目标宏保留两套调用。
There was a problem hiding this comment.
感谢指出,这里确实有问题,构建脚本会改掉 ESP-IDF-latest/.../gdma.c ,破坏掉c3的构建。所以我的想法是在 SConstruct 里把这段改写去掉;我现在打算在 gdma.c 里按目标宏保留两套调用;改完我会依次编译 C6 和 C3,确认两边都能过。之所以选择是目标宏,我觉得应该会比 C6 单独复制一份好维护。
| else | ||
| { | ||
| LOG_E("data width %u is not supported\n", (rt_uint32_t)configuration->data_width); | ||
| return -RT_ENOSYS; |
There was a problem hiding this comment.
位宽检查发生在 spi_bus_initialize() 成功之后。首次请求 16 位返回 -RT_ENOSYS,随后改用 8 位重试,会因总线已初始化而触发中止。应先校验位宽,再申请资源。
There was a problem hiding this comment.
感谢指出,经过检查,现在的顺序确实有问题。我打算把位宽校验挪到 spi_bus_initialize() 之前,不支持的位宽直接返回错误,不申请任何资源。
…ed gdma.c, early width check
Summary
BSP_USING_SPIon ESP32-C6 now links the IDF SPI master. The default image still leaves SPI off.SPI2_IOMUX_PIN_NUM_CS. C6 asks forSPI_DMA_DISABLED. Other chips keepSPI_DMA_CH_AUTO.spi_configure()returns-RT_EINVALwhenconfigurationis null. The unusedesp32_spi_init()call that passed NULL is gone.Test plan
RT_USING_SPI,BSP_USING_SPIandBSP_USING_SPI2added tortconfig.h,RT_USING_ADCkept:sconsexit 0.rtthread.binis 466416 bytes.textis 371342. The link includesdrv_spi,spi_common,spi_master,spi_halandgdma.sconsagain: exit 0.rtthread.binis 445408 bytes.textis 340218. The link does not includedrv_spi.