diff --git a/Firmware/Marlin_main.cpp b/Firmware/Marlin_main.cpp index 157b97ab7a..329ba2b56c 100644 --- a/Firmware/Marlin_main.cpp +++ b/Firmware/Marlin_main.cpp @@ -2192,16 +2192,29 @@ bool calibrate_z_auto() } #endif //TMC2130 +static void nozzle_crash_handler() { + // Exit whatever homing or endstop mode was enabled +#ifdef TMC2130 + FORCE_HIGH_POWER_END; + tmc2130_home_exit(); +#endif + enable_endstops(false); + enable_z_endstop(false); + // Fix the planner position to a known value + current_position[Z_AXIS] = 0; + plan_set_position_curposXYZE(); + // Raize Z to release pressure on bed after nozzle crash + current_position[Z_AXIS] += MESH_HOME_Z_SEARCH; + plan_buffer_line_curposXYZE(max_feedrate[Z_AXIS]); + st_synchronize(); +} + #ifdef TMC2130 void check_Z_crash(void) { if (!READ(Z_TMC2130_DIAG)) { //Z crash - FORCE_HIGH_POWER_END; - current_position[Z_AXIS] = 0; - plan_set_position_curposXYZE(); - current_position[Z_AXIS] += MESH_HOME_Z_SEARCH; - plan_buffer_line_curposXYZE(max_feedrate[Z_AXIS]); - st_synchronize(); + nozzle_crash_handler(); + // throw unrecoverable error kill(_T(MSG_BED_LEVELING_FAILED_POINT_LOW)); } } @@ -3281,6 +3294,7 @@ bool gcode_M45(bool onlyZ, int8_t verbosity_level) } else { + nozzle_crash_handler(); lcd_show_fullscreen_message_and_wait_P(PSTR("Calibration failed! Check the axes and run again.")); final_result = false; } diff --git a/Firmware/mesh_bed_calibration.cpp b/Firmware/mesh_bed_calibration.cpp index b1ded7247b..7652fcbc3b 100644 --- a/Firmware/mesh_bed_calibration.cpp +++ b/Firmware/mesh_bed_calibration.cpp @@ -947,6 +947,7 @@ bool find_bed_induction_sensor_point_z(float minimum_z, uint8_t n_iter, int #endif //SUPPORT_VERBOSITY ) { + bool result = false; bool high_deviation_occured = false; bedPWMDisabled = 1; #ifdef TMC2130 @@ -974,13 +975,13 @@ bool find_bed_induction_sensor_point_z(float minimum_z, uint8_t n_iter, int if (! endstop_z_hit_on_purpose()) { //printf_P(PSTR("endstop not hit 1, current_pos[Z]: %f \n"), current_position[Z_AXIS]); - goto error; + goto end; } #ifdef TMC2130 if (!READ(Z_TMC2130_DIAG)) { //printf_P(PSTR("crash detected 1, current_pos[Z]: %f \n"), current_position[Z_AXIS]); - goto error; //crash Z detected + goto end; //crash Z detected } #endif //TMC2130 for (uint8_t i = 0; i < n_iter; ++ i) @@ -1010,12 +1011,12 @@ bool find_bed_induction_sensor_point_z(float minimum_z, uint8_t n_iter, int if (!endstop_z_hit_on_purpose()) { //printf_P(PSTR("i = %d, endstop not hit 2, current_pos[Z]: %f \n"), i, current_position[Z_AXIS]); - goto error; + goto end; } #ifdef TMC2130 if (!READ(Z_TMC2130_DIAG)) { //printf_P(PSTR("crash detected 2, current_pos[Z]: %f \n"), current_position[Z_AXIS]); - goto error; //crash Z detected + goto end; //crash Z detected } #endif //TMC2130 // SERIAL_ECHOPGM("Bed find_bed_induction_sensor_point_z low, height: "); @@ -1035,7 +1036,7 @@ bool find_bed_induction_sensor_point_z(float minimum_z, uint8_t n_iter, int z = 0; } else { - goto error; + goto end; } } //printf_P(PSTR("PINDA triggered at %f\n"), current_position[Z_AXIS]); @@ -1044,7 +1045,8 @@ bool find_bed_induction_sensor_point_z(float minimum_z, uint8_t n_iter, int if (n_iter > 1) current_position[Z_AXIS] /= float(n_iter); - + result = true; //success +end: enable_endstops(endstops_enabled); enable_z_endstop(endstop_z_enabled); // SERIAL_ECHOLNPGM("find_bed_induction_sensor_point_z 3"); @@ -1052,17 +1054,7 @@ bool find_bed_induction_sensor_point_z(float minimum_z, uint8_t n_iter, int if (bHighPowerForced) FORCE_HIGH_POWER_END; #endif bedPWMDisabled = 0; - return true; - -error: -// SERIAL_ECHOLNPGM("find_bed_induction_sensor_point_z 4"); - enable_endstops(endstops_enabled); - enable_z_endstop(endstop_z_enabled); -#ifdef TMC2130 - if (bHighPowerForced) FORCE_HIGH_POWER_END; -#endif - bedPWMDisabled = 0; - return false; + return result; } #ifdef NEW_XYZCAL