4.0 KiB
4.0 KiB
AGENTS.md - Development Guidelines for E32-433TBH-SC
Project Overview
This is an STM32F103C8T6 embedded C project using STM32CubeMX code generation. The project implements a LoRa module (E32-TTL-433) control system with USB CDC communication, OLED display (u8g2), and a menu system.
Build System
- IDE: Keil MDK-ARM V5.32
- Linker: GCC
- Project File:
project.ioc(STM32CubeMX configuration) - No standard build system (Makefile/CMake) - build via Keil uVision or re-generate with CubeMX
To rebuild:
- Open
project.iocin STM32CubeMX - Click "Generate Code"
- Open the generated project in Keil uVision
- Build using Keil's build system
There is no test framework - this is a bare-metal embedded project without unit tests.
Code Style Guidelines
Naming Conventions
- Functions:
snake_case(e.g.,e32_hal_uart_tx,Menu_Init) - Variables:
snake_case(e.g.,usb_rx_data,my_usb_rx_num) - Constants/Defines:
UPPER_SNAKE_CASE(e.g.,GPIO_PIN_RESET,E32_USE_GPIO_AUX) - Types/Enums:
snake_case_tsuffix for types (e.g.,key_name_t,work_mode_t) - Pin Defines: Follow CubeMX pattern (e.g.,
RESET_Pin,AUX_GPIO_Port)
File Organization
Core/Src/ - Main application source (main.c, gpio.c, usart.c, etc.)
Core/Inc/ - Main application headers
Middlewares/ - Third-party libraries (u8g2, MultMenu, USB)
USB_DEVICE/ - USB CDC implementation
docs/ - Documentation
Code Structure
- Use HAL library for peripheral access (e.g.,
HAL_UART_Transmit,HAL_GPIO_ReadPin) - Follow CubeMX USER CODE blocks - place custom code between
/* USER CODE BEGIN ... */and/* USER CODE END ... */ - Keep hardware-specific code in
Core/Src/(e.g.,e32_hal.c,u8g2_hal.c) - Keep application logic separate from HAL
Formatting
- Use tabs for indentation (consistent with generated CubeMX code)
- Opening brace on same line as function declaration
- Maximum line width: ~120 characters (follow existing style)
- No enforced code formatter - maintain consistency with surrounding code
Comments
- Use Doxygen-style function comments:
/** * @brief Brief description * @param param_name Description * @retval Return value description */ - Chinese comments are acceptable (project uses mixed EN/ZH)
- Comment complex logic, not trivial code
Error Handling
- Use
Error_Handler()(defined in main.c) for fatal errors - Check HAL return values for UART, I2C, USB operations
- Implement timeout mechanisms for blocking operations
- Use
HAL_Delay()for timing-critical operations
Includes
- Group includes: standard library, HAL, application-specific
- Use include guards in headers (
#ifndef __FILE_H,#define __FILE_H) - Use
extern "C"guards when mixing C/C++ headers
Types and Constants
- Use stdint types (
uint8_t,uint16_t,uint32_t) for portability - Prefer
booloveruint8_tfor boolean values (include<stdbool.h>) - Define magic numbers as constants or enums
Important Notes
- Never modify auto-generated code outside USER CODE sections - it will be overwritten by CubeMX
- Preserve the project.ioc - this is the single source of truth for hardware configuration
- USB CDC uses
usbd_cdc_if.cfor custom implementation - Menu system uses MultMenu middleware in
Middlewares/MultMenu/ - Display driver uses u8g2 in
Middlewares/u8g2Lib/
Key Files
Core/Src/main.c- Application entry pointCore/Src/e32_hal.c- E32 LoRa module HALCore/Src/u8g2_hal.c- OLED display HALCore/Src/key.c- Key input handlingMiddlewares/MultMenu/menu/menu.c- Menu systemUSB_DEVICE/App/usbd_cdc_if.c- USB CDC interfaceproject.ioc- STM32CubeMX project configuration
Working with this Repository
- Edit source files in
Core/Src/orCore/Inc/ - For hardware changes, edit
project.iocin STM32CubeMX and regenerate - Build with Keil uVision (project.uvprojx)
- Flash using ST-Link or compatible programmer