Skip to content

Commit 5e410e3

Browse files
committed
🩹 Minor fixes, updates, comments
1 parent 62bb61b commit 5e410e3

File tree

8 files changed

+107
-96
lines changed

8 files changed

+107
-96
lines changed

Marlin/src/MarlinCore.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -152,8 +152,8 @@
152152
#include "feature/encoder_i2c.h"
153153
#endif
154154

155-
#if (HAS_TRINAMIC_CONFIG || HAS_TMC_SPI) && DISABLED(PSU_DEFAULT_OFF)
156-
#include "feature/tmc_util.h"
155+
#if HAS_TRINAMIC_CONFIG
156+
#include "module/stepper/trinamic.h"
157157
#endif
158158

159159
#if HAS_CUTTER

Marlin/src/feature/tmc_util.cpp

Lines changed: 12 additions & 80 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,12 @@
2424

2525
#if HAS_TRINAMIC_CONFIG
2626

27+
/**
28+
* feature/tmc_util.cpp - Functions for debugging Trinamic stepper drivers.
29+
* The main entry point is `tmc_report_all` which is called by M122 to collect
30+
* and report diagnostic information about each enabled TMC driver.
31+
*/
32+
2733
#include "tmc_util.h"
2834
#include "../MarlinCore.h"
2935

@@ -710,14 +716,8 @@
710716
case TMC_FSACTIVE: if (st.fsactive()) SERIAL_CHAR('*'); break;
711717
case TMC_DRV_CS_ACTUAL: if (st.CS_ACTUAL()) SERIAL_CHAR('*'); break;
712718
case TMC_STALLGUARD: if (st.stallguard()) SERIAL_CHAR('*'); break;
713-
//case TMC_OT: if (st.ot()) SERIAL_CHAR('*'); break;
714-
case TMC_DEBUG_OTPW: print_true_or_false(st.otpw()); break;
715-
//case TMC_S2GA: if (st.s2ga()) SERIAL_CHAR('*'); break;
716-
//case TMC_S2GB: if (st.s2gb()) SERIAL_CHAR('*'); break;
717-
//case TMC_OLA: if (st.ola()) SERIAL_CHAR('*'); break;
718-
//case TMC_OLB: if (st.olb()) SERIAL_CHAR('*'); break;
719+
case TMC_OT: if (st.ot()) SERIAL_CHAR('*'); break;
719720
case TMC_SG_RESULT: SERIAL_ECHO(st.SG_RESULT()); break;
720-
case TMC_STST: if (!st.stst()) SERIAL_CHAR('*'); break;
721721
default: break; // other...
722722
}
723723
}
@@ -844,7 +844,8 @@
844844
case TMC_OT: if (st.ot()) SERIAL_CHAR('*'); break;
845845
case TMC_DRV_STATUS_HEX: {
846846
const uint32_t drv_status = st.DRV_STATUS();
847-
SERIAL_CHAR('\t'); st.printLabel(); SERIAL_CHAR('\t'); print_hex_long(drv_status, ':', true);
847+
SERIAL_CHAR('\t'); st.printLabel();
848+
SERIAL_CHAR('\t'); print_hex_long(drv_status, ':', true);
848849
if (drv_status == 0xFFFFFFFF || drv_status == 0) SERIAL_ECHOPGM("\t Bad response!");
849850
SERIAL_EOL();
850851
} break;
@@ -1167,6 +1168,9 @@
11671168
bool tmc_enable_stallguard(TMC2240Stepper &st) {
11681169
const bool stealthchop_was_enabled = st.en_pwm_mode();
11691170

1171+
// TODO: Use StallGuard4 when stealthChop is enabled
1172+
// and leave stealthChop state unchanged.
1173+
11701174
st.TCOOLTHRS(0xFFFFF);
11711175
st.en_pwm_mode(false);
11721176
st.diag0_stall(true);
@@ -1250,75 +1254,3 @@ void test_tmc_connection(LOGICAL_AXIS_ARGS_LC(const bool)) {
12501254
}
12511255

12521256
#endif // HAS_TRINAMIC_CONFIG
1253-
1254-
#if HAS_TMC_SPI
1255-
#define SET_CS_PIN(st) OUT_WRITE(st##_CS_PIN, HIGH)
1256-
void tmc_init_cs_pins() {
1257-
#if AXIS_HAS_SPI(X)
1258-
SET_CS_PIN(X);
1259-
#endif
1260-
#if AXIS_HAS_SPI(Y)
1261-
SET_CS_PIN(Y);
1262-
#endif
1263-
#if AXIS_HAS_SPI(Z)
1264-
SET_CS_PIN(Z);
1265-
#endif
1266-
#if AXIS_HAS_SPI(X2)
1267-
SET_CS_PIN(X2);
1268-
#endif
1269-
#if AXIS_HAS_SPI(Y2)
1270-
SET_CS_PIN(Y2);
1271-
#endif
1272-
#if AXIS_HAS_SPI(Z2)
1273-
SET_CS_PIN(Z2);
1274-
#endif
1275-
#if AXIS_HAS_SPI(Z3)
1276-
SET_CS_PIN(Z3);
1277-
#endif
1278-
#if AXIS_HAS_SPI(Z4)
1279-
SET_CS_PIN(Z4);
1280-
#endif
1281-
#if AXIS_HAS_SPI(I)
1282-
SET_CS_PIN(I);
1283-
#endif
1284-
#if AXIS_HAS_SPI(J)
1285-
SET_CS_PIN(J);
1286-
#endif
1287-
#if AXIS_HAS_SPI(K)
1288-
SET_CS_PIN(K);
1289-
#endif
1290-
#if AXIS_HAS_SPI(U)
1291-
SET_CS_PIN(U);
1292-
#endif
1293-
#if AXIS_HAS_SPI(V)
1294-
SET_CS_PIN(V);
1295-
#endif
1296-
#if AXIS_HAS_SPI(W)
1297-
SET_CS_PIN(W);
1298-
#endif
1299-
#if AXIS_HAS_SPI(E0)
1300-
SET_CS_PIN(E0);
1301-
#endif
1302-
#if AXIS_HAS_SPI(E1)
1303-
SET_CS_PIN(E1);
1304-
#endif
1305-
#if AXIS_HAS_SPI(E2)
1306-
SET_CS_PIN(E2);
1307-
#endif
1308-
#if AXIS_HAS_SPI(E3)
1309-
SET_CS_PIN(E3);
1310-
#endif
1311-
#if AXIS_HAS_SPI(E4)
1312-
SET_CS_PIN(E4);
1313-
#endif
1314-
#if AXIS_HAS_SPI(E5)
1315-
SET_CS_PIN(E5);
1316-
#endif
1317-
#if AXIS_HAS_SPI(E6)
1318-
SET_CS_PIN(E6);
1319-
#endif
1320-
#if AXIS_HAS_SPI(E7)
1321-
SET_CS_PIN(E7);
1322-
#endif
1323-
}
1324-
#endif // HAS_TMC_SPI

Marlin/src/feature/tmc_util.h

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -474,7 +474,3 @@ void test_tmc_connection(LOGICAL_AXIS_DECL_LC(const bool, true));
474474
#endif // HAS_HOMING_CURRENT
475475

476476
#endif // HAS_TRINAMIC_CONFIG
477-
478-
#if HAS_TMC_SPI
479-
void tmc_init_cs_pins();
480-
#endif

Marlin/src/gcode/feature/trinamic/M122.cpp

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,9 @@
3636
*
3737
* With TMC_DEBUG:
3838
* V - Report raw register data. Refer to the datasheet to decipher the report.
39-
* S - Flag to enable/disable continuous debug reporting.
40-
* P<ms> - Interval between continuous debug reports, in milliseconds.
39+
* S0 - Disable continuous debug reporting.
40+
* S1 - Enable continuous debug reporting with the default interval.
41+
* P<ms> - Enable continuous debug reporting with the given interval in ms.
4142
*/
4243
void GcodeSuite::M122() {
4344
xyze_bool_t print_axis = ARRAY_N_1(LOGICAL_AXES, false);
@@ -51,12 +52,12 @@ void GcodeSuite::M122() {
5152

5253
#if ENABLED(TMC_DEBUG)
5354
#if ENABLED(MONITOR_DRIVER_STATUS)
54-
const bool sflag = parser.seen_test('S'), sval = sflag && parser.value_bool();
55-
if (sflag && !sval)
55+
const bool sflag = parser.seen('S'), sval = sflag && parser.value_bool();
56+
if (sflag && !sval) // "S0"
5657
tmc_set_report_interval(0);
57-
else if (parser.seenval('P'))
58+
else if (parser.seenval('P')) // "P<ms>"
5859
tmc_set_report_interval(_MAX(uint16_t(250), parser.value_ushort()));
59-
else if (sval)
60+
else if (sval) // "S" or "S1"
6061
tmc_set_report_interval(MONITOR_DRIVER_STATUS_INTERVAL_MS);
6162
#endif
6263

Marlin/src/module/stepper/trinamic.cpp

Lines changed: 79 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,82 @@ enum StealthIndex : uint8_t {
154154
TMC_SPI_DEFINE_E(7);
155155
#endif
156156

157+
#if HAS_TMC_SPI
158+
159+
// Init CS pins (active-low) for TMC SPI drivers.
160+
#define INIT_CS_PIN(st) OUT_WRITE(st##_CS_PIN, HIGH)
161+
162+
void tmc_init_cs_pins() {
163+
#if AXIS_HAS_SPI(X)
164+
INIT_CS_PIN(X);
165+
#endif
166+
#if AXIS_HAS_SPI(Y)
167+
INIT_CS_PIN(Y);
168+
#endif
169+
#if AXIS_HAS_SPI(Z)
170+
INIT_CS_PIN(Z);
171+
#endif
172+
#if AXIS_HAS_SPI(X2)
173+
INIT_CS_PIN(X2);
174+
#endif
175+
#if AXIS_HAS_SPI(Y2)
176+
INIT_CS_PIN(Y2);
177+
#endif
178+
#if AXIS_HAS_SPI(Z2)
179+
INIT_CS_PIN(Z2);
180+
#endif
181+
#if AXIS_HAS_SPI(Z3)
182+
INIT_CS_PIN(Z3);
183+
#endif
184+
#if AXIS_HAS_SPI(Z4)
185+
INIT_CS_PIN(Z4);
186+
#endif
187+
#if AXIS_HAS_SPI(I)
188+
INIT_CS_PIN(I);
189+
#endif
190+
#if AXIS_HAS_SPI(J)
191+
INIT_CS_PIN(J);
192+
#endif
193+
#if AXIS_HAS_SPI(K)
194+
INIT_CS_PIN(K);
195+
#endif
196+
#if AXIS_HAS_SPI(U)
197+
INIT_CS_PIN(U);
198+
#endif
199+
#if AXIS_HAS_SPI(V)
200+
INIT_CS_PIN(V);
201+
#endif
202+
#if AXIS_HAS_SPI(W)
203+
INIT_CS_PIN(W);
204+
#endif
205+
#if AXIS_HAS_SPI(E0)
206+
INIT_CS_PIN(E0);
207+
#endif
208+
#if AXIS_HAS_SPI(E1)
209+
INIT_CS_PIN(E1);
210+
#endif
211+
#if AXIS_HAS_SPI(E2)
212+
INIT_CS_PIN(E2);
213+
#endif
214+
#if AXIS_HAS_SPI(E3)
215+
INIT_CS_PIN(E3);
216+
#endif
217+
#if AXIS_HAS_SPI(E4)
218+
INIT_CS_PIN(E4);
219+
#endif
220+
#if AXIS_HAS_SPI(E5)
221+
INIT_CS_PIN(E5);
222+
#endif
223+
#if AXIS_HAS_SPI(E6)
224+
INIT_CS_PIN(E6);
225+
#endif
226+
#if AXIS_HAS_SPI(E7)
227+
INIT_CS_PIN(E7);
228+
#endif
229+
}
230+
231+
#endif // HAS_TMC_SPI
232+
157233
#ifndef TMC_BAUD_RATE
158234
// Reduce baud rate for boards not already overriding TMC_BAUD_RATE for software serial.
159235
// Testing has shown that 115200 is not 100% reliable on AVR platforms, occasionally
@@ -313,6 +389,7 @@ enum StealthIndex : uint8_t {
313389
// TMC2208/2209 Driver objects and inits
314390
//
315391
#if HAS_TMC_UART
392+
316393
#if AXIS_HAS_UART(X)
317394
#ifdef X_HARDWARE_SERIAL
318395
TMC_UART_DEFINE(HW, X, X);
@@ -685,7 +762,8 @@ enum StealthIndex : uint8_t {
685762
#endif
686763
#endif
687764
}
688-
#endif
765+
766+
#endif // HAS_TMC_UART
689767

690768
#if HAS_DRIVER(TMC2208)
691769
template<char AXIS_LETTER, char DRIVER_ID, AxisEnum AXIS_ID>

Marlin/src/module/stepper/trinamic.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,10 @@
109109
#define CHOPPER_TIMING_E CHOPPER_TIMING
110110
#endif
111111

112+
#if HAS_TMC_SPI
113+
void tmc_init_cs_pins();
114+
#endif
115+
112116
#if HAS_TMC_UART
113117
void tmc_serial_begin();
114118
#endif

ini/features.ini

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ MARLIN_TEST_BUILD = build_src_filter=+<src/tests>
2020
POSTMORTEM_DEBUGGING = build_src_filter=+<src/HAL/shared/cpu_exception> +<src/HAL/shared/backtrace>
2121
build_flags=-funwind-tables
2222
MKS_WIFI_MODULE = QRCode=https://github.com/makerbase-mks/QRCode/archive/261c5a696a.zip
23-
HAS_TRINAMIC_CONFIG = TMCStepper=https://github.com/MarlinFirmware/TMCStepper/archive/v0.8.7.zip
23+
HAS_TRINAMIC_CONFIG = TMCStepper=https://github.com/MarlinFirmware/TMCStepper/archive/v0.8.8.zip
2424
build_src_filter=+<src/module/stepper/trinamic.cpp> +<src/gcode/feature/trinamic/M122.cpp> +<src/gcode/feature/trinamic/M906.cpp> +<src/gcode/feature/trinamic/M911-M914.cpp> +<src/gcode/feature/trinamic/M919.cpp>
2525
HAS_STEPPER_CONTROL = build_src_filter=+<src/module/stepper/control.cpp>
2626
HAS_T(RINAMIC_CONFIG|MC_SPI) = build_src_filter=+<src/feature/tmc_util.cpp>

ini/stm32f4.ini

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -320,7 +320,7 @@ build_unflags = ${env:STM32F407VG_btt.build_unflags} -DUSBD_USE_CDC
320320
[env:STM32F407VG_btt_USB_debug]
321321
extends = env:STM32F407VG_btt_USB
322322
build_flags = ${env:STM32F407VG_btt_USB.build_flags} -O0
323-
build_unflags = ${env:STM32F407VG_btt_USB.build_unflags} -Os -NDEBUG
323+
build_unflags = ${env:STM32F407VG_btt_USB.build_unflags} -Os -DNDEBUG
324324

325325
#
326326
# Bigtreetech SKR V2.0 (STM32F429VGT6 ARM Cortex-M4) with USB Flash Drive Support
@@ -340,7 +340,7 @@ build_unflags = ${env:STM32F429VG_btt.build_unflags} -DUSBD_USE_CDC
340340
[env:STM32F429VG_btt_USB_debug]
341341
extends = env:STM32F429VG_btt_USB
342342
build_flags = ${env:STM32F429VG_btt_USB.build_flags} -O0
343-
build_unflags = ${env:STM32F429VG_btt_USB.build_unflags} -Os -NDEBUG
343+
build_unflags = ${env:STM32F429VG_btt_USB.build_unflags} -Os -DNDEBUG
344344

345345
#
346346
# BigTreeTech Octopus V1.0/1.1 / Octopus Pro V1.0 (STM32F446ZET6 ARM Cortex-M4)

0 commit comments

Comments
 (0)