HF-TMC9660 Driver 0.1.0-dev
Hardware Agnostic C++ Driver for the TMC9660
Loading...
Searching...
No Matches
tmc9660 Namespace Reference

Namespaces

namespace  bootaddr
 Bootloader configuration register addresses.
 
namespace  bootcfg
 Bootloader configuration namespace containing all configuration structures and enums.
 
namespace  register_mode
 
namespace  tmcl
 TMCL command interface namespace for TMC9660.
 

Classes

struct  ABN1Config
 ABN encoder 1 configuration for incremental encoder feedback. More...
 
struct  ABN2Config
 ABN encoder 2 configuration for second incremental encoder. More...
 
struct  BootConfig
 Bootloader behavior configuration structure. More...
 
struct  BootloaderCommandSPI
 Bootloader command structure for SPI (40-bit / 5-byte protocol). More...
 
struct  BootloaderCommandUART
 Bootloader command structure for UART (64-bit / 8-byte protocol). More...
 
struct  BootloaderConfig
 Complete bootloader configuration structure. More...
 
struct  BootloaderFeatures
 Feature flags indicating available bootloader capabilities. More...
 
struct  BootloaderReplySPI
 Bootloader reply structure for SPI (40-bit / 5-byte protocol). More...
 
struct  BootloaderReplyUART
 Bootloader reply structure for UART (64-bit / 8-byte protocol). More...
 
struct  BootloaderVersion
 Bootloader version information structure. More...
 
struct  BrakeChopperConfig
 Brake chopper configuration for dynamic braking. More...
 
struct  ClockConfig
 System clock configuration structure. More...
 
class  CommInterface
 SPI status codes as per TMC9660 Parameter Mode. More...
 
struct  GitInfo
 Git version control information from bootloader firmware. More...
 
struct  GPIOConfig
 GPIO configuration structure for bootloader operation. More...
 
struct  HallConfig
 Hall encoder configuration for BLDC motor feedback. More...
 
struct  I2CConfig
 External I2C EEPROM configuration structure. More...
 
struct  LDOConfig
 Configuration structure for on-chip LDO regulators. More...
 
struct  MechBrakeConfig
 Mechanical brake configuration for holding motor position. More...
 
struct  MemStorageConfig
 External memory storage configuration for TMCL scripts and parameters. More...
 
struct  OtpBurnResult
 OTP burn operation result information. More...
 
struct  OtpLoadResult
 OTP load operation result information. More...
 
struct  PartitionVersion
 External memory partition version information. More...
 
struct  RefConfig
 Reference switches configuration for limit detection and homing. More...
 
struct  RS485Config
 RS485 transceiver configuration structure. More...
 
struct  SPIBootConfig
 SPI interface configuration for bootloader commands. More...
 
class  SpiCommInterface
 CRTP-based SPI implementation of TMC9660CommInterface. More...
 
struct  SPIEncConfig
 SPI encoder configuration for SPI-based position sensors. More...
 
struct  SPIFlashConfig
 External SPI flash memory configuration structure. More...
 
struct  StepDirConfig
 Step/Direction interface configuration for stepper motor control. More...
 
class  TMC9660
 Main class representing a TMC9660 motor driver in Parameter Mode. More...
 
class  TMC9660Bootloader
 Main TMC9660 bootloader interface class. More...
 
struct  TMCLFrame
 Frame structure for TMCL commands. More...
 
struct  TMCLReply
 Reply structure returned by TMCL command operations. More...
 
class  UartCommInterface
 CRTP-based UART implementation of TMC9660CommInterface. More...
 
struct  UARTConfig
 UART communication configuration structure. More...
 

Enumerations

enum class  BootloaderStatus : uint8_t {
  OK = 0 , CMD_NOT_FOUND = 1 , INVALID_ADDR = 3 , INVALID_VALUE = 4 ,
  INVALID_BANK = 14 , BUSY = 15 , MEM_UNCONFIGURED = 17 , OTP_ERROR = 18 ,
  SESSION_START = 19 , CMD_NOT_AVAILABLE = 20 , BOOTLOADER_RESUMED
}
 Bootloader status codes returned by command replies. More...
 
enum class  BootloaderCommand : uint8_t {
  GET_INFO = 0 , GET_BANK = 8 , SET_BANK = 9 , GET_ADDRESS = 10 ,
  SET_ADDRESS = 11 , READ_32 = 12 , READ_32_INC = 13 , READ_16 = 14 ,
  READ_16_INC = 15 , READ_8 = 16 , READ_8_INC = 17 , WRITE_32 = 18 ,
  WRITE_32_INC = 19 , WRITE_16 = 20 , WRITE_16_INC = 21 , WRITE_8 = 22 ,
  WRITE_8_INC = 23 , NO_OP = 29 , OTP_LOAD = 30 , OTP_BURN = 31 ,
  MEM_IS_CONFIGURED = 32 , MEM_IS_CONNECTED = 33 , FLASH_SEND_CMD = 36 , FLASH_ERASE_SECTOR = 37 ,
  MEM_IS_BUSY = 40 , BOOTSTRAP_RS485 = 255
}
 Bootloader command codes for memory and configuration operations. More...
 
enum class  MemoryBank : uint8_t {
  RAM = 0 , OTP = 1 , SPI_FLASH = 2 , I2C_EEPROM = 3 ,
  RESERVED = 4 , CONFIG = 5
}
 Memory bank identifiers for bootloader operations. More...
 
enum class  InfoQuery : uint32_t {
  CHIP_TYPE = 0 , BL_VERSION = 1 , FEATURES = 2 , GIT_INFO = 12 ,
  CHIP_VERSION = 13 , CHIP_FREQUENCY = 14 , CONFIG_MEM_START = 17 , CONFIG_MEM_SIZE = 18 ,
  OTP_MEM_SIZE = 19 , I2C_MEM_SIZE = 20 , SPI_MEM_SIZE = 21 , PARTITION_VERSION = 22 ,
  SPI_MEM_PARTITIONS = 25 , I2C_MEM_PARTITIONS = 26 , CHIP_VARIANT = 28
}
 GET_INFO query types for retrieving system information. More...
 
enum class  OtpBurnError : int8_t {
  INVALID_PAGE = -1 , NO_MORE_BURNS = -2 , CHARGE_PUMP_FAILED = -3 , BURN_PROCEDURE_FAILED = -4 ,
  CLOCK_SETUP_FAILED = -5 , CLOCK_RESTORE_FAILED = -6
}
 OTP burn operation error codes. More...
 
enum class  CommMode { SPI , UART }
 Supported physical communication modes for TMC9660. More...
 
enum class  TMC9660CtrlPin { RST , DRV_EN , FAULTN , WAKE }
 TMC9660 control pin identifiers with board-agnostic naming. More...
 
enum class  GpioSignal { INACTIVE = 0 , ACTIVE = 1 }
 GPIO signal states with board-agnostic naming. More...
 
enum class  SPIStatus : uint8_t { OK = 0xFF , CHECKSUM_ERROR = 0x00 , FIRST_CMD = 0x0C , NOT_READY = 0xF0 }
 SPI status codes as per TMC9660 Parameter Mode specification. More...
 

Functions

static constexpr uint8_t reverseByte (uint8_t b) noexcept
 Helper function for CRC-8 calculation (UART only).
 
static constexpr uint8_t crc8Bootloader (const uint8_t *data, size_t len) noexcept
 CRC-8 calculation for UART protocol (TMC9660 datasheet method).
 
const charGetDriverVersion () noexcept
 Get the TMC9660 driver version string (namespace-level).
 
static constexpr uint8_t tmclChecksum (const uint8_t *bytes, size_t n, uint8_t start=0) noexcept
 Calculate 8-bit checksum using sum of bytes method.
 

Enumeration Type Documentation

◆ BootloaderCommand

Bootloader command codes for memory and configuration operations.

These commands allow reading and writing to memory banks, configuring external devices, and querying system information. Each command may be followed by command-specific parameters in the 32-bit value field.

Note
Per TMC9660 datasheet Table 23
Enumerator
GET_INFO 

Get various basic information about the connected TMC9660.

GET_BANK 

Get the currently selected memory bank.

SET_BANK 

Set the memory bank.

GET_ADDRESS 

Get the current memory address.

SET_ADDRESS 

Set the memory address.

READ_32 

Read 32-bit data from selected memory bank/address.

READ_32_INC 

Read 32-bit data and increment address.

READ_16 

Read 16-bit data from selected memory bank/address.

READ_16_INC 

Read 16-bit data and increment address.

READ_8 

Read 8-bit data from selected memory bank/address.

READ_8_INC 

Read 8-bit data and increment address.

WRITE_32 

Write 32-bit data to selected memory bank/address.

WRITE_32_INC 

Write 32-bit data and increment address.

WRITE_16 

Write 16-bit data to selected memory bank/address.

WRITE_16_INC 

Write 16-bit data and increment address.

WRITE_8 

Write 8-bit data to selected memory bank/address.

WRITE_8_INC 

Write 8-bit data and increment address.

NO_OP 

No operation (for retrieving previous reply in SPI)

OTP_LOAD 

Read a programmed OTP page.

OTP_BURN 

Burn an OTP page.

MEM_IS_CONFIGURED 

Check whether an external memory bank is configured.

MEM_IS_CONNECTED 

Check whether an external memory is connected.

FLASH_SEND_CMD 

Send arbitrary commands to an external flash.

FLASH_ERASE_SECTOR 

Send a sector erase command to an external flash.

MEM_IS_BUSY 

Check whether an external memory is busy.

BOOTSTRAP_RS485 

Set up RS485 settings.

◆ BootloaderStatus

Bootloader status codes returned by command replies.

These status codes are returned by the bootloader to indicate the result of each command. Status OK (0) indicates successful command execution. Other status codes indicate various error conditions or special states.

Note
Per TMC9660 datasheet Table 23
Enumerator
OK 

Command executed successfully.

CMD_NOT_FOUND 

The request has an invalid command number.

INVALID_ADDR 

The memory address is not valid for the requested command.

INVALID_VALUE 

The request has an invalid value.

INVALID_BANK 

The memory bank is not valid for the requested command.

BUSY 

Bootloader has not yet finished processing the last command (SPI only)

MEM_UNCONFIGURED 

The external memory is not configured.

OTP_ERROR 

The OTP command has failed.

SESSION_START 

First SPI datagram after power-on (SPI only)

CMD_NOT_AVAILABLE 

The command is currently not available.

BOOTLOADER_RESUMED 

First SPI datagram after returning to bootloader from motor control (SPI only)

◆ CommMode

Supported physical communication modes for TMC9660.

Defines the available communication interfaces that can be used to communicate with the TMC9660 motor driver.

Enumerator
SPI 

SPI (Serial Peripheral Interface) mode - 4-wire synchronous communication.

UART 

UART (Universal Asynchronous Receiver-Transmitter) mode - 2-wire asynchronous communication

◆ GpioSignal

GPIO signal states with board-agnostic naming.

These signal states abstract the physical voltage levels to provide a consistent interface regardless of board implementation (active-high or active-low signals, inverters, etc.).

Enumerator
INACTIVE 

Inactive signal state (logical low)

ACTIVE 

Active signal state (logical high)

◆ InfoQuery

GET_INFO query types for retrieving system information.

These query types retrieve various system information including chip type, bootloader version, available features, memory sizes, and hardware capabilities. Use TMC9660Bootloader::getInfo() to query these values.

Note
Per TMC9660 datasheet Table 24
Enumerator
CHIP_TYPE 

Get the Chip type (returns 0x544D0001)

BL_VERSION 

Get bootloader version (major in upper 16 bits, minor in lower 16 bits)

FEATURES 

Get available feature groups (bit flags)

GIT_INFO 

Get Git version control information.

CHIP_VERSION 

Get silicon revision (TMC9660 reports revision 1)

CHIP_FREQUENCY 

Get system frequency in MHz.

CONFIG_MEM_START 

Get starting address of CONFIG memory.

CONFIG_MEM_SIZE 

Get size of CONFIG memory.

OTP_MEM_SIZE 

Get size of one OTP memory page.

I2C_MEM_SIZE 

Get memory size of connected I2C memory.

SPI_MEM_SIZE 

Get memory size of connected SPI memory.

PARTITION_VERSION 

Get version of external memory partition format.

SPI_MEM_PARTITIONS 

Get number of SPI memory partitions.

I2C_MEM_PARTITIONS 

Get number of I2C memory partitions.

CHIP_VARIANT 

Get chip variant (TMC9660 reports value 2)

◆ MemoryBank

Memory bank identifiers for bootloader operations.

The TMC9660 organizes memory into several banks for different purposes. The bootloader allows reading from and writing to these memory banks for configuration and program storage.

Enumerator
RAM 

Internal RAM.

OTP 

OTP memory.

SPI_FLASH 

External SPI Flash.

I2C_EEPROM 

External I2C EEPROM.

RESERVED 

Reserved.

CONFIG 

Configuration memory (runtime reconfiguration)

◆ OtpBurnError

OTP burn operation error codes.

These error codes are returned when an OTP burn operation fails. Negative values indicate specific failure modes during the programming process. Positive values (0 or greater) indicate successful operations.

Note
Per TMC9660 datasheet
Enumerator
INVALID_PAGE 

The OTP page number is invalid.

NO_MORE_BURNS 

Last OTP page burnt, no more burns possible.

CHARGE_PUMP_FAILED 

Setting up internal OTP charge pump failed.

BURN_PROCEDURE_FAILED 

The burn procedure failed.

CLOCK_SETUP_FAILED 

Internal clock setup for OTP operation failed.

CLOCK_RESTORE_FAILED 

Restoring original clock setup after OTP operation failed.

◆ SPIStatus

SPI status codes as per TMC9660 Parameter Mode specification.

These status codes are returned in the first byte of SPI replies to indicate the communication status and any errors that occurred.

Enumerator
OK 

Operation successful.

CHECKSUM_ERROR 

Checksum verification failed.

FIRST_CMD 

First command after initialization.

NOT_READY 

System busy, resend datagram.

◆ TMC9660CtrlPin

TMC9660 control pin identifiers with board-agnostic naming.

These pin identifiers abstract the physical pin assignments to provide a consistent interface regardless of board implementation (direct connection, inverters, level shifters, etc.).

Enumerator
RST 

External System Reset Input (pin 22) - Active high reset signal.

DRV_EN 

Driver enable input (pin 21) - Enables motor driver outputs.

FAULTN 

FAULT output signal (pin 20) - Open drain fault indication.

WAKE 

Wake input (pin 19) - Wake from hibernation mode.

Function Documentation

◆ crc8Bootloader()

static constexpr uint8_t tmc9660::crc8Bootloader ( const uint8_t * data,
size_t len )
staticconstexprnoexcept

CRC-8 calculation for UART protocol (TMC9660 datasheet method).

Calculates CRC-8 checksum using the TMC9660-specific algorithm. This is NOT a standard CRC-8 implementation - each input byte is bit-reversed before processing through the polynomial division.

Polynomial: x^8 + x^2 + x^1 + x^0 (9-bit: 0b100000111) Algorithm: Bit-reverse each input byte, perform polynomial division, return MSB-first result

Parameters
dataPointer to data bytes to calculate CRC over
lenNumber of data bytes
Returns
Calculated CRC-8 value
Note
This is NOT a standard CRC-8! Each byte is bit-reversed before processing.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ GetDriverVersion()

const char * tmc9660::GetDriverVersion ( )
inlinenoexcept

Get the TMC9660 driver version string (namespace-level).

Here is the caller graph for this function:

◆ reverseByte()

static constexpr uint8_t tmc9660::reverseByte ( uint8_t b)
staticconstexprnoexcept

Helper function for CRC-8 calculation (UART only).

These functions are used by the UART bootloader protocol for checksum calculation. They are automatically called by the ::BootloaderCommandUART serialization methods.

Bit-reverse a byte (LSB ↔ MSB).

Helper function used by the bootloader CRC-8 calculation to reverse the bit order of each input byte before polynomial division.

Parameters
bInput byte to reverse
Returns
Bit-reversed byte
Here is the caller graph for this function:

◆ tmclChecksum()

static constexpr uint8_t tmc9660::tmclChecksum ( const uint8_t * bytes,
size_t n,
uint8_t start = 0 )
staticconstexprnoexcept

Calculate 8-bit checksum using sum of bytes method.

This function implements the TMCL checksum algorithm which is simply the sum of all bytes in the datagram. The checksum is used to verify data integrity during communication.

Parameters
bytesPointer to the data bytes to checksum
nNumber of bytes to include in the checksum calculation
startStarting byte offset for checksum calculation (default: 0)
Returns
8-bit checksum value
Here is the caller graph for this function: