From 6dfbdd3735f59fc57f67d8d508529043c5b5ced2 Mon Sep 17 00:00:00 2001 From: vintagepc <53943260+vintagepc@users.noreply.github.com> Date: Fri, 21 Feb 2020 17:50:38 -0500 Subject: [PATCH 1/4] Enable M914/5, Show in settings if overloaded --- Firmware/Marlin_main.cpp | 3 ++- Firmware/ultralcd.cpp | 11 ++++++++++- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/Firmware/Marlin_main.cpp b/Firmware/Marlin_main.cpp index 4d56adfbd..76a08b8f3 100644 --- a/Firmware/Marlin_main.cpp +++ b/Firmware/Marlin_main.cpp @@ -8229,9 +8229,9 @@ Sigma_Exit: } break; +#endif // TMC2130_SERVICE_CODES_M910_M918 /*! ### M914 - Set TMC2130 normal mode M914: Set TMC2130 normal mode - Not active in default, only if `TMC2130_SERVICE_CODES_M910_M918` is defined in source code. */ case 914: { @@ -8253,6 +8253,7 @@ Sigma_Exit: } break; +#ifdef TMC2130_SERVICE_CODES_M910_M918 /*! ### M916 - Set TMC2130 Stallguard sensitivity threshold M916: Set TMC2130 Stallguard sensitivity threshold Not active in default, only if `TMC2130_SERVICE_CODES_M910_M918` is defined in source code. diff --git a/Firmware/ultralcd.cpp b/Firmware/ultralcd.cpp index 70da183a0..69e445565 100644 --- a/Firmware/ultralcd.cpp +++ b/Firmware/ultralcd.cpp @@ -4223,7 +4223,16 @@ do\ {\ if(!farm_mode)\ {\ - if (SilentModeMenu == SILENT_MODE_NORMAL)\ + bool bDesync = SilentModeMenu != tmc2130_mode; \ + if (SilentModeMenu == SILENT_MODE_NORMAL && bDesync) \ + {\ + MENU_ITEM_TOGGLE_P(_T(MSG_MODE), PSTR("M915"), lcd_silent_mode_set);\ + }\ + else if (bDesync) \ + {\ + MENU_ITEM_TOGGLE_P(_T(MSG_MODE), PSTR("M914") , lcd_silent_mode_set);\ + }\ + else if (SilentModeMenu == SILENT_MODE_NORMAL)\ {\ MENU_ITEM_TOGGLE_P(_T(MSG_MODE), _T(MSG_NORMAL), lcd_silent_mode_set);\ }\ From 487c7d63e1125693250e928203d2e11f8b557396 Mon Sep 17 00:00:00 2001 From: vintagepc <53943260+vintagepc@users.noreply.github.com> Date: Fri, 21 Feb 2020 22:23:05 -0500 Subject: [PATCH 2/4] Partial --- Firmware/Marlin_main.cpp | 26 +++++++++++++++++++++----- Firmware/ultralcd.cpp | 26 ++++++++++++++------------ 2 files changed, 35 insertions(+), 17 deletions(-) diff --git a/Firmware/Marlin_main.cpp b/Firmware/Marlin_main.cpp index 76a08b8f3..069edc2e5 100644 --- a/Firmware/Marlin_main.cpp +++ b/Firmware/Marlin_main.cpp @@ -8233,11 +8233,17 @@ Sigma_Exit: /*! ### M914 - Set TMC2130 normal mode M914: Set TMC2130 normal mode */ +#ifdef TMC2130 case 914: { - tmc2130_mode = TMC2130_MODE_NORMAL; + printf_P(_n("tmc2130mode/smm/eep: %d %d %d\n"),tmc2130_mode,SilentModeMenu,eeprom_read_byte((uint8_t*)EEPROM_SILENT)); + if (tmc2130_mode != TMC2130_MODE_NORMAL) + { + tmc2130_mode = TMC2130_MODE_NORMAL; update_mode_profile(); tmc2130_init(TMCInitParams(false, FarmOrUserECool())); + printf_P(_n("tmc2130mode/smm/eep: %d %d %d\n"),tmc2130_mode,SilentModeMenu,eeprom_read_byte((uint8_t*)EEPROM_SILENT)); + } } break; @@ -8246,13 +8252,23 @@ Sigma_Exit: Not active in default, only if `TMC2130_SERVICE_CODES_M910_M918` is defined in source code. */ case 915: - { - tmc2130_mode = TMC2130_MODE_SILENT; - update_mode_profile(); - tmc2130_init(TMCInitParams(false, FarmOrUserECool())); + { + printf_P(_n("tmc2130mode/smm/eep: %d %d %d\n"),tmc2130_mode,SilentModeMenu,eeprom_read_byte((uint8_t*)EEPROM_SILENT)); + if (tmc2130_mode != TMC2130_MODE_SILENT) + { // This is basically the equivalent of force_high_power_mode for silent mode. + st_synchronize(); + cli(); + tmc2130_mode = TMC2130_MODE_SILENT; + update_mode_profile(); + tmc2130_init(TMCInitParams(false, FarmOrUserECool())); + printf_P(_n("tmc2130mode/smm/eep: %d %d %d\n"),tmc2130_mode,SilentModeMenu,eeprom_read_byte((uint8_t*)EEPROM_SILENT)); + st_reset_timer(); + sei(); + } } break; +#endif // TMC2130 #ifdef TMC2130_SERVICE_CODES_M910_M918 /*! ### M916 - Set TMC2130 Stallguard sensitivity threshold M916: Set TMC2130 Stallguard sensitivity threshold diff --git a/Firmware/ultralcd.cpp b/Firmware/ultralcd.cpp index 69e445565..5c7b65511 100644 --- a/Firmware/ultralcd.cpp +++ b/Firmware/ultralcd.cpp @@ -4223,20 +4223,22 @@ do\ {\ if(!farm_mode)\ {\ - bool bDesync = SilentModeMenu != tmc2130_mode; \ - if (SilentModeMenu == SILENT_MODE_NORMAL && bDesync) \ - {\ - MENU_ITEM_TOGGLE_P(_T(MSG_MODE), PSTR("M915"), lcd_silent_mode_set);\ - }\ - else if (bDesync) \ - {\ - MENU_ITEM_TOGGLE_P(_T(MSG_MODE), PSTR("M914") , lcd_silent_mode_set);\ - }\ - else if (SilentModeMenu == SILENT_MODE_NORMAL)\ + /* M914/5 do not update eeprom, only tmc2130_mode */\ + bool bDesync = tmc2130_mode ^ eeprom_read_byte((uint8_t*)EEPROM_SILENT);\ + if (SilentModeMenu == SILENT_MODE_NORMAL) \ {\ - MENU_ITEM_TOGGLE_P(_T(MSG_MODE), _T(MSG_NORMAL), lcd_silent_mode_set);\ + if (bDesync)\ + MENU_ITEM_TOGGLE_P(_T(MSG_MODE), PSTR("M915"), lcd_silent_mode_set);\ + else\ + MENU_ITEM_TOGGLE_P(_T(MSG_MODE), _T(MSG_NORMAL), lcd_silent_mode_set);\ }\ - else MENU_ITEM_TOGGLE_P(_T(MSG_MODE), _T(MSG_STEALTH), lcd_silent_mode_set);\ + else\ + {\ + if (bDesync)\ + MENU_ITEM_TOGGLE_P(_T(MSG_MODE), PSTR("M914") , lcd_silent_mode_set);\ + else\ + MENU_ITEM_TOGGLE_P(_T(MSG_MODE), _T(MSG_STEALTH), lcd_silent_mode_set);\ + }\ if (SilentModeMenu == SILENT_MODE_NORMAL)\ {\ if (lcd_crash_detect_enabled()) MENU_ITEM_TOGGLE_P(_T(MSG_CRASHDETECT), _T(MSG_ON), crash_mode_switch);\ From 7214584723fae5dac2ce3c87c7a64a29bf524f27 Mon Sep 17 00:00:00 2001 From: vintagepc <53943260+vintagepc@users.noreply.github.com> Date: Sat, 22 Feb 2020 10:02:07 -0500 Subject: [PATCH 3/4] Fixed conflict with force_z, added P flags --- Firmware/Marlin.h | 1 + Firmware/Marlin_main.cpp | 41 +++++++++++++++++++++++++++++++--------- Firmware/ultralcd.cpp | 28 ++++++++++++++++++++++----- 3 files changed, 56 insertions(+), 14 deletions(-) diff --git a/Firmware/Marlin.h b/Firmware/Marlin.h index ac55a7874..3828ccb01 100755 --- a/Firmware/Marlin.h +++ b/Firmware/Marlin.h @@ -173,6 +173,7 @@ void manage_inactivity(bool ignore_stepper_queue=false); #define enable_z() poweron_z() #define disable_z() poweroff_z() #else + extern bool bEnableForce_z; // Used by ultralcd stealth toggle void init_force_z(); void check_force_z(); void enable_force_z(); diff --git a/Firmware/Marlin_main.cpp b/Firmware/Marlin_main.cpp index 069edc2e5..11d7bd359 100644 --- a/Firmware/Marlin_main.cpp +++ b/Firmware/Marlin_main.cpp @@ -8230,30 +8230,53 @@ Sigma_Exit: break; #endif // TMC2130_SERVICE_CODES_M910_M918 - /*! + /*! ### M914 - Set TMC2130 normal mode M914: Set TMC2130 normal mode + Updates EEPROM only if "P" is given, otherwise temporary (lasts until reset or motor idle timeout) + #### Usage + + M914 [P] + + #### Parameters + - `P` - Make the mode change permanent (write to EEPROM) */ #ifdef TMC2130 case 914: { - printf_P(_n("tmc2130mode/smm/eep: %d %d %d\n"),tmc2130_mode,SilentModeMenu,eeprom_read_byte((uint8_t*)EEPROM_SILENT)); - if (tmc2130_mode != TMC2130_MODE_NORMAL) + if (code_seen('P')) + { + eeprom_update_byte((unsigned char *)EEPROM_SILENT, SILENT_MODE_NORMAL); + SilentModeMenu = SILENT_MODE_NORMAL; + } + //printf_P(_n("tmc2130mode/smm/eep: %d %d %d %d"),tmc2130_mode,SilentModeMenu,eeprom_read_byte((uint8_t*)EEPROM_SILENT), bEnableForce_z); + if (tmc2130_mode != TMC2130_MODE_NORMAL) { tmc2130_mode = TMC2130_MODE_NORMAL; - update_mode_profile(); - tmc2130_init(TMCInitParams(false, FarmOrUserECool())); - printf_P(_n("tmc2130mode/smm/eep: %d %d %d\n"),tmc2130_mode,SilentModeMenu,eeprom_read_byte((uint8_t*)EEPROM_SILENT)); + update_mode_profile(); + tmc2130_init(TMCInitParams(false, FarmOrUserECool())); + //printf_P(_n("tmc2130mode/smm/eep: %d %d %d\n"),tmc2130_mode,SilentModeMenu,eeprom_read_byte((uint8_t*)EEPROM_SILENT)); } } break; /*! ### M915 - Set TMC2130 silent mode M915: Set TMC2130 silent mode - Not active in default, only if `TMC2130_SERVICE_CODES_M910_M918` is defined in source code. + Updates EEPROM only if "P" is given, otherwise temporary (lasts until reset or motor idle timeout) + #### Usage + + M915 [P] + + #### Parameters + - `P` - Make the mode change permanent (write to EEPROM) */ case 915: { - printf_P(_n("tmc2130mode/smm/eep: %d %d %d\n"),tmc2130_mode,SilentModeMenu,eeprom_read_byte((uint8_t*)EEPROM_SILENT)); + if (code_seen('P')) + { + eeprom_update_byte((unsigned char *)EEPROM_SILENT, SILENT_MODE_STEALTH); + SilentModeMenu = SILENT_MODE_STEALTH; + } + //printf_P(_n("tmc2130mode/smm/eep: %d %d %d %d"),tmc2130_mode,SilentModeMenu,eeprom_read_byte((uint8_t*)EEPROM_SILENT), bEnableForce_z); if (tmc2130_mode != TMC2130_MODE_SILENT) { // This is basically the equivalent of force_high_power_mode for silent mode. st_synchronize(); @@ -8261,7 +8284,7 @@ Sigma_Exit: tmc2130_mode = TMC2130_MODE_SILENT; update_mode_profile(); tmc2130_init(TMCInitParams(false, FarmOrUserECool())); - printf_P(_n("tmc2130mode/smm/eep: %d %d %d\n"),tmc2130_mode,SilentModeMenu,eeprom_read_byte((uint8_t*)EEPROM_SILENT)); + //printf_P(_n("tmc2130mode/smm/eep: %d %d %d\n"),tmc2130_mode,SilentModeMenu,eeprom_read_byte((uint8_t*)EEPROM_SILENT)); st_reset_timer(); sei(); } diff --git a/Firmware/ultralcd.cpp b/Firmware/ultralcd.cpp index 5c7b65511..03e4afec6 100644 --- a/Firmware/ultralcd.cpp +++ b/Firmware/ultralcd.cpp @@ -4218,16 +4218,25 @@ static void mmu_reset() } #ifdef TMC2130 + + +#ifdef PSU_Delta // This setup changes to "stealth" mode on timeout, need to check for that. +#define SILENT_DESYNC_IF if (bDesync && bEnableForce_z) +#else +#define SILENT_DESYNC_IF if (bDesync) +#endif + + #define SETTINGS_SILENT_MODE \ do\ {\ if(!farm_mode)\ {\ - /* M914/5 do not update eeprom, only tmc2130_mode */\ + /* M914/5 do not update SilentModeMenu, only tmc2130_mode */\ bool bDesync = tmc2130_mode ^ eeprom_read_byte((uint8_t*)EEPROM_SILENT);\ if (SilentModeMenu == SILENT_MODE_NORMAL) \ {\ - if (bDesync)\ + SILENT_DESYNC_IF\ MENU_ITEM_TOGGLE_P(_T(MSG_MODE), PSTR("M915"), lcd_silent_mode_set);\ else\ MENU_ITEM_TOGGLE_P(_T(MSG_MODE), _T(MSG_NORMAL), lcd_silent_mode_set);\ @@ -4238,7 +4247,7 @@ do\ MENU_ITEM_TOGGLE_P(_T(MSG_MODE), PSTR("M914") , lcd_silent_mode_set);\ else\ MENU_ITEM_TOGGLE_P(_T(MSG_MODE), _T(MSG_STEALTH), lcd_silent_mode_set);\ - }\ + }\ if (SilentModeMenu == SILENT_MODE_NORMAL)\ {\ if (lcd_crash_detect_enabled()) MENU_ITEM_TOGGLE_P(_T(MSG_CRASHDETECT), _T(MSG_ON), crash_mode_switch);\ @@ -5618,15 +5627,24 @@ static void lcd_tune_menu() #ifdef TMC2130 if(!farm_mode) { + bool bDesync = tmc2130_mode ^ eeprom_read_byte((uint8_t*)EEPROM_SILENT); if (SilentModeMenu == SILENT_MODE_NORMAL) { - MENU_ITEM_TOGGLE_P(_T(MSG_MODE), _T(MSG_NORMAL), lcd_silent_mode_set); + SILENT_DESYNC_IF { + MENU_ITEM_TOGGLE_P(_T(MSG_MODE), PSTR("M915"), lcd_silent_mode_set); + } else { + MENU_ITEM_TOGGLE_P(_T(MSG_MODE), _T(MSG_NORMAL), lcd_silent_mode_set); + } if (lcd_crash_detect_enabled()) { MENU_ITEM_TOGGLE_P(_T(MSG_CRASHDETECT), _T(MSG_ON), crash_mode_switch); } else { MENU_ITEM_TOGGLE_P(_T(MSG_CRASHDETECT), _T(MSG_OFF), crash_mode_switch); } } else { - MENU_ITEM_TOGGLE_P(_T(MSG_MODE), _T(MSG_STEALTH), lcd_silent_mode_set); + if (bDesync) { + MENU_ITEM_TOGGLE_P(_T(MSG_MODE), PSTR("M914") , lcd_silent_mode_set); + } else { + MENU_ITEM_TOGGLE_P(_T(MSG_MODE), _T(MSG_STEALTH), lcd_silent_mode_set); + } MENU_ITEM_TOGGLE_P(_T(MSG_CRASHDETECT), NULL, lcd_crash_mode_info); } } From 13f7ba81ffe2ab4e99caec2bd52d9f7689a34d73 Mon Sep 17 00:00:00 2001 From: vintagepc <53943260+vintagepc@users.noreply.github.com> Date: Sat, 22 Feb 2020 12:35:27 -0500 Subject: [PATCH 4/4] Cleanup, share more M914/5/FORCE code --- Firmware/Marlin.h | 1 + Firmware/Marlin_main.cpp | 91 +++++++++++++++---------------- Firmware/mesh_bed_calibration.cpp | 11 +++- 3 files changed, 54 insertions(+), 49 deletions(-) diff --git a/Firmware/Marlin.h b/Firmware/Marlin.h index 3828ccb01..0a67b02cb 100755 --- a/Firmware/Marlin.h +++ b/Firmware/Marlin.h @@ -453,6 +453,7 @@ extern int8_t busy_state; #define FORCE_HIGH_POWER_END force_high_power_mode(false) void force_high_power_mode(bool start_high_power_section); +void change_power_mode_live(uint8_t mode); #endif //TMC2130 diff --git a/Firmware/Marlin_main.cpp b/Firmware/Marlin_main.cpp index 11d7bd359..8164c22bc 100644 --- a/Firmware/Marlin_main.cpp +++ b/Firmware/Marlin_main.cpp @@ -2416,25 +2416,30 @@ void retract(bool retracting, bool swapretract = false) { #ifdef TMC2130 -void force_high_power_mode(bool start_high_power_section) { -#ifdef PSU_Delta - if (start_high_power_section == true) enable_force_z(); -#endif //PSU_Delta - uint8_t silent; - silent = eeprom_read_byte((uint8_t*)EEPROM_SILENT); - if (silent == 1) { - //we are in silent mode, set to normal mode to enable crash detection - // Wait for the planner queue to drain and for the stepper timer routine to reach an idle state. +void change_power_mode_live(uint8_t mode) +{ + // Wait for the planner queue to drain and for the stepper timer routine to reach an idle state. st_synchronize(); cli(); - tmc2130_mode = (start_high_power_section == true) ? TMC2130_MODE_NORMAL : TMC2130_MODE_SILENT; + tmc2130_mode = mode; update_mode_profile(); tmc2130_init(TMCInitParams(FarmOrUserECool())); // We may have missed a stepper timer interrupt due to the time spent in the tmc2130_init() routine. // Be safe than sorry, reset the stepper timer before re-enabling interrupts. st_reset_timer(); sei(); +} + +void force_high_power_mode(bool start_high_power_section) { +#ifdef PSU_Delta + if (start_high_power_section == true) enable_force_z(); +#endif //PSU_Delta + uint8_t silent; + silent = eeprom_read_byte((uint8_t*)EEPROM_SILENT); + if (silent == 1 || tmc2130_mode == TMC2130_MODE_SILENT) { + //we are in silent mode, set to normal mode to enable crash detection + change_power_mode_live((start_high_power_section == true) ? TMC2130_MODE_NORMAL : TMC2130_MODE_SILENT); } } #endif //TMC2130 @@ -8235,58 +8240,52 @@ Sigma_Exit: Updates EEPROM only if "P" is given, otherwise temporary (lasts until reset or motor idle timeout) #### Usage - M914 [P] + M914 [ P | R ] #### Parameters - `P` - Make the mode change permanent (write to EEPROM) + - `R` - Revert to EEPROM value */ -#ifdef TMC2130 - case 914: - { - if (code_seen('P')) - { - eeprom_update_byte((unsigned char *)EEPROM_SILENT, SILENT_MODE_NORMAL); - SilentModeMenu = SILENT_MODE_NORMAL; - } - //printf_P(_n("tmc2130mode/smm/eep: %d %d %d %d"),tmc2130_mode,SilentModeMenu,eeprom_read_byte((uint8_t*)EEPROM_SILENT), bEnableForce_z); - if (tmc2130_mode != TMC2130_MODE_NORMAL) - { - tmc2130_mode = TMC2130_MODE_NORMAL; - update_mode_profile(); - tmc2130_init(TMCInitParams(false, FarmOrUserECool())); - //printf_P(_n("tmc2130mode/smm/eep: %d %d %d\n"),tmc2130_mode,SilentModeMenu,eeprom_read_byte((uint8_t*)EEPROM_SILENT)); - } - } - break; /*! ### M915 - Set TMC2130 silent mode M915: Set TMC2130 silent mode Updates EEPROM only if "P" is given, otherwise temporary (lasts until reset or motor idle timeout) #### Usage - M915 [P] + M915 [ P | R ] #### Parameters - `P` - Make the mode change permanent (write to EEPROM) + - `R` - Revert to EEPROM value */ +#ifdef TMC2130 + case 914: case 915: - { - if (code_seen('P')) - { - eeprom_update_byte((unsigned char *)EEPROM_SILENT, SILENT_MODE_STEALTH); - SilentModeMenu = SILENT_MODE_STEALTH; - } + { + uint8_t newMode = (mcode_in_progress==914) ? TMC2130_MODE_NORMAL : TMC2130_MODE_SILENT; //printf_P(_n("tmc2130mode/smm/eep: %d %d %d %d"),tmc2130_mode,SilentModeMenu,eeprom_read_byte((uint8_t*)EEPROM_SILENT), bEnableForce_z); - if (tmc2130_mode != TMC2130_MODE_SILENT) - { // This is basically the equivalent of force_high_power_mode for silent mode. - st_synchronize(); - cli(); - tmc2130_mode = TMC2130_MODE_SILENT; - update_mode_profile(); - tmc2130_init(TMCInitParams(false, FarmOrUserECool())); - //printf_P(_n("tmc2130mode/smm/eep: %d %d %d\n"),tmc2130_mode,SilentModeMenu,eeprom_read_byte((uint8_t*)EEPROM_SILENT)); - st_reset_timer(); - sei(); + if (code_seen('R')) + { + newMode = eeprom_read_byte((uint8_t*)EEPROM_SILENT); + } + else if (code_seen('P')) + { + uint8_t newMenuMode = (mcode_in_progress==914) ? SILENT_MODE_NORMAL : SILENT_MODE_STEALTH; + eeprom_update_byte((unsigned char *)EEPROM_SILENT, newMenuMode); + SilentModeMenu = newMenuMode; + //printf_P(_n("tmc2130mode/smm/eep: %d %d %d %d"),tmc2130_mode,SilentModeMenu,eeprom_read_byte((uint8_t*)EEPROM_SILENT), bEnableForce_z); + } + + if (tmc2130_mode != newMode +#ifdef PSU_Delta + || !bEnableForce_z +#endif + ) + { +#ifdef PSU_Delta + enable_force_z(); +#endif + change_power_mode_live(newMode); } } break; diff --git a/Firmware/mesh_bed_calibration.cpp b/Firmware/mesh_bed_calibration.cpp index 308421010..247fd5866 100644 --- a/Firmware/mesh_bed_calibration.cpp +++ b/Firmware/mesh_bed_calibration.cpp @@ -953,7 +953,12 @@ bool find_bed_induction_sensor_point_z(float minimum_z, uint8_t n_iter, int bool high_deviation_occured = false; bedPWMDisabled = 1; #ifdef TMC2130 - FORCE_HIGH_POWER_START; + bool bHighPowerForced = false; + if (tmc2130_mode == TMC2130_MODE_SILENT) + { + FORCE_HIGH_POWER_START; + bHighPowerForced = true; + } #endif //printf_P(PSTR("Min. Z: %f\n"), minimum_z); #ifdef SUPPORT_VERBOSITY @@ -1047,7 +1052,7 @@ bool find_bed_induction_sensor_point_z(float minimum_z, uint8_t n_iter, int enable_z_endstop(endstop_z_enabled); // SERIAL_ECHOLNPGM("find_bed_induction_sensor_point_z 3"); #ifdef TMC2130 - FORCE_HIGH_POWER_END; + if (bHighPowerForced) FORCE_HIGH_POWER_END; #endif bedPWMDisabled = 0; return true; @@ -1057,7 +1062,7 @@ error: enable_endstops(endstops_enabled); enable_z_endstop(endstop_z_enabled); #ifdef TMC2130 - FORCE_HIGH_POWER_END; + if (bHighPowerForced) FORCE_HIGH_POWER_END; #endif bedPWMDisabled = 0; return false;