File Structure and Software Layers

This section describes the directory layout of the motor control solution, the role of each source file, and how SysConfig generates peripheral initialization code that ties the hardware to the application.

Software Layer Overview

The motor control software is organized into four layers. Each layer has a well-defined responsibility and communicates only with the layer directly above or below it.

digraph software_layers { rankdir=TB; node [shape=box, style="filled,rounded", fontname="Helvetica", fontsize=11, margin="0.2,0.1"]; edge [color="#555555"]; A [label="Application Entry Point\nmain.c / isr.c", fillcolor="#d4e6f1", color="#2980b9"]; B [label="Application Library\napplication.c / foc.h", fillcolor="#d5f5e3", color="#27ae60"]; C [label="Motor Control HAL\nhal.c / hal_foc_interface / hal_gate_driver", fillcolor="#fdebd0", color="#e67e22"]; D [label="SDK Driverlib + SysConfig Generated\nti_sdk_dl_config.h / dl_adc.h / dl_timer.h", fillcolor="#f9ebea", color="#e74c3c"]; E [label="AM13E2X Hardware\nADC · MCPWM · CMPSS · UART · GPIO", fillcolor="#f2f3f4", color="#7f8c8d"]; A -> B -> C -> D -> E; }

Layer

Files

Responsibility

Application Entry

main.c, isr.c, main.h

System init, ISR registration, background loop

Application Library

application.c, application.h, foc.h, motor_common.h, ti_tune.h

FOC algorithm, state machines, observers

Motor Control HAL

hal.c, hal_foc_interface, hal_gate_driver, hal_communication

Hardware abstraction for ADC, PWM, gate driver

SDK Driverlib + SysConfig

ti_sdk_dl_config.h, dl_adc.h, dl_timer.h

Register-level peripheral access, generated init


Directory Structure

solutions/motor_control/
├── ufoc_lp_bxl/
│   ├── 3sh_sen_less_foc_drv8323rh/          ← 3-shunt example (DRV8323RH gate driver)
│   │   ├── main.c                      ← System init, background loop
│   │   ├── isr.c                       ← ADC ISR → application_run()
│   │   ├── main.h                      ← System-level defines (LED, relay timing)
│   │   ├── README_<DEVICE>.md          ← e.g. README_AM13E230X.md, README_AM13E232X.md
│   │   └── <device>_lp/m33_nortos/     ← e.g. am13e230x_lp, am13e232x_lp
│   │       ├── 3sh_sen_less_foc_drv8323rh*.syscfg   ← SysConfig: ADC, PWM, CMPSS, UART
│   │       ├── ti_arm_clang/           ← CCS project files
│   │       └── iar_arm/                ← IAR project files
│   │
│   └── 1sh_sen_less_foc_drv8329a/           ← 1-shunt example (DRV8329A gate driver)
│       ├── main.c
│       ├── isr.c
│       ├── main.h
│       └── am13e230x_lp/m33_nortos/    ← AM13E230X only
│           └── 1sh_sen_less_foc_drv8329a.syscfg
│
└── common_files/                       ← Shared across all motor control examples
    ├── app_lib/
    │   ├── include/
    │   │   ├── application.h           ← ISR state machine, inline FOC helpers
    │   │   ├── foc.h                   ← FOC feedback, observers, feedforward
    │   │   ├── motor_common.h          ← All motor structs, enums, fault flags
    │   │   └── ti_tune.h               ← TiTune parameter identification API
    │   └── source/
    │       ├── application.c           ← application_run(), FOC_runLowPriorityStateMachine()
    │       ├── motor_common.c          ← Motor monitor, fault handling
    │       └── ti_tune.c               ← TiTune state machine implementation
    │
    ├── hal/
    │   ├── controller_interface/
    │   │   ├── include/
    │   │   │   ├── hal.h               ← HAL public API (init, setParams, interrupts)
    │   │   │   ├── hal_obj.h           ← HAL object structure
    │   │   │   └── hal_data.h          ← ADC data, PWM data structures
    │   │   └── source/
    │   │       └── hal.c               ← HAL_init(), HAL_setParams()
    │   ├── foc_interface/
    │   │   ├── include/
    │   │   │   ├── hal_foc_interface.h ← HAL_FOC_Interface_t, ADC/PWM config
    │   │   │   ├── hal_1sh_foc_interface.h  ← 1-shunt current reconstruction
    │   │   │   └── hal_3sh_foc_interface.h  ← 3-shunt direct current reading
    │   │   └── source/
    │   │       ├── hal_1sh_foc_interface.c
    │   │       └── hal_3sh_foc_interface.c
    │   ├── gate_driver_interface/
    │   │   ├── include/
    │   │   │   └── hal_gate_driver.h   ← HAL_GD_vTable_t vtable interface
    │   │   ├── drv8323rh/
    │   │   │   ├── drv8323rh_interface.h
    │   │   │   └── drv8323rh_interface.c
    │   │   └── drv8329a/
    │   │       ├── drv8329a_interface.h
    │   │       └── drv8329a_interface.c
    │   └── communication_interface/
    │       └── include/
    │           └── hal_communication.h ← Serial plot (UART), DAC debug output
    │
    ├── app_lib/
    │   ├── include/
    │   │   └── motor_params.h          ← Motor_ParamsType: Rs, Ls, flux, poles
    │   └── source/
    │       └── motor_params.c          ← Motor parameter tables (Teknic, Panasonic, ...)
    │
ufoc_lp_bxl/<solution>/
    ├── system_config/
    │   ├── user_mtr1.h                 ← Board constants: PWM freq, sense gains, limits
    │   ├── mtr_config.h                ← Aggregates user_mtr1.h + mtr1_init.h
    │   ├── mtr1_init.h                 ← Global variable declarations, init prototypes
    │   ├── mtr1_init.c                 ← initMotor1Handles(), initMotor1CtrlParameters()
    │   ├── system_config.c             ← HAL_FOC_Config_t, gate driver obj, interface instantiation
    │   └── system_config.h             ← extern declarations for all objects above
    │

Key Source Files

Application Entry Point

File

Purpose

main.c

Calls Device_Init(), SYSCFG_DL_init(), HAL init, motor init, calibration, then enters background loop

isr.c

Defines ADC0_INT1_IRQHandler — acknowledges ADC interrupt, calls application_run()

main.h

System timing constants: LED_BLINK_FREQ_Hz, POWER_RELAY_WAIT_TIME_ms, LOW_PRIORITY_WAIT_TIME_1ms

Application Library

File

Purpose

application.h

All state machine handlers as static inline functions; application_run() and FOC_runLowPriorityStateMachine() declarations

foc.h

FOC algorithm sections: FOC_runFeedback(), FOC_runObservers(), FOC_runFeedforward() as static inline

application.c

application_run() — calls the 5 FOC sections in order; FOC_runLowPriorityStateMachine()

motor_common.h

All motor data structures, enums (MOTOR_State_e, ESTIMATOR_Mode_e), fault flags

ti_tune.h

TiTune API: TiTune_Run_stateMachine(), TiTune_Obj, state enum

Motor Configuration

File

Purpose

user_mtr1.h

Board-level constants — PWM frequency, ISR tick ratios, current/voltage sense scale factors, over-current limits

motor_params.h

Motor_ParamsType struct — motor nameplate data (Rs, Ld, Lq, flux, pole pairs)

motor_params.c

Motor parameter tables for supported motors; motorParams_M1 pointer selects active motor

mtr1_init.h

Global variable declarations (motorVars_M1, motorSetVars_M1, userParams_M1); init function prototypes

mtr_config.h

Aggregation header — includes user_mtr1.h, mtr1_init.h, userParams.h

system_config.c (3-shunt)

Hardware wiring file (3-shunt) — instantiates HAL_FOC_Config_t, HAL_DRV8323_Obj, HAL_GD_Interface_t, HAL_FOC_Interface_t, and MOTOR_Vars_t; primary file to update when migrating to a new board

system_config.h (3-shunt)

extern declarations for all objects in system_config.c (3-shunt)

system_config.c (1-shunt)

Hardware wiring file (1-shunt) — equivalent of the 3-shunt system_config.c for DRV8329A topology

system_config.h (1-shunt)

extern declarations for all objects in system_config.c (1-shunt)


SysConfig Integration

SysConfig (.syscfg) is the graphical peripheral configuration tool. It generates ti_sdk_dl_config.h and ti_sdk_dl_config.c which contain all peripheral initialization code and symbolic macro names used throughout the motor control software.

digraph syscfg_flow { rankdir=LR; node [shape=box, style="filled,rounded", fontname="Helvetica", fontsize=11, margin="0.2,0.1"]; edge [color="#555555", fontname="Helvetica", fontsize=9]; A [label="SysConfig GUI\n*.syscfg", fillcolor="#d4e6f1", color="#2980b9"]; B [label="ti_sdk_dl_config.h\nPeripheral macros & init", fillcolor="#fdebd0", color="#e67e22"]; C [label="hal.c\nHAL_init()", fillcolor="#d5f5e3", color="#27ae60"]; D [label="hal_foc_interface.c\nADC channel names", fillcolor="#d5f5e3", color="#27ae60"]; E [label="isr.c\nIRQ handler names", fillcolor="#d5f5e3", color="#27ae60"]; F [label="SYSCFG_DL_init()\nin main.c", fillcolor="#f9ebea", color="#e74c3c"]; A -> B [label="generates"]; B -> C; B -> D; B -> E; A -> F [label="calls"]; }

What SysConfig Configures

Peripheral

SysConfig Module

Generated Macro Example

ADC channels

adc

MTR1_IW_SEN, MTR1_VU_SEN, MTR1_VW_SEN

PWM (MCPWM)

mcpwm

MTR1_PWM_U, MTR1_PWM_V, MTR1_PWM_W

Comparator (CMPSS)

cmpsslite

MTR1_CMPSS_U, MTR1_CMPSS_V, MTR1_CMPSS_W

ADC trigger

pwmxbar

DL_ADC_TRIGGER_PWM4_SOCA

UART (serial plot)

uart

SERIAL_DATA_PLOT_INST

GPIO (timing pin)

gpio

MTR1_FOC_CTRL_ISR_TIMING_PORT, MTR1_FOC_CTRL_ISR_TIMING_PIN

ECAP (IPD)

ecap

MTR1_ECAP_INST

Startup Sequence

int main(void)
{
    Device_Init();          // Clock, power domain init
    SYSCFG_DL_init();       // All peripherals configured by SysConfig

    HAL_disableGlobalInts();
    halHandle = HAL_init(&hal, sizeof(hal));   // HAL wraps SysConfig handles
    HAL_setParams(halHandle);                  // Apply motor-specific settings
    // ...
}

SYSCFG_DL_init() is the single call that initializes every peripheral. The HAL layer then wraps these peripheral handles with motor-control-specific logic.


1-Shunt vs 3-Shunt Topology

The two examples differ in how phase currents are measured. This affects the SysConfig configuration, the HAL FOC interface, and the gate driver.

digraph topology_compare { rankdir=TB; node [shape=box, style="filled,rounded", fontname="Helvetica", fontsize=11, margin="0.2,0.1"]; edge [color="#555555"]; subgraph cluster_3sh { label="3-Shunt (DRV8323RH)"; style=dashed; color="#2980b9"; A3 [label="3 × ADC channels\nIa, Ib, Ic direct", fillcolor="#d4e6f1", color="#2980b9"]; C3 [label="3 × CMPSS\nPer-phase OC protection", fillcolor="#d4e6f1", color="#2980b9"]; B3 [label="hal_3sh_foc_interface.c\nDirect Clarke transform", fillcolor="#fdebd0", color="#e67e22"]; A3 -> B3; C3 -> B3; } subgraph cluster_1sh { label="1-Shunt (DRV8329A)"; style=dashed; color="#27ae60"; A1 [label="1 × ADC channel\nDC-link current", fillcolor="#d5f5e3", color="#27ae60"]; C1 [label="1 × CMPSS\nDC-link OC protection", fillcolor="#d5f5e3", color="#27ae60"]; B1 [label="hal_1sh_foc_interface.c\nCurrent reconstruction", fillcolor="#fdebd0", color="#e67e22"]; A1 -> B1; C1 -> B1; } D [label="motor_common.h\nHAL_ADCData_t.I_A[]", fillcolor="#f9ebea", color="#e74c3c"]; B3 -> D; B1 -> D; }

Aspect

3-Shunt

1-Shunt

ADC channels

3 (Ia, Ib, Ic)

1 (DC-link)

CMPSS instances

3

1

Current reconstruction

Not needed

Required (sample timing critical)

HAL interface

hal_3sh_foc_interface.c

hal_1sh_foc_interface.c

Gate driver

DRV8323RH

DRV8329A

Include path

hal/gate_driver_interface/drv8323rh

hal/gate_driver_interface/drv8329a

The correct gate driver interface header directory must be added to the project’s include paths in CCS project settings (Project Properties → Build → Arm Compiler → Include Options).

The application code in motor_common.h uses CURRENTSEN_Type_e to select the correct current reading path at runtime, while the HAL FOC interface files provide the topology-specific HAL_ReadPhaseCurrents() implementation.