// CMM (Command Macro Language): TRACE32's built-in scripting language
// Variables: GLOBAL (persist) vs LOCAL (sub-program scope)
GLOBAL &deviceId &testResult
LOCAL &loopCount &tempVal
// Assign values
&deviceId=0x1A560000
&loopCount=0. // decimal suffix required for decimal literals
&tempVal=Var.VALUE(g_vehicleSpeed_mps) // read from target
// String variables
LOCAL &msg
&msg="ECU Debug Session v3.2"
PRINT &msg
// Arithmetic
&tempVal=&tempVal*3.6 // convert m/s to km/h
PRINT "Speed: " FORMAT.FLOAT(2.,1.,&tempVal) " km/h"
// Hex formatting
PRINT "DeviceID: 0x" FORMAT.HEX(8.,&deviceId)
// Conditional
IF &tempVal>200.
PRINT %ERROR "Speed exceeds 200 km/h — verify sensor"
ELSE
PRINT "Speed OK"
// TRACE32 state checks
IF STATE.RUN() // CPU is currently running
PRINT "CPU running"
IF !STATE.RUN() // CPU is halted
PRINT "CPU halted at " FORMAT.ADDRESS(Register(PC))CMM Language Basics
Control Flow and Error Handling
// CMM control flow: loops, GOSUB, error handling
// WHILE loop: poll until flag set (max 10 iterations)
LOCAL &i &done
&i=0.
&done=0.
WHILE (&i<10.)&&(&done==0.)
(
IF Var.VALUE(g_initDone)==1
&done=1.
ELSE
(
WAIT 100ms
&i=&i+1.
)
)
IF &done==0.
PRINT %ERROR "g_initDone never set after 1s!"
// GOSUB: call sub-routine in same file
GOSUB WaitForHalt 5000. // 5000ms timeout
RETURN // end of main script
WaitForHalt:
ENTRY &timeout_ms
LOCAL &deadline
&deadline=CLOCK.HIRES()+(&timeout_ms*1000.)
WHILE STATE.RUN()
(
IF CLOCK.HIRES()>&deadline
(
PRINT %ERROR "Timeout waiting for halt"
RETURN
)
WAIT 10ms
)
PRINT "Halted at: " FORMAT.ADDRESS(Register(PC))
RETURN
// Error handling: ON.ERROR
ON.ERROR GOTO ErrorHandler
Data.LOAD.Elf "missing_file.elf" // this will fail
GOTO EndScript
ErrorHandler:
PRINT %ERROR "Script error: " ERROR.MESSAGE()
ENDDO
EndScript:
PRINT "Script complete"
ENDDOReusable CMM Macros Library
// Reusable TRACE32 utility macros — include with DO debug_utils.cmm
// Usage: DO debug_utils.cmm ; GOSUB WaitAndCheck "g_flag" 1. 2000.
RETURN // if called directly, return immediately
WaitAndCheck:
ENTRY &varname &expected &timeout_ms
LOCAL &start &val
&start=CLOCK.HIRES()
WHILE CLOCK.HIRES()-&start < (&timeout_ms*1000.)
(
&val=Var.VALUE(&varname)
IF &val==&expected
(
PRINT "OK: " &varname "==" FORMAT.HEX(8.,&expected) " in " (CLOCK.HIRES()-&start)/1000. "ms"
RETURN 0.
)
WAIT 10ms
)
PRINT %ERROR "TIMEOUT: " &varname " never reached " FORMAT.HEX(8.,&expected)
RETURN 1.
DumpCanStats:
LOCAL &txcnt &rxcnt &errcnt
&txcnt=Var.VALUE(g_CanTxCount)
&rxcnt=Var.VALUE(g_CanRxCount)
&errcnt=Var.VALUE(g_CanErrCount)
PRINT "CAN TX=" &txcnt " RX=" &rxcnt " ERR=" &errcnt
RETURNAutomated Regression Test with CMM
// Automated regression: run 5 test cases; report PASS/FAIL summary
LOCAL &pass &fail
&pass=0.
&fail=0.
// Test 1: CAN receive counter increments
Go CanRx_MainFunction
WAIT !STATE.RUN() 2s
LOCAL &cnt1 &cnt2
&cnt1=Var.VALUE(g_CanRxCount)
Go CanRx_MainFunction // run one more iteration
WAIT !STATE.RUN() 2s
&cnt2=Var.VALUE(g_CanRxCount)
IF &cnt2>&cnt1
&pass=&pass+1.
ELSE
(
PRINT %ERROR "FAIL TC1: CanRxCount did not increment"
&fail=&fail+1.
)
// Test 2: Speed conversion accurate to 0.1 km/h
Var.SET g_speedRaw 2778. // 100 km/h in 0.036 m/s units
Go App_SpeedFilter
WAIT !STATE.RUN() 2s
LOCAL &speed_kmh
&speed_kmh=Var.VALUE(g_speed_kmh)
IF ((&speed_kmh>99.9)&&(&speed_kmh<100.1))
&pass=&pass+1.
ELSE
(
PRINT %ERROR "FAIL TC2: speed=" FORMAT.FLOAT(2.,2.,&speed_kmh) " expected 100.0"
&fail=&fail+1.
)
PRINT ""
PRINT "=== Results: PASS=" &pass " FAIL=" &fail " ==="
IF &fail>0.
ENDDO 1. // exit code 1 = CI failure
ENDDO 0.Summary
CMM's LOCAL/GLOBAL scoping, GOSUB sub-routines, and ON.ERROR handlers make it a practical automation language for TRACE32. A well-structured CMM regression suite — connecting, loading, running to checkpoints, asserting variable values, and returning an exit code — integrates TRACE32 into CI pipelines using the T32 API or command-line t32mppc.exe. The key discipline is building a shared utility library (debug_utils.cmm) so individual test scripts stay short and focused on the test case, not the boilerplate of connecting and resetting.
🔬 Deep Dive — Core Concepts Expanded
This section builds on the foundational concepts covered above with additional technical depth, edge cases, and configuration nuances that separate competent engineers from experts. When working on production ECU projects, the details covered here are the ones most commonly responsible for integration delays and late-phase defects.
Key principles to reinforce:
- Configuration over coding: In AUTOSAR and automotive middleware environments, correctness is largely determined by ARXML configuration, not application code. A correctly implemented algorithm can produce wrong results due to a single misconfigured parameter.
- Traceability as a first-class concern: Every configuration decision should be traceable to a requirement, safety goal, or architecture decision. Undocumented configuration choices are a common source of regression defects when ECUs are updated.
- Cross-module dependencies: In tightly integrated automotive software stacks, changing one module's configuration often requires corresponding updates in dependent modules. Always perform a dependency impact analysis before submitting configuration changes.
🏭 How This Topic Appears in Production Projects
- Project integration phase: The concepts covered in this lesson are most commonly encountered during ECU integration testing — when multiple software components from different teams are combined for the first time. Issues that were invisible in unit tests frequently surface at this stage.
- Supplier/OEM interface: This is a topic that frequently appears in technical discussions between Tier-1 ECU suppliers and OEM system integrators. Engineers who can speak fluently about these details earn credibility and are often brought into critical design review meetings.
- Automotive tool ecosystem: Vector CANoe/CANalyzer, dSPACE tools, and ETAS INCA are the standard tools used to validate and measure the correct behaviour of the systems described in this lesson. Familiarity with these tools alongside the conceptual knowledge dramatically accelerates debugging in real projects.
⚠️ Common Mistakes and How to Avoid Them
- Assuming default configuration is correct: Automotive software tools ship with default configurations that are designed to compile and link, not to meet project-specific requirements. Every configuration parameter needs to be consciously set. 'It compiled' is not the same as 'it is correctly configured'.
- Skipping documentation of configuration rationale: In a 3-year ECU project with team turnover, undocumented configuration choices become tribal knowledge that disappears when engineers leave. Document why a parameter is set to a specific value, not just what it is set to.
- Testing only the happy path: Automotive ECUs must behave correctly under fault conditions, voltage variations, and communication errors. Always test the error handling paths as rigorously as the nominal operation. Many production escapes originate in untested error branches.
- Version mismatches between teams: In a multi-team project, the BSW team, SWC team, and system integration team may use different versions of the same ARXML file. Version management of all ARXML files in a shared repository is mandatory, not optional.
📊 Industry Note
Engineers who master both the theoretical concepts and the practical toolchain skills covered in this course are among the most sought-after professionals in the automotive software industry. The combination of AUTOSAR standards knowledge, safety engineering understanding, and hands-on configuration experience commands premium salaries at OEMs and Tier-1 suppliers globally.