Skip to content

[mprotect][kconfig] Add safe defaults for MPU region count options - #11766

Open
Zepp-Hanzj wants to merge 1 commit into
RT-Thread:masterfrom
Zepp-Hanzj:fix/cortex-m4-stack-guard-kconfig
Open

[mprotect][kconfig] Add safe defaults for MPU region count options#11766
Zepp-Hanzj wants to merge 1 commit into
RT-Thread:masterfrom
Zepp-Hanzj:fix/cortex-m4-stack-guard-kconfig

Conversation

@Zepp-Hanzj

Copy link
Copy Markdown
Contributor

描述 / Description

修复 NUM_MEM_REGIONS / NUM_CONFIGURABLE_REGIONS / NUM_EXCLUSIVE_REGIONS 缺少 Kconfig 默认值导致的问题:开启 RT_USING_HW_STACK_GUARD 但未显式配置时,rtconfig.h 会生成空宏(如 #define NUM_CONFIGURABLE_REGIONS),进而展开成非法 C 表达式((2 + )for (i = 0U; i < ; i++)),导致 cortex-m4/m7/m33 的 MPU 代码编译失败。

Fix empty-macro compile failure caused by missing Kconfig defaults on the three MPU region count options.

修复 / Changes

  • components/mprotect/Kconfig:为三个 int 配置项添加安全默认值
    • NUM_MEM_REGIONS = 8(Cortex-M4/M7/M33 常见值,按实际 MCU 修改)
    • NUM_CONFIGURABLE_REGIONS = 0
    • NUM_EXCLUSIVE_REGIONS = 0
  • components/mprotect/README.md:补充 CubeMX 生成的 MemManage_Handler 与 mpu.c 强符号冲突的说明及解决方式

验证 / Validation

  • 本地模拟开启 RT_USING_HW_STACK_GUARD 且不显式配置 NUM_*:生成 NUM_MEM_REGIONS 8 / NUM_CONFIGURABLE_REGIONS 0 / NUM_EXCLUSIVE_REGIONS 0,不再为空宏
  • STM32F407 BSP 编译通过(开启 HW_STACK_GUARD),mpu.o 正常编译、LINK rt-thread.elf 成功
  • 确认 MemManage_Handler 符号唯一(来自 mpu.c),stm32f4xx_it.c 默认不参与编译

参考 / Reference

NUM_MEM_REGIONS / NUM_CONFIGURABLE_REGIONS / NUM_EXCLUSIVE_REGIONS had no
Kconfig defaults. Enabling RT_USING_HW_STACK_GUARD without explicitly
setting them generated empty macros in rtconfig.h (e.g.
'#define NUM_CONFIGURABLE_REGIONS'), which expanded into invalid C
expressions like '(2 + )' and 'for (i = 0U; i < ; i++)', breaking
compilation for cortex-m4/m7/m33 MPU code.

Add safe defaults: NUM_MEM_REGIONS=8, NUM_CONFIGURABLE_REGIONS=0,
NUM_EXCLUSIVE_REGIONS=0. Also document the MemManage_Handler strong-symbol
conflict with CubeMX-generated stm32f4xx_it.c and how to resolve it.

Reported-by: wdfk-prog
@github-actions

Copy link
Copy Markdown

👋 感谢您对 RT-Thread 的贡献!Thank you for your contribution to RT-Thread!

为确保代码符合 RT-Thread 的编码规范,请在你的仓库中执行以下步骤运行代码格式化工作流(如果格式化CI运行失败)。
To ensure your code complies with RT-Thread's coding style, please run the code formatting workflow by following the steps below (If the formatting of CI fails to run).


🛠 操作步骤 | Steps

  1. 前往 Actions 页面 | Go to the Actions page
    点击进入工作流 → | Click to open workflow →

  2. 点击 Run workflow | Click Run workflow

  • Use workflow from 保持默认分支(通常为 master
    Keep the default branch (usually master) in Use workflow from
  • branch 输入框填写 PR 分支 fix/cortex-m4-stack-guard-kconfig
    Enter PR branch fix/cortex-m4-stack-guard-kconfig in the branch field
  • 设置需排除的文件/目录(目录请以"/"结尾)
    Set files/directories to exclude (directories should end with "/")
  1. 等待工作流完成 | Wait for the workflow to complete
    格式化后的代码将作为独立提交推送至你的分支。
    The formatting changes will be pushed to your branch as a separate commit.

完成后,提交将自动更新至 fix/cortex-m4-stack-guard-kconfig 分支,关联的 Pull Request 也会同步更新。
Once completed, commits will be pushed to the fix/cortex-m4-stack-guard-kconfig branch automatically, and the related Pull Request will be updated.

如有问题欢迎联系我们,再次感谢您的贡献!💐
If you have any questions, feel free to reach out. Thanks again for your contribution!

@github-actions

Copy link
Copy Markdown

📌 Code Review Assignment

🏷️ Tag: components

Reviewers: @Maihuanyi

Changed Files (Click to expand)
  • components/mprotect/Kconfig
  • components/mprotect/README.md

📊 Current Review Status (Last Updated: 2026-08-28 18:13 CST)


📝 Review Instructions

  1. 维护者可以通过单击此处来刷新审查状态: 🔄 刷新状态
    Maintainers can refresh the review status by clicking here: 🔄 Refresh Status

  2. 确认审核通过后评论 LGTM/lgtm
    Comment LGTM/lgtm after confirming approval

  3. PR合并前需至少一位维护者确认
    PR must be confirmed by at least one maintainer before merging

ℹ️ 刷新CI状态操作需要具备仓库写入权限。
ℹ️ Refresh CI status operation requires repository Write permission.

@wdfk-prog wdfk-prog left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@BernardXiong BernardXiong added the +1 Agree +1 label Aug 28, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants