# UF4DigitalPowerV2 **Repository Path**: UF4DigitalPower/UF4DigitalPowerV2 ## Basic Information - **Project Name**: UF4DigitalPowerV2 - **Description**: 一个基于STM32G4的数字电源 - **Primary Language**: Unknown - **License**: Not specified - **Default Branch**: POWER_DEBUG_BMP - **Homepage**: https://me.hepi.ng - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2026-08-23 - **Last Updated**: 2026-10-04 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # UF4 STM32G474 数字电源固件 这是运行在 STM32G474RBT6 上的裸机数字电源控制固件。它负责功率级控制、保护、参数服务和 UF4COM 通信;本工程不使用 RTOS。 ## 构建 需要安装 `arm-none-eabi-gcc`、CMake 和 Ninja 或 Make: ```powershell cmake -S . -B cmake-build-debug -DCMAKE_BUILD_TYPE=Debug cmake --build cmake-build-debug --target STM32G474CBT6.elf -j 8 ``` 通过 UF4 CMSIS-DAP 选择并烧录 G474。PC 端串口使用 115200 8N1;连线需要 TX/RX 都通,并与控制板共地。 ## 目录 - `Core/`:启动和外设代码。 - `Drivers/`:STM32 HAL 与 CMSIS。 - `USER/Control/`:控制环和状态机。 - `USER/Communication/`:UF4COM 适配层。 - `USER/Bsp/`、`USER/BSP_Config/`:板级配置和硬件抽象。 - `USER/ADP_Scheduler/`:ADP 调度与可选的离线训练权重头文件。 ## Runtime Architecture ## Runtime Architecture The G474 is a bare-metal firmware. Power-stage control and communication run in separate real-time domains; no RTOS is linked or required. | Domain | Rate / trigger | Responsibility | Restrictions | | --- | --- | --- | --- | | HRTIM ISR | 50 kHz | FMAC Q1.15 current 2P2Z/PI, PWM update, fast protection accounting | Fixed execution time; no RTOS calls, logging, protocol, or Flash access | | TIM6 ISR | 10 kHz | F32 voltage PI and Iref publication | CC/CV arbitration and topology qualification only | | Foreground service | `main()` loop | Drain UART RX, parse UF4COM, state machine, fan and parameter service | No blocking waits or Flash operations in interrupts | | Startup sequence | before foreground service | Peripheral and power application initialization | Outputs remain disabled until `SELF_CHECK` passes | USART2 is configured at 115200 baud. Its RX DMA uses 128-byte receive-to-idle blocks; the UART/DMA ISR copies a completed block into a 512-byte ring buffer. `Foreground_Service()` drains that ring, runs the UF4COM protocol timers and applies command-mailbox updates. ## Build And Target Test Build the active target: ```powershell cmake --build cmake-build-debug --target STM32G474CBT6.elf -j 8 ``` Select and program the G474 using the UF4 CMSIS-DAP, then use `COM12` at 115200 8N1 for the UF4COM link. A voltage read request uses source ID `0`, destination ID `1`, `ACK_REQ`, and TV IDs `0x0A` (Vin) and `0x0C` (Vout). Example request, including CRC16-CCITT in little-endian wire order: ```text AA 55 00 01 40 01 01 06 0A 00 00 0C 00 00 1C D0 ``` The expected response has command `81` and ACK-frame flag `02`. A successful PC-to-G474 test requires both directions: `COM12 TX -> PA3 (USART2_RX)` and `PA2 (USART2_TX) -> COM12 RX`, plus common ground. Receiving the request alone is not sufficient to observe a reply at the PC. ## Timing Checks Keep the 50 kHz ISR below its configured cycle budget. During communication tests monitor `uf4_uart_diagnostics_t`: `rx_queue_drops`, `rx_uart_errors`, and `tx_hal_errors` must remain zero. A growing RX-drop count means foreground work is not keeping up and must be profiled before increasing bus traffic. The RX DMA block size is 128 bytes and the software ring is 512 bytes. An occasional count while the peer is already transmitting during reset is expected; it must settle after startup. Sustained traffic is handled by the foreground service rather than a byte-by-byte ISR.