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;