🩹 Minor fixes, updates, comments
Some checks are pending
CI - Build Tests / Build Test (push) Waiting to run
CI - Unit Tests / Unit Test (push) Waiting to run

This commit is contained in:
Scott Lahteine 2025-06-19 23:43:11 -05:00
parent 62bb61b3d9
commit 5e410e35ab
8 changed files with 107 additions and 96 deletions

View file

@ -152,8 +152,8 @@
#include "feature/encoder_i2c.h"
#endif
#if (HAS_TRINAMIC_CONFIG || HAS_TMC_SPI) && DISABLED(PSU_DEFAULT_OFF)
#include "feature/tmc_util.h"
#if HAS_TRINAMIC_CONFIG
#include "module/stepper/trinamic.h"
#endif
#if HAS_CUTTER

View file

@ -24,6 +24,12 @@
#if HAS_TRINAMIC_CONFIG
/**
* feature/tmc_util.cpp - Functions for debugging Trinamic stepper drivers.
* The main entry point is `tmc_report_all` which is called by M122 to collect
* and report diagnostic information about each enabled TMC driver.
*/
#include "tmc_util.h"
#include "../MarlinCore.h"
@ -710,14 +716,8 @@
case TMC_FSACTIVE: if (st.fsactive()) SERIAL_CHAR('*'); break;
case TMC_DRV_CS_ACTUAL: if (st.CS_ACTUAL()) SERIAL_CHAR('*'); break;
case TMC_STALLGUARD: if (st.stallguard()) SERIAL_CHAR('*'); break;
//case TMC_OT: if (st.ot()) SERIAL_CHAR('*'); break;
case TMC_DEBUG_OTPW: print_true_or_false(st.otpw()); break;
//case TMC_S2GA: if (st.s2ga()) SERIAL_CHAR('*'); break;
//case TMC_S2GB: if (st.s2gb()) SERIAL_CHAR('*'); break;
//case TMC_OLA: if (st.ola()) SERIAL_CHAR('*'); break;
//case TMC_OLB: if (st.olb()) SERIAL_CHAR('*'); break;
case TMC_OT: if (st.ot()) SERIAL_CHAR('*'); break;
case TMC_SG_RESULT: SERIAL_ECHO(st.SG_RESULT()); break;
case TMC_STST: if (!st.stst()) SERIAL_CHAR('*'); break;
default: break; // other...
}
}
@ -844,7 +844,8 @@
case TMC_OT: if (st.ot()) SERIAL_CHAR('*'); break;
case TMC_DRV_STATUS_HEX: {
const uint32_t drv_status = st.DRV_STATUS();
SERIAL_CHAR('\t'); st.printLabel(); SERIAL_CHAR('\t'); print_hex_long(drv_status, ':', true);
SERIAL_CHAR('\t'); st.printLabel();
SERIAL_CHAR('\t'); print_hex_long(drv_status, ':', true);
if (drv_status == 0xFFFFFFFF || drv_status == 0) SERIAL_ECHOPGM("\t Bad response!");
SERIAL_EOL();
} break;
@ -1167,6 +1168,9 @@
bool tmc_enable_stallguard(TMC2240Stepper &st) {
const bool stealthchop_was_enabled = st.en_pwm_mode();
// TODO: Use StallGuard4 when stealthChop is enabled
// and leave stealthChop state unchanged.
st.TCOOLTHRS(0xFFFFF);
st.en_pwm_mode(false);
st.diag0_stall(true);
@ -1250,75 +1254,3 @@ void test_tmc_connection(LOGICAL_AXIS_ARGS_LC(const bool)) {
}
#endif // HAS_TRINAMIC_CONFIG
#if HAS_TMC_SPI
#define SET_CS_PIN(st) OUT_WRITE(st##_CS_PIN, HIGH)
void tmc_init_cs_pins() {
#if AXIS_HAS_SPI(X)
SET_CS_PIN(X);
#endif
#if AXIS_HAS_SPI(Y)
SET_CS_PIN(Y);
#endif
#if AXIS_HAS_SPI(Z)
SET_CS_PIN(Z);
#endif
#if AXIS_HAS_SPI(X2)
SET_CS_PIN(X2);
#endif
#if AXIS_HAS_SPI(Y2)
SET_CS_PIN(Y2);
#endif
#if AXIS_HAS_SPI(Z2)
SET_CS_PIN(Z2);
#endif
#if AXIS_HAS_SPI(Z3)
SET_CS_PIN(Z3);
#endif
#if AXIS_HAS_SPI(Z4)
SET_CS_PIN(Z4);
#endif
#if AXIS_HAS_SPI(I)
SET_CS_PIN(I);
#endif
#if AXIS_HAS_SPI(J)
SET_CS_PIN(J);
#endif
#if AXIS_HAS_SPI(K)
SET_CS_PIN(K);
#endif
#if AXIS_HAS_SPI(U)
SET_CS_PIN(U);
#endif
#if AXIS_HAS_SPI(V)
SET_CS_PIN(V);
#endif
#if AXIS_HAS_SPI(W)
SET_CS_PIN(W);
#endif
#if AXIS_HAS_SPI(E0)
SET_CS_PIN(E0);
#endif
#if AXIS_HAS_SPI(E1)
SET_CS_PIN(E1);
#endif
#if AXIS_HAS_SPI(E2)
SET_CS_PIN(E2);
#endif
#if AXIS_HAS_SPI(E3)
SET_CS_PIN(E3);
#endif
#if AXIS_HAS_SPI(E4)
SET_CS_PIN(E4);
#endif
#if AXIS_HAS_SPI(E5)
SET_CS_PIN(E5);
#endif
#if AXIS_HAS_SPI(E6)
SET_CS_PIN(E6);
#endif
#if AXIS_HAS_SPI(E7)
SET_CS_PIN(E7);
#endif
}
#endif // HAS_TMC_SPI

View file

@ -474,7 +474,3 @@ void test_tmc_connection(LOGICAL_AXIS_DECL_LC(const bool, true));
#endif // HAS_HOMING_CURRENT
#endif // HAS_TRINAMIC_CONFIG
#if HAS_TMC_SPI
void tmc_init_cs_pins();
#endif

View file

@ -36,8 +36,9 @@
*
* With TMC_DEBUG:
* V - Report raw register data. Refer to the datasheet to decipher the report.
* S - Flag to enable/disable continuous debug reporting.
* P<ms> - Interval between continuous debug reports, in milliseconds.
* S0 - Disable continuous debug reporting.
* S1 - Enable continuous debug reporting with the default interval.
* P<ms> - Enable continuous debug reporting with the given interval in ms.
*/
void GcodeSuite::M122() {
xyze_bool_t print_axis = ARRAY_N_1(LOGICAL_AXES, false);
@ -51,12 +52,12 @@ void GcodeSuite::M122() {
#if ENABLED(TMC_DEBUG)
#if ENABLED(MONITOR_DRIVER_STATUS)
const bool sflag = parser.seen_test('S'), sval = sflag && parser.value_bool();
if (sflag && !sval)
const bool sflag = parser.seen('S'), sval = sflag && parser.value_bool();
if (sflag && !sval) // "S0"
tmc_set_report_interval(0);
else if (parser.seenval('P'))
else if (parser.seenval('P')) // "P<ms>"
tmc_set_report_interval(_MAX(uint16_t(250), parser.value_ushort()));
else if (sval)
else if (sval) // "S" or "S1"
tmc_set_report_interval(MONITOR_DRIVER_STATUS_INTERVAL_MS);
#endif

View file

@ -154,6 +154,82 @@ enum StealthIndex : uint8_t {
TMC_SPI_DEFINE_E(7);
#endif
#if HAS_TMC_SPI
// Init CS pins (active-low) for TMC SPI drivers.
#define INIT_CS_PIN(st) OUT_WRITE(st##_CS_PIN, HIGH)
void tmc_init_cs_pins() {
#if AXIS_HAS_SPI(X)
INIT_CS_PIN(X);
#endif
#if AXIS_HAS_SPI(Y)
INIT_CS_PIN(Y);
#endif
#if AXIS_HAS_SPI(Z)
INIT_CS_PIN(Z);
#endif
#if AXIS_HAS_SPI(X2)
INIT_CS_PIN(X2);
#endif
#if AXIS_HAS_SPI(Y2)
INIT_CS_PIN(Y2);
#endif
#if AXIS_HAS_SPI(Z2)
INIT_CS_PIN(Z2);
#endif
#if AXIS_HAS_SPI(Z3)
INIT_CS_PIN(Z3);
#endif
#if AXIS_HAS_SPI(Z4)
INIT_CS_PIN(Z4);
#endif
#if AXIS_HAS_SPI(I)
INIT_CS_PIN(I);
#endif
#if AXIS_HAS_SPI(J)
INIT_CS_PIN(J);
#endif
#if AXIS_HAS_SPI(K)
INIT_CS_PIN(K);
#endif
#if AXIS_HAS_SPI(U)
INIT_CS_PIN(U);
#endif
#if AXIS_HAS_SPI(V)
INIT_CS_PIN(V);
#endif
#if AXIS_HAS_SPI(W)
INIT_CS_PIN(W);
#endif
#if AXIS_HAS_SPI(E0)
INIT_CS_PIN(E0);
#endif
#if AXIS_HAS_SPI(E1)
INIT_CS_PIN(E1);
#endif
#if AXIS_HAS_SPI(E2)
INIT_CS_PIN(E2);
#endif
#if AXIS_HAS_SPI(E3)
INIT_CS_PIN(E3);
#endif
#if AXIS_HAS_SPI(E4)
INIT_CS_PIN(E4);
#endif
#if AXIS_HAS_SPI(E5)
INIT_CS_PIN(E5);
#endif
#if AXIS_HAS_SPI(E6)
INIT_CS_PIN(E6);
#endif
#if AXIS_HAS_SPI(E7)
INIT_CS_PIN(E7);
#endif
}
#endif // HAS_TMC_SPI
#ifndef TMC_BAUD_RATE
// Reduce baud rate for boards not already overriding TMC_BAUD_RATE for software serial.
// Testing has shown that 115200 is not 100% reliable on AVR platforms, occasionally
@ -313,6 +389,7 @@ enum StealthIndex : uint8_t {
// TMC2208/2209 Driver objects and inits
//
#if HAS_TMC_UART
#if AXIS_HAS_UART(X)
#ifdef X_HARDWARE_SERIAL
TMC_UART_DEFINE(HW, X, X);
@ -685,7 +762,8 @@ enum StealthIndex : uint8_t {
#endif
#endif
}
#endif
#endif // HAS_TMC_UART
#if HAS_DRIVER(TMC2208)
template<char AXIS_LETTER, char DRIVER_ID, AxisEnum AXIS_ID>

View file

@ -109,6 +109,10 @@
#define CHOPPER_TIMING_E CHOPPER_TIMING
#endif
#if HAS_TMC_SPI
void tmc_init_cs_pins();
#endif
#if HAS_TMC_UART
void tmc_serial_begin();
#endif

View file

@ -20,7 +20,7 @@ MARLIN_TEST_BUILD = build_src_filter=+<src/tests>
POSTMORTEM_DEBUGGING = build_src_filter=+<src/HAL/shared/cpu_exception> +<src/HAL/shared/backtrace>
build_flags=-funwind-tables
MKS_WIFI_MODULE = QRCode=https://github.com/makerbase-mks/QRCode/archive/261c5a696a.zip
HAS_TRINAMIC_CONFIG = TMCStepper=https://github.com/MarlinFirmware/TMCStepper/archive/v0.8.7.zip
HAS_TRINAMIC_CONFIG = TMCStepper=https://github.com/MarlinFirmware/TMCStepper/archive/v0.8.8.zip
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>
HAS_STEPPER_CONTROL = build_src_filter=+<src/module/stepper/control.cpp>
HAS_T(RINAMIC_CONFIG|MC_SPI) = build_src_filter=+<src/feature/tmc_util.cpp>

View file

@ -320,7 +320,7 @@ build_unflags = ${env:STM32F407VG_btt.build_unflags} -DUSBD_USE_CDC
[env:STM32F407VG_btt_USB_debug]
extends = env:STM32F407VG_btt_USB
build_flags = ${env:STM32F407VG_btt_USB.build_flags} -O0
build_unflags = ${env:STM32F407VG_btt_USB.build_unflags} -Os -NDEBUG
build_unflags = ${env:STM32F407VG_btt_USB.build_unflags} -Os -DNDEBUG
#
# 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
[env:STM32F429VG_btt_USB_debug]
extends = env:STM32F429VG_btt_USB
build_flags = ${env:STM32F429VG_btt_USB.build_flags} -O0
build_unflags = ${env:STM32F429VG_btt_USB.build_unflags} -Os -NDEBUG
build_unflags = ${env:STM32F429VG_btt_USB.build_unflags} -Os -DNDEBUG
#
# BigTreeTech Octopus V1.0/1.1 / Octopus Pro V1.0 (STM32F446ZET6 ARM Cortex-M4)