From 2ed9571c2f0e43519f5d41a15e2bcda894ad26b9 Mon Sep 17 00:00:00 2001 From: Scott Lahteine Date: Wed, 26 Mar 2025 23:08:17 -0500 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20EDITABLE=5FHOMING=5FCURRENT?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Marlin/Configuration_adv.h | 2 + Marlin/src/core/language.h | 3 +- Marlin/src/feature/tmc_util.cpp | 4 + Marlin/src/feature/tmc_util.h | 26 ++++ Marlin/src/gcode/feature/trinamic/M906.cpp | 9 +- Marlin/src/gcode/feature/trinamic/M920.cpp | 144 +++++++++++++++++++++ Marlin/src/gcode/gcode.cpp | 7 +- Marlin/src/gcode/gcode.h | 5 + Marlin/src/lcd/language/language_en.h | 1 + Marlin/src/lcd/menu/menu_tmc.cpp | 34 ++++- Marlin/src/module/motion.cpp | 55 ++------ Marlin/src/module/settings.cpp | 51 ++++++++ buildroot/tests/STM32F103RC_btt | 5 +- ini/features.ini | 1 + 14 files changed, 291 insertions(+), 56 deletions(-) create mode 100644 Marlin/src/gcode/feature/trinamic/M920.cpp diff --git a/Marlin/Configuration_adv.h b/Marlin/Configuration_adv.h index 7cc54b2a9600..f24ece598685 100644 --- a/Marlin/Configuration_adv.h +++ b/Marlin/Configuration_adv.h @@ -2995,6 +2995,8 @@ #define HOLD_MULTIPLIER 0.5 // Scales down the holding current from run current + //#define EDITABLE_HOMING_CURRENT // Add a G-code and menu to modify the Homing Current + /** * Interpolate microsteps to 256 * Override for each driver with _INTERPOLATE settings below diff --git a/Marlin/src/core/language.h b/Marlin/src/core/language.h index dddc00dba800..3a50fcdc6b96 100644 --- a/Marlin/src/core/language.h +++ b/Marlin/src/core/language.h @@ -312,8 +312,9 @@ #define STR_FILAMENT_RUNOUT_SENSOR "Filament runout sensor" #define STR_DRIVER_STEPPING_MODE "Driver stepping mode" #define STR_STEPPER_DRIVER_CURRENT "Stepper driver current" +#define STR_HOMING_CURRENT "Homing Current (mA)" #define STR_HYBRID_THRESHOLD "Hybrid Threshold" -#define STR_STALLGUARD_THRESHOLD "StallGuard threshold" +#define STR_STALLGUARD_THRESHOLD "StallGuard Threshold" #define STR_HOME_OFFSET "Home offset" #define STR_SOFT_ENDSTOPS "Soft endstops" #define STR_MATERIAL_HEATUP "Material heatup parameters" diff --git a/Marlin/src/feature/tmc_util.cpp b/Marlin/src/feature/tmc_util.cpp index 62972eb7f53c..753cb003ff23 100644 --- a/Marlin/src/feature/tmc_util.cpp +++ b/Marlin/src/feature/tmc_util.cpp @@ -43,6 +43,10 @@ #endif #endif +#if ENABLED(EDITABLE_HOMING_CURRENT) + homing_current_t homing_current_mA; +#endif + /** * Check for over temperature or short to ground error flags. * Report and log warning of overtemperature condition. diff --git a/Marlin/src/feature/tmc_util.h b/Marlin/src/feature/tmc_util.h index 27aae23f896e..4cac2969a7f3 100644 --- a/Marlin/src/feature/tmc_util.h +++ b/Marlin/src/feature/tmc_util.h @@ -375,6 +375,32 @@ void test_tmc_connection(LOGICAL_AXIS_DECL_LC(const bool, true)); #endif // USE_SENSORLESS +#if HAS_HOMING_CURRENT + + // Axes that have a distinct homing current + struct homing_current_t { + OPTCODE(X_HAS_HOME_CURRENT, uint16_t X) + OPTCODE(Y_HAS_HOME_CURRENT, uint16_t Y) + OPTCODE(Z_HAS_HOME_CURRENT, uint16_t Z) + OPTCODE(X2_HAS_HOME_CURRENT, uint16_t X2) + OPTCODE(Y2_HAS_HOME_CURRENT, uint16_t Y2) + OPTCODE(Z2_HAS_HOME_CURRENT, uint16_t Z2) + OPTCODE(Z3_HAS_HOME_CURRENT, uint16_t Z3) + OPTCODE(Z4_HAS_HOME_CURRENT, uint16_t Z4) + OPTCODE(I_HAS_HOME_CURRENT, uint16_t I) + OPTCODE(J_HAS_HOME_CURRENT, uint16_t J) + OPTCODE(K_HAS_HOME_CURRENT, uint16_t K) + OPTCODE(U_HAS_HOME_CURRENT, uint16_t U) + OPTCODE(V_HAS_HOME_CURRENT, uint16_t V) + OPTCODE(W_HAS_HOME_CURRENT, uint16_t W) + }; + + #if ENABLED(EDITABLE_HOMING_CURRENT) + extern homing_current_t homing_current_mA; + #endif + +#endif // HAS_HOMING_CURRENT + #endif // HAS_TRINAMIC_CONFIG #if HAS_TMC_SPI diff --git a/Marlin/src/gcode/feature/trinamic/M906.cpp b/Marlin/src/gcode/feature/trinamic/M906.cpp index 43d980098edf..74bbf9cae0dc 100644 --- a/Marlin/src/gcode/feature/trinamic/M906.cpp +++ b/Marlin/src/gcode/feature/trinamic/M906.cpp @@ -37,6 +37,8 @@ static void tmc_print_current(TMC &st) { /** * M906: Set motor current in milliamps. * + * With no parameters report driver currents. + * * Parameters: * X[current] - Set mA current for X driver(s) * Y[current] - Set mA current for Y driver(s) @@ -52,9 +54,14 @@ static void tmc_print_current(TMC &st) { * I[index] - Axis sub-index (Omit or 0 for X, Y, Z; 1 for X2, Y2, Z2; 2 for Z3; 3 for Z4.) * T[index] - Extruder index (Zero-based. Omit for E0 only.) * - * With no parameters report driver currents. + * With EDITABLE_HOMING_CURRENT: + * H - Set / Report Homing Current. Alias for M920. */ void GcodeSuite::M906() { + #if ENABLED(EDITABLE_HOMING_CURRENT) + if (parser.seen_test('H')) return M920(); + #endif + #define TMC_SAY_CURRENT(Q) tmc_print_current(stepper##Q) #define TMC_SET_CURRENT(Q) stepper##Q.rms_current(value) diff --git a/Marlin/src/gcode/feature/trinamic/M920.cpp b/Marlin/src/gcode/feature/trinamic/M920.cpp new file mode 100644 index 000000000000..2852f8bf4436 --- /dev/null +++ b/Marlin/src/gcode/feature/trinamic/M920.cpp @@ -0,0 +1,144 @@ +/** + * Marlin 3D Printer Firmware + * Copyright (c) 2025 MarlinFirmware [https://github.com/MarlinFirmware/Marlin] + * + * Based on Sprinter and grbl. + * Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + * + */ + +#include "../../../inc/MarlinConfigPre.h" + +#if ENABLED(EDITABLE_HOMING_CURRENT) + +#include "../../gcode.h" +#include "../../../feature/tmc_util.h" + +#if AXIS_COLLISION('I') + #define I_PARAM 'S' + #define I_PARAM_STR "S" + #warning "Use 'M920 S' instead of 'M920 I' for the stepper number." +#else + #define I_PARAM 'I' + #define I_PARAM_STR "I" +#endif + +/** + * M920: Set Homing Current for one or more axes + * + * Parameters: + * X[current] - Homing Current to use for X axis stepper(s) + * Y[current] - Homing Current to use for Y axis stepper(s) + * Z[current] - Homing Current to use for Z axis stepper(s) + * A[current] - Homing Current to use for A axis stepper(s) + * B[current] - Homing Current to use for B axis stepper(s) + * C[current] - Homing Current to use for C axis stepper(s) + * U[current] - Homing Current to use for U axis stepper(s) + * V[current] - Homing Current to use for V axis stepper(s) + * W[current] - Homing Current to use for W axis stepper(s) + * + * I - For multi-stepper axes, the zero-based index of the stepper to modify in each axis. + * If omitted all steppers of each axis will be set to the given axis current. + */ +void GcodeSuite::M920() { + bool report = true; + const uint8_t index = parser.byteval(I_PARAM); + LOOP_NUM_AXES(i) if (parser.seen(AXIS_CHAR(i))) { + const int16_t value = parser.value_int(); + report = false; + switch (i) { + #if X_HAS_HOME_CURRENT + case X_AXIS: + if (index < 1) homing_current_mA.X = value; + TERN_(X2_HAS_HOME_CURRENT, if (!index || index == 1) homing_current_mA.X2 = value); + break; + #endif + #if Y_HAS_HOME_CURRENT + case Y_AXIS: + if (index < 1) homing_current_mA.Y = value; + TERN_(Y2_HAS_HOME_CURRENT, if (!index || index == 1) homing_current_mA.Y2 = value); + break; + #endif + #if Z_HAS_HOME_CURRENT + case Z_AXIS: + if (index < 1) homing_current_mA.Z = value; + TERN_(Z2_HAS_HOME_CURRENT, if (!index || index == 1) homing_current_mA.Z2 = value); + TERN_(Z3_HAS_HOME_CURRENT, if (!index || index == 2) homing_current_mA.Z3 = value); + TERN_(Z4_HAS_HOME_CURRENT, if (!index || index == 3) homing_current_mA.Z4 = value); + break; + #endif + OPTCODE(I_HAS_HOME_CURRENT, case I_AXIS: homing_current_mA.I = value; break) + OPTCODE(J_HAS_HOME_CURRENT, case J_AXIS: homing_current_mA.J = value; break) + OPTCODE(K_HAS_HOME_CURRENT, case K_AXIS: homing_current_mA.K = value; break) + OPTCODE(U_HAS_HOME_CURRENT, case U_AXIS: homing_current_mA.U = value; break) + OPTCODE(V_HAS_HOME_CURRENT, case V_AXIS: homing_current_mA.V = value; break) + OPTCODE(W_HAS_HOME_CURRENT, case W_AXIS: homing_current_mA.W = value; break) + } + } + + if (report) M920_report(); +} + +void GcodeSuite::M920_report(const bool forReplay/*=true*/) { + TERN_(MARLIN_SMALL_BUILD, return); + + report_heading(forReplay, F(STR_HOMING_CURRENT)); + + auto say_M920 = [](const bool forReplay, int16_t index=-1) { + report_echo_start(forReplay); + SERIAL_ECHOPGM(" M920"); + if (index >= 0) SERIAL_ECHOPGM(" " I_PARAM_STR, index); + }; + + #if X_SENSORLESS || Y_SENSORLESS || Z_SENSORLESS + #if X2_SENSORLESS || Y2_SENSORLESS || Z2_SENSORLESS || Z3_SENSORLESS || Z4_SENSORLESS + say_M920(forReplay, 0); + #else + say_M920(forReplay); + #endif + TERN_(X_SENSORLESS, SERIAL_ECHOPGM_P(SP_X_STR, homing_current_mA.X)); + TERN_(Y_SENSORLESS, SERIAL_ECHOPGM_P(SP_Y_STR, homing_current_mA.Y)); + TERN_(Z_SENSORLESS, SERIAL_ECHOPGM_P(SP_Z_STR, homing_current_mA.Z)); + #if X2_SENSORLESS || Y2_SENSORLESS || Z2_SENSORLESS || Z3_SENSORLESS || Z4_SENSORLESS + say_M920(forReplay); + #endif + TERN_(I_SENSORLESS, SERIAL_ECHOPGM_P(SP_I_STR, homing_current_mA.I)); + TERN_(J_SENSORLESS, SERIAL_ECHOPGM_P(SP_J_STR, homing_current_mA.J)); + TERN_(K_SENSORLESS, SERIAL_ECHOPGM_P(SP_K_STR, homing_current_mA.K)); + TERN_(U_SENSORLESS, SERIAL_ECHOPGM_P(SP_U_STR, homing_current_mA.U)); + TERN_(V_SENSORLESS, SERIAL_ECHOPGM_P(SP_V_STR, homing_current_mA.V)); + TERN_(W_SENSORLESS, SERIAL_ECHOPGM_P(SP_W_STR, homing_current_mA.W)); + SERIAL_EOL(); + #endif + + #if X2_SENSORLESS || Y2_SENSORLESS || Z2_SENSORLESS + say_M920(forReplay, 1); + TERN_(X2_SENSORLESS, SERIAL_ECHOPGM_P(SP_X_STR, homing_current_mA.X2)); + TERN_(Y2_SENSORLESS, SERIAL_ECHOPGM_P(SP_Y_STR, homing_current_mA.Y2)); + TERN_(Z2_SENSORLESS, SERIAL_ECHOPGM_P(SP_Z_STR, homing_current_mA.Z2)); + SERIAL_EOL(); + #endif + #if Z3_SENSORLESS + say_M920(forReplay, 2); + SERIAL_ECHOLNPGM(" Z", homing_current_mA.Z3); + #endif + #if Z4_SENSORLESS + say_M920(forReplay, 3); + SERIAL_ECHOLNPGM(" Z", homing_current_mA.Z4); + #endif +} + +#endif // EDITABLE_HOMING_CURRENT diff --git a/Marlin/src/gcode/gcode.cpp b/Marlin/src/gcode/gcode.cpp index 64326b32af21..8a444053e623 100644 --- a/Marlin/src/gcode/gcode.cpp +++ b/Marlin/src/gcode/gcode.cpp @@ -1056,12 +1056,15 @@ void GcodeSuite::process_parsed_command(const bool no_ok/*=false*/) { case 912: M912(); break; // M912: Clear TMC2130 prewarn triggered flags #endif #if ENABLED(HYBRID_THRESHOLD) - case 913: M913(); break; // M913: Set HYBRID_THRESHOLD speed. + case 913: M913(); break; // M913: Set HYBRID_THRESHOLD speed #endif #if USE_SENSORLESS - case 914: M914(); break; // M914: Set StallGuard sensitivity. + case 914: M914(); break; // M914: Set StallGuard sensitivity #endif case 919: M919(); break; // M919: Set stepper Chopper Times + #if ENABLED(EDITABLE_HOMING_CURRENT) + case 920: M920(); break; // M920: Set Homing Current + #endif #endif #if HAS_MICROSTEPS diff --git a/Marlin/src/gcode/gcode.h b/Marlin/src/gcode/gcode.h index 7ba1c58d2a32..1d39dc3a6b04 100644 --- a/Marlin/src/gcode/gcode.h +++ b/Marlin/src/gcode/gcode.h @@ -320,6 +320,7 @@ * M914 - Set StallGuard sensitivity. (Requires SENSORLESS_HOMING or SENSORLESS_PROBING) * M919 - Set or Report motor Chopper Times (time_off, hysteresis_end, hysteresis_start) using axis codes XYZE, etc. * If no parameters are given, report. (Requires *_DRIVER_TYPE TMC(2130|2160|5130|5160|2208|2209|2660)) + * M920 - Set Homing Current. (Requires distinct *_CURRENT_HOME settings) * M936 - OTA update firmware. (Requires OTA_FIRMWARE_UPDATE) * M951 - Set Magnetic Parking Extruder parameters. (Requires MAGNETIC_PARKING_EXTRUDER) * M3426 - Read MCP3426 ADC over I2C. (Requires HAS_MCP3426_ADC) @@ -1259,6 +1260,10 @@ class GcodeSuite { static void M914_report(const bool forReplay=true); #endif static void M919(); + #if ENABLED(EDITABLE_HOMING_CURRENT) + static void M920(); + static void M920_report(const bool forReplay=true); + #endif #endif #if HAS_MOTOR_CURRENT_SPI || HAS_MOTOR_CURRENT_PWM || HAS_MOTOR_CURRENT_I2C || HAS_MOTOR_CURRENT_DAC diff --git a/Marlin/src/lcd/language/language_en.h b/Marlin/src/lcd/language/language_en.h index ca2e50d063c7..571f85e8ceef 100644 --- a/Marlin/src/lcd/language/language_en.h +++ b/Marlin/src/lcd/language/language_en.h @@ -883,6 +883,7 @@ namespace LanguageNarrow_en { LSTR MSG_TMC_HOMING_THRS = _UxGT("Sensorless Homing"); LSTR MSG_TMC_STEPPING_MODE = _UxGT("Stepping Mode"); LSTR MSG_TMC_STEALTHCHOP = _UxGT("StealthChop"); + LSTR MSG_TMC_HOMING_CURRENT = _UxGT("Homing Current"); LSTR MSG_SERVICE_RESET = _UxGT("Reset"); LSTR MSG_SERVICE_IN = _UxGT(" in:"); diff --git a/Marlin/src/lcd/menu/menu_tmc.cpp b/Marlin/src/lcd/menu/menu_tmc.cpp index 2cf180ac9732..2ddb38f3a43b 100644 --- a/Marlin/src/lcd/menu/menu_tmc.cpp +++ b/Marlin/src/lcd/menu/menu_tmc.cpp @@ -110,6 +110,33 @@ void menu_tmc_current() { #endif // SENSORLESS_HOMING +#if ENABLED(EDITABLE_HOMING_CURRENT) + + #define TMC_EDIT_HOMING_CURRENT(ST, STR) EDIT_ITEM_FAST_F(uint16_4, F(STR), &homing_current_mA.ST, ST##_CURRENT / 3, ST##_CURRENT) + + void menu_tmc_homing_current() { + START_MENU(); + STATIC_ITEM(MSG_TMC_HOMING_CURRENT); + BACK_ITEM(MSG_TMC_DRIVERS); + TERN_( X_HAS_HOME_CURRENT, TMC_EDIT_HOMING_CURRENT(X, STR_X)); + TERN_(X2_HAS_HOME_CURRENT, TMC_EDIT_HOMING_CURRENT(X2, STR_X2)); + TERN_( Y_HAS_HOME_CURRENT, TMC_EDIT_HOMING_CURRENT(Y, STR_Y)); + TERN_(Y2_HAS_HOME_CURRENT, TMC_EDIT_HOMING_CURRENT(Y2, STR_Y2)); + TERN_( Z_HAS_HOME_CURRENT, TMC_EDIT_HOMING_CURRENT(Z, STR_Z)); + TERN_(Z2_HAS_HOME_CURRENT, TMC_EDIT_HOMING_CURRENT(Z2, STR_Z2)); + TERN_(Z3_HAS_HOME_CURRENT, TMC_EDIT_HOMING_CURRENT(Z3, STR_Z3)); + TERN_(Z4_HAS_HOME_CURRENT, TMC_EDIT_HOMING_CURRENT(Z4, STR_Z4)); + TERN_( I_HAS_HOME_CURRENT, TMC_EDIT_HOMING_CURRENT(I, STR_I)); + TERN_( J_HAS_HOME_CURRENT, TMC_EDIT_HOMING_CURRENT(J, STR_J)); + TERN_( K_HAS_HOME_CURRENT, TMC_EDIT_HOMING_CURRENT(K, STR_K)); + TERN_( U_HAS_HOME_CURRENT, TMC_EDIT_HOMING_CURRENT(U, STR_U)); + TERN_( V_HAS_HOME_CURRENT, TMC_EDIT_HOMING_CURRENT(V, STR_V)); + TERN_( W_HAS_HOME_CURRENT, TMC_EDIT_HOMING_CURRENT(W, STR_W)); + END_MENU(); + } + +#endif // EDITABLE_HOMING_CURRENT + #if HAS_STEALTHCHOP #define TMC_EDIT_STEP_MODE(ST, STR) EDIT_ITEM_F(bool, F(STR), &stepper##ST.stored.stealthChop_enabled, []{ stepper##ST.refresh_stepping_mode(); }) @@ -143,9 +170,10 @@ void menu_tmc() { START_MENU(); BACK_ITEM(MSG_ADVANCED_SETTINGS); SUBMENU(MSG_TMC_CURRENT, menu_tmc_current); - TERN_(HYBRID_THRESHOLD, SUBMENU(MSG_TMC_HYBRID_THRS, menu_tmc_hybrid_thrs)); - TERN_(SENSORLESS_HOMING, SUBMENU(MSG_TMC_HOMING_THRS, menu_tmc_homing_thrs)); - TERN_(HAS_STEALTHCHOP, SUBMENU(MSG_TMC_STEPPING_MODE, menu_tmc_step_mode)); + TERN_(HYBRID_THRESHOLD, SUBMENU(MSG_TMC_HYBRID_THRS, menu_tmc_hybrid_thrs)); + TERN_(SENSORLESS_HOMING, SUBMENU(MSG_TMC_HOMING_THRS, menu_tmc_homing_thrs)); + TERN_(EDITABLE_HOMING_CURRENT, SUBMENU(MSG_TMC_HOMING_CURRENT, menu_tmc_homing_current)); + TERN_(HAS_STEALTHCHOP, SUBMENU(MSG_TMC_STEALTHCHOP, menu_tmc_step_mode)); END_MENU(); } diff --git a/Marlin/src/module/motion.cpp b/Marlin/src/module/motion.cpp index 386d46665d28..fcaaf613e401 100644 --- a/Marlin/src/module/motion.cpp +++ b/Marlin/src/module/motion.cpp @@ -271,48 +271,7 @@ void report_current_position_projected() { #define debug_current(...) #endif - #if HAS_CURRENT_HOME_X - int16_t saved_current_X; - #endif - #if HAS_CURRENT_HOME_Y - int16_t saved_current_Y; - #endif - #if HAS_CURRENT_HOME_Z - int16_t saved_current_Z; - #endif - #if HAS_CURRENT_HOME_X2 - int16_t saved_current_X2; - #endif - #if HAS_CURRENT_HOME_Y2 - int16_t saved_current_Y2; - #endif - #if HAS_CURRENT_HOME_Z2 - int16_t saved_current_Z2; - #endif - #if HAS_CURRENT_HOME_Z3 - int16_t saved_current_Z3; - #endif - #if HAS_CURRENT_HOME_Z4 - int16_t saved_current_Z4; - #endif - #if HAS_CURRENT_HOME_I - int16_t saved_current_I; - #endif - #if HAS_CURRENT_HOME_J - int16_t saved_current_J; - #endif - #if HAS_CURRENT_HOME_K - int16_t saved_current_K; - #endif - #if HAS_CURRENT_HOME_U - int16_t saved_current_U; - #endif - #if HAS_CURRENT_HOME_V - int16_t saved_current_V; - #endif - #if HAS_CURRENT_HOME_W - int16_t saved_current_W; - #endif + homing_current_t saved_current_mA; /** * Set motors to their homing / probing currents. @@ -320,11 +279,13 @@ void report_current_position_projected() { */ void set_homing_current(const AxisEnum axis) { + #define HOMING_CURRENT(A) TERN(EDITABLE_HOMING_CURRENT, homing_current_mA.A, A##_CURRENT_HOME) + // Saves the running current of the motor at the moment the function is called and sets current to CURRENT_HOME #define _SAVE_SET_CURRENT(A) \ - saved_current_##A = stepper##A.getMilliamps(); \ - stepper##A.rms_current(A##_CURRENT_HOME); \ - debug_current(F(STR_##A), saved_current_##A, A##_CURRENT_HOME) + saved_current_mA.A = stepper##A.getMilliamps(); \ + stepper##A.rms_current(HOMING_CURRENT(A)); \ + debug_current(F(STR_##A), saved_current_mA.A, HOMING_CURRENT(A)) #define _MAP_SAVE_SET(A) OPTCODE(A##_HAS_HOME_CURRENT, _SAVE_SET_CURRENT(A)) @@ -478,8 +439,8 @@ void report_current_position_projected() { // Restore the saved current #define _RESTORE_CURRENT(A) \ - stepper##A.rms_current(saved_current_##A); \ - debug_current(F(STR_##A), A##_CURRENT_HOME, saved_current_##A) + stepper##A.rms_current(saved_current_mA.A); \ + debug_current(F(STR_##A), HOMING_CURRENT(A), saved_current_mA.A) #define _MAP_RESTORE(A) OPTCODE(A##_HAS_HOME_CURRENT, _RESTORE_CURRENT(A)) diff --git a/Marlin/src/module/settings.cpp b/Marlin/src/module/settings.cpp index a7e791951ba4..c2b4e3da389f 100644 --- a/Marlin/src/module/settings.cpp +++ b/Marlin/src/module/settings.cpp @@ -469,6 +469,13 @@ typedef struct SettingsDataStruct { xyz_feedrate_t homing_feedrate_mm_m; // M210 X Y Z I J K U V W #endif + // + // TMC Homing Current + // + #if ENABLED(EDITABLE_HOMING_CURRENT) + homing_current_t homing_current_mA; // M920 X Y Z... + #endif + // // !NO_VOLUMETRIC // @@ -1355,6 +1362,14 @@ void MarlinSettings::postprocess() { EEPROM_WRITE(homing_feedrate_mm_m); #endif + // + // TMC Homing Current + // + #if ENABLED(EDITABLE_HOMING_CURRENT) + _FIELD_TEST(homing_current_mA); + EEPROM_WRITE(homing_current_mA); + #endif + // // Volumetric & Filament Size // @@ -2414,6 +2429,14 @@ void MarlinSettings::postprocess() { EEPROM_READ(homing_feedrate_mm_m); #endif + // + // TMC Homing Current + // + #if ENABLED(EDITABLE_HOMING_CURRENT) + _FIELD_TEST(homing_current_mA); + EEPROM_READ(homing_current_mA); + #endif + // // Volumetric & Filament Size // @@ -3626,6 +3649,29 @@ void MarlinSettings::reset() { // TERN_(EDITABLE_HOMING_FEEDRATE, homing_feedrate_mm_m = xyz_feedrate_t(HOMING_FEEDRATE_MM_M)); + // + // TMC Homing Current + // + #if ENABLED(EDITABLE_HOMING_CURRENT) + homing_current_t base_homing_current_mA = { + OPTITEM(X_HAS_HOME_CURRENT, X_CURRENT_HOME) + OPTITEM(Y_HAS_HOME_CURRENT, Y_CURRENT_HOME) + OPTITEM(Z_HAS_HOME_CURRENT, Z_CURRENT_HOME) + OPTITEM(X2_HAS_HOME_CURRENT, X2_CURRENT_HOME) + OPTITEM(Y2_HAS_HOME_CURRENT, Y2_CURRENT_HOME) + OPTITEM(Z2_HAS_HOME_CURRENT, Z2_CURRENT_HOME) + OPTITEM(Z3_HAS_HOME_CURRENT, Z3_CURRENT_HOME) + OPTITEM(Z4_HAS_HOME_CURRENT, Z4_CURRENT_HOME) + OPTITEM(I_HAS_HOME_CURRENT, I_CURRENT_HOME) + OPTITEM(J_HAS_HOME_CURRENT, J_CURRENT_HOME) + OPTITEM(K_HAS_HOME_CURRENT, K_CURRENT_HOME) + OPTITEM(U_HAS_HOME_CURRENT, U_CURRENT_HOME) + OPTITEM(V_HAS_HOME_CURRENT, V_CURRENT_HOME) + OPTITEM(W_HAS_HOME_CURRENT, W_CURRENT_HOME) + }; + homing_current_mA = base_homing_current_mA; + #endif + // // Volumetric & Filament Size // @@ -4058,6 +4104,11 @@ void MarlinSettings::reset() { TERN_(USE_SENSORLESS, gcode.M914_report(forReplay)); #endif + // + // TMC Homing Current + // + TERN_(EDITABLE_HOMING_CURRENT, gcode.M920_report(forReplay)); + // // TMC stepping mode // diff --git a/buildroot/tests/STM32F103RC_btt b/buildroot/tests/STM32F103RC_btt index 178170455fb0..2b05d429223a 100755 --- a/buildroot/tests/STM32F103RC_btt +++ b/buildroot/tests/STM32F103RC_btt @@ -11,8 +11,9 @@ set -e # restore_configs opt_set MOTHERBOARD BOARD_BTT_SKR_MINI_E3_V1_0 SERIAL_PORT 1 SERIAL_PORT_2 -1 \ - X_DRIVER_TYPE TMC2209 Y_DRIVER_TYPE TMC2209 Z_DRIVER_TYPE TMC2209 E0_DRIVER_TYPE TMC2209 -opt_enable CR10_STOCKDISPLAY PINS_DEBUGGING Z_IDLE_HEIGHT \ + X_DRIVER_TYPE TMC2209 Y_DRIVER_TYPE TMC2209 Z_DRIVER_TYPE TMC2209 E0_DRIVER_TYPE TMC2209 \ + X_CURRENT_HOME X_CURRENT/2 Y_CURRENT_HOME Y_CURRENT/2 Z_CURRENT_HOME Y_CURRENT/2 +opt_enable CR10_STOCKDISPLAY PINS_DEBUGGING Z_IDLE_HEIGHT EDITABLE_HOMING_CURRENT \ FT_MOTION FT_MOTION_MENU BIQU_MICROPROBE_V1 PROBE_ENABLE_DISABLE Z_SAFE_HOMING AUTO_BED_LEVELING_BILINEAR \ ADAPTIVE_STEP_SMOOTHING NONLINEAR_EXTRUSION exec_test $1 $2 "BigTreeTech SKR Mini E3 1.0 - TMC2209 HW Serial, FT_MOTION" "$3" diff --git a/ini/features.ini b/ini/features.ini index f56175a3d64d..1cff1a61f4dc 100644 --- a/ini/features.ini +++ b/ini/features.ini @@ -23,6 +23,7 @@ MKS_WIFI_MODULE = QRCode=https://github.com/makerbase-mks HAS_TRINAMIC_CONFIG = TMCStepper=https://github.com/MarlinFirmware/TMCStepper/archive/marlin-2.1.3.x.zip build_src_filter=+ + + + + HAS_T(RINAMIC_CONFIG|MC_SPI) = build_src_filter=+ +EDITABLE_HOMING_CURRENT = build_src_filter=+ SR_LCD_3W_NL = SailfishLCD=https://github.com/mikeshub/SailfishLCD/archive/6f53c19a8a.zip HAS_MOTOR_CURRENT_(I2C|DAC|SPI|PWM) = build_src_filter=+ HAS_MOTOR_CURRENT_I2C = SlowSoftI2CMaster