# lupi13/g474re_dnc_motor_control architecture

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

- Interactive diagram: https://gitdiagram.com/lupi13/g474re_dnc_motor_control
- Repository: https://github.com/lupi13/g474re_dnc_motor_control

## Overview

이 저장소는 STM32G474 기반 3상 PMSM FOC 드라이브 펌웨어입니다. 주 경로는 CANopen 또는 디버그 명령을 받아 속도/전류 지령으로 만들고, 1 kHz 속도 루프와 40 kHz 전류 루프를 거쳐 HRTIM PWM을 출력하는 것입니다. Hall 피드백, 보호, 파라미터 영속화는 별도 도메인 단계로 표시했습니다. 주요 주기와 지령 흐름은 README에 근거하며, 일부 세부 호출 관계는 발췌되지 않아 생략했습니다.

Main entry points: [`Core/App/app.c`](https://github.com/lupi13/g474re_dnc_motor_control/blob/main/Core/App/app.c) (드라이브 앱), [`Core/Control/motor_control.c`](https://github.com/lupi13/g474re_dnc_motor_control/blob/main/Core/Control/motor_control.c) (모터 제어 조정), [`Core/App/canopen_service.c`](https://github.com/lupi13/g474re_dnc_motor_control/blob/main/Core/App/canopen_service.c) (CANopen 서비스), [`Core/App/drive_parameter_manager.c`](https://github.com/lupi13/g474re_dnc_motor_control/blob/main/Core/App/drive_parameter_manager.c) (파라미터 관리자)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_commands["명령 및 CANopen"]
  node_canservice["CANopen 서비스<br/>[canopen_service.c]"]
  node_od["Object Dictionary<br/>[OD.c]"]
  node_commandsrc["명령 라우터<br/>[drive_command.c]"]
  node_debugsrc["디버그 명령"]
end

subgraph group_control["모터 제어"]
  node_app["드라이브 앱<br/>[app.c]"]
  node_motor["모터 제어 조정<br/>[motor_control.c]"]
  node_speed["속도 제어기<br/>[speed_controller.c]"]
  node_foc["FOC 전류 제어<br/>[foc.c]"]
  node_svpwm["SVPWM 변조<br/>[svpwm.c]"]
  node_hall_decode["Hall 디코더<br/>[hall_decoder.c]"]
  node_hall_estimate["Hall 추정기<br/>[hall_estimator.c]"]
end

subgraph group_hardware["보드 입출력"]
  node_main["초기화·주 루프<br/>[main.c]"]
  node_canadapter["FDCAN 어댑터"]
  node_adc["ADC 드라이버<br/>[adc_driver.c]"]
  node_current["전류 센서<br/>[current_sensor.c]"]
  node_voltage["전압 센서<br/>[voltage_sensor.c]"]
  node_hall_driver["Hall 입력<br/>[hall_driver.c]"]
  node_pwm["HRTIM PWM<br/>[pwm_driver.c]"]
end

subgraph group_safety["보호 및 관측"]
  node_fault["Fault 관리자<br/>[fault_manager.c]"]
  node_observer["디버그 관측"]
end

subgraph group_settings["설정 및 저장"]
  node_params["드라이브 파라미터<br/>[drive_parameters.c]"]
  node_manager["파라미터 관리자"]
  node_flash[("Flash 저장 드라이버")]
end

node_master(("CANopen master"))
node_debugger(("디버거"))

node_master -->|"CAN 프레임"| node_canadapter
node_canadapter -->|"수신 전달"| node_canservice
node_canservice -->|"OD 접근"| node_od
node_canservice -->|"명령 dispatch"| node_commandsrc
node_debugger -.->|"명령 입력"| node_debugsrc
node_debugsrc -.->|"지령 전달"| node_app
node_commandsrc -->|"지령 전달"| node_app
node_main -->|"주기 실행"| node_app
node_adc -->|"ADC 완료"| node_app
node_current -->|"전류 측정"| node_app
node_voltage -->|"DC 링크 측정"| node_app
node_hall_driver -->|"Hall 신호"| node_hall_decode
node_hall_decode -->|"위치 상태"| node_hall_estimate
node_hall_estimate -->|"회전자 피드백"| node_motor
node_app -->|"1 kHz 갱신"| node_speed
node_speed -->|"q축 전류 지령"| node_app
node_app -->|"고속 루프"| node_motor
node_motor -->|"전류 제어"| node_foc
node_foc -->|"전압 지령"| node_svpwm
node_motor -->|"듀티 출력"| node_pwm
node_app -->|"측정 보호"| node_fault
node_app -->|"상태 갱신"| node_observer
node_params -->|"기본값 제공"| node_manager
node_manager -->|"읽기·쓰기"| node_flash
node_manager -->|"설정 적용"| node_motor

click node_main "https://github.com/lupi13/g474re_dnc_motor_control/blob/main/Core/Src/main.c"
click node_canservice "https://github.com/lupi13/g474re_dnc_motor_control/blob/main/Core/App/canopen_service.c"
click node_od "https://github.com/lupi13/g474re_dnc_motor_control/blob/main/Core/Communication/object_dictionary/OD.c"
click node_canadapter "https://github.com/lupi13/g474re_dnc_motor_control/blob/main/Core/Platform/canopen_fdcan_adapter.c"
click node_commandsrc "https://github.com/lupi13/g474re_dnc_motor_control/blob/main/Core/App/drive_command.c"
click node_debugsrc "https://github.com/lupi13/g474re_dnc_motor_control/blob/main/Core/App/drive_debug_command_source.c"
click node_app "https://github.com/lupi13/g474re_dnc_motor_control/blob/main/Core/App/app.c"
click node_motor "https://github.com/lupi13/g474re_dnc_motor_control/blob/main/Core/Control/motor_control.c"
click node_speed "https://github.com/lupi13/g474re_dnc_motor_control/blob/main/Core/Control/speed_controller.c"
click node_foc "https://github.com/lupi13/g474re_dnc_motor_control/blob/main/Core/Control/foc.c"
click node_svpwm "https://github.com/lupi13/g474re_dnc_motor_control/blob/main/Core/Algorithm/svpwm.c"
click node_adc "https://github.com/lupi13/g474re_dnc_motor_control/blob/main/Core/Platform/adc_driver.c"
click node_current "https://github.com/lupi13/g474re_dnc_motor_control/blob/main/Core/Platform/current_sensor.c"
click node_voltage "https://github.com/lupi13/g474re_dnc_motor_control/blob/main/Core/Platform/voltage_sensor.c"
click node_hall_driver "https://github.com/lupi13/g474re_dnc_motor_control/blob/main/Core/Platform/hall_driver.c"
click node_hall_decode "https://github.com/lupi13/g474re_dnc_motor_control/blob/main/Core/Control/hall_decoder.c"
click node_hall_estimate "https://github.com/lupi13/g474re_dnc_motor_control/blob/main/Core/Control/hall_estimator.c"
click node_pwm "https://github.com/lupi13/g474re_dnc_motor_control/blob/main/Core/Platform/pwm_driver.c"
click node_fault "https://github.com/lupi13/g474re_dnc_motor_control/blob/main/Core/App/fault_manager.c"
click node_observer "https://github.com/lupi13/g474re_dnc_motor_control/blob/main/Core/App/drive_debug_observer.c"
click node_params "https://github.com/lupi13/g474re_dnc_motor_control/blob/main/Core/Config/drive_parameters.c"
click node_manager "https://github.com/lupi13/g474re_dnc_motor_control/blob/main/Core/App/drive_parameter_manager.c"
click node_flash "https://github.com/lupi13/g474re_dnc_motor_control/blob/main/Core/Platform/flash_storage_driver.c"

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_canservice,node_od,node_commandsrc,node_debugsrc toneBlue
class node_app,node_motor,node_speed,node_foc,node_svpwm,node_hall_decode,node_hall_estimate toneAmber
class node_main,node_canadapter,node_adc,node_current,node_voltage,node_hall_driver,node_pwm toneMint
class node_fault,node_observer toneRose
class node_params,node_manager,node_flash,node_master,node_debugger toneIndigo
```

## Components

### 명령 및 CANopen

- [CANopen 서비스](https://github.com/lupi13/g474re_dnc_motor_control/blob/main/Core/App/canopen_service.c): `Core/App/canopen_service.c`
- [Object Dictionary](https://github.com/lupi13/g474re_dnc_motor_control/blob/main/Core/Communication/object_dictionary/OD.c): `Core/Communication/object_dictionary/OD.c`
- [명령 라우터](https://github.com/lupi13/g474re_dnc_motor_control/blob/main/Core/App/drive_command.c): `Core/App/drive_command.c`
- [디버그 명령](https://github.com/lupi13/g474re_dnc_motor_control/blob/main/Core/App/drive_debug_command_source.c): `Core/App/drive_debug_command_source.c`

### 모터 제어

- [드라이브 앱](https://github.com/lupi13/g474re_dnc_motor_control/blob/main/Core/App/app.c): `Core/App/app.c`
- [모터 제어 조정](https://github.com/lupi13/g474re_dnc_motor_control/blob/main/Core/Control/motor_control.c): `Core/Control/motor_control.c`
- [속도 제어기](https://github.com/lupi13/g474re_dnc_motor_control/blob/main/Core/Control/speed_controller.c): `Core/Control/speed_controller.c`
- [FOC 전류 제어](https://github.com/lupi13/g474re_dnc_motor_control/blob/main/Core/Control/foc.c): `Core/Control/foc.c`
- [SVPWM 변조](https://github.com/lupi13/g474re_dnc_motor_control/blob/main/Core/Algorithm/svpwm.c): `Core/Algorithm/svpwm.c`
- [Hall 디코더](https://github.com/lupi13/g474re_dnc_motor_control/blob/main/Core/Control/hall_decoder.c): `Core/Control/hall_decoder.c`
- [Hall 추정기](https://github.com/lupi13/g474re_dnc_motor_control/blob/main/Core/Control/hall_estimator.c): `Core/Control/hall_estimator.c`

### 보드 입출력

- [초기화·주 루프](https://github.com/lupi13/g474re_dnc_motor_control/blob/main/Core/Src/main.c): `Core/Src/main.c`
- [FDCAN 어댑터](https://github.com/lupi13/g474re_dnc_motor_control/blob/main/Core/Platform/canopen_fdcan_adapter.c): `Core/Platform/canopen_fdcan_adapter.c`
- [ADC 드라이버](https://github.com/lupi13/g474re_dnc_motor_control/blob/main/Core/Platform/adc_driver.c): `Core/Platform/adc_driver.c`
- [전류 센서](https://github.com/lupi13/g474re_dnc_motor_control/blob/main/Core/Platform/current_sensor.c): `Core/Platform/current_sensor.c`
- [전압 센서](https://github.com/lupi13/g474re_dnc_motor_control/blob/main/Core/Platform/voltage_sensor.c): `Core/Platform/voltage_sensor.c`
- [Hall 입력](https://github.com/lupi13/g474re_dnc_motor_control/blob/main/Core/Platform/hall_driver.c): `Core/Platform/hall_driver.c`
- [HRTIM PWM](https://github.com/lupi13/g474re_dnc_motor_control/blob/main/Core/Platform/pwm_driver.c): `Core/Platform/pwm_driver.c`

### 보호 및 관측

- [Fault 관리자](https://github.com/lupi13/g474re_dnc_motor_control/blob/main/Core/App/fault_manager.c): `Core/App/fault_manager.c`
- [디버그 관측](https://github.com/lupi13/g474re_dnc_motor_control/blob/main/Core/App/drive_debug_observer.c): `Core/App/drive_debug_observer.c`

### 설정 및 저장

- [드라이브 파라미터](https://github.com/lupi13/g474re_dnc_motor_control/blob/main/Core/Config/drive_parameters.c): `Core/Config/drive_parameters.c`
- [파라미터 관리자](https://github.com/lupi13/g474re_dnc_motor_control/blob/main/Core/App/drive_parameter_manager.c): `Core/App/drive_parameter_manager.c`
- [Flash 저장 드라이버](https://github.com/lupi13/g474re_dnc_motor_control/blob/main/Core/Platform/flash_storage_driver.c): `Core/Platform/flash_storage_driver.c`

### Other components

- **CANopen master**
- **디버거**

## Connections

- CANopen master → FDCAN 어댑터: CAN 프레임
- FDCAN 어댑터 → CANopen 서비스: 수신 전달
- CANopen 서비스 → Object Dictionary: OD 접근
- CANopen 서비스 → 명령 라우터: 명령 dispatch
- 디버거 → 디버그 명령: 명령 입력
- 디버그 명령 → 드라이브 앱: 지령 전달
- 명령 라우터 → 드라이브 앱: 지령 전달
- 초기화·주 루프 → 드라이브 앱: 주기 실행
- ADC 드라이버 → 드라이브 앱: ADC 완료
- 전류 센서 → 드라이브 앱: 전류 측정
- 전압 센서 → 드라이브 앱: DC 링크 측정
- Hall 입력 → Hall 디코더: Hall 신호
- Hall 디코더 → Hall 추정기: 위치 상태
- Hall 추정기 → 모터 제어 조정: 회전자 피드백
- 드라이브 앱 → 속도 제어기: 1 kHz 갱신
- 속도 제어기 → 드라이브 앱: q축 전류 지령
- 드라이브 앱 → 모터 제어 조정: 고속 루프
- 모터 제어 조정 → FOC 전류 제어: 전류 제어
- FOC 전류 제어 → SVPWM 변조: 전압 지령
- 모터 제어 조정 → HRTIM PWM: 듀티 출력
- 드라이브 앱 → Fault 관리자: 측정 보호
- 드라이브 앱 → 디버그 관측: 상태 갱신
- 드라이브 파라미터 → 파라미터 관리자: 기본값 제공
- 파라미터 관리자 → Flash 저장 드라이버: 읽기·쓰기
- 파라미터 관리자 → 모터 제어 조정: 설정 적용
