Files
STM32F4-Base/.opencode/skills/new-source-file/SKILL.md
T

40 lines
2.0 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
---
name: new-source-file
description: 新增 .c 源文件的双端注册:MDK-ARM/STM32F407-Demo.uvprojx 与 simulator/CMakeLists.txt 均为显式文件列表,新文件必须手动加进两处再双端构建验证。Use when 新建 App/、Drivers/BSP/ 下的 .c 文件,或构建/运行报 undefined reference、"改了代码没生效" 而怀疑文件漏注册。
---
# 新文件双端注册
本工程 Keil 工程与 PC 模拟器都使用**显式文件列表**(无通配扫描)——新 `.c` 文件不手动注册就不会被编译;只注册一端 = 另一端**静默**缺文件(不一定报错,功能悄悄不生效)。
## 注册步骤
1. **Keil MDK**:编辑 `MDK-ARM/STM32F407-Demo.uvprojx`,在对应 `<GroupName>` 的 `<Files>` 中按相邻条目格式插入(`..\` 开头反斜杠路径):
```xml
<File>
<FileName>ui_new_module.c</FileName>
<FileType>1</FileType>
<FilePath>..\Drivers\BSP\UI\ui_new_module.c</FilePath>
</File>
```
现有组:`App`、`Drivers/BSP`、`Drivers/BSP/UI`、`Test` 等;新文件放语义对应的组。
2. **模拟器**(仅当文件需 PC 端编译,如 `Drivers/BSP/UI/*.c`):在 `simulator/CMakeLists.txt` 的 `set(UI_SOURCES ...)` 列表加一行 `${UI_DIR}/ui_new_module.c`。非 UI 模块文件通常不需模拟器注册。
3. **双端构建验证**(两端都必须过):
```powershell
cmake --build simulator/build --config Debug # 0 警告
& "MDK-ARM\build.bat" # BUILD_OK,0 错 0 警
```
## 注意
- **禁止**把源文件复制进 `simulator/`——两端共用 `Drivers/BSP/` 原件(UI_界面制作流程.md C7)
- 只注册 `.c`(含 `.s`);`.h` 靠 include 路径找到,不加工程
- 漏注册的典型症状:一端编译失败(undefined reference)或一端行为悄悄停留在旧逻辑
- 注册完成后跑回归:UI 文件 → `ui-verify` skill;其他模块 → `@test`(`test/host/run_boot_test.py`)
- 改过 `CMakeLists.txt` 后需重新 `cmake -B build` 配置