ESP32-C6 TMC9660 Comprehensive Test Suite
This directory contains comprehensive test suites for the TMC9660 motor driver using the ESP32-C6 DevKit-M-1. The tests support both the TMC9660-3PH-EVKIT (BLDC motor board) and TMC9660-STP-EVKIT (Stepper motor board).
π Table of Contents
- Hardware Overview
- Pin Connections
- Hardware Setup
- Building the Tests
- Running the Tests
- Test Suites
- Troubleshooting
π Hardware Overview
ESP32-C6 DevKit-M-1
The ESP32-C6 DevKit-M-1 serves as the host controller for communicating with the TMC9660 motor driver via SPI or UART.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
βββββββββββββββββββββββββββββββββββββββββββββββββββ
β ESP32-C6 DevKit-M-1 β
β β
β ββββββββββββββββββββββββββββββββββββββββββββ β
β β ESP32-C6 Microcontroller β β
β β β β
β β GPIO Pins: β β
β β β’ SPI: MOSI, MISO, SCLK, CS β β
β β β’ UART: TX, RX β β
β β β’ Control: RST, DRV_EN, FAULTN, WAKE β β
β ββββββββββββββββββββββββββββββββββββββββββββ β
β β
β USB-C Connector β
β (Power + Serial Communication) β
βββββββββββββββββββββββββββββββββββββββββββββββββββ
TMC9660-3PH-EVKIT (BLDC Motor Board)
Evaluation kit for 3-phase BLDC motor control with Hall sensors and ABN encoders.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
βββββββββββββββββββββββββββββββββββββββββββββββββββ
β TMC9660-3PH-EVKIT β
β β
β ββββββββββββββββββββββββββββββββββββββββββββ β
β β TMC9660 IC β β
β β β β
β β Features: β β
β β β’ 3-phase BLDC motor driver β β
β β β’ Hall sensor inputs (U, V, W) β β
β β β’ Dual ABN encoder inputs β β
β β β’ SPI Flash memory β β
β β β’ Brake chopper & mechanical brake β β
β ββββββββββββββββββββββββββββββββββββββββββββ β
β β
β Motor Connectors: β
β β’ U, V, W (3-phase motor) β
β β’ Hall sensors (GPIO2, 3, 4) β
β β’ ABN encoder 1 (GPIO8, 13, 14) β
β β’ ABN encoder 2 (GPIO15, 16) β
βββββββββββββββββββββββββββββββββββββββββββββββββββ
TMC9660-STP-EVKIT (Stepper Motor Board)
Evaluation kit for stepper motor control with reference switches and ABN encoders.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
βββββββββββββββββββββββββββββββββββββββββββββββββββ
β TMC9660-STP-EVKIT β
β β
β ββββββββββββββββββββββββββββββββββββββββββββ β
β β TMC9660 IC β β
β β β β
β β Features: β β
β β β’ Stepper motor driver β β
β β β’ Reference switches (Left, Right, Home)β β
β β β’ Dual ABN encoder inputs β β
β β β’ SPI Flash memory β β
β ββββββββββββββββββββββββββββββββββββββββββββ β
β β
β Motor Connectors: β
β β’ Step/Direction interface β
β β’ Reference switches (GPIO2, 3, 4) β
β β’ ABN encoder 1 (GPIO8, 13, 14) β
β β’ ABN encoder 2 (GPIO15, 16) β
βββββββββββββββββββββββββββββββββββββββββββββββββββ
π Pin Connections
SPI Communication Interface
1
2
3
4
5
6
7
8
9
10
11
12
13
ESP32-C6 DevKit-M-1 TMC9660-3PH-EVKIT / STP-EVKIT
ββββββββββββββββββ βββββββββββββββββββββββββββββββ
GPIO7 (MOSI) βββββββ> SPI MOSI
GPIO2 (MISO) <βββββββ SPI MISO
GPIO6 (SCLK) βββββββ> SPI SCLK
GPIO18 (CS) βββββββ> SPI CS
Control Pins:
ββββββββββββββββββ βββββββββββββββββββββββββββββββ
GPIO22 (RST) βββββββ> RST (Active HIGH)
GPIO20 (DRV_EN) βββββββ> DRV_EN (Active HIGH)
GPIO19 (FAULTN) <βββββββ FAULTN (Active LOW, open-drain)
GPIO21 (WAKE) βββββββ> WAKE (Active LOW)
UART Communication Interface (Alternative)
1
2
3
4
ESP32-C6 DevKit-M-1 TMC9660-3PH-EVKIT / STP-EVKIT
ββββββββββββββββββ βββββββββββββββββββββββββββββββ
GPIO5 (TX) βββββββ> UART RX (GPIO6 on TMC9660)
GPIO4 (RX) <βββββββ UART TX (GPIO7 on TMC9660)
Power and Common
1
2
3
4
ESP32-C6 DevKit-M-1 TMC9660-3PH-EVKIT / STP-EVKIT
ββββββββββββββββββ βββββββββββββββββββββββββββββββ
GND βββββββ> GND (Common ground)
3.3V / 5V βββββββ> VCC (if needed for level shifting)
π οΈ Hardware Setup
BLDC Motor Board Setup (TMC9660-3PH-EVKIT)
Connection Diagram
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
βββββββββββββββββββββββ βββββββββββββββββββββββ
β ESP32-C6 DevKit β β TMC9660-3PH-EVKIT β
β β β β
β GPIO7 (MOSI) ββββββΌββββββββββΌβ> SPI MOSI β
β GPIO2 (MISO) <βββββΌββββββββββΌβ< SPI MISO β
β GPIO6 (SCLK) ββββββΌββββββββββΌβ> SPI SCLK β
β GPIO18(CS) ββββββΌββββββββββΌβ> SPI CS β
β β β β
β GPIO22(RST) ββββββΌββββββββββΌβ> RST β
β GPIO20(DRV_EN) βββββΌββββββββββΌβ> DRV_EN β
β GPIO19(FAULTN)<βββββΌββββββββββΌβ< FAULTN β
β GPIO21(WAKE) ββββββΌββββββββββΌβ> WAKE β
β β β β
β GND ββββββΌββββββββββΌβ> GND β
β β β β
β β β Motor Connections: β
β β β β’ U, V, W (3-phase)β
β β β β’ Hall (2,3,4) β
β β β β’ Encoder1(8,13,14)β
β β β β’ Encoder2 (15,16) β
βββββββββββββββββββββββ βββββββββββββββββββββββ
Setup Steps
-
Power Off: Ensure both boards are powered off before making connections.
- Connect SPI Interface:
- Connect ESP32 GPIO7 β TMC9660 SPI MOSI
- Connect ESP32 GPIO2 β TMC9660 SPI MISO
- Connect ESP32 GPIO6 β TMC9660 SPI SCLK
- Connect ESP32 GPIO18 β TMC9660 SPI CS
- Connect Control Pins:
- Connect ESP32 GPIO22 β TMC9660 RST
- Connect ESP32 GPIO20 β TMC9660 DRV_EN
- Connect ESP32 GPIO19 β TMC9660 FAULTN
- Connect ESP32 GPIO21 β TMC9660 WAKE
-
Connect Ground: Connect GND between ESP32 and TMC9660 boards.
- Connect Motor (if testing with actual motor):
- Connect 3-phase BLDC motor to U, V, W terminals
- Connect Hall sensors to Hall connector (if using Hall feedback)
- Connect ABN encoder to Encoder connector (if using encoder feedback)
- Power On:
- Power ESP32 via USB-C
- Power TMC9660 board via its power supply (typically 12V-48V)
Stepper Motor Board Setup (TMC9660-STP-EVKIT)
Connection Diagram
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
βββββββββββββββββββββββ βββββββββββββββββββββββ
β ESP32-C6 DevKit β β TMC9660-STP-EVKIT β
β β β β
β GPIO7 (MOSI) ββββββΌββββββββββΌβ> SPI MOSI β
β GPIO2 (MISO) <βββββΌββββββββββΌβ< SPI MISO β
β GPIO6 (SCLK) ββββββΌββββββββββΌβ> SPI SCLK β
β GPIO18(CS) ββββββΌββββββββββΌβ> SPI CS β
β β β β
β GPIO22(RST) ββββββΌββββββββββΌβ> RST β
β GPIO20(DRV_EN) βββββΌββββββββββΌβ> DRV_EN β
β GPIO19(FAULTN)<βββββΌββββββββββΌβ< FAULTN β
β GPIO21(WAKE) ββββββΌββββββββββΌβ> WAKE β
β β β β
β GND ββββββΌββββββββββΌβ> GND β
β β β β
β β β Motor Connections: β
β β β β’ Step/Dir β
β β β β’ Ref Switches β
β β β (Left,Right,Home)β
β β β β’ Encoder1 (8,13,14)β
β β β β’ Encoder2 (15,16) β
βββββββββββββββββββββββ βββββββββββββββββββββββ
Setup Steps
-
Power Off: Ensure both boards are powered off before making connections.
- Connect SPI Interface: (Same as BLDC board)
- Connect ESP32 GPIO7 β TMC9660 SPI MOSI
- Connect ESP32 GPIO2 β TMC9660 SPI MISO
- Connect ESP32 GPIO6 β TMC9660 SPI SCLK
- Connect ESP32 GPIO18 β TMC9660 SPI CS
- Connect Control Pins: (Same as BLDC board)
- Connect ESP32 GPIO22 β TMC9660 RST
- Connect ESP32 GPIO20 β TMC9660 DRV_EN
- Connect ESP32 GPIO19 β TMC9660 FAULTN
- Connect ESP32 GPIO21 β TMC9660 WAKE
-
Connect Ground: Connect GND between ESP32 and TMC9660 boards.
- Connect Motor (if testing with actual motor):
- Connect stepper motor to motor connector
- Connect reference switches to REF SWITCHES connector (Left=GPIO2, Right=GPIO3, Home=GPIO4)
- Connect ABN encoder to Encoder connector (if using encoder feedback)
- Power On:
- Power ESP32 via USB-C
- Power TMC9660 board via its power supply
ποΈ Building the Tests
Prerequisites
- ESP-IDF: Version 5.5 (release/v5.5) or later
- Python: Version 3.8 or later (for ESP-IDF tools)
- CMake: Version 3.16 or later
- Git: For cloning the repository
- Bash: For running the build scripts (Linux/macOS/Git Bash on Windows)
Installation Steps
-
Install ESP-IDF (if not already installed):
1 2 3 4 5 6 7 8 9 10 11 12 13
# Clone ESP-IDF git clone --recursive https://github.com/espressif/esp-idf.git cd esp-idf # Checkout release version 5.5 git checkout release/v5.5 git submodule update --init --recursive # Install ESP-IDF (Linux/macOS) ./install.sh esp32c6 # Set up environment (add to ~/.bashrc or ~/.zshrc for persistence) . ./export.sh
-
Clone the Repository:
1 2
git clone <repository-url> cd hf-tmc9660-driver -
Navigate to ESP32 Examples:
1
cd examples/esp32 -
Setup Repository (First time only):
1 2 3
# Make scripts executable and setup the build environment chmod +x scripts/*.sh ./scripts/setup_repo.sh
Available Test Applications
The test suites use a centralized build system with scripts. Available applications:
| Application Name | Description | Board |
|---|---|---|
bldc_comprehensive_test |
Comprehensive BLDC motor testing with Hall sensors, ABN encoders, and velocity control | TMC9660-3PH-EVKIT |
stepper_comprehensive_test |
Comprehensive Stepper motor testing with FOC and step/dir control | TMC9660-STP-EVKIT |
dc_comprehensive_test |
Comprehensive DC motor testing with current and velocity control | TMC9660-3PH-EVKIT |
telemetry_comprehensive_test |
Comprehensive telemetry monitoring for temperature, current, voltage, and status | TMC9660-3PH-EVKIT |
bootloader_comprehensive_test |
Comprehensive bootloader testing for initialization and configuration | TMC9660-3PH-EVKIT |
List Available Applications
1
2
# List all available applications
./scripts/build_app.sh list
Output:
1
2
3
4
5
6
Available Applications:
β’ bldc_comprehensive_test - Comprehensive BLDC motor testing suite
β’ stepper_comprehensive_test - Comprehensive Stepper motor testing suite
β’ dc_comprehensive_test - Comprehensive DC motor testing suite
β’ telemetry_comprehensive_test - Comprehensive telemetry monitoring test suite
β’ bootloader_comprehensive_test - Comprehensive bootloader testing suite
Building Applications
Build Syntax
1
./scripts/build_app.sh <app_type> <build_type>
Parameters:
<app_type>: Application name (e.g.,bldc_comprehensive_test)<build_type>: Build configuration -DebugorRelease
Build Examples
1
2
3
4
5
6
7
8
9
10
11
12
13
14
# Build BLDC comprehensive test (Release build)
./scripts/build_app.sh bldc_comprehensive_test Release
# Build Stepper comprehensive test (Debug build)
./scripts/build_app.sh stepper_comprehensive_test Debug
# Build DC motor comprehensive test (Release build)
./scripts/build_app.sh dc_comprehensive_test Release
# Build Telemetry comprehensive test (Debug build)
./scripts/build_app.sh telemetry_comprehensive_test Debug
# Build Bootloader comprehensive test (Release build)
./scripts/build_app.sh bootloader_comprehensive_test Release
Build Output
Build artifacts are located in:
1
build-app-<app_type>-type-<build_type>-target-esp32c6-idf-<idf_version>/
Example:
1
build-app-bldc_comprehensive_test-type-Release-target-esp32c6-idf-release_v5.5/
Build Types
| Build Type | Optimization | Debug Info | Use Case |
|---|---|---|---|
Debug |
-O0 (no optimization) |
Full (-g3) |
Development, debugging |
Release |
-O2 (optimized) |
Minimal (-g0) |
Production, performance testing |
π Running the Tests
Flashing and Monitoring
The build scripts provide convenient commands for flashing and monitoring your ESP32-C6.
Flash and Monitor (Auto-detect Port)
1
./scripts/flash_app.sh <app_type> <build_type>
This command will:
- Auto-detect the ESP32 serial port
- Flash the firmware
- Start monitoring serial output
Flash and Monitor (Specify Port)
1
2
3
./scripts/flash_app.sh <app_type> <build_type> /dev/ttyUSB0 # Linux
./scripts/flash_app.sh <app_type> <build_type> /dev/cu.usbserial-* # macOS
./scripts/flash_app.sh <app_type> <build_type> COM3 # Windows
Flash Only (No Monitor)
1
./scripts/flash_app.sh <app_type> <build_type> --no-monitor
Monitor Only (Reconnect)
1
2
./scripts/monitor_app.sh
./scripts/monitor_app.sh /dev/ttyUSB0 # Linux (specify port)
Complete Workflow Example
1
2
3
4
5
6
7
8
9
10
11
# 1. Build the application
./scripts/build_app.sh bldc_comprehensive_test Release
# 2. Flash and monitor
./scripts/flash_app.sh bldc_comprehensive_test Release
# Output will show:
# β
Building app: bldc_comprehensive_test
# β
Build type: Release
# β
Flashing firmware...
# β
Starting monitor...
Expected Output
After flashing and running, you should see output like:
1
2
3
4
5
6
7
8
9
10
11
12
13
ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β ESP32-C6 BLDC COMPREHENSIVE TEST SUITE β
β HardFOC TMC9660 Driver Tests β
ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
Debug logging enabled for TMCL communication traces
ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β BLDC TEST SECTION CONFIGURATION β
ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
I (1234) BLDC_Test: Running core BLDC functionality tests...
I (5678) BLDC_Test: β
SPI bootloader initialization successful with EVKIT config
...
Test Progression Indicator
The test suite uses GPIO14 as a visual test progression indicator:
- LOW β HIGH β LOW: Each transition indicates a completed test
- Monitor GPIO14 with an oscilloscope or logic analyzer for visual feedback
Available Scripts
| Script | Purpose | Usage |
|---|---|---|
build_app.sh |
Build specific application | ./scripts/build_app.sh <app> <build_type> |
flash_app.sh |
Flash and monitor application | ./scripts/flash_app.sh <app> <build_type> [port] |
monitor_app.sh |
Monitor serial output | ./scripts/monitor_app.sh [port] |
setup_repo.sh |
Initial repository setup | ./scripts/setup_repo.sh |
clean_app.sh |
Clean build artifacts | ./scripts/clean_app.sh <app> <build_type> |
Advanced Build Options
For advanced configuration, you can use ESP-IDFβs menuconfig:
1
2
# Configure build options
./scripts/config_app.sh <app_type> <build_type>
This opens the ESP-IDF menuconfig where you can customize:
- Component config β TMC9660 Driver: Driver configuration options
- Serial flasher config: Serial port and flash settings
- Compiler options: Optimization and debug settings
π Test Suites
BLDC Comprehensive Test (BLDCComprehensiveTest.cpp)
Tests for 3-phase BLDC motor control:
- β Bootloader initialization and configuration
- β Motor type configuration (BLDC with various pole pairs)
- β Hall sensor configuration and testing
- β ABN encoder configuration and testing
- β FOC control loop configuration
- β Velocity and current control
- β Commutation modes (FOC_HALL, FOC_ABN, FOC_OPENLOOP)
- β Telemetry monitoring
- β Performance benchmarking
- β Error handling and edge cases
Board: TMC9660-3PH-EVKIT
Stepper Comprehensive Test (StepperComprehensiveTest.cpp)
Tests for stepper motor control:
- β Bootloader initialization and configuration
- β Motor type configuration (Stepper)
- β Reference switch configuration (Left, Right, Home)
- β ABN encoder configuration
- β FOC position control
- β Step/Direction control
- β Microstepping configuration
- β Position and velocity control
- β Stall detection
- β Telemetry monitoring
Board: TMC9660-STP-EVKIT
DC Motor Comprehensive Test (DCComprehensiveTest.cpp)
Tests for DC motor control:
- β Bootloader initialization and configuration
- β Motor type configuration (DC motor)
- β Current control and torque limiting
- β Velocity control with encoder feedback
- β Open-loop current mode
- β H-bridge control
- β Protection features
- β Telemetry monitoring
Board: TMC9660-3PH-EVKIT (same board as BLDC)
Telemetry Comprehensive Test (TelemetryComprehensiveTest.cpp)
Tests for telemetry and monitoring:
- β Temperature monitoring
- β Current monitoring
- β Voltage monitoring
- β Position and velocity feedback
- β System status reporting
- β Performance benchmarking
- β Multi-device monitoring
Board: TMC9660-3PH-EVKIT
Bootloader Comprehensive Test (BootloaderComprehensiveTest.cpp)
Tests for bootloader functionality:
- β Bootloader initialization
- β Mode detection (bootloader vs parameter)
- β Configuration reading and writing
- β Flash memory operations
- β Reset and recovery procedures
Board: TMC9660-3PH-EVKIT or TMC9660-STP-EVKIT
βοΈ Test Configuration
Each test suite supports enabling/disabling specific test categories via compile-time flags at the top of each test file:
1
2
3
4
5
// Enable/disable specific test categories
static constexpr bool ENABLE_CORE_TESTS = true;
static constexpr bool ENABLE_HALL_SENSOR_TESTS = true;
static constexpr bool ENABLE_ABN_ENCODER_TESTS = true;
// ... etc
Edit these flags to customize which tests run.
π§ Troubleshooting
Common Issues
1. Communication Timeout
Symptoms: Tests fail with communication timeout errors
Solutions:
- Verify all SPI/UART connections are secure
- Check that GPIO pins match the configuration
- Ensure proper ground connection between boards
- Check power supply voltage (TMC9660 may need 12V-48V)
2. Bootloader Not Detected
Symptoms: Tests fail at bootloader initialization
Solutions:
- Verify RST pin is properly connected (GPIO22)
- Check that FAULTN pin is connected (GPIO19)
- Try power cycling both boards
- Verify SPI communication with a logic analyzer
3. Motor Not Starting
Symptoms: Motor configuration succeeds but motor doesnβt run
Solutions:
- Verify DRV_EN pin is set (GPIO20)
- Check motor connections (U, V, W for BLDC)
- Verify current limits are set appropriately
- Check that PWM frequency is configured before setting current limits
- Ensure motor feedback (Hall/encoder) is properly connected if using closed-loop control
4. FAULTN Asserted
Symptoms: FAULTN pin is low (fault condition)
Solutions:
- Check TMC9660 datasheet for fault conditions
- Verify power supply voltage is within range
- Check for overcurrent conditions
- Verify motor connections are correct
- Check temperature (overtemperature protection)
5. Build Errors
Symptoms: ./scripts/build_app.sh fails
Solutions:
- Verify ESP-IDF is properly installed and sourced:
. $IDF_PATH/export.sh - Check that all submodules are initialized:
git submodule update --init --recursive - Verify script is executable:
chmod +x scripts/build_app.sh - Clean build:
./scripts/clean_app.sh <app_type> <build_type>then rebuild - Verify CMake and Python versions meet requirements
- Check that app name is valid:
./scripts/build_app.sh list
6. Script Not Found
Symptoms: ./scripts/build_app.sh: No such file or directory
Solutions:
- Ensure youβre in the
examples/esp32directory - Verify scripts exist:
ls scripts/ - Make scripts executable:
chmod +x scripts/*.sh - Run setup script:
./scripts/setup_repo.sh
Debugging Tips
-
Enable Debug Logging: The test suites enable DEBUG logging by default. Monitor serial output for detailed communication traces.
-
Use GPIO14 Indicator: Monitor GPIO14 with an oscilloscope to see test progression visually.
-
Logic Analyzer: Use a logic analyzer to monitor SPI/UART communication for detailed protocol analysis.
-
Oscilloscope: Monitor control pins (RST, DRV_EN, FAULTN, WAKE) to verify timing and states.
πΈ Hardware Setup Photos
Add photos of your actual hardware setup here:
- ESP32-C6 DevKit connected to TMC9660-3PH-EVKIT
- ESP32-C6 DevKit connected to TMC9660-STP-EVKIT
- Motor connections
- Overall test setup
π Additional Resources
- TMC9660 Datasheet: TMC9660.pdf
- TMC9660-3PH-EVKIT User Guide: tmc9660-3ph-eval-kit-ug.pdf
- TMC9660 Configuration Guide: tmc9660-configuration-and-bootstrapping.pdf
- TMCL Protocol Reference: TMCL_reference_2015.pdf
π License
Copyright (c) 2025 HardFOC. All rights reserved.
π₯ Contributing
Contributions are welcome! Please see the main repositoryβs CONTRIBUTING.md for guidelines.
Happy Testing! π