| | |
| | | ## Repo overview (quick) |
| | | --- |
| | | alwaysApply: true |
| | | --- |
| | | # AI助手核心规则 |
| | | |
| | | - This is an STM32H7 firmware project for a lawnmower MCU. Key folders: |
| | | - `Core/` — HAL/RTOS entry (Cube-generated code; see `Core/Src/main.c`). |
| | | - `Drivers/` — STM32 HAL driver sources. |
| | | - `APL/` — high-level application config and app entry (`APL/app.c`, `APL/AppConfig.h`). |
| | | - `FML/` — feature modules (GPS, Internet, Bluetooth, UDPClient, etc.). Example: `FML/GPS.c` parses NMEA and uploads via `UDPClient`. |
| | | - `HIDOLibrary/Include` — shared utility types and helpers (HIDO_* API and types used everywhere). |
| | | - `MDK-ARM/` — Keil project files (`STM32H743.uvprojx`, `.uvoptx`) and build artifacts. |
| | | ## 三阶段工作流 |
| | | |
| | | ## What matters for edits |
| | | ### 阶段一:分析问题 |
| | | |
| | | - Entry flow: `Core/Src/main.c` initializes HAL, registers UARTs and starts the RTOS. It calls `app_main()` (implemented in `APL/app.c`) before `osKernelStart()`. |
| | | - Main app loop runs in `APL/app_task` which polls subsystems after being awakened by a binary semaphore. ISR-to-main wake uses `app_trigger_from_isr()` (gives the same semaphore). |
| | | - Use existing registration patterns: `Uart_Register(...)` for UART endpoints, `GPS_PinRegister(...)` for GPIO pins, and module init functions e.g. `GPS_Init()`, `Internet_Init()`, `UDPClient_Init()`. |
| | | - Preserve Cube-generated sections: keep code inside/near `/* USER CODE BEGIN */` / `/* USER CODE END */` unchanged when modifying generated files. |
| | | **声明格式**:`【分析问题】` |
| | | |
| | | ## Build & debug notes (concrete) |
| | | **目的** |
| | | 因为可能存在多个可选方案,要做出正确的决策,需要足够的依据。 |
| | | |
| | | - Two supported project entry points are present: STM32Cube `.ioc` (STM32H743/STM32H743.ioc) and Keil MDK `.uvprojx` (MDK-ARM/STM32H743.uvprojx). Developers typically: |
| | | - Open the `.ioc` in STM32CubeIDE and generate code, or |
| | | - Open the `.uvprojx` in Keil uVision (MDK) to build and flash. |
| | | - Debug/log serial: `USART1` is used as debug (`huart1`) at 921600 (see `MX_USART1_UART_Init` in `main.c`). GPS is on `USART2` (115200 default). |
| | | - UARTs use DMA for RX/TX in many places — be careful when changing buffer sizes or switching to interrupt-based I/O. |
| | | **必须做的事**: |
| | | - 理解我的意图,如果有歧义请问我 |
| | | - 搜索所有相关代码 |
| | | - 识别问题根因 |
| | | |
| | | ## Project-specific conventions & patterns |
| | | **主动发现问题** |
| | | - 发现重复代码 |
| | | - 识别不合理的命名 |
| | | - 发现多余的代码、类 |
| | | - 发现可能过时的设计 |
| | | - 发现过于复杂的设计、调用 |
| | | - 发现不一致的类型定义 |
| | | - 进一步搜索代码,看是否更大范围内有类似问题 |
| | | |
| | | - Types and helpers use the `HIDO_` prefix (e.g. `HIDO_UINT32`, `HIDO_Util*`, `HIDO_Debug`). Search `HIDOLibrary/Include` for helper APIs. |
| | | - Polling model: many subsystems expose `*_Init()` and `*_Poll()` (e.g. `GPS_Poll()`, `Internet_Poll()`). Work is driven by the `app_task` loop. |
| | | - ISR -> application wake uses the global semaphore from `app_trigger_from_isr()` — prefer this pattern rather than direct task notifications in new code for consistency. |
| | | - Generated HAL code pattern: keep peripheral init in `MX_*_Init()` functions within `main.c` and put higher-level logic in `APL/` or `FML/`. |
| | | 做完以上事项,就可以向我提问了。 |
| | | |
| | | ## Examples for common changes |
| | | **绝对禁止**: |
| | | - ❌ 修改任何代码 |
| | | - ❌ 急于给出解决方案 |
| | | - ❌ 跳过搜索和理解步骤 |
| | | - ❌ 不分析就推荐方案 |
| | | |
| | | - Add a new UART-based sensor: call `Uart_Register(UART_ID_X, &huartX)` in `main.c` after the corresponding `MX_USARTX_UART_Init()`, then create `Sensor_Init()`/`Sensor_Poll()` in `FML/` and call from `app_task`. |
| | | - Change debug log speed: edit `MX_USART1_UART_Init` in `Core/Src/main.c` and adjust callers that assume 921600. |
| | | - Add a periodic job: use the existing `HIDO_Timer` utilities and the app semaphore wake flow; follow `app_task`'s pattern to poll on wake. |
| | | **阶段转换规则** |
| | | 本阶段你要向我提问。 |
| | | 如果存在多个你无法抉择的方案,要问我,作为提问的一部分。 |
| | | 如果没有需要问我的,则直接进入下一阶段。 |
| | | |
| | | ## Where to look (quick file list) |
| | | ### 阶段二:制定方案 |
| | | **声明格式**:`【制定方案】` |
| | | |
| | | - Entry & init: `Core/Src/main.c` |
| | | - App startup & scheduler task: `APL/app.c`, `Core/Src/freertos.c` |
| | | - Feature modules: `FML/GPS.c`, `FML/Internet/*.c`, `FML/UDPClient.c` |
| | | - Utilities and shared types: `HIDOLibrary/Include/*` (HIDO_* APIs) |
| | | - Project files: `STM32H743/STM32H743.ioc`, `MDK-ARM/STM32H743.uvprojx` |
| | | **前置条件**: |
| | | - 我明确回答了关键技术决策。 |
| | | |
| | | ## Short guidelines for AI agents |
| | | **必须做的事**: |
| | | - 列出变更(新增、修改、删除)的文件,简要描述每个文件的变化 |
| | | - 消除重复逻辑:如果发现重复代码,必须通过复用或抽象来消除 |
| | | - 确保修改后的代码符合DRY原则和良好的架构设计 |
| | | |
| | | - Only change generated files inside USER CODE blocks unless you also regenerate the Cube project (.ioc); prefer adding new modules under `FML/` or `APL/`. |
| | | - Follow existing naming and type conventions: use `HIDO_` helpers and typedefs for cross-module compatibility. |
| | | - When modifying peripheral config, update `MX_*_Init()` in `main.c` and check related registration calls (`Uart_Register`, `GPIO` pin registers). |
| | | - Use the semaphore-based `app_trigger_from_isr()` to wake the main loop from ISRs. |
| | | 如果新发现了向我收集的关键决策,在这个阶段你还可以继续问我,直到没有不明确的问题之后,本阶段结束。 |
| | | 本阶段不允许自动切换到下一阶段。 |
| | | |
| | | If you'd like, I can convert this into a shorter or longer version, or merge any existing instructions you have. Any areas you want me to expand or examples to add? |
| | | ### 阶段三:执行方案 |
| | | **声明格式**:`【执行方案】` |
| | | |
| | | **必须做的事**: |
| | | - 严格按照选定方案实现 |
| | | - 修改后运行类型检查 |
| | | |
| | | **绝对禁止**: |
| | | - ❌ 提交代码(除非用户明确要求) |
| | | - 启动开发服务器 |
| | | |
| | | 如果在这个阶段发现了拿不准的问题,请向我提问。 |
| | | |
| | | 收到用户消息时,一般从【分析问题】阶段开始,除非用户明确指定阶段的名字。 |