Browse Source

Removed SG software homming
After Calibration Z enabled minstop (SG and PINDA)
TMC2130 code simplification

Robert Pelnar 6 years ago
parent
commit
c6e10fb903

+ 0 - 3
Firmware/Configuration_prusa.h

@@ -175,13 +175,10 @@ const bool Z_MIN_ENDSTOP_INVERTING = false; // set to true to invert the logic o
 #define TMC2130_TCOOLTHRS_E 500       // TCOOLTHRS - coolstep treshold
 
 #define TMC2130_SG_HOMING       1     // stallguard homing
-//#define TMC2130_SG_HOMING_SW_XY  1    // stallguard "software" homing for XY axes
-#define TMC2130_SG_HOMING_SW_Z  1     // stallguard "software" homing for Z axis
 #define TMC2130_SG_THRS_X       3     // stallguard sensitivity for X axis
 #define TMC2130_SG_THRS_Y       4     // stallguard sensitivity for Y axis
 #define TMC2130_SG_THRS_Z       3     // stallguard sensitivity for Z axis
 #define TMC2130_SG_THRS_E       3     // stallguard sensitivity for E axis
-#define TMC2130_SG_DELTA      128    // stallguard delta [usteps] (minimum usteps before stallguard readed - SW homing)
 
 //new settings is possible for vsense = 1, running current value > 31 set vsense to zero and shift both currents by 1 bit right (Z axis only)
 #define TMC2130_CURRENTS_H {13, 20, 20, 35}  // default holding currents for all axes

+ 94 - 67
Firmware/Marlin_main.cpp

@@ -1658,7 +1658,6 @@ bool calibrate_z_auto()
 	destination[Z_AXIS] += (1.1 * max_length(Z_AXIS) * axis_up_dir);
 	feedrate = homing_feedrate[Z_AXIS];
 	plan_buffer_line(destination[X_AXIS], destination[Y_AXIS], destination[Z_AXIS], destination[E_AXIS], feedrate/60, active_extruder);
-	tmc2130_home_restart(Z_AXIS);
 	st_synchronize();
 //	current_position[axis] = 0;
 //	plan_set_position(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS]);
@@ -1948,13 +1947,15 @@ void force_high_power_mode(bool start_high_power_section) {
 }
 #endif //TMC2130
 
-bool gcode_M45(bool onlyZ) {
+bool gcode_M45(bool onlyZ)
+{
 	bool final_result = false;
 	#ifdef TMC2130
 	FORCE_HIGH_POWER_START;
 	#endif // TMC2130
 	// Only Z calibration?
-	if (!onlyZ) {
+	if (!onlyZ)
+	{
 		setTargetBed(0);
 		setTargetHotend(0, 0);
 		setTargetHotend(0, 1);
@@ -1983,15 +1984,19 @@ bool gcode_M45(bool onlyZ) {
 
 	// Let the user move the Z axes up to the end stoppers.
 #ifdef TMC2130
-	if (calibrate_z_auto()) {
+	if (calibrate_z_auto())
+	{
 #else //TMC2130
-	if (lcd_calibrate_z_end_stop_manual(onlyZ)) {
+	if (lcd_calibrate_z_end_stop_manual(onlyZ))
+	{
 #endif //TMC2130
 		refresh_cmd_timeout();
-		//if (((degHotend(0) > MAX_HOTEND_TEMP_CALIBRATION) || (degBed() > MAX_BED_TEMP_CALIBRATION)) && (!onlyZ)) {
+		//if (((degHotend(0) > MAX_HOTEND_TEMP_CALIBRATION) || (degBed() > MAX_BED_TEMP_CALIBRATION)) && (!onlyZ))
+		//{
 		//	lcd_wait_for_cool_down();
 		//}
-		if(!onlyZ){
+		if(!onlyZ)
+		{
 			KEEPALIVE_STATE(PAUSED_FOR_USER);
 			bool result = lcd_show_fullscreen_message_yes_no_and_wait_P(MSG_STEEL_SHEET_CHECK, false, false);
 			if(result) lcd_show_fullscreen_message_and_wait_P(MSG_REMOVE_STEEL_SHEET);
@@ -2004,80 +2009,101 @@ bool gcode_M45(bool onlyZ) {
 		}
 		// Move the print head close to the bed.
 		current_position[Z_AXIS] = MESH_HOME_Z_SEARCH;
+
+		bool endstops_enabled  = enable_endstops(true);
+		tmc2130_home_enter(Z_AXIS_MASK);
 		plan_buffer_line(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS], homing_feedrate[Z_AXIS] / 40, active_extruder);
+
 		st_synchronize();
+		tmc2130_home_exit();
+		enable_endstops(endstops_enabled);
 
+		if (st_get_position_mm(Z_AXIS) == MESH_HOME_Z_SEARCH)
+		{
 
-		//#ifdef TMC2130
-		//		tmc2130_home_enter(X_AXIS_MASK | Y_AXIS_MASK);
-		//#endif
+			//#ifdef TMC2130
+			//		tmc2130_home_enter(X_AXIS_MASK | Y_AXIS_MASK);
+			//#endif
 
-		int8_t verbosity_level = 0;
-		if (code_seen('V')) {
-			// Just 'V' without a number counts as V1.
-			char c = strchr_pointer[1];
-			verbosity_level = (c == ' ' || c == '\t' || c == 0) ? 1 : code_value_short();
-		}
+			int8_t verbosity_level = 0;
+			if (code_seen('V'))
+			{
+				// Just 'V' without a number counts as V1.
+				char c = strchr_pointer[1];
+				verbosity_level = (c == ' ' || c == '\t' || c == 0) ? 1 : code_value_short();
+			}
 
-		if (onlyZ) {
-			clean_up_after_endstop_move();
-			// Z only calibration.
-			// Load the machine correction matrix
-			world2machine_initialize();
-			// and correct the current_position to match the transformed coordinate system.
-			world2machine_update_current();
-			//FIXME
-			bool result = sample_mesh_and_store_reference();
-			if (result) {
-				if (calibration_status() == CALIBRATION_STATUS_Z_CALIBRATION)
-					// Shipped, the nozzle height has been set already. The user can start printing now.
-					calibration_status_store(CALIBRATION_STATUS_CALIBRATED);
-					final_result = true;
-				// babystep_apply();
+			if (onlyZ)
+			{
+				clean_up_after_endstop_move();
+				// Z only calibration.
+				// Load the machine correction matrix
+				world2machine_initialize();
+				// and correct the current_position to match the transformed coordinate system.
+				world2machine_update_current();
+				//FIXME
+				bool result = sample_mesh_and_store_reference();
+				if (result)
+				{
+					if (calibration_status() == CALIBRATION_STATUS_Z_CALIBRATION)
+						// Shipped, the nozzle height has been set already. The user can start printing now.
+						calibration_status_store(CALIBRATION_STATUS_CALIBRATED);
+						final_result = true;
+					// babystep_apply();
+				}
 			}
-		}
-		else {
-			// Reset the baby step value and the baby step applied flag.
-			calibration_status_store(CALIBRATION_STATUS_ASSEMBLED);
-			eeprom_update_word((uint16_t*)EEPROM_BABYSTEP_Z, 0);
-			// Complete XYZ calibration.
-			uint8_t point_too_far_mask = 0;
-			BedSkewOffsetDetectionResultType result = find_bed_offset_and_skew(verbosity_level, point_too_far_mask);
-			clean_up_after_endstop_move();
-			// Print head up.
-			current_position[Z_AXIS] = MESH_HOME_Z_SEARCH;
-			plan_buffer_line(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS], homing_feedrate[Z_AXIS] / 40, active_extruder);
-			st_synchronize();
-			if (result >= 0) {
-				point_too_far_mask = 0;
-				// Second half: The fine adjustment.
-				// Let the planner use the uncorrected coordinates.
-				mbl.reset();
-				world2machine_reset();
-				// Home in the XY plane.
-				setup_for_endstop_move();
-				home_xy();
-				result = improve_bed_offset_and_skew(1, verbosity_level, point_too_far_mask);
+			else
+			{
+				// Reset the baby step value and the baby step applied flag.
+				calibration_status_store(CALIBRATION_STATUS_ASSEMBLED);
+				eeprom_update_word((uint16_t*)EEPROM_BABYSTEP_Z, 0);
+				// Complete XYZ calibration.
+				uint8_t point_too_far_mask = 0;
+				BedSkewOffsetDetectionResultType result = find_bed_offset_and_skew(verbosity_level, point_too_far_mask);
 				clean_up_after_endstop_move();
 				// Print head up.
 				current_position[Z_AXIS] = MESH_HOME_Z_SEARCH;
 				plan_buffer_line(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS], homing_feedrate[Z_AXIS] / 40, active_extruder);
 				st_synchronize();
-				// if (result >= 0) babystep_apply();
-			}
-			lcd_bed_calibration_show_result(result, point_too_far_mask);
-			if (result >= 0) {
-				// Calibration valid, the machine should be able to print. Advise the user to run the V2Calibration.gcode.
-				calibration_status_store(CALIBRATION_STATUS_LIVE_ADJUST);
-				if (eeprom_read_byte((uint8_t*)EEPROM_WIZARD_ACTIVE) != 1) lcd_show_fullscreen_message_and_wait_P(MSG_BABYSTEP_Z_NOT_SET);
-				final_result = true;
+				if (result >= 0)
+				{
+					point_too_far_mask = 0;
+					// Second half: The fine adjustment.
+					// Let the planner use the uncorrected coordinates.
+					mbl.reset();
+					world2machine_reset();
+					// Home in the XY plane.
+					setup_for_endstop_move();
+					home_xy();
+					result = improve_bed_offset_and_skew(1, verbosity_level, point_too_far_mask);
+					clean_up_after_endstop_move();
+					// Print head up.
+					current_position[Z_AXIS] = MESH_HOME_Z_SEARCH;
+					plan_buffer_line(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS], homing_feedrate[Z_AXIS] / 40, active_extruder);
+					st_synchronize();
+					// if (result >= 0) babystep_apply();
+				}
+				lcd_bed_calibration_show_result(result, point_too_far_mask);
+				if (result >= 0)
+				{
+					// Calibration valid, the machine should be able to print. Advise the user to run the V2Calibration.gcode.
+					calibration_status_store(CALIBRATION_STATUS_LIVE_ADJUST);
+					if (eeprom_read_byte((uint8_t*)EEPROM_WIZARD_ACTIVE) != 1) lcd_show_fullscreen_message_and_wait_P(MSG_BABYSTEP_Z_NOT_SET);
+					final_result = true;
+				}
 			}
-		}
 #ifdef TMC2130
-		tmc2130_home_exit();
+			tmc2130_home_exit();
 #endif
+		}
+		else
+		{
+			lcd_show_fullscreen_message_and_wait_P(PSTR("Calibration failed! Check the axes and run again."));
+			final_result = false;
+		}
 	}
-	else {
+	else
+	{
 		// Timeouted.
 	}
 	lcd_update_enable(true);
@@ -2085,9 +2111,10 @@ bool gcode_M45(bool onlyZ) {
 	FORCE_HIGH_POWER_END;
 #endif // TMC2130
 	return final_result;
-	}
+}
 
-void gcode_M701() {
+void gcode_M701()
+{
 #ifdef SNMM
 	extr_adj(snmm_extruder);//loads current extruder
 #else

+ 28 - 30
Firmware/stepper.cpp

@@ -466,12 +466,8 @@ void isr() {
           #if ( (defined(X_MIN_PIN) && (X_MIN_PIN > -1)) || defined(TMC2130_SG_HOMING) ) && !defined(DEBUG_DISABLE_XMINLIMIT)
             
             #ifdef TMC2130_SG_HOMING
-            // Stall guard homing turned on, now decide if software or hardware one
-                #ifndef TMC2130_SG_HOMING_SW_XY
-                x_min_endstop = (READ(X_TMC2130_DIAG) != X_MIN_ENDSTOP_INVERTING);
-                #else //TMC2130_SG_HOMING_SW_XY
-                x_min_endstop = tmc2130_axis_stalled[X_AXIS];
-                #endif //TMC2130_SG_HOMING_SW_XY
+            // Stall guard homing turned on
+                x_min_endstop = (READ(X_TMC2130_DIAG) != 0);
             #else
             // Normal homing
             x_min_endstop = (READ(X_MIN_PIN) != X_MIN_ENDSTOP_INVERTING);
@@ -493,12 +489,8 @@ void isr() {
           #if ( (defined(X_MAX_PIN) && (X_MAX_PIN > -1)) || defined(TMC2130_SG_HOMING) ) && !defined(DEBUG_DISABLE_XMAXLIMIT)
             
             #ifdef TMC2130_SG_HOMING
-            // Stall guard homing turned on, now decide if software or hardware one
-                #ifndef TMC2130_SG_HOMING_SW_XY
-                x_max_endstop = (READ(X_TMC2130_DIAG) != X_MAX_ENDSTOP_INVERTING);
-                #else //TMC2130_SG_HOMING_SW_XY
-                x_max_endstop = tmc2130_axis_stalled[X_AXIS];
-                #endif //TMC2130_SG_HOMING_SW_XY
+            // Stall guard homing turned on
+                x_max_endstop = (READ(X_TMC2130_DIAG) != 0);
             #else
             // Normal homing
             x_max_endstop = (READ(X_MAX_PIN) != X_MAX_ENDSTOP_INVERTING);
@@ -525,12 +517,8 @@ void isr() {
         #if ( (defined(Y_MIN_PIN) && (Y_MIN_PIN > -1)) || defined(TMC2130_SG_HOMING) ) && !defined(DEBUG_DISABLE_YMINLIMIT)
                   
         #ifdef TMC2130_SG_HOMING
-        // Stall guard homing turned on, now decide if software or hardware one
-            #ifndef TMC2130_SG_HOMING_SW_XY
-            y_min_endstop = (READ(Y_TMC2130_DIAG) != Y_MIN_ENDSTOP_INVERTING);
-            #else //TMC2130_SG_HOMING_SW_XY
-            y_min_endstop = tmc2130_axis_stalled[Y_AXIS];
-            #endif //TMC2130_SG_HOMING_SW_XY
+        // Stall guard homing turned on
+            y_min_endstop = (READ(Y_TMC2130_DIAG) != 0);
         #else
         // Normal homing
         y_min_endstop = (READ(Y_MIN_PIN) != Y_MIN_ENDSTOP_INVERTING);
@@ -550,12 +538,8 @@ void isr() {
         #if ( (defined(Y_MAX_PIN) && (Y_MAX_PIN > -1)) || defined(TMC2130_SG_HOMING) ) && !defined(DEBUG_DISABLE_YMAXLIMIT)
                   
         #ifdef TMC2130_SG_HOMING
-        // Stall guard homing turned on, now decide if software or hardware one
-            #ifndef TMC2130_SG_HOMING_SW_XY
-            y_max_endstop = (READ(Y_TMC2130_DIAG) != Y_MAX_ENDSTOP_INVERTING);
-            #else //TMC2130_SG_HOMING_SW_XY
-            y_max_endstop = tmc2130_axis_stalled[Y_AXIS];
-            #endif //TMC2130_SG_HOMING_SW_XY
+        // Stall guard homing turned on
+            y_max_endstop = (READ(Y_TMC2130_DIAG) != 0);
         #else
         // Normal homing
         y_max_endstop = (READ(Y_MAX_PIN) != Y_MAX_ENDSTOP_INVERTING);
@@ -581,7 +565,12 @@ void isr() {
       if(check_endstops && ! check_z_endstop)
       {
         #if defined(Z_MIN_PIN) && (Z_MIN_PIN > -1) && !defined(DEBUG_DISABLE_ZMINLIMIT)
-          z_min_endstop=(READ(Z_MIN_PIN) != Z_MIN_ENDSTOP_INVERTING);
+            #ifdef TMC2130_SG_HOMING
+            // Stall guard homing turned on
+                z_min_endstop = (READ(Z_MIN_PIN) != Z_MIN_ENDSTOP_INVERTING) || (READ(Z_TMC2130_DIAG) != 0);
+            #else
+				z_min_endstop = (READ(Z_MIN_PIN) != Z_MIN_ENDSTOP_INVERTING);
+            #endif //TMC2130_SG_HOMING
           if(z_min_endstop && old_z_min_endstop && (current_block->steps_z > 0)) {
             endstops_trigsteps[Z_AXIS] = count_position[Z_AXIS];
             endstop_z_hit=true;
@@ -602,11 +591,12 @@ void isr() {
       CHECK_ENDSTOPS
       {
         #if defined(Z_MAX_PIN) && (Z_MAX_PIN > -1) && !defined(DEBUG_DISABLE_ZMAXLIMIT)
-			#ifndef TMC2130_SG_HOMING_SW_Z
+            #ifdef TMC2130_SG_HOMING
+            // Stall guard homing turned on
+                z_max_endstop = (READ(Z_TMC2130_DIAG) != 0);
+            #else
 				z_max_endstop = (READ(Z_MAX_PIN) != Z_MAX_ENDSTOP_INVERTING);
-			#else //TMC2130_SG_HOMING_SW_Z
-				z_max_endstop = tmc2130_axis_stalled[Z_AXIS];
-			#endif //TMC2130_SG_HOMING_SW_Z
+            #endif //TMC2130_SG_HOMING
           if(z_max_endstop && old_z_max_endstop && (current_block->steps_z > 0)) {
             endstops_trigsteps[Z_AXIS] = count_position[Z_AXIS];
             endstop_z_hit=true;
@@ -622,7 +612,12 @@ void isr() {
     if(check_z_endstop) {
         // Check the Z min end-stop no matter what.
         // Good for searching for the center of an induction target.
-        z_min_endstop=(READ(Z_MIN_PIN) != Z_MIN_ENDSTOP_INVERTING);
+            #ifdef TMC2130_SG_HOMING
+            // Stall guard homing turned on
+                z_min_endstop = (READ(Z_MIN_PIN) != Z_MIN_ENDSTOP_INVERTING) || (READ(Z_TMC2130_DIAG) != 0);
+            #else
+				z_min_endstop = (READ(Z_MIN_PIN) != Z_MIN_ENDSTOP_INVERTING);
+            #endif //TMC2130_SG_HOMING
         if(z_min_endstop && old_z_min_endstop) {
           endstops_trigsteps[Z_AXIS] = count_position[Z_AXIS];
           endstop_z_hit=true;
@@ -1009,6 +1004,9 @@ void st_init()
     
     SET_INPUT(Z_TMC2130_DIAG);
     WRITE(Z_TMC2130_DIAG,HIGH);
+
+	SET_INPUT(E0_TMC2130_DIAG);
+    WRITE(E0_TMC2130_DIAG,HIGH);
     
   #endif
     

+ 22 - 160
Firmware/tmc2130.cpp

@@ -22,16 +22,12 @@ extern void crashdet_stop_and_save_print2();
 
 //chipselect pins
 uint8_t tmc2130_cs[4] = { X_TMC2130_CS, Y_TMC2130_CS, Z_TMC2130_CS, E0_TMC2130_CS };
-//diag pins
-uint8_t tmc2130_diag[4] = { X_TMC2130_DIAG, Y_TMC2130_DIAG, Z_TMC2130_DIAG, E0_TMC2130_DIAG };
 //mode
 uint8_t tmc2130_mode = TMC2130_MODE_NORMAL;
 //holding currents
 uint8_t tmc2130_current_h[4] = TMC2130_CURRENTS_H;
 //running currents
 uint8_t tmc2130_current_r[4] = TMC2130_CURRENTS_R;
-//axis stalled flags
-uint8_t tmc2130_axis_stalled[4] = {0, 0, 0, 0};
 
 //running currents for homing
 uint8_t tmc2130_current_r_home[4] = {10, 10, 20, 10};
@@ -52,7 +48,6 @@ uint8_t tmc2130_mres[4] = {0, 0, 0, 0}; //will be filed at begin of init
 uint8_t tmc2130_sg_thr[4] = {TMC2130_SG_THRS_X, TMC2130_SG_THRS_Y, TMC2130_SG_THRS_Z, TMC2130_SG_THRS_E};
 uint8_t tmc2130_sg_thr_home[4] = {3, 3, TMC2130_SG_THRS_Z, TMC2130_SG_THRS_E};
 
-uint32_t tmc2130_sg_pos[4] = {0, 0, 0, 0};
 
 uint8_t sg_homing_axes_mask = 0x00;
 
@@ -62,8 +57,8 @@ uint32_t tmc2130_sg_meassure_val = 0;
 
 
 bool tmc2130_sg_stop_on_crash = true;
+uint8_t tmc2130_sg_diag_mask = 0x00;
 bool tmc2130_sg_crash = false;
-uint8_t tmc2130_diag_mask = 0x00;
 uint16_t tmc2130_sg_err[4] = {0, 0, 0, 0};
 uint16_t tmc2130_sg_cnt[4] = {0, 0, 0, 0};
 bool tmc2130_sg_change = false;
@@ -71,6 +66,10 @@ bool tmc2130_sg_change = false;
 
 bool skip_debug_msg = false;
 
+#define DBG(args...) printf_P(args)
+#define _n PSTR
+#define _i PSTR
+
 //TMC2130 registers
 #define TMC2130_REG_GCONF      0x00 // 17 bits
 #define TMC2130_REG_GSTAT      0x01 // 3 bits
@@ -128,12 +127,11 @@ void tmc2130_setup_chopper(uint8_t axis, uint8_t mres, uint8_t current_h, uint8_
 
 void tmc2130_init()
 {
+	DBG(_n("tmc2130_init(), mode=%S\n"), tmc2130_mode?_n("NORMAL"):_n("STEALTH"));
 	tmc2130_mres[0] = tmc2130_calc_mres(TMC2130_USTEPS_XY);
 	tmc2130_mres[1] = tmc2130_calc_mres(TMC2130_USTEPS_XY);
 	tmc2130_mres[2] = tmc2130_calc_mres(TMC2130_USTEPS_Z);
 	tmc2130_mres[3] = tmc2130_calc_mres(TMC2130_USTEPS_E);
-	MYSERIAL.print("tmc2130_init mode=");
-	MYSERIAL.println(tmc2130_mode, DEC);
 	WRITE(X_TMC2130_CS, HIGH);
 	WRITE(Y_TMC2130_CS, HIGH);
 	WRITE(Z_TMC2130_CS, HIGH);
@@ -189,6 +187,7 @@ void tmc2130_init()
 
 		tmc2130_wr(tmc2130_cs[axis], TMC2130_REG_TPOWERDOWN, 0x00000000);
 		tmc2130_wr(tmc2130_cs[axis], TMC2130_REG_GCONF, TMC2130_GCONF_SGSENS);
+
 	}
 	for (int axis = 3; axis < 4; axis++) // E axis
 	{
@@ -228,7 +227,7 @@ void tmc2130_st_isr(uint8_t last_step_mask)
 	bool crash = false;
 	uint8_t diag_mask = tmc2130_sample_diag();
 //	for (uint8_t axis = X_AXIS; axis <= E_AXIS; axis++)
-	for (uint8_t axis = X_AXIS; axis <= Y_AXIS; axis++)
+	for (uint8_t axis = X_AXIS; axis <= Z_AXIS; axis++)
 	{
 		uint8_t mask = (X_AXIS_MASK << axis);
 		if (diag_mask & mask) tmc2130_sg_err[axis]++;
@@ -244,10 +243,7 @@ void tmc2130_st_isr(uint8_t last_step_mask)
 				crash = true;
 			}
 		}
-//		if ((diag_mask & mask)/* && !(tmc2130_diag_mask & mask)*/)
-//			crash = true;
 	}
-	tmc2130_diag_mask = diag_mask;
 	if (sg_homing_axes_mask == 0)
 	{
 /*		if (crash)
@@ -266,96 +262,24 @@ void tmc2130_st_isr(uint8_t last_step_mask)
 	}
 }
 
-void tmc2130_update_sg_axis(uint8_t axis)
-{
-	if (!tmc2130_axis_stalled[axis])
-	{
-		uint8_t cs = tmc2130_cs[axis];
-		uint16_t tstep = tmc2130_rd_TSTEP(cs);
-		if (tstep < TMC2130_TCOOLTHRS_Z)
-		{
-			long pos = st_get_position(axis);
-			if (abs(pos - tmc2130_sg_pos[axis]) > TMC2130_SG_DELTA)
-			{
-				uint16_t sg = tmc2130_rd_DRV_STATUS(cs) & 0x3ff;
-				if (sg == 0)
-					tmc2130_axis_stalled[axis] = true;
-			}
-		}
-	}
-}
 
 bool tmc2130_update_sg()
 {
-//	uint16_t tstep = tmc2130_rd_TSTEP(tmc2130_cs[0]);
-//	MYSERIAL.print("TSTEP_X=");
-//	MYSERIAL.println((int)tstep);
 	if (tmc2130_sg_meassure <= E_AXIS)
 	{
 		uint8_t cs = tmc2130_cs[tmc2130_sg_meassure];
 		uint16_t sg = tmc2130_rd_DRV_STATUS(cs) & 0x3ff;
 		tmc2130_sg_meassure_val += sg;
 		tmc2130_sg_meassure_cnt++;
-
 //		printf_P(PSTR("tmc2130_update_sg - meassure - sg=%d\n"), sg);
 		return true;
 	}
-#ifdef TMC2130_SG_HOMING_SW_XY
-	if (sg_homing_axes_mask & X_AXIS_MASK) tmc2130_update_sg_axis(X_AXIS);
-	if (sg_homing_axes_mask & Y_AXIS_MASK) tmc2130_update_sg_axis(Y_AXIS);
-#endif //TMC2130_SG_HOMING_SW_XY
-#ifdef TMC2130_SG_HOMING_SW_Z
-	if (sg_homing_axes_mask & Z_AXIS_MASK) tmc2130_update_sg_axis(Z_AXIS);
-#endif //TMC2130_SG_HOMING_SW_Z
-#if (defined(TMC2130_SG_HOMING) && defined(TMC2130_SG_HOMING_SW_XY))
-	if (sg_homing_axes_mask == 0) return false;
-#ifdef TMC2130_DEBUG
-	MYSERIAL.print("tmc2130_update_sg mask=0x");
-	MYSERIAL.print((int)sg_homing_axes_mask, 16);
-	MYSERIAL.print(" stalledX=");
-	MYSERIAL.print((int)tmc2130_axis_stalled[0]);
-	MYSERIAL.print(" stalledY=");
-	MYSERIAL.println((int)tmc2130_axis_stalled[1]);
-#endif //TMC2130_DEBUG
-	for (uint8_t axis = X_AXIS; axis <= Y_AXIS; axis++) //only X and Y axes
-	{
-		uint8_t mask = (X_AXIS_MASK << axis);
-		if (sg_homing_axes_mask & mask)
-		{
-			if (!tmc2130_axis_stalled[axis])
-			{
-				uint8_t cs = tmc2130_cs[axis];
-				uint16_t tstep = tmc2130_rd_TSTEP(cs);
-				if (tstep < TMC2130_TCOOLTHRS)
-				{
-					long pos = st_get_position(axis);
-					if (abs(pos - tmc2130_sg_pos[axis]) > TMC2130_SG_DELTA)
-					{
-						uint16_t sg = tmc2130_rd_DRV_STATUS(cs) & 0x3ff;
-						if (sg == 0)
-						{
-							tmc2130_axis_stalled[axis] = true;
-#ifdef TMC2130_DEBUG
-	MYSERIAL.print("tmc2130_update_sg AXIS STALLED ");
-	MYSERIAL.println((int)axis);
-#endif //TMC2130_DEBUG
-						}
-					}
-				}
-			}
-		}
-	}
-	return true;
-#endif
 	return false;
 }
 
 void tmc2130_home_enter(uint8_t axes_mask)
 {
-#ifdef TMC2130_DEBUG
-	MYSERIAL.print("tmc2130_home_enter mask=0x");
-	MYSERIAL.println((int)axes_mask, 16);
-#endif //TMC2130_DEBUG
+//	printf_P(PSTR("tmc2130_home_enter(axes_mask=0x%02x)\n"), axes_mask);
 #ifdef TMC2130_SG_HOMING
 	for (uint8_t axis = X_AXIS; axis <= Z_AXIS; axis++) //X Y and Z axes
 	{
@@ -364,18 +288,14 @@ void tmc2130_home_enter(uint8_t axes_mask)
 		if (axes_mask & mask)
 		{
 			sg_homing_axes_mask |= mask;
-			tmc2130_sg_pos[axis] = st_get_position(axis);
-			tmc2130_axis_stalled[axis] = false;
 			//Configuration to spreadCycle
 			tmc2130_wr(cs, TMC2130_REG_GCONF, TMC2130_GCONF_NORMAL);
 			tmc2130_wr(cs, TMC2130_REG_COOLCONF, (((uint32_t)tmc2130_sg_thr_home[axis]) << 16));
 //			tmc2130_wr(cs, TMC2130_REG_COOLCONF, (((uint32_t)tmc2130_sg_thr[axis]) << 16) | ((uint32_t)1 << 24));
 			tmc2130_wr(cs, TMC2130_REG_TCOOLTHRS, (axis==X_AXIS)?TMC2130_TCOOLTHRS_X:TMC2130_TCOOLTHRS_Y);
 			tmc2130_setup_chopper(axis, tmc2130_mres[axis], tmc2130_current_h[axis], tmc2130_current_r_home[axis]);
-#ifndef TMC2130_SG_HOMING_SW_XY
-			if (mask & (X_AXIS_MASK | Y_AXIS_MASK))
+			if (mask & (X_AXIS_MASK | Y_AXIS_MASK | Z_AXIS_MASK))
 				tmc2130_wr(cs, TMC2130_REG_GCONF, TMC2130_GCONF_SGSENS); //stallguard output DIAG1, DIAG1 = pushpull
-#endif //TMC2130_SG_HOMING_SW_XY
 		}
 	}
 #endif //TMC2130_SG_HOMING
@@ -383,10 +303,7 @@ void tmc2130_home_enter(uint8_t axes_mask)
 
 void tmc2130_home_exit()
 {
-#ifdef TMC2130_DEBUG
-	MYSERIAL.print("tmc2130_home_exit mask=0x");
-	MYSERIAL.println((int)sg_homing_axes_mask, 16);
-#endif //TMC2130_DEBUG
+//	printf_P(PSTR("tmc2130_home_exit sg_homing_axes_mask=0x%02x\n"), sg_homing_axes_mask);
 #ifdef TMC2130_SG_HOMING
 	if (sg_homing_axes_mask)
 	{
@@ -403,47 +320,21 @@ void tmc2130_home_exit()
 				}
 				else
 				{
-#ifdef TMC2130_SG_HOMING_SW_XY
-					tmc2130_wr(tmc2130_cs[axis], TMC2130_REG_GCONF, TMC2130_GCONF_NORMAL);
-#else //TMC2130_SG_HOMING_SW_XY
 //					tmc2130_wr(tmc2130_cs[axis], TMC2130_REG_GCONF, TMC2130_GCONF_NORMAL);
 					tmc2130_setup_chopper(axis, tmc2130_mres[axis], tmc2130_current_h[axis], tmc2130_current_r[axis]);
 //					tmc2130_wr(tmc2130_cs[axis], TMC2130_REG_COOLCONF, (((uint32_t)tmc2130_sg_thr[axis]) << 16) | ((uint32_t)1 << 24));
 					tmc2130_wr(tmc2130_cs[axis], TMC2130_REG_COOLCONF, (((uint32_t)tmc2130_sg_thr[axis]) << 16));
 					tmc2130_wr(tmc2130_cs[axis], TMC2130_REG_TCOOLTHRS, (tmc2130_mode == TMC2130_MODE_SILENT)?0:((axis==X_AXIS)?TMC2130_TCOOLTHRS_X:TMC2130_TCOOLTHRS_Y));
 					tmc2130_wr(tmc2130_cs[axis], TMC2130_REG_GCONF, TMC2130_GCONF_SGSENS);
-#endif //TMC2130_SG_HOMING_SW_XY
 				}
 			}
-			tmc2130_axis_stalled[axis] = false;
 		}
 		sg_homing_axes_mask = 0x00;
 	}
+	tmc2130_sg_crash = false;
 #endif
 }
 
-void tmc2130_home_pause(uint8_t axis)
-{
-	if (tmc2130_mode == TMC2130_MODE_NORMAL)
-	{
-		tmc2130_wr(tmc2130_cs[axis], TMC2130_REG_GCONF, TMC2130_GCONF_NORMAL);
-	}
-}
-
-void tmc2130_home_resume(uint8_t axis)
-{
-	if (tmc2130_mode == TMC2130_MODE_NORMAL)
-	{
-		tmc2130_wr(tmc2130_cs[axis], TMC2130_REG_GCONF, TMC2130_GCONF_SGSENS);
-	}
-}
-
-void tmc2130_home_restart(uint8_t axis)
-{
-	tmc2130_sg_pos[axis] = st_get_position(axis);
-	tmc2130_axis_stalled[axis] = false;
-}
-
 void tmc2130_sg_meassure_start(uint8_t axis)
 {
 	tmc2130_sg_meassure = axis;
@@ -460,7 +351,7 @@ uint16_t tmc2130_sg_meassure_stop()
 
 bool tmc2130_wait_standstill_xy(int timeout)
 {
-//	MYSERIAL.println("tmc2130_wait_standstill_xy");
+	DBG(_n("tmc2130_wait_standstill_xy(timeout=%d)\n"), timeout);
 	bool standstill = false;
 	while (!standstill && (timeout > 0))
 	{
@@ -468,12 +359,7 @@ bool tmc2130_wait_standstill_xy(int timeout)
 		uint32_t drv_status_y = 0;
 		tmc2130_rd(tmc2130_cs[X_AXIS], TMC2130_REG_DRV_STATUS, &drv_status_x);
 		tmc2130_rd(tmc2130_cs[Y_AXIS], TMC2130_REG_DRV_STATUS, &drv_status_y);
-/*		MYSERIAL.print(timeout, 10);
-		MYSERIAL.println(' ');
-		MYSERIAL.print(drv_status_x, 16);
-		MYSERIAL.println(' ');
-		MYSERIAL.print(drv_status_y, 16);
-		MYSERIAL.println('#');*/
+		DBG(_n("\tdrv_status_x=0x%08x drv_status_x=0x%08x\n"), drv_status_x, drv_status_y);
 		standstill = (drv_status_x & 0x80000000) && (drv_status_y & 0x80000000);
 		tmc2130_check_overtemp();
 		timeout--;
@@ -488,16 +374,11 @@ void tmc2130_check_overtemp()
 	static uint32_t checktime = 0;
 	if (millis() - checktime > 1000 )
 	{
-//		MYSERIAL.print("DRV_STATUS ");
 		for (int i = 0; i < 4; i++)
 		{
 			uint32_t drv_status = 0;
 			skip_debug_msg = true;
 			tmc2130_rd(tmc2130_cs[i], TMC2130_REG_DRV_STATUS, &drv_status);
-/*			MYSERIAL.print(i, DEC);
-			MYSERIAL.print(' ');
-			MYSERIAL.print(drv_status, 16);*/
-
 			if (drv_status & ((uint32_t)1 << 26))
 			{ // BIT 26 - over temp prewarning ~120C (+-20C)
 				SERIAL_ERRORRPGM(TMC_OVERTEMP_MSG);
@@ -508,7 +389,6 @@ void tmc2130_check_overtemp()
 			}
 
 		}
-//		MYSERIAL.println('#');
 		checktime = millis();
 		tmc2130_sg_change = true;
 	}
@@ -544,44 +424,26 @@ void tmc2130_setup_chopper(uint8_t axis, uint8_t mres, uint8_t current_h, uint8_
 
 void tmc2130_set_current_h(uint8_t axis, uint8_t current)
 {
-	MYSERIAL.print("tmc2130_set_current_h ");
-	MYSERIAL.print((int)axis);
-	MYSERIAL.print(" ");
-	MYSERIAL.println((int)current);
+	DBG(_n("tmc2130_set_current_h(axis=%d, current=%d\n"), axis, current);
 	tmc2130_current_h[axis] = current;
 	tmc2130_setup_chopper(axis, tmc2130_mres[axis], tmc2130_current_h[axis], tmc2130_current_r[axis]);
 }
 
 void tmc2130_set_current_r(uint8_t axis, uint8_t current)
 {
-	MYSERIAL.print("tmc2130_set_current_r ");
-	MYSERIAL.print((int)axis);
-	MYSERIAL.print(" ");
-	MYSERIAL.println((int)current);
+	DBG(_n("tmc2130_set_current_r(axis=%d, current=%d\n"), axis, current);
 	tmc2130_current_r[axis] = current;
 	tmc2130_setup_chopper(axis, tmc2130_mres[axis], tmc2130_current_h[axis], tmc2130_current_r[axis]);
 }
 
 void tmc2130_print_currents()
 {
-	MYSERIAL.println("tmc2130_print_currents");
-	MYSERIAL.println("\tH\rR");
-	MYSERIAL.print("X\t");
-	MYSERIAL.print((int)tmc2130_current_h[0]);
-	MYSERIAL.print("\t");
-	MYSERIAL.println((int)tmc2130_current_r[0]);
-	MYSERIAL.print("Y\t");
-	MYSERIAL.print((int)tmc2130_current_h[1]);
-	MYSERIAL.print("\t");
-	MYSERIAL.println((int)tmc2130_current_r[1]);
-	MYSERIAL.print("Z\t");
-	MYSERIAL.print((int)tmc2130_current_h[2]);
-	MYSERIAL.print("\t");
-	MYSERIAL.println((int)tmc2130_current_r[2]);
-	MYSERIAL.print("E\t");
-	MYSERIAL.print((int)tmc2130_current_h[3]);
-	MYSERIAL.print("\t");
-	MYSERIAL.println((int)tmc2130_current_r[3]);
+	DBG(_n("tmc2130_print_currents()\n\tH\tR\nX\t%d\t%d\nY\t%d\t%d\nZ\t%d\t%d\nE\t%d\t%d\n"),
+		tmc2130_current_h[0], tmc2130_current_r[0],
+		tmc2130_current_h[1], tmc2130_current_r[1],
+		tmc2130_current_h[2], tmc2130_current_r[2],
+		tmc2130_current_h[3], tmc2130_current_r[3]
+	);
 }
 
 void tmc2130_set_pwm_ampl(uint8_t axis, uint8_t pwm_ampl)

+ 0 - 5
Firmware/tmc2130.h

@@ -9,7 +9,6 @@ extern uint8_t tmc2130_mode;
 extern uint8_t tmc2130_current_h[4];
 extern uint8_t tmc2130_current_r[4];
 //flags for axis stall detection
-extern uint8_t tmc2130_axis_stalled[4];
 
 extern uint8_t tmc2130_sg_thr[4];
 
@@ -35,8 +34,6 @@ extern void tmc2130_check_overtemp();
 extern void tmc2130_home_enter(uint8_t axes_mask);
 //exit homing (called from homeaxis after homing ends)
 extern void tmc2130_home_exit();
-//restart homing (called from homeaxis befor move)
-extern void tmc2130_home_restart(uint8_t axis);
 
 //start stallguard meassuring for single axis
 extern void tmc2130_sg_meassure_start(uint8_t axis);
@@ -59,8 +56,6 @@ extern void tmc2130_set_pwm_grad(uint8_t axis, uint8_t pwm_ampl);
 
 extern uint16_t tmc2130_rd_MSCNT(uint8_t cs);
 
-extern void tmc2130_home_pause(uint8_t axis);
-extern void tmc2130_home_resume(uint8_t axis);
 extern bool tmc2130_wait_standstill_xy(int timeout);
 
 extern void tmc2130_eeprom_load_config();

+ 0 - 1
Firmware/variants/1_75mm_MK3-EINY03-E3Dv6full.h

@@ -140,7 +140,6 @@ const bool Z_MIN_ENDSTOP_INVERTING = false; // set to true to invert the logic o
 #define TMC2130_TCOOLTHRS 239       // TCOOLTHRS - coolstep treshold
 
 #define TMC2130_SG_HOMING       1     // stallguard homing
-//#define TMC2130_SG_HOMING_SW_XY  1    // stallguard "software" homing for XY axes
 #define TMC2130_SG_HOMING_SW_Z  1     // stallguard "software" homing for Z axis
 #define TMC2130_SG_THRS_X       0     // stallguard sensitivity for X axis
 #define TMC2130_SG_THRS_Y       0     // stallguard sensitivity for Y axis

+ 0 - 1
Firmware/variants/1_75mm_MK3-EINY04-E3Dv6full.h

@@ -140,7 +140,6 @@ const bool Z_MIN_ENDSTOP_INVERTING = false; // set to true to invert the logic o
 #define TMC2130_TCOOLTHRS 500       // TCOOLTHRS - coolstep treshold
 
 #define TMC2130_SG_HOMING       1     // stallguard homing
-//#define TMC2130_SG_HOMING_SW_XY  1    // stallguard "software" homing for XY axes
 #define TMC2130_SG_HOMING_SW_Z  1     // stallguard "software" homing for Z axis
 #define TMC2130_SG_THRS_X       6     // stallguard sensitivity for X axis
 #define TMC2130_SG_THRS_Y       6     // stallguard sensitivity for Y axis