![]() |
no-OS
|
Header file for TMC5240 driver. More...
Go to the source code of this file.
Classes | |
| struct | tmc5240_dev |
| TMC5240 device descriptor. More... | |
| struct | tmc5240_init_param |
| TMC5240 initialization parameters. More... | |
Macros | |
| #define | TMC5240_DEFAULT_D1 10 |
| #define | TMC5240_DEFAULT_D2 10 |
| #define | TMC5240_DEFAULT_VSTOP 10 |
Functions | |
| int | tmc5240_init (struct tmc5240_dev **device, struct tmc5240_init_param *init_param) |
| Initialize the TMC5240 device. | |
| int | tmc5240_remove (struct tmc5240_dev *device) |
| Free the resources allocated by the tmc5240_init() | |
| int | tmc5240_reg_read (struct tmc5240_dev *device, uint8_t reg_addr, uint32_t *reg_data) |
| Reads data from a given TMC5240 Register. | |
| int | tmc5240_reg_write (struct tmc5240_dev *device, uint8_t reg_addr, uint32_t reg_data) |
| Writes data to a given TMC5240 Register. | |
| int | tmc5240_reg_update (struct tmc5240_dev *device, uint8_t reg_addr, uint32_t mask, uint32_t val) |
| Read-modify-write a TMC5240 register. | |
| int | tmc5240_set_motion_profile (struct tmc5240_dev *device) |
| Set motion profile parameters for the TMC5240 motor driver. | |
| int | tmc5240_get_target_pos (struct tmc5240_dev *device, int32_t *position) |
| Get the target position of the motor. | |
| int | tmc5240_set_target_pos (struct tmc5240_dev *device, int32_t position) |
| Set the target position for the TMC5240 motor driver. | |
| int | tmc5240_get_current_pos (struct tmc5240_dev *device, int32_t *position) |
| Get the current position of the motor. | |
| int | tmc5240_set_current_pos (struct tmc5240_dev *device, int32_t position) |
| Replace the current position of the motor with a new absolute position value. | |
| int | tmc5240_get_current_accel (struct tmc5240_dev *device, int32_t *acceleration) |
| Get the current acceleration of the motor. | |
| int | tmc5240_get_current_vel (struct tmc5240_dev *device, int32_t *velocity) |
| Get the current velocity of the motor. | |
| int | tmc5240_set_target_vel (struct tmc5240_dev *device, int32_t velocity) |
| Set the target velocity for the TMC5240 motor driver. | |
| int | tmc5240_get_shaft_dir (struct tmc5240_dev *device, uint8_t *dir) |
| Get the shaft direction setting from the TMC5240 device. | |
| int | tmc5240_set_shaft_dir (struct tmc5240_dev *device, uint8_t dir) |
| Set the shaft direction for the TMC5240 device. | |
| int | tmc5240_get_amax (struct tmc5240_dev *device, int32_t *amax) |
| Get the maximum acceleration (AMAX) value. | |
| int | tmc5240_set_amax (struct tmc5240_dev *device, int32_t amax) |
| Set the maximum acceleration (AMAX) value. | |
| int | tmc5240_get_vmax (struct tmc5240_dev *device, int32_t *vmax) |
| Get the maximum velocity (VMAX) value. | |
| int | tmc5240_set_vmax (struct tmc5240_dev *device, int32_t vmax) |
| Set the maximum velocity (VMAX) value. | |
| int | tmc5240_get_dmax (struct tmc5240_dev *device, int32_t *dmax) |
| Get the maximum deceleration (DMAX) value. | |
| int | tmc5240_set_dmax (struct tmc5240_dev *device, int32_t dmax) |
| Set the maximum deceleration (DMAX) value. | |
| int | tmc5240_get_vstart (struct tmc5240_dev *device, int32_t *vstart) |
| Get the start velocity (VSTART) value. | |
| int | tmc5240_set_vstart (struct tmc5240_dev *device, int32_t vstart) |
| Set the start velocity (VSTART) value. | |
| int | tmc5240_get_a1 (struct tmc5240_dev *device, int32_t *a1) |
| Get the first acceleration phase (A1) value. | |
| int | tmc5240_set_a1 (struct tmc5240_dev *device, int32_t a1) |
| Set the first acceleration phase (A1) value. | |
| int | tmc5240_get_v1 (struct tmc5240_dev *device, int32_t *v1) |
| Get the first velocity threshold (V1) value. | |
| int | tmc5240_set_v1 (struct tmc5240_dev *device, int32_t v1) |
| Set the first velocity threshold (V1) value. | |
| int | tmc5240_get_a2 (struct tmc5240_dev *device, int32_t *a2) |
| Get the second acceleration phase (A2) value. | |
| int | tmc5240_set_a2 (struct tmc5240_dev *device, int32_t a2) |
| Set the second acceleration phase (A2) value. | |
| int | tmc5240_get_v2 (struct tmc5240_dev *device, int32_t *v2) |
| Get the second velocity threshold (V2) value. | |
| int | tmc5240_set_v2 (struct tmc5240_dev *device, int32_t v2) |
| Set the second velocity threshold (V2) value. | |
| int | tmc5240_get_d1 (struct tmc5240_dev *device, int32_t *d1) |
| Get the first deceleration phase (D1) value. | |
| int | tmc5240_set_d1 (struct tmc5240_dev *device, int32_t d1) |
| Set the first deceleration phase (D1) value. | |
| int | tmc5240_get_d2 (struct tmc5240_dev *device, int32_t *d2) |
| Get the second deceleration phase (D2) value. | |
| int | tmc5240_set_d2 (struct tmc5240_dev *device, int32_t d2) |
| Set the second deceleration phase (D2) value. | |
| int | tmc5240_get_vstop (struct tmc5240_dev *device, int32_t *vstop) |
| Get the stop velocity (VSTOP) value. | |
| int | tmc5240_set_vstop (struct tmc5240_dev *device, int32_t vstop) |
| Set the stop velocity (VSTOP) value. | |
| int | tmc5240_get_rampmode (struct tmc5240_dev *device, int32_t *rampmode) |
| Get the ramp mode configuration. | |
| int | tmc5240_set_rampmode (struct tmc5240_dev *device, int32_t rampmode) |
| Set the ramp mode configuration. | |
| int | tmc5240_stop (struct tmc5240_dev *device) |
| Stop the motor by setting VMAX to 0. | |
Header file for TMC5240 driver.
Copyright 2026(c) Analog Devices, Inc.
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
THIS SOFTWARE IS PROVIDED BY ANALOG DEVICES, INC. “AS IS” AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL ANALOG DEVICES, INC. BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
| #define TMC5240_DEFAULT_D1 10 |
| #define TMC5240_DEFAULT_D2 10 |
| #define TMC5240_DEFAULT_VSTOP 10 |
| int tmc5240_get_a1 | ( | struct tmc5240_dev * | device, |
| int32_t * | a1 ) |
Get the first acceleration phase (A1) value.
Get first acceleration phase
| device | - Pointer to the TMC5240 device structure. |
| a1 | - Pointer to store the retrieved A1 value. |
| int tmc5240_get_a2 | ( | struct tmc5240_dev * | device, |
| int32_t * | a2 ) |
Get the second acceleration phase (A2) value.
Get second acceleration phase
| device | - Pointer to the TMC5240 device structure. |
| a2 | - Pointer to store the retrieved A2 value. |
| int tmc5240_get_amax | ( | struct tmc5240_dev * | device, |
| int32_t * | amax ) |
Get the maximum acceleration (AMAX) value.
Get maximum acceleration
| device | - Pointer to the TMC5240 device structure. |
| amax | - Pointer to store the retrieved AMAX value. |
| int tmc5240_get_current_accel | ( | struct tmc5240_dev * | device, |
| int32_t * | acceleration ) |
Get the current acceleration of the motor.
Get current acceleration
This function reads the actual acceleration value from the TMC5240 device.
| device | - Pointer to the TMC5240 device structure. |
| acceleration | - Pointer to store the read acceleration value. |
| int tmc5240_get_current_pos | ( | struct tmc5240_dev * | device, |
| int32_t * | position ) |
Get the current position of the motor.
Get current position
This function reads the actual position register (XACTUAL) from the TMC5240 device and stores the result in the provided position pointer.
| device | - Pointer to the TMC5240 device structure. |
| position | - Pointer to store the current motor position value. |
| int tmc5240_get_current_vel | ( | struct tmc5240_dev * | device, |
| int32_t * | velocity ) |
Get the current velocity of the motor.
Get current velocity
This function reads the actual velocity register (VACTUAL) from the TMC5240 device and returns the velocity value as a signed 24-bit integer converted to 32-bit format.
| device | - Pointer to the TMC5240 device structure. |
| velocity | - Pointer to store the current velocity value. The value is sign-extended from 24-bit to 32-bit. |
| int tmc5240_get_d1 | ( | struct tmc5240_dev * | device, |
| int32_t * | d1 ) |
Get the first deceleration phase (D1) value.
Get first deceleration phase
| device | - Pointer to the TMC5240 device structure. |
| d1 | - Pointer to store the retrieved D1 value. |
| int tmc5240_get_d2 | ( | struct tmc5240_dev * | device, |
| int32_t * | d2 ) |
Get the second deceleration phase (D2) value.
Get second deceleration phase
| device | - Pointer to the TMC5240 device structure. |
| d2 | - Pointer to store the retrieved D2 value. |
| int tmc5240_get_dmax | ( | struct tmc5240_dev * | device, |
| int32_t * | dmax ) |
Get the maximum deceleration (DMAX) value.
Get maximum deceleration
| device | - Pointer to the TMC5240 device structure. |
| dmax | - Pointer to store the retrieved DMAX value. |
| int tmc5240_get_rampmode | ( | struct tmc5240_dev * | device, |
| int32_t * | rampmode ) |
Get the ramp mode configuration.
Get ramp mode
| device | - Pointer to the TMC5240 device structure. |
| rampmode | - Pointer to store the retrieved ramp mode value. Possible values:
|
| int tmc5240_get_shaft_dir | ( | struct tmc5240_dev * | device, |
| uint8_t * | dir ) |
Get the shaft direction setting from the TMC5240 device.
Get shaft direction
This function reads the GCONF register and extracts the shaft direction bit. The shaft direction determines whether the motor rotates in normal or inverted direction.
| device | - Pointer to the TMC5240 device structure |
| dir | - Pointer to store the shaft direction value:
|
| int tmc5240_get_target_pos | ( | struct tmc5240_dev * | device, |
| int32_t * | position ) |
Get the target position of the motor.
Get target position
This function reads the target position register (XTARGET) from the TMC5240 device and stores the result in the provided position pointer. The target position represents the desired destination when operating in position mode.
| device | - Pointer to the TMC5240 device structure. |
| position | - Pointer to store the target position value in microsteps. |
| int tmc5240_get_v1 | ( | struct tmc5240_dev * | device, |
| int32_t * | v1 ) |
Get the first velocity threshold (V1) value.
Get first velocity threshold
| device | - Pointer to the TMC5240 device structure. |
| v1 | - Pointer to store the retrieved V1 value. |
| int tmc5240_get_v2 | ( | struct tmc5240_dev * | device, |
| int32_t * | v2 ) |
Get the second velocity threshold (V2) value.
Get second velocity threshold
| device | - Pointer to the TMC5240 device structure. |
| v2 | - Pointer to store the retrieved V2 value. |
| int tmc5240_get_vmax | ( | struct tmc5240_dev * | device, |
| int32_t * | vmax ) |
Get the maximum velocity (VMAX) value.
Get maximum velocity
| device | - Pointer to the TMC5240 device structure. |
| vmax | - Pointer to store the retrieved VMAX value. |
| int tmc5240_get_vstart | ( | struct tmc5240_dev * | device, |
| int32_t * | vstart ) |
Get the start velocity (VSTART) value.
Get start velocity
| device | - Pointer to the TMC5240 device structure. |
| vstart | - Pointer to store the retrieved VSTART value. |
| int tmc5240_get_vstop | ( | struct tmc5240_dev * | device, |
| int32_t * | vstop ) |
Get the stop velocity (VSTOP) value.
Get stop velocity
| device | - Pointer to the TMC5240 device structure. |
| vstop | - Pointer to store the retrieved VSTOP value. |
| int tmc5240_init | ( | struct tmc5240_dev ** | device, |
| struct tmc5240_init_param * | init_param ) |
Initialize the TMC5240 device.
Initialize the TMC5240 device
| device | - TMC5240 device descriptor |
| init_param | - Initialization parameter containing information about the TMC5240 device to be initialized. |
| int tmc5240_reg_read | ( | struct tmc5240_dev * | device, |
| uint8_t | reg_addr, | ||
| uint32_t * | reg_data ) |
Reads data from a given TMC5240 Register.
Read from a TMC5240 register
This function wraps the TMC-API readRegister function to read data from a specified register of the TMC5240 device.
| device | - The device structure. |
| reg_addr | - Address of the register. |
| reg_data | - Stores data read from the register. |
| int tmc5240_reg_update | ( | struct tmc5240_dev * | device, |
| uint8_t | reg_addr, | ||
| uint32_t | mask, | ||
| uint32_t | val ) |
Read-modify-write a TMC5240 register.
Read-modify-write a TMC5240 register field
This function reads the current value of a register, clears the bits specified by the mask, sets new bits from val prepared with the same mask, and writes the result back.
| device | - Pointer to the TMC5240 device structure. |
| reg_addr | - Address of the register. |
| mask | - Bitmask of the field(s) to update. |
| val | - New value for the field, pre-shifted to the correct position. |
| int tmc5240_reg_write | ( | struct tmc5240_dev * | device, |
| uint8_t | reg_addr, | ||
| uint32_t | reg_data ) |
Writes data to a given TMC5240 Register.
Write to a TMC5240 register
This function wraps the TMC-API writeRegister function to write data to a specified register of the TMC5240 device.
| device | - The device structure. |
| reg_addr | - Address of the register to write to. |
| reg_data | - 32-bit data value to write to the register. |
| int tmc5240_remove | ( | struct tmc5240_dev * | device | ) |
Free the resources allocated by the tmc5240_init()
Free resources allocated by tmc5240_init()
| device | - TMC5240 device descriptor |
| int tmc5240_set_a1 | ( | struct tmc5240_dev * | device, |
| int32_t | a1 ) |
Set the first acceleration phase (A1) value.
Set first acceleration phase
| device | - Pointer to the TMC5240 device structure. |
| a1 | - The A1 value to set. |
| int tmc5240_set_a2 | ( | struct tmc5240_dev * | device, |
| int32_t | a2 ) |
Set the second acceleration phase (A2) value.
Set second acceleration phase
| device | - Pointer to the TMC5240 device structure. |
| a2 | - The A2 value to set. |
| int tmc5240_set_amax | ( | struct tmc5240_dev * | device, |
| int32_t | amax ) |
Set the maximum acceleration (AMAX) value.
Set maximum acceleration
| device | - Pointer to the TMC5240 device structure. |
| amax | - The AMAX value to set. |
| int tmc5240_set_current_pos | ( | struct tmc5240_dev * | device, |
| int32_t | position ) |
Replace the current position of the motor with a new absolute position value.
Set current position
This function sets the motor's current position register (XACTUAL) to a specified value. Before updating the position, it switches the motor to hold mode (RAMPMODE = MODE_HOLD) to ensure the position can be safely updated without triggering unwanted motion. This is useful for rehoming or synchronizing the motor's internal position counter with an external reference system.
| device | - Pointer to the TMC5240 device structure. |
| position | - The new position value to set in microsteps. |
| int tmc5240_set_d1 | ( | struct tmc5240_dev * | device, |
| int32_t | d1 ) |
Set the first deceleration phase (D1) value.
Set first deceleration phase
| device | - Pointer to the TMC5240 device structure. |
| d1 | - The D1 value to set. |
| int tmc5240_set_d2 | ( | struct tmc5240_dev * | device, |
| int32_t | d2 ) |
Set the second deceleration phase (D2) value.
Set second deceleration phase
| device | - Pointer to the TMC5240 device structure. |
| d2 | - The D2 value to set. |
| int tmc5240_set_dmax | ( | struct tmc5240_dev * | device, |
| int32_t | dmax ) |
Set the maximum deceleration (DMAX) value.
Set maximum deceleration
| device | - Pointer to the TMC5240 device structure. |
| dmax | - The DMAX value to set. |
| int tmc5240_set_motion_profile | ( | struct tmc5240_dev * | device | ) |
Set motion profile parameters for the TMC5240 motor driver.
Set motion profile parameters
This function configures all motion profile parameters including multi-phase acceleration and deceleration settings. It applies default values for d1, d2, and vstop if they are zero, and ensures vstop is not less than vstart.
| device | - Pointer to the TMC5240 device structure. |
| int tmc5240_set_rampmode | ( | struct tmc5240_dev * | device, |
| int32_t | rampmode ) |
Set the ramp mode configuration.
Set ramp mode
| device | - Pointer to the TMC5240 device structure. |
| rampmode | - The ramp mode value to set. Possible values:
|
| int tmc5240_set_shaft_dir | ( | struct tmc5240_dev * | device, |
| uint8_t | dir ) |
Set the shaft direction for the TMC5240 device.
Set shaft direction
This function modifies the GCONF register to set the shaft direction bit. Setting the shaft direction allows reversing the motor rotation direction without changing the wiring.
| device | - Pointer to the TMC5240 device structure |
| dir | - Shaft direction value to set:
|
| int tmc5240_set_target_pos | ( | struct tmc5240_dev * | device, |
| int32_t | position ) |
Set the target position for the TMC5240 motor driver.
Set target position
This function configures the TMC5240 to move to a specified target position in position mode. It ensures that the acceleration (AMAX) and maximum velocity (VMAX) parameters are properly configured before setting the target. If either AMAX or VMAX is zero, the function restores them to the device's stored default values to enable motion. The motor will ramp up to VMAX, move toward the target, and decelerate according to the configured motion profile.
| device | - Pointer to the TMC5240 device structure. |
| position | - Target position value to move to in microsteps. |
| int tmc5240_set_target_vel | ( | struct tmc5240_dev * | device, |
| int32_t | velocity ) |
Set the target velocity for the TMC5240 motor driver.
Set target velocity
This function sets the target velocity for the motor by configuring the VMAX register and the appropriate ramp mode (positive or negative velocity). If the maximum acceleration (AMAX) is zero, it will be set to the device's default value before setting the velocity.
| device | - Pointer to the TMC5240 device structure. |
| velocity | - Target velocity value. Positive values result in positive velocity ramp mode, negative values result in negative velocity ramp mode. The absolute value is written to VMAX. |
| int tmc5240_set_v1 | ( | struct tmc5240_dev * | device, |
| int32_t | v1 ) |
Set the first velocity threshold (V1) value.
Set first velocity threshold
| device | - Pointer to the TMC5240 device structure. |
| v1 | - The V1 value to set. |
| int tmc5240_set_v2 | ( | struct tmc5240_dev * | device, |
| int32_t | v2 ) |
Set the second velocity threshold (V2) value.
Set second velocity threshold
| device | - Pointer to the TMC5240 device structure. |
| v2 | - The V2 value to set. |
| int tmc5240_set_vmax | ( | struct tmc5240_dev * | device, |
| int32_t | vmax ) |
Set the maximum velocity (VMAX) value.
Set maximum velocity
| device | - Pointer to the TMC5240 device structure. |
| vmax | - The VMAX value to set. |
| int tmc5240_set_vstart | ( | struct tmc5240_dev * | device, |
| int32_t | vstart ) |
Set the start velocity (VSTART) value.
Set start velocity
| device | - Pointer to the TMC5240 device structure. |
| vstart | - The VSTART value to set. |
| int tmc5240_set_vstop | ( | struct tmc5240_dev * | device, |
| int32_t | vstop ) |
Set the stop velocity (VSTOP) value.
Set stop velocity
| device | - Pointer to the TMC5240 device structure. |
| vstop | - The VSTOP value to set. |
| int tmc5240_stop | ( | struct tmc5240_dev * | device | ) |
Stop the motor by setting VMAX to 0.
Stop the motor
| device | - Pointer to the TMC5240 device structure. |