-
Notifications
You must be signed in to change notification settings - Fork 5.3k
feat[SPI]: Add SPI device detach function #10733
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
Conversation
📌 Code Review Assignment🏷️ Tag: bsp_stm32Reviewers: Liang1795 hamburger-os wdfk-prog Changed Files (Click to expand)
🏷️ Tag: componentsReviewers: Maihuanyi Changed Files (Click to expand)
🏷️ Tag: components_driver_spiReviewers: Liang1795 wdfk-prog Changed Files (Click to expand)
📊 Current Review Status (Last Updated: 2025-09-25 10:32 CST)
📝 Review Instructions
|
|
👋 感谢您对 RT-Thread 的贡献!Thank you for your contribution to RT-Thread! 为确保代码符合 RT-Thread 的编码规范,请在你的仓库中执行以下步骤运行代码格式化工作流。 🛠 操作步骤 | Steps
完成后,提交将自动更新至 如有问题欢迎联系我们,再次感谢您的贡献!💐 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR adds detach functionality for SPI devices in RT-Thread, enabling proper cleanup and removal of SPI devices from the system. This is a complementary feature to the existing attach functionality.
- Adds core detach functions for SPI devices in the driver framework
- Implements hardware-specific detach function for STM32 BSP
- Provides proper resource cleanup including device unregistration and CS pin reset
Reviewed Changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 4 comments.
| File | Description |
|---|---|
| components/drivers/spi/dev_spi_core.c | Implements core SPI device detach functions with resource cleanup |
| components/drivers/include/drivers/dev_spi.h | Adds function declarations and documentation for detach APIs |
| bsp/stm32/libraries/HAL_Drivers/drivers/drv_spi.h | Declares STM32-specific SPI device detach function |
| bsp/stm32/libraries/HAL_Drivers/drivers/drv_spi.c | Implements STM32-specific SPI device detach with memory cleanup |
| return result; | ||
| } | ||
|
|
||
| rt_free(spi_device); |
Copilot
AI
Sep 24, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
English: The function frees the SPI device memory directly, but this assumes the device was dynamically allocated. If the device was statically allocated or managed elsewhere, this will cause undefined behavior or memory corruption.
中文: 该函数直接释放SPI设备内存,但这假设设备是动态分配的。如果设备是静态分配的或在其他地方管理,这将导致未定义行为或内存损坏。
| rt_free(spi_device); | |
| /* Do not free spi_device here, as its allocation source is unknown. */ |
3d53020 to
690c419
Compare
690c419 to
f75fb03
Compare
拉取/合并请求描述:(PR description)
[
为什么提交这份PR (why to submit this PR)
你的解决方案是什么 (what is your solution)
请提供验证的bsp和config (provide the config and bsp)
]
当前拉取/合并请求的状态 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