[stm32][drivers] Add BDMA support for SPI - #11689
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)
📊 Current Review Status (Last Updated: 2026-08-29 08:55 CST)
📝 Review Instructions
|
|
|
现在还是草稿阶段...稍后整理一下BSP部分,开启一个BSP的PR再推上来吧 |
struct stm32_bdma_config
{
void *Instance; /**< BDMA channel instance pointer. */
rt_uint32_t dma_rcc; /**< RCC enable bit for the BDMA controller. */
IRQn_Type dma_irq; /**< NVIC IRQ number for the BDMA channel. */
rt_uint32_t priority; /**< BDMA transfer priority. */
rt_uint8_t preempt_priority; /**< NVIC preempt priority for the BDMA IRQ. */
rt_uint8_t sub_priority; /**< NVIC sub priority for the BDMA IRQ. */
rt_uint32_t request; /**< BDMA request selector. */
rt_uint32_t direction; /**< BDMA transfer direction. */
rt_uint32_t periph_inc; /**< Peripheral address increment mode. */
rt_uint32_t mem_inc; /**< Memory address increment mode. */
rt_uint32_t periph_data_alignment; /**< Peripheral data alignment. */
rt_uint32_t mem_data_alignment; /**< Memory data alignment. */
rt_uint32_t mode; /**< BDMA transfer mode. */
};
/**
* @brief Static DMA endpoint description used by board-level config headers.
*
* This descriptor stores one complete DMA endpoint configuration so peripheral
* drivers can initialize DMA directly from the board-level config tables.
*/
struct stm32_dma_config
{
DMA_INSTANCE_TYPE *Instance; /**< DMA controller instance pointer. */
rt_uint32_t dma_rcc; /**< RCC enable bit for the DMA controller. */
IRQn_Type dma_irq; /**< DMA global IRQ number. */
rt_uint32_t priority; /**< DMA transfer priority. */
rt_uint8_t preempt_priority; /**< NVIC preempt priority for the DMA IRQ. */
rt_uint8_t sub_priority; /**< NVIC sub priority for the DMA IRQ. */
#if defined(STM32_DMA_USES_GPDMA)
rt_uint32_t request; /**< DMA request selector for the GPDMA channel. */
rt_uint32_t blk_hw_request; /**< GPDMA block hardware request mode. */
rt_uint32_t direction; /**< DMA transfer direction. */
rt_uint32_t src_inc; /**< GPDMA source increment mode. */
rt_uint32_t dest_inc; /**< GPDMA destination increment mode. */
rt_uint32_t src_data_width; /**< GPDMA source data width. */
rt_uint32_t dest_data_width; /**< GPDMA destination data width. */
rt_uint32_t src_burst_length; /**< GPDMA source burst length. */
rt_uint32_t dest_burst_length; /**< GPDMA destination burst length. */
rt_uint32_t transfer_allocated_port;/**< GPDMA allocated port selection. */
rt_uint32_t transfer_event_mode; /**< GPDMA transfer event mode. */
rt_uint32_t mode; /**< DMA transfer mode. */
#else
#ifdef STM32_DMA_USES_CHANNEL
rt_uint32_t channel; /**< DMA channel selector for stream-based DMA. */
#endif /* STM32_DMA_USES_CHANNEL */
#ifdef STM32_DMA_USES_REQUEST
rt_uint32_t request; /**< DMA request selector for DMAMUX/request-based DMA. */
#endif /* STM32_DMA_USES_REQUEST */
rt_uint32_t direction; /**< DMA transfer direction. */
rt_uint32_t periph_inc; /**< Peripheral address increment mode. */
rt_uint32_t mem_inc; /**< Memory address increment mode. */
rt_uint32_t periph_data_alignment; /**< Peripheral data alignment. */
rt_uint32_t mem_data_alignment; /**< Memory data alignment. */
rt_uint32_t mode; /**< DMA transfer mode. */
#if defined(STM32_DMA_SUPPORTS_FIFO)
rt_uint32_t fifo_mode; /**< FIFO enable state. */
rt_uint32_t fifo_threshold; /**< FIFO threshold selection. */
rt_uint32_t mem_burst; /**< Memory burst transfer mode. */
rt_uint32_t periph_burst; /**< Peripheral burst transfer mode. */
#endif /* defined(STM32_DMA_SUPPORTS_FIFO) */
#endif /* defined(STM32_DMA_USES_GPDMA) */
};
|
|
|
@wdfk-prog 您好!我根据您的意见大概修改了一下,不过我选择的是实现了个简单的DMA的类来继承,把原来的DMA和BDMA逻辑都转发到通用的DMA内部处理函数里面。不知道可以可以不可以?
|
|
| const struct stm32_dma_config *dma_config, | ||
| rt_bool_t abort_first); | ||
|
|
||
| #endif /* HAL_DMA_MODULE_ENABLED */ |
|
|
||
| #endif /* BSP_USING_BDMA && (SOC_SERIES_STM32H7 || SOC_SERIES_STM32H7RS) */ | ||
|
|
||
| #if defined(BSP_USING_BDMA) && (defined(SOC_SERIES_STM32H7) || defined(SOC_SERIES_STM32H7RS)) |
There was a problem hiding this comment.
- 这个宏不是跟上面的一样的吗?为什么单独又来一个#if
|
|
||
| #endif /* HAL_DMA_MODULE_ENABLED */ | ||
|
|
||
| #if defined(BSP_USING_BDMA) && (defined(SOC_SERIES_STM32H7) || defined(SOC_SERIES_STM32H7RS)) |
There was a problem hiding this comment.
- L374~L482 这些需要特地区分出来吗?
- 如果只是为了体现BDMA却跟DMA用法一样的话,不需要额外多这么多定义
| if (dma_rcc == 0) | ||
| { | ||
| LOG_E("bdma enable clock failed, dma_rcc is 0"); | ||
| __HAL_RCC_BDMA_CLK_ENABLE(); |
There was a problem hiding this comment.
- 这个没看懂,这里是要异常退出吧?为什么还使能BDMA CLK了?
| { | ||
| rt_uint32_t tmpreg = 0x00U; | ||
|
|
||
| #if defined(BSP_USING_BDMA) && (defined(SOC_SERIES_STM32H7) || defined(SOC_SERIES_STM32H7RS)) |
There was a problem hiding this comment.
- 这一段能跟下面的
#if defined(STM32_DMA_USES_RCC_AHBENR)判断逻辑一样放在同一个IF ELIF里面吗?这样子会更好
| #if defined(BSP_USING_BDMA) && (defined(SOC_SERIES_STM32H7) || defined(SOC_SERIES_STM32H7RS)) | ||
| if (is_bdma) | ||
| { | ||
| if (dma_rcc == 0) |
There was a problem hiding this comment.
- dma_rcc = 0是异常吗?那可以未所有dma都做判断,而不只是bdma
- 或者也可以不限制用户的自由?否则的话这里异常退出没有返回值
| * @param is_bdma RT_TRUE for BDMA clock enable, RT_FALSE for regular DMA. | ||
| */ | ||
| static void stm32_dma_enable_clock(rt_uint32_t dma_rcc) | ||
| static void stm32_dma_enable_clock(rt_uint32_t dma_rcc, rt_bool_t is_bdma) |
There was a problem hiding this comment.
- 我看不需要增加
is_bdma的变量吧?可以在dma_config中增加一个变量传入即可,这样子不需要改动这么多函数和定义
88b4a16 to
44978e3
Compare
|
@wdfk-prog 您好!根据您的意见我又修改了一版,PTAL |
|
82198e7 to
679e4d6
Compare
8aa7d8b to
3e6b210
Compare
|
@wdfk-prog PTAL |
重新按当前版本复审了一遍,也结合上一轮 review 再确认了一下修改方向。 相比最初版本,现在已经开始把 BDMA 收到现有 DMA framework 中,这个方向是对的。这里我补充一下我对最终结构的建议:这次允许同时调整现有 DMA / GPDMA,不要求为了减少 diff 而完全保持旧实现;但既然要重构,就建议一次把 DMA / BDMA / GPDMA 的公共层次整理清楚,避免形成新的临时兼容层。 当前版本我仍然建议继续修改后再 review,主要有以下问题。 1.
|
This update integrates SPI6 BDMA support into the unified DMA interface, allowing for a consistent handling of DMA and BDMA configurations. The changes include modifications to the DMA configuration structures and the SPI driver to accommodate both DMA types seamlessly. Additionally, Kconfig adjustments ensure proper selection between DMA and BDMA for SPI6. - Updated DMA type definitions and configurations. - Refactored SPI driver to route SPI6 BDMA through the unified DMA interface. - Adjusted Kconfig to prevent mutual exclusivity issues between DMA and BDMA for SPI6. Signed-off-by: moment-NEW
… into feat/spi-bdma
拉取/合并请求描述:(PR description)
[
为什么提交这份PR (why to submit this PR)
对于H7系列的SPI,其缺失BDMA驱动,因此制作了相关驱动使其正常工作
你的解决方案是什么 (what is your solution)
仿照drv_dma的设计,在驱动层单独设计了一套bdma驱动,而上层spi处基本复用dma逻辑。
请提供验证的bsp和config (provide the config and bsp)
已在DM-MC02 上完成验证工作,验证使用自行编写的WS2812驱动软件包,测试正常点亮,效果与阻塞一致,且不影响串口等其他外设。该BSP以及相关软件包会稍后进行格式清理等后推送。此外进行了scons -j8等编译均通过。
]
当前拉取/合并请求的状态 Intent for your PR
必须选择一项 Choose one (Mandatory):
代码质量 Code Quality:
我在这个拉取/合并请求中已经考虑了 As part of this pull request, I've considered the following:
#if 0代码,不包含已经被注释了的代码 All redundant code is removed and cleaned up