HF-TMC51x0 Driver (TMC5130 & TMC5160) 0.1.0-dev
Hardware Agnostic C++ Driver for the TMC51x0 (TMC5130 & TMC5160)
Loading...
Searching...
No Matches
esp32_tmc51x0_test_config.hpp File Reference

ESP32 GPIO pin configuration and compile-time configuration for TMC51x0 driver (TMC5130 & TMC5160) More...

#include "driver/gpio.h"
#include "tmc51x0_comm_interface.hpp"
#include "features/tmc51x0_config_builder.hpp"
#include "esp32_tmc51x0_bus.hpp"
Include dependency graph for esp32_tmc51x0_test_config.hpp:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  tmc51x0_test_config::MotorConfig_17HS4401S
 Motor Configuration for 17HS4401S-PG518 NEMA 17 Stepper Motor (WITH GEARBOX) More...
 
struct  tmc51x0_test_config::MotorConfig_17HS4401S_Direct
 Motor Configuration for 17HS4401S NEMA 17 Stepper Motor (DIRECT DRIVE, NO GEARBOX) More...
 
struct  tmc51x0_test_config::MotorConfig_AppliedMotion_5034_369
 Motor Configuration for Applied Motion 5034-369 NEMA 34 Stepper Motor. More...
 
struct  tmc51x0_test_config::TestConfig_17HS4401S
 Test Rig Configuration Defaults. More...
 
struct  tmc51x0_test_config::TestConfig_17HS4401S::Motion
 
struct  tmc51x0_test_config::TestConfig_17HS4401S::StallGuard
 
struct  tmc51x0_test_config::TestConfig_AppliedMotion_5034
 Test Configuration for Applied Motion 5034-369 Motor. More...
 
struct  tmc51x0_test_config::TestConfig_AppliedMotion_5034::Motion
 
struct  tmc51x0_test_config::TestConfig_AppliedMotion_5034::StallGuard
 
struct  tmc51x0_test_config::BoardConfig_TMC51x0_EVAL
 Board hardware configuration for TMC51x0 Evaluation Kit. More...
 
struct  tmc51x0_test_config::BoardConfig_TMC51x0_BOB
 Board hardware configuration for TMC51x0 Break-Out Board (BOB) More...
 
struct  tmc51x0_test_config::PlatformConfig_CoreDriverTestRig
 Platform configuration for Core Driver Test Rig. More...
 
struct  tmc51x0_test_config::PlatformConfig_CoreDriverTestRig::ReferenceSwitches
 
struct  tmc51x0_test_config::PlatformConfig_CoreDriverTestRig::Encoder
 
struct  tmc51x0_test_config::PlatformConfig_CoreDriverTestRig::Mechanical
 
struct  tmc51x0_test_config::PlatformConfig_FatigueTestRig
 Platform configuration for Fatigue Test Rig. More...
 
struct  tmc51x0_test_config::PlatformConfig_FatigueTestRig::ReferenceSwitches
 
struct  tmc51x0_test_config::PlatformConfig_FatigueTestRig::Encoder
 
struct  tmc51x0_test_config::PlatformConfig_FatigueTestRig::Mechanical
 
struct  tmc51x0_test_config::TestConfigAccessor< motor_type >
 Test configuration accessor struct. More...
 
struct  tmc51x0_test_config::TestConfigAccessor< motor_type >::StallGuard
 
struct  tmc51x0_test_config::TestConfigAccessor< motor_type >::Motion
 
struct  tmc51x0_test_config::TestRigConfig< TestRigType::TEST_RIG_CORE_DRIVER >
 Test rig configuration for TEST_RIG_CORE_DRIVER. More...
 
struct  tmc51x0_test_config::TestRigConfig< TestRigType::TEST_RIG_FATIGUE >
 Test rig configuration for TEST_RIG_FATIGUE. More...
 

Namespaces

namespace  tmc51x0_test_config
 
namespace  tmc51x0_test_config::anonymous_namespace{esp32_tmc51x0_test_config.hpp}
 
namespace  tmc51x0_test_config::ConfigValidators
 Validator helper - checks if a type has required members.
 

Typedefs

template<TestRigType test_rig>
using tmc51x0_test_config::GetTestConfigForTestRig = typename TestRigConfig<test_rig>::Test
 Get test configuration accessor for a given test rig.
 

Enumerations

enum class  tmc51x0_test_config::MotorType { tmc51x0_test_config::MOTOR_17HS4401S_GEARBOX , tmc51x0_test_config::MOTOR_17HS4401S_DIRECT , tmc51x0_test_config::MOTOR_APPLIED_MOTION_5034 }
 Motor type enumeration for compile-time motor selection. More...
 
enum class  tmc51x0_test_config::BoardType { tmc51x0_test_config::BOARD_TMC51x0_EVAL , tmc51x0_test_config::BOARD_TMC51x0_BOB }
 Board type enumeration. More...
 
enum class  tmc51x0_test_config::PlatformType { tmc51x0_test_config::PLATFORM_CORE_DRIVER_TEST_RIG , tmc51x0_test_config::PLATFORM_FATIGUE_TEST_RIG }
 Platform type enumeration. More...
 
enum class  tmc51x0_test_config::TestRigType { tmc51x0_test_config::TEST_RIG_CORE_DRIVER , tmc51x0_test_config::TEST_RIG_FATIGUE }
 Test rig type enumeration. More...
 

Functions

Esp32SpiPinConfig tmc51x0_test_config::GetDefaultPinConfig () noexcept
 Complete pin configuration for all tests.
 
template<BoardType board_type>
void tmc51x0_test_config::ApplyBoardConfig (tmc51x0::DriverConfig &cfg) noexcept
 Helper function to apply board configuration to DriverConfig.
 
void tmc51x0_test_config::ConfigureDriverFromMotor_17HS4401S_Gearbox (tmc51x0::DriverConfig &cfg) noexcept
 Helper function to populate DriverConfig from 17HS4401S gearbox motor configuration.
 
void tmc51x0_test_config::ConfigureDriverFromMotor_17HS4401S_Direct (tmc51x0::DriverConfig &cfg) noexcept
 Helper function to populate DriverConfig from 17HS4401S direct drive motor configuration.
 
void tmc51x0_test_config::ConfigureDriverFromMotor_AppliedMotion_5034 (tmc51x0::DriverConfig &cfg) noexcept
 Helper function to populate DriverConfig from Applied Motion 5034 motor configuration.
 
template<PlatformType platform_type>
void tmc51x0_test_config::ApplyPlatformConfig (tmc51x0::DriverConfig &cfg) noexcept
 Helper function to apply platform configuration to DriverConfig.
 
template<PlatformType platform_type>
tmc51x0::ReferenceSwitchConfig tmc51x0_test_config::GetReferenceSwitchConfig () noexcept
 Helper function to configure reference switches from platform config.
 
template<PlatformType platform_type>
tmc51x0::EncoderConfig tmc51x0_test_config::GetEncoderConfig () noexcept
 Helper function to configure encoder from platform config.
 
template<PlatformType platform_type>
constexpr uint16_t tmc51x0_test_config::GetEncoderPulsesPerRev () noexcept
 Helper function to get encoder pulses per revolution from platform config.
 
template<PlatformType platform_type>
bool tmc51x0_test_config::GetEncoderInvertDirection () noexcept
 Helper function to get encoder invert direction flag from platform config.
 
template<TestRigType test_rig>
constexpr MotorType tmc51x0_test_config::GetTestRigMotorType () noexcept
 Get motor type for a given test rig.
 
template<TestRigType test_rig>
constexpr BoardType tmc51x0_test_config::GetTestRigBoardType () noexcept
 Get board type for a given test rig.
 
template<TestRigType test_rig>
constexpr PlatformType tmc51x0_test_config::GetTestRigPlatformType () noexcept
 Get platform type for a given test rig.
 
template<TestRigType test_rig>
void tmc51x0_test_config::ConfigureDriverFromTestRig (tmc51x0::DriverConfig &cfg, bool use_direct_drive=false) noexcept
 Configure driver from test rig selection.
 
template<TestRigType test_rig>
tmc51x0::ReferenceSwitchConfig tmc51x0_test_config::GetTestRigReferenceSwitchConfig () noexcept
 Get reference switch configuration for a test rig.
 
template<TestRigType test_rig>
tmc51x0::EncoderConfig tmc51x0_test_config::GetTestRigEncoderConfig () noexcept
 Get encoder configuration for a test rig.
 
template<TestRigType test_rig>
constexpr uint16_t tmc51x0_test_config::GetTestRigEncoderPulsesPerRev () noexcept
 Get encoder pulses per revolution for a test rig.
 
template<TestRigType test_rig>
bool tmc51x0_test_config::GetTestRigEncoderInvertDirection () noexcept
 Get encoder invert direction flag for a test rig.
 
template<TestRigType test_rig>
constexpr uint16_t tmc51x0_test_config::GetTestRigMotorOutputFullSteps (bool use_direct_drive=false) noexcept
 Get motor output full steps per revolution for a test rig.
 

Variables

constexpr gpio_num_t tmc51x0_test_config::SPI_SCK = GPIO_NUM_5
 SPI clock pin.
 
constexpr gpio_num_t tmc51x0_test_config::SPI_MOSI = GPIO_NUM_6
 SPI MOSI (master out, slave in)
 
constexpr gpio_num_t tmc51x0_test_config::SPI_MISO = GPIO_NUM_2
 SPI MISO (master in, slave out)
 
constexpr gpio_num_t tmc51x0_test_config::SPI_CS = GPIO_NUM_18
 SPI chip select pin.
 
constexpr gpio_num_t tmc51x0_test_config::DRV_EN = GPIO_NUM_11
 Driver enable pin (DRV_ENN)
 
constexpr gpio_num_t tmc51x0_test_config::CLK = GPIO_NUM_10
 Clock input pin (CLK, pin 12)
 
constexpr gpio_num_t tmc51x0_test_config::SPI_MODE_PIN = GPIO_NUM_0
 SPI_MODE pin (pin 22) - GPIO0 if available as control pin.
 
constexpr gpio_num_t tmc51x0_test_config::SD_MODE_PIN = GPIO_NUM_1
 SD_MODE pin (pin 21) - GPIO1 if available as control pin.
 
constexpr gpio_num_t tmc51x0_test_config::DIAG0 = GPIO_NUM_23
 Diagnostic output 0 (DIAG0_SWN, pin 26)
 
constexpr gpio_num_t tmc51x0_test_config::DIAG1 = GPIO_NUM_15
 Diagnostic output 1 (DIAG1_SWP, pin 27)
 
constexpr gpio_num_t tmc51x0_test_config::DIR = static_cast<gpio_num_t>(-1)
 Direction pin (optional)
 
constexpr gpio_num_t tmc51x0_test_config::STEP = static_cast<gpio_num_t>(-1)
 Step pin (optional)
 
constexpr uint32_t tmc51x0_test_config::SPI_CLOCK_SPEED_HZ = 500000
 SPI clock speed.
 
constexpr spi_host_device_t tmc51x0_test_config::SPI_HOST = SPI2_HOST
 SPI host device.
 

Detailed Description

ESP32 GPIO pin configuration and compile-time configuration for TMC51x0 driver (TMC5130 & TMC5160)

This file defines compile-time configuration for TMC51x0 driver initialization using struct-based configuration with static constexpr members for zero runtime overhead.

Configuration Structure

All configurations are defined as structs with static constexpr members:

  • MotorConfig: Motor-specific configurations (physical specs, chopper, StealthChop)
  • BoardConfig: Board-specific hardware parameters (sense resistor, MOSFETs, clock)
  • PlatformConfig: Platform/application-specific configuration (switches, encoder, mechanical)
  • TestConfig: Test-specific parameters (StallGuard, motion profiles)

Configuration Hierarchy

  1. BoardConfig: Hardware parameters that stay the same for the same driver board
    • Sense resistor value (0.05Ω typical)
    • Clock frequency (12 MHz internal)
    • MOSFET characteristics (Miller charge, BBM time)
    • Short protection defaults
  2. MotorConfig: Motor-specific parameters that depend on the motor being used
    • Motor physical specs (steps/rev, rated current, resistance, inductance)
    • Chopper settings (TOFF, TBL, HSTRT, HEND)
    • StealthChop settings (PWM frequency, offset, autoscale)
    • Current settings (calculated automatically from motor specs)
  3. PlatformConfig: Application/platform-specific parameters
    • Reference switches (endstops) configuration
    • Encoder configuration
    • Mechanical system (gearing, leadscrew, belt drive)
  4. TestConfig: Test-specific parameters for bounds finding and motion profiles
    • StallGuard thresholds and CoolStep settings
    • Homing speeds and timeouts
    • Fatigue test defaults

Usage

Unified Test Rig Selection (Recommended)

The TestRigConfig template provides unified access to all configurations:

// Select test rig at compile time - automatically selects motor, board, and platform
// 1. Configure driver from test rig (automatically configures everything)
// Or use the convenience function:
tmc51x0_test_config::ConfigureDriverFromTestRig<SELECTED_TEST_RIG>(cfg);
// 2. Initialize driver
driver.Initialize(cfg);
// 3. Access test configuration values
float speed = Config::Test::Motion::BOUNDS_SEARCH_SPEED_RPM;
int8_t sgt = Config::Test::StallGuard::SGT_HOMING;
// 4. Get encoder and reference switch configs
auto ref_cfg = Config::GetReferenceSwitchConfig();
auto enc_cfg = Config::GetEncoderConfig();
driver.switches.ConfigureReferenceSwitch(ref_cfg);
driver.encoder.Configure(enc_cfg);
static constexpr tmc51x0_test_config::TestRigType SELECTED_TEST_RIG
Definition main.cpp:50
TestRigType
Test rig type enumeration.
Definition esp32_tmc51x0_test_config.hpp:325
@ TEST_RIG_FATIGUE
Fatigue test rig (Applied Motion 5034-369 motor, TMC51x0 EVAL board, reference switches,...
Driver initialization configuration structure.
Definition tmc51x0_types.hpp:2870
Base template for test rig configuration (undefined - forces explicit specialization)
Definition esp32_tmc51x0_test_config.hpp:996

Direct Struct Access

You can also access configuration structs directly:

// Access motor config values
uint16_t steps = MotorConfig_17HS4401S::OUTPUT_FULL_STEPS;
float gear_ratio = MotorConfig_17HS4401S::GEAR_RATIO;
// Access board config values
uint32_t sense_res = BoardConfig_TMC51x0_EVAL::SENSE_RESISTOR_MOHM;
// Access platform config values
auto left_level = PlatformConfig_CoreDriverTestRig::ReferenceSwitches::LEFT_ACTIVE_LEVEL;
uint16_t pulses = PlatformConfig_CoreDriverTestRig::Encoder::PULSES_PER_REV;
// Access test config values
float speed = TestConfig_17HS4401S::Motion::BOUNDS_SEARCH_SPEED_RPM;

Manual Selection (Advanced)

For advanced use cases, you can still manually select motor, board, and platform:

tmc51x0_test_config::ApplyBoardConfig<tmc51x0_test_config::BoardType::BOARD_TMC51x0_EVAL>(cfg);
tmc51x0_test_config::ApplyPlatformConfig<tmc51x0_test_config::PlatformType::PLATFORM_CORE_DRIVER_TEST_RIG>(cfg);
driver.Initialize(cfg);
void ConfigureDriverFromMotor_17HS4401S_Gearbox(tmc51x0::DriverConfig &cfg) noexcept
Helper function to populate DriverConfig from 17HS4401S gearbox motor configuration.
Definition esp32_tmc51x0_test_config.hpp:1078

This file also provides GPIO pin assignments and a complete Esp32SpiPinConfig structure.

Test Rig Configuration

The project uses two test rigs, each with a specific motor, board, and platform configuration:

  1. Core Driver Test Rig (TEST_RIG_CORE_DRIVER):
    • Motor: 17HS4401S motor with gearbox (default) or direct drive
    • Board: TMC51x0 Evaluation Kit (BOARD_TMC51x0_EVAL)
    • Platform: Core Driver Test Rig (PLATFORM_CORE_DRIVER_TEST_RIG)
    • Features: Reference switches, encoder (AS5047U), gearbox or direct drive
    • Used for: Most comprehensive tests, core driver functionality
    • Examples: internal_ramp_comprehensive_test, spi_daisy_chain_comprehensive_test, stallguard_tuning
  2. Fatigue Test Rig (TEST_RIG_FATIGUE):
    • Motor: Applied Motion 5034-369 motor (MOTOR_APPLIED_MOTION_5034)
    • Board: TMC51x0 Evaluation Kit (BOARD_TMC51x0_EVAL)
    • Platform: Fatigue Test Rig (PLATFORM_FATIGUE_TEST_RIG)
    • Features: Reference switches, encoder (AS5047U), direct drive (NEMA 34)
    • Used for: Bounds finding and sinusoidal motion testing
    • Examples: fatigue_test_stallguard, fatigue_test_encoder, internal_ramp_sinusoidal
Author
Nebiyu Tadesse
Date
2025