# ericzhengpig1-png/rm27_training_framework_hw architecture

> Architecture diagram of the GitHub repository ericzhengpig1-png/rm27_training_framework_hw, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-10-17). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/ericzhengpig1-png/rm27_training_framework_hw
- Repository: https://github.com/ericzhengpig1-png/rm27_training_framework_hw

## Overview

This is an educational STM32 C-board firmware framework for learning and building robot-control features. The intended workflow is to initialize board peripherals and ThreadX, acquire BMI088 sensor data, use threads to monitor and share runtime state, and control DJI/M2006 motors over CAN. The README also describes UART/PWM/CAN BSP wrappers, PID/math/CRC libraries, and optional magnetometer or attitude-estimation work. Several implementation details are TODOs; unsampled subsystems are represented only where the README documents their role.

Main entry points: [`threads/src/alivethread.cpp`](https://github.com/ericzhengpig1-png/rm27_training_framework_hw/blob/main/threads/src/alivethread.cpp) (IMU and control tasks), [`modules/src/DJIMotorHandler.cpp`](https://github.com/ericzhengpig1-png/rm27_training_framework_hw/blob/main/modules/src/DJIMotorHandler.cpp) (Motor CAN handler), [`bsp/src/bsp_can.cpp`](https://github.com/ericzhengpig1-png/rm27_training_framework_hw/blob/main/bsp/src/bsp_can.cpp) (CAN BSP), [`libs/src/pid.cpp`](https://github.com/ericzhengpig1-png/rm27_training_framework_hw/blob/main/libs/src/pid.cpp) (PID utilities)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_board["Board runtime"]
  node_firmware["Startup and peripherals<br/>[main.c]"]
  node_threadx["ThreadX setup<br/>[app_threadx.c]"]
  node_hal["Generated HAL drivers"]
end

subgraph group_bsp["Peripheral abstraction"]
  node_canbsp["CAN BSP<br/>[bsp_can.cpp]"]
  node_uartbsp["UART BSP<br/>[bsp_usart.cpp]"]
  node_pwmbsp["PWM BSP<br/>[bsp_pwm.cpp]"]
end

subgraph group_libraries["Control utilities"]
  node_pid["PID utilities<br/>[pid.cpp]"]
  node_mathcrc["Math and CRC<br/>[crc.cpp]"]
end

subgraph group_robot["Robot modules"]
  node_imuapi["IMU data types<br/>[IMU.hpp]"]
  node_bmi088["BMI088 driver<br/>[BMI088.cpp]"]
  node_motor["DJI motor model<br/>[DJIMotor.hpp]"]
  node_m2006["M2006 motor<br/>[M2006.cpp]"]
  node_motorhandler["Motor CAN handler"]
  node_motorcontrol["Motor control<br/>[MotorControl.cpp]"]
  node_ist8310["IST8310 option"]
end

subgraph group_threads["ThreadX tasks"]
  node_tasks["IMU and control tasks<br/>[alivethread.cpp]"]
  node_threadapi["Thread data snapshots<br/>[threads.hpp]"]
end

node_boardhardware(("STM32 board"))
node_sensor["IMU sensor"]
node_motors["CAN motors"]

node_boardhardware -->|"starts"| node_firmware
node_firmware -->|"initializes"| node_hal
node_firmware -->|"starts"| node_threadx
node_threadx -.->|"creates tasks"| node_tasks
node_tasks -->|"reads sensor"| node_bmi088
node_sensor -.->|"supplies measurements"| node_bmi088
node_bmi088 -->|"produces IMU data"| node_imuapi
node_tasks -->|"publishes snapshots"| node_threadapi
node_tasks -->|"initializes CAN"| node_canbsp
node_tasks -->|"initializes control"| node_motorcontrol
node_motorcontrol -.->|"uses PID"| node_pid
node_motorcontrol -.->|"updates outputs"| node_motorhandler
node_motorhandler -->|"registers and updates"| node_motor
node_motorhandler -->|"handles model"| node_m2006
node_motorhandler -->|"transmits CAN"| node_canbsp
node_canbsp -.->|"sends frames"| node_motors
node_bmi088 -.->|"uses peripheral"| node_pwmbsp
node_uartbsp -.->|"uses UART"| node_boardhardware
node_tasks -->|"monitors motor health"| node_motorhandler
node_ist8310 -.->|"optional sensor task"| node_tasks
node_canbsp -.->|"layer order"| node_uartbsp
node_uartbsp -.->|"layer order"| node_pid
node_pid -.->|"layer order"| node_motorhandler
node_motorhandler -.->|"layer order"| node_tasks
node_pid -.->|"shared utilities"| node_mathcrc

click node_firmware "https://github.com/ericzhengpig1-png/rm27_training_framework_hw/blob/main/board/Core/Src/main.c"
click node_threadx "https://github.com/ericzhengpig1-png/rm27_training_framework_hw/blob/main/board/Core/Src/app_threadx.c"
click node_hal "https://github.com/ericzhengpig1-png/rm27_training_framework_hw/tree/main/board/Core/Src"
click node_canbsp "https://github.com/ericzhengpig1-png/rm27_training_framework_hw/blob/main/bsp/src/bsp_can.cpp"
click node_uartbsp "https://github.com/ericzhengpig1-png/rm27_training_framework_hw/blob/main/bsp/src/bsp_usart.cpp"
click node_pwmbsp "https://github.com/ericzhengpig1-png/rm27_training_framework_hw/blob/main/bsp/src/bsp_pwm.cpp"
click node_pid "https://github.com/ericzhengpig1-png/rm27_training_framework_hw/blob/main/libs/src/pid.cpp"
click node_mathcrc "https://github.com/ericzhengpig1-png/rm27_training_framework_hw/blob/main/libs/src/crc.cpp"
click node_imuapi "https://github.com/ericzhengpig1-png/rm27_training_framework_hw/blob/main/modules/include/IMU.hpp"
click node_bmi088 "https://github.com/ericzhengpig1-png/rm27_training_framework_hw/blob/main/modules/src/BMI088.cpp"
click node_motor "https://github.com/ericzhengpig1-png/rm27_training_framework_hw/blob/main/modules/include/DJIMotor.hpp"
click node_m2006 "https://github.com/ericzhengpig1-png/rm27_training_framework_hw/blob/main/modules/src/M2006.cpp"
click node_motorhandler "https://github.com/ericzhengpig1-png/rm27_training_framework_hw/blob/main/modules/src/DJIMotorHandler.cpp"
click node_motorcontrol "https://github.com/ericzhengpig1-png/rm27_training_framework_hw/blob/main/modules/src/MotorControl.cpp"
click node_ist8310 "https://github.com/ericzhengpig1-png/rm27_training_framework_hw/tree/main/modules"
click node_tasks "https://github.com/ericzhengpig1-png/rm27_training_framework_hw/blob/main/threads/src/alivethread.cpp"
click node_threadapi "https://github.com/ericzhengpig1-png/rm27_training_framework_hw/blob/main/threads/include/threads.hpp"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_firmware,node_threadx,node_hal toneBlue
class node_canbsp,node_uartbsp,node_pwmbsp toneAmber
class node_pid,node_mathcrc toneMint
class node_imuapi,node_bmi088,node_motor,node_m2006,node_motorhandler,node_motorcontrol,node_ist8310 toneRose
class node_tasks,node_threadapi,node_boardhardware,node_sensor,node_motors toneIndigo
```

## Components

### Board runtime

- [Startup and peripherals](https://github.com/ericzhengpig1-png/rm27_training_framework_hw/blob/main/board/Core/Src/main.c): `board/Core/Src/main.c`
- [ThreadX setup](https://github.com/ericzhengpig1-png/rm27_training_framework_hw/blob/main/board/Core/Src/app_threadx.c): `board/Core/Src/app_threadx.c`
- [Generated HAL drivers](https://github.com/ericzhengpig1-png/rm27_training_framework_hw/tree/main/board/Core/Src): `board/Core/Src`

### Peripheral abstraction

- [CAN BSP](https://github.com/ericzhengpig1-png/rm27_training_framework_hw/blob/main/bsp/src/bsp_can.cpp): `bsp/src/bsp_can.cpp`
- [UART BSP](https://github.com/ericzhengpig1-png/rm27_training_framework_hw/blob/main/bsp/src/bsp_usart.cpp): `bsp/src/bsp_usart.cpp`
- [PWM BSP](https://github.com/ericzhengpig1-png/rm27_training_framework_hw/blob/main/bsp/src/bsp_pwm.cpp): `bsp/src/bsp_pwm.cpp`

### Control utilities

- [PID utilities](https://github.com/ericzhengpig1-png/rm27_training_framework_hw/blob/main/libs/src/pid.cpp): `libs/src/pid.cpp`
- [Math and CRC](https://github.com/ericzhengpig1-png/rm27_training_framework_hw/blob/main/libs/src/crc.cpp): `libs/src/crc.cpp`

### Robot modules

- [IMU data types](https://github.com/ericzhengpig1-png/rm27_training_framework_hw/blob/main/modules/include/IMU.hpp): `modules/include/IMU.hpp`
- [BMI088 driver](https://github.com/ericzhengpig1-png/rm27_training_framework_hw/blob/main/modules/src/BMI088.cpp): `modules/src/BMI088.cpp`
- [DJI motor model](https://github.com/ericzhengpig1-png/rm27_training_framework_hw/blob/main/modules/include/DJIMotor.hpp): `modules/include/DJIMotor.hpp`
- [M2006 motor](https://github.com/ericzhengpig1-png/rm27_training_framework_hw/blob/main/modules/src/M2006.cpp): `modules/src/M2006.cpp`
- [Motor CAN handler](https://github.com/ericzhengpig1-png/rm27_training_framework_hw/blob/main/modules/src/DJIMotorHandler.cpp): `modules/src/DJIMotorHandler.cpp`
- [Motor control](https://github.com/ericzhengpig1-png/rm27_training_framework_hw/blob/main/modules/src/MotorControl.cpp): `modules/src/MotorControl.cpp`
- [IST8310 option](https://github.com/ericzhengpig1-png/rm27_training_framework_hw/tree/main/modules): `modules`

### ThreadX tasks

- [IMU and control tasks](https://github.com/ericzhengpig1-png/rm27_training_framework_hw/blob/main/threads/src/alivethread.cpp): `threads/src/alivethread.cpp`
- [Thread data snapshots](https://github.com/ericzhengpig1-png/rm27_training_framework_hw/blob/main/threads/include/threads.hpp): `threads/include/threads.hpp`

### Other components

- **STM32 board**
- **IMU sensor**
- **CAN motors**

## Connections

- STM32 board → Startup and peripherals: starts (evidence: `board/Core/Src/main.c`)
- Startup and peripherals → Generated HAL drivers: initializes (evidence: `board/Core/Src/main.c`)
- Startup and peripherals → ThreadX setup: starts (evidence: `board/Core/Src/main.c`)
- ThreadX setup → IMU and control tasks: creates tasks
- IMU and control tasks → BMI088 driver: reads sensor (evidence: `threads/src/alivethread.cpp`)
- IMU sensor → BMI088 driver: supplies measurements
- BMI088 driver → IMU data types: produces IMU data
- IMU and control tasks → Thread data snapshots: publishes snapshots (evidence: `threads/src/alivethread.cpp`)
- IMU and control tasks → CAN BSP: initializes CAN (evidence: `threads/src/alivethread.cpp`)
- IMU and control tasks → Motor control: initializes control (evidence: `threads/src/alivethread.cpp`)
- Motor control → PID utilities: uses PID
- Motor control → Motor CAN handler: updates outputs
- Motor CAN handler → DJI motor model: registers and updates (evidence: `modules/src/DJIMotorHandler.cpp`)
- Motor CAN handler → M2006 motor: handles model (evidence: `modules/src/DJIMotorHandler.cpp`)
- Motor CAN handler → CAN BSP: transmits CAN (evidence: `modules/src/DJIMotorHandler.cpp`)
- CAN BSP → CAN motors: sends frames
- BMI088 driver → PWM BSP: uses peripheral
- UART BSP → STM32 board: uses UART
- IMU and control tasks → Motor CAN handler: monitors motor health (evidence: `threads/src/alivethread.cpp`)
- IST8310 option → IMU and control tasks: optional sensor task (evidence: `README.md`)
- CAN BSP → UART BSP: layer order (evidence: `README.md`)
- UART BSP → PID utilities: layer order (evidence: `README.md`)
- PID utilities → Motor CAN handler: layer order (evidence: `README.md`)
- Motor CAN handler → IMU and control tasks: layer order (evidence: `README.md`)
- PID utilities → Math and CRC: shared utilities (evidence: `README.md`)
