Skip to content

Commit 242e6ea

Browse files
apni2kartben
authored andcommitted
drivers: stepper: adi_tmc: Prepare for tmc51xx support
Add Kconfig option. Find common regs. Update ramp generator data. Signed-off-by: Anders Nielsen <[email protected]>
1 parent 92b2d46 commit 242e6ea

File tree

6 files changed

+143
-45
lines changed

6 files changed

+143
-45
lines changed

drivers/stepper/adi_tmc/Kconfig

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,5 +21,6 @@ comment "Trinamic Stepper Drivers"
2121

2222
rsource "Kconfig.tmc22xx"
2323
rsource "Kconfig.tmc50xx"
24+
rsource "Kconfig.tmc51xx"
2425

2526
endif # STEPPER_ADI_TMC
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# SPDX-FileCopyrightText: Copyright (c) 2025 Prevas A/S
2+
# SPDX-License-Identifier: Apache-2.0
3+
4+
config STEPPER_ADI_TMC51XX
5+
bool "Activate trinamic tmc51xx stepper driver"
6+
depends on DT_HAS_ADI_TMC51XX_ENABLED && STEPPER_ADI_TMC
7+
select STEPPER_ADI_TMC_SPI
8+
default y
9+
10+
module = TMC51XX
11+
module-str = tmc51xx
12+
rsource "Kconfig.tmc_rampgen_template"

drivers/stepper/adi_tmc/adi_tmc50xx_stepper_controller.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
#include "adi_tmc5xxx_common.h"
1616

1717
#include <zephyr/logging/log.h>
18-
1918
LOG_MODULE_REGISTER(tmc50xx, CONFIG_STEPPER_LOG_LEVEL);
2019

2120
struct tmc50xx_data {
@@ -730,7 +729,7 @@ static DEVICE_API(stepper, tmc50xx_stepper_api) = {
730729
stallguard_velocity_check_interval_ms), \
731730
.is_sg_enabled = DT_PROP(child, activate_stallguard2), \
732731
IF_ENABLED(CONFIG_STEPPER_ADI_TMC50XX_RAMP_GEN, \
733-
(.default_ramp_config = TMC_RAMP_DT_SPEC_GET(child))) };
732+
(.default_ramp_config = TMC_RAMP_DT_SPEC_GET_TMC50XX(child))) };
734733

735734
#define TMC50XX_STEPPER_DATA_DEFINE(child) \
736735
static struct tmc50xx_stepper_data tmc50xx_stepper_data_##child = { \

drivers/stepper/adi_tmc/adi_tmc_reg.h

Lines changed: 59 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
/*
99
* SPDX-FileCopyrightText: Copyright (c) 2024 Carl Zeiss Meditec AG
10+
* SPDX-FileCopyrightText: Copyright (c) 2025 Prevas A/S
1011
* SPDX-License-Identifier: Apache-2.0
1112
*/
1213

@@ -18,12 +19,12 @@ extern "C" {
1819
#endif
1920

2021
/** Common Registers for TMC50XX and TMC51XX */
21-
#if defined(CONFIG_STEPPER_ADI_TMC50XX)
22+
#if defined(CONFIG_STEPPER_ADI_TMC50XX) || defined(CONFIG_STEPPER_ADI_TMC51XX)
2223

2324
#define TMC5XXX_WRITE_BIT 0x80U
2425
#define TMC5XXX_ADDRESS_MASK 0x7FU
2526

26-
#define TMC5XXX_CLOCK_FREQ_SHIFT 24
27+
#define TMC5XXX_CLOCK_FREQ_SHIFT 24
2728

2829
#define TMC5XXX_GCONF 0x00
2930
#define TMC5XXX_GSTAT 0x01
@@ -79,12 +80,32 @@ extern "C" {
7980
#define TMC5XXX_DRV_STATUS_SG_STATUS_MASK BIT(24)
8081
#define TMC5XXX_DRV_STATUS_SG_STATUS_SHIFT 24
8182

83+
#define TMC50XX_MOTOR_ADDR(m) (0x20 << (m))
84+
#define TMC50XX_MOTOR_ADDR_DRV(m) ((m) << 4)
85+
86+
#define TMC50XX_RAMPMODE(motor) (0x00 | TMC50XX_MOTOR_ADDR(motor))
87+
#define TMC50XX_XACTUAL(motor) (0x01 | TMC50XX_MOTOR_ADDR(motor))
88+
#define TMC50XX_VACTUAL(motor) (0x02 | TMC50XX_MOTOR_ADDR(motor))
89+
#define TMC50XX_VSTART(motor) (0x03 | TMC50XX_MOTOR_ADDR(motor))
90+
#define TMC50XX_A1(motor) (0x04 | TMC50XX_MOTOR_ADDR(motor))
91+
#define TMC50XX_V1(motor) (0x05 | TMC50XX_MOTOR_ADDR(motor))
92+
#define TMC50XX_AMAX(motor) (0x06 | TMC50XX_MOTOR_ADDR(motor))
93+
#define TMC50XX_VMAX(motor) (0x07 | TMC50XX_MOTOR_ADDR(motor))
94+
#define TMC50XX_DMAX(motor) (0x08 | TMC50XX_MOTOR_ADDR(motor))
95+
#define TMC50XX_D1(motor) (0x0A | TMC50XX_MOTOR_ADDR(motor))
96+
#define TMC50XX_VSTOP(motor) (0x0B | TMC50XX_MOTOR_ADDR(motor))
97+
#define TMC50XX_TZEROWAIT(motor) (0x0C | TMC50XX_MOTOR_ADDR(motor))
98+
#define TMC50XX_XTARGET(motor) (0x0D | TMC50XX_MOTOR_ADDR(motor))
99+
#define TMC50XX_SWMODE(motor) (0x14 | TMC50XX_MOTOR_ADDR(motor))
100+
#define TMC50XX_RAMPSTAT(motor) (0x15 | TMC50XX_MOTOR_ADDR(motor))
101+
#define TMC50XX_CHOPCONF(motor) (0x6C | TMC50XX_MOTOR_ADDR_DRV(motor))
102+
#define TMC50XX_COOLCONF(motor) (0x6D | TMC50XX_MOTOR_ADDR_DRV(motor))
103+
#define TMC50XX_DRVSTATUS(motor) (0x6F | TMC50XX_MOTOR_ADDR_DRV(motor))
104+
82105
#endif
83106

84107
#ifdef CONFIG_STEPPER_ADI_TMC50XX
85108

86-
#define TMC50XX_MOTOR_ADDR(m) (0x20 << (m))
87-
#define TMC50XX_MOTOR_ADDR_DRV(m) ((m) << 4)
88109
#define TMC50XX_MOTOR_ADDR_PWM(m) ((m) << 3)
89110

90111
/**
@@ -102,24 +123,9 @@ extern "C" {
102123
#define TMC50XX_PWMCONF(motor) (0x10 | TMC50XX_MOTOR_ADDR_PWM(motor))
103124
#define TMC50XX_PWM_STATUS(motor) (0x11 | TMC50XX_MOTOR_ADDR_PWM(motor))
104125

105-
#define TMC50XX_RAMPMODE(motor) (0x00 | TMC50XX_MOTOR_ADDR(motor))
106-
#define TMC50XX_XACTUAL(motor) (0x01 | TMC50XX_MOTOR_ADDR(motor))
107-
#define TMC50XX_VACTUAL(motor) (0x02 | TMC50XX_MOTOR_ADDR(motor))
108-
#define TMC50XX_VSTART(motor) (0x03 | TMC50XX_MOTOR_ADDR(motor))
109-
#define TMC50XX_A1(motor) (0x04 | TMC50XX_MOTOR_ADDR(motor))
110-
#define TMC50XX_V1(motor) (0x05 | TMC50XX_MOTOR_ADDR(motor))
111-
#define TMC50XX_AMAX(motor) (0x06 | TMC50XX_MOTOR_ADDR(motor))
112-
#define TMC50XX_VMAX(motor) (0x07 | TMC50XX_MOTOR_ADDR(motor))
113-
#define TMC50XX_DMAX(motor) (0x08 | TMC50XX_MOTOR_ADDR(motor))
114-
#define TMC50XX_D1(motor) (0x0A | TMC50XX_MOTOR_ADDR(motor))
115-
#define TMC50XX_VSTOP(motor) (0x0B | TMC50XX_MOTOR_ADDR(motor))
116-
#define TMC50XX_TZEROWAIT(motor) (0x0C | TMC50XX_MOTOR_ADDR(motor))
117-
#define TMC50XX_XTARGET(motor) (0x0D | TMC50XX_MOTOR_ADDR(motor))
118126
#define TMC50XX_IHOLD_IRUN(motor) (0x10 | TMC50XX_MOTOR_ADDR(motor))
119127
#define TMC50XX_VCOOLTHRS(motor) (0x11 | TMC50XX_MOTOR_ADDR(motor))
120128
#define TMC50XX_VHIGH(motor) (0x12 | TMC50XX_MOTOR_ADDR(motor))
121-
#define TMC50XX_SWMODE(motor) (0x14 | TMC50XX_MOTOR_ADDR(motor))
122-
#define TMC50XX_RAMPSTAT(motor) (0x15 | TMC50XX_MOTOR_ADDR(motor))
123129
#define TMC50XX_XLATCH(motor) (0x16 | TMC50XX_MOTOR_ADDR(motor))
124130

125131
#define TMC50XX_MSLUT0(motor) (0x60 | TMC50XX_MOTOR_ADDR_DRV(motor))
@@ -134,12 +140,43 @@ extern "C" {
134140
#define TMC50XX_MSLUTSTART(motor) (0x69 | TMC50XX_MOTOR_ADDR_DRV(motor))
135141
#define TMC50XX_MSCNT(motor) (0x6A | TMC50XX_MOTOR_ADDR_DRV(motor))
136142
#define TMC50XX_MSCURACT(motor) (0x6B | TMC50XX_MOTOR_ADDR_DRV(motor))
137-
#define TMC50XX_CHOPCONF(motor) (0x6C | TMC50XX_MOTOR_ADDR_DRV(motor))
138-
#define TMC50XX_COOLCONF(motor) (0x6D | TMC50XX_MOTOR_ADDR_DRV(motor))
139-
#define TMC50XX_DRVSTATUS(motor) (0x6F | TMC50XX_MOTOR_ADDR_DRV(motor))
140143

141144
#endif /* CONFIG_STEPPER_ADI_TMC50XX */
142145

146+
#ifdef CONFIG_STEPPER_ADI_TMC51XX
147+
148+
#define TMC51XX_GCONF_EN_PWM_MODE_SHIFT 2
149+
#define TMC51XX_GCONF_SHAFT_SHIFT 4
150+
#define TMC51XX_GCONF_TEST_MODE_SHIFT 17
151+
152+
#define TMC51XX_IHOLD_IRUN 0x10
153+
#define TMC51XX_TPOWER_DOWN 0x11
154+
#define TMC51XX_TSTEP 0x12
155+
#define TMC51XX_TPWMTHRS 0x13
156+
#define TMC51XX_TCOOLTHRS 0x14
157+
#define TMC51XX_THIGH 0x15
158+
159+
#define TMC51XX_RAMPMODE TMC50XX_RAMPMODE(0)
160+
#define TMC51XX_XACTUAL TMC50XX_XACTUAL(0)
161+
#define TMC51XX_VACTUAL TMC50XX_VACTUAL(0)
162+
#define TMC51XX_VSTART TMC50XX_VSTART(0)
163+
#define TMC51XX_A1 TMC50XX_A1(0)
164+
#define TMC51XX_V1 TMC50XX_V1(0)
165+
#define TMC51XX_AMAX TMC50XX_AMAX(0)
166+
#define TMC51XX_VMAX TMC50XX_VMAX(0)
167+
#define TMC51XX_DMAX TMC50XX_DMAX(0)
168+
#define TMC51XX_D1 TMC50XX_D1(0)
169+
#define TMC51XX_VSTOP TMC50XX_VSTOP(0)
170+
#define TMC51XX_TZEROWAIT TMC50XX_TZEROWAIT(0)
171+
#define TMC51XX_XTARGET TMC50XX_XTARGET(0)
172+
#define TMC51XX_SWMODE TMC50XX_SWMODE(0)
173+
#define TMC51XX_RAMPSTAT TMC50XX_RAMPSTAT(0)
174+
#define TMC51XX_CHOPCONF TMC50XX_CHOPCONF(0)
175+
#define TMC51XX_COOLCONF TMC50XX_COOLCONF(0)
176+
#define TMC51XX_DRVSTATUS TMC50XX_DRVSTATUS(0)
177+
178+
#endif /* CONFIG_STEPPER_ADI_TMC51XX */
179+
143180
/**
144181
* @}
145182
*/

dts/bindings/stepper/adi/adi,tmc50xx.yaml

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ description: |
1313
tmc50xx: tmc50xx@0 {
1414
compatible = "adi,tmc50xx";
1515
reg = <0>;
16-
spi-max-frequency = <DT_FREQ_M(24)>; /* Maximum SPI bus frequency */
16+
spi-max-frequency = <DT_FREQ_M(8)>; /* Maximum SPI bus frequency */
1717
1818
#address-cells = <1>;
1919
#size-cells = <0>;
@@ -61,8 +61,6 @@ include:
6161
- name: adi,trinamic-gconf.yaml
6262
property-allowlist:
6363
- poscmp-enable
64-
- shaft1
65-
- shaft2
6664
- test-mode
6765
- lock-gconf
6866

include/zephyr/drivers/stepper/stepper_trinamic.h

Lines changed: 69 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
/*
99
* SPDX-FileCopyrightText: Copyright (c) 2024 Carl Zeiss Meditec AG
10+
* SPDX-FileCopyrightText: Copyright (c) 2025 Prevas A/S
1011
*
1112
* SPDX-License-Identifier: Apache-2.0
1213
*/
@@ -49,16 +50,28 @@ extern "C" {
4950
#define TMC_RAMP_VSTOP_MIN 1
5051
#define TMC_RAMP_TZEROWAIT_MAX (GENMASK(15, 0) - 512)
5152
#define TMC_RAMP_TZEROWAIT_MIN 0
52-
#define TMC_RAMP_VCOOLTHRS_MAX GENMASK(22, 0)
53-
#define TMC_RAMP_VCOOLTHRS_MIN 0
54-
#define TMC_RAMP_VHIGH_MAX GENMASK(22, 0)
55-
#define TMC_RAMP_VHIGH_MIN 0
5653
#define TMC_RAMP_IHOLD_IRUN_MAX GENMASK(4, 0)
5754
#define TMC_RAMP_IHOLD_IRUN_MIN 0
5855
#define TMC_RAMP_IHOLDDELAY_MAX GENMASK(3, 0)
5956
#define TMC_RAMP_IHOLDDELAY_MIN 0
6057
#define TMC_RAMP_VACTUAL_SHIFT 22
6158

59+
/* TMC50XX specific */
60+
#define TMC_RAMP_VCOOLTHRS_MAX GENMASK(22, 0)
61+
#define TMC_RAMP_VCOOLTHRS_MIN 0
62+
#define TMC_RAMP_VHIGH_MAX GENMASK(22, 0)
63+
#define TMC_RAMP_VHIGH_MIN 0
64+
65+
/* TMC51XX specific */
66+
#define TMC_RAMP_TPOWERDOWN_MAX GENMASK(7, 0)
67+
#define TMC_RAMP_TPOWERDOWN_MIN 0
68+
#define TMC_RAMP_TPWMTHRS_MAX GENMASK(19, 0)
69+
#define TMC_RAMP_TPWMTHRS_MIN 0
70+
#define TMC_RAMP_TCOOLTHRS_MAX GENMASK(19, 0)
71+
#define TMC_RAMP_TCOOLTHRS_MIN 0
72+
#define TMC_RAMP_THIGH_MAX GENMASK(19, 0)
73+
#define TMC_RAMP_THIGH_MIN 0
74+
6275
/**
6376
* @brief Trinamic Stepper Ramp Generator data
6477
*/
@@ -72,9 +85,21 @@ struct tmc_ramp_generator_data {
7285
uint16_t dmax;
7386
uint32_t vstop;
7487
uint16_t tzerowait;
75-
uint32_t vcoolthrs;
76-
uint32_t vhigh;
7788
uint32_t iholdrun;
89+
union {
90+
/* TMC50XX specific */
91+
struct {
92+
uint32_t vcoolthrs;
93+
uint32_t vhigh;
94+
};
95+
/* TMC51XX specific */
96+
struct {
97+
uint32_t tpowerdown;
98+
uint32_t tpwmthrs;
99+
uint32_t tcoolthrs;
100+
uint32_t thigh;
101+
};
102+
};
78103
};
79104

80105
/**
@@ -108,12 +133,6 @@ struct tmc_ramp_generator_data {
108133
COND_CODE_1(DT_PROP_EXISTS(node, tzerowait), \
109134
BUILD_ASSERT(IN_RANGE(DT_PROP(node, tzerowait), TMC_RAMP_TZEROWAIT_MIN, \
110135
TMC_RAMP_TZEROWAIT_MAX), "tzerowait out of range"), ()); \
111-
COND_CODE_1(DT_PROP_EXISTS(node, vcoolthrs), \
112-
BUILD_ASSERT(IN_RANGE(DT_PROP(node, vcoolthrs), TMC_RAMP_VCOOLTHRS_MIN, \
113-
TMC_RAMP_VCOOLTHRS_MAX), "vcoolthrs out of range"), ()); \
114-
COND_CODE_1(DT_PROP_EXISTS(node, vhigh), \
115-
BUILD_ASSERT(IN_RANGE(DT_PROP(node, vhigh), TMC_RAMP_VHIGH_MIN, \
116-
TMC_RAMP_VHIGH_MAX), "vhigh out of range"), ()); \
117136
COND_CODE_1(DT_PROP_EXISTS(node, ihold), \
118137
BUILD_ASSERT(IN_RANGE(DT_PROP(node, ihold), TMC_RAMP_IHOLD_IRUN_MIN, \
119138
TMC_RAMP_IHOLD_IRUN_MAX), "ihold out of range"), ()); \
@@ -122,7 +141,27 @@ struct tmc_ramp_generator_data {
122141
TMC_RAMP_IHOLD_IRUN_MAX), "irun out of range"), ()); \
123142
COND_CODE_1(DT_PROP_EXISTS(node, iholddelay), \
124143
BUILD_ASSERT(IN_RANGE(DT_PROP(node, iholddelay), TMC_RAMP_IHOLDDELAY_MIN, \
125-
TMC_RAMP_IHOLDDELAY_MAX), "iholddelay out of range"), ());
144+
TMC_RAMP_IHOLDDELAY_MAX), "iholddelay out of range"), ());\
145+
/* TMC50XX specific */ \
146+
COND_CODE_1(DT_PROP_EXISTS(node, vcoolthrs), \
147+
BUILD_ASSERT(IN_RANGE(DT_PROP(node, vcoolthrs), TMC_RAMP_VCOOLTHRS_MIN, \
148+
TMC_RAMP_VCOOLTHRS_MAX), "vcoolthrs out of range"), ()); \
149+
COND_CODE_1(DT_PROP_EXISTS(node, vhigh), \
150+
BUILD_ASSERT(IN_RANGE(DT_PROP(node, vhigh), TMC_RAMP_VHIGH_MIN, \
151+
TMC_RAMP_VHIGH_MAX), "vhigh out of range"), ()); \
152+
/* TMC51XX specific */ \
153+
COND_CODE_1(DT_PROP_EXISTS(node, tpowerdown), \
154+
BUILD_ASSERT(IN_RANGE(DT_PROP(node, tpowerdown), TMC_RAMP_TPOWERDOWN_MIN, \
155+
TMC_RAMP_TPOWERDOWN_MAX), "tpowerdown out of range"), ());\
156+
COND_CODE_1(DT_PROP_EXISTS(node, tpwmthrs), \
157+
BUILD_ASSERT(IN_RANGE(DT_PROP(node, tpwmthrs), TMC_RAMP_TPWMTHRS_MIN, \
158+
TMC_RAMP_TPWMTHRS_MAX), "tpwmthrs out of range"), ()); \
159+
COND_CODE_1(DT_PROP_EXISTS(node, tcoolthrs), \
160+
BUILD_ASSERT(IN_RANGE(DT_PROP(node, tcoolthrs), TMC_RAMP_TCOOLTHRS_MIN, \
161+
TMC_RAMP_TCOOLTHRS_MAX), "tcoolthrs out of range"), ()); \
162+
COND_CODE_1(DT_PROP_EXISTS(node, thigh), \
163+
BUILD_ASSERT(IN_RANGE(DT_PROP(node, thigh), TMC_RAMP_THIGH_MIN, \
164+
TMC_RAMP_THIGH_MAX), "thigh out of range"), ());
126165

127166
/**
128167
* @brief Get Trinamic Stepper Ramp Generator data from DT
@@ -131,8 +170,7 @@ struct tmc_ramp_generator_data {
131170
*
132171
* @return struct tmc_ramp_generator_data
133172
*/
134-
#define TMC_RAMP_DT_SPEC_GET(node) \
135-
{ \
173+
#define TMC_RAMP_DT_SPEC_GET_COMMON(node) \
136174
.vstart = DT_PROP(node, vstart), \
137175
.v1 = DT_PROP(node, v1), \
138176
.vmax = DT_PROP(node, vmax), \
@@ -142,11 +180,24 @@ struct tmc_ramp_generator_data {
142180
.dmax = DT_PROP(node, dmax), \
143181
.vstop = DT_PROP(node, vstop), \
144182
.tzerowait = DT_PROP(node, tzerowait), \
145-
.vcoolthrs = DT_PROP(node, vcoolthrs), \
146-
.vhigh = DT_PROP(node, vhigh), \
147183
.iholdrun = (TMC5XXX_IRUN(DT_PROP(node, irun)) | \
148184
TMC5XXX_IHOLD(DT_PROP(node, ihold)) | \
149-
TMC5XXX_IHOLDDELAY(DT_PROP(node, iholddelay))), \
185+
TMC5XXX_IHOLDDELAY(DT_PROP(node, iholddelay))),
186+
187+
#define TMC_RAMP_DT_SPEC_GET_TMC50XX(node) \
188+
{ \
189+
TMC_RAMP_DT_SPEC_GET_COMMON(node) \
190+
.vhigh = DT_PROP(node, vhigh), \
191+
.vcoolthrs = DT_PROP(node, vcoolthrs), \
192+
}
193+
194+
#define TMC_RAMP_DT_SPEC_GET_TMC51XX(node) \
195+
{ \
196+
TMC_RAMP_DT_SPEC_GET_COMMON(DT_DRV_INST(node)) \
197+
.tpowerdown = DT_INST_PROP(node, tpowerdown), \
198+
.tpwmthrs = DT_INST_PROP(node, tpwmthrs), \
199+
.tcoolthrs = DT_INST_PROP(node, tcoolthrs), \
200+
.thigh = DT_INST_PROP(node, thigh), \
150201
}
151202

152203
/**

0 commit comments

Comments
 (0)