Useful or not, from you.
Marlin [BUG] Z homing with BLTouch and Z-endstop switch

I know this is the same title as #12726, however I rather started a new issue for clarity as I made quite a few tests. It is also hard to decide if this is a [BUG] or [FR] for Marlin, however it is certainly [BUG] for me.

I have Ender 3 with SKR Mini E3 v1.2 board, which has separate connectors for Z-endstop switch and BLTouch probe. For the whole day I am trying to configure Marlin bugfix-2.0.x to achieve seemingly very simple things:

  • Always monitor endstop switches when moving. This is a no-brainer for every CNC owner which finds it logical for Endstop and E-Stop switches being de-facto limits which unconditionaly stop any CNC movement (unless disabled with M121). However, this is not so straightforward to achieve with Marlin - there is ENDSTOPS_ALWAYS_ON_DEFAULT in Configuration_adv.h, however look at the following line.
  • By always I also mean when homing. This gramatically and logically indeed falls under previous line, but look at Option 7.
  • If BLTouch is present and enabled, use it for homing.

That's it. Below is the description of all combinations of configurations, tested on the Ender 3 using SKR Mini E3 v1.2 with Z-endstop switch connected to the Z-STOP connector (PC2) and BLTouch connected to the SERVOS and PROBE connector (PC14).

Setup

Thanks to #7470, #define ENDSTOPS_ALWAYS_ON_DEFAULT is always uncommented (enabled). In every step/combination, all other relevant configuration defines are shown for clarity. All 4 files are also in the attached Base config (Z-endstop only, no BLTouch, homing at X=0, Y=0).zip file, the configuration in them matches the config in Option 1.

Steps to Reproduce

Option 1

/* pins_BTT_SKR_MINI_E3_V1_2.h */
#define Z_STOP_PIN         PC2
#define Z_MIN_PROBE_PIN    PC14
/* Configuration.h */
//#define BLTOUCH
//#define Z_SAFE_HOMING
//#define Z_MIN_PROBE_USES_Z_MIN_ENDSTOP_PIN
/* Conditionals_LCD.h */
  #define HAS_CUSTOM_PROBE_PIN  DISABLED(Z_MIN_PROBE_USES_Z_MIN_ENDSTOP_PIN)
  #define HOMING_Z_WITH_PROBE   (Z_HOME_DIR < 0 && !HAS_CUSTOM_PROBE_PIN)

Default configuration, using only Z-endstop switch as Z-endstop. Printer homes X and Y, then Z at the same spot (X = 0, Y = 0).

  1. :heavy_check_mark: Z-endstop switch is monitored while homing Z.
  2. :heavy_check_mark: BLTouch is ignored (not deployed nor monitored) while homing Z.
  3. :heavy_check_mark: No BLTouch LCD menu.
  4. :heavy_check_mark: Z-endstop switch is monitored when moving Z axis down via LCD menu or G0.

From this point onwards, the following is also uncommented:

// Configuration.h
#define ENDSTOPPULLUP_ZMIN_PROBE
// Configuration_adv.h
#define BABYSTEP_ZPROBE_OFFSET          // Combine M851 Z and Babystepping
#define BABYSTEP_ZPROBE_GFX_OVERLAY   // Enable graphical overlay on Z-offset editor

In every of the following options, after homing X and Y, printer goes to the center of the bed and performs Z-homing (Z_SAFE_HOMING) :heavy_check_mark:.

Option 2

/* pins_BTT_SKR_MINI_E3_V1_2.h */
#define Z_STOP_PIN         PC2
#define Z_MIN_PROBE_PIN    PC14
/* Configuration.h */
#define BLTOUCH
#define Z_SAFE_HOMING
//#define Z_MIN_PROBE_USES_Z_MIN_ENDSTOP_PIN
/* Conditionals_LCD.h */
  #define HAS_CUSTOM_PROBE_PIN  DISABLED(Z_MIN_PROBE_USES_Z_MIN_ENDSTOP_PIN)
  #define HOMING_Z_WITH_PROBE   (Z_HOME_DIR < 0 && !HAS_CUSTOM_PROBE_PIN)
  1. :heavy_check_mark: Z-endstop switch is monitored while homing Z.
  2. :heavy_multiplication_x: BLTouch is not deployed nor monitored. This could be intentional as indeed the BLTouch is attached, but we didn't explicitly specify that it must be used as a Z probe. But what else to uncomment, then? :interrobang:
  3. :heavy_check_mark: BLTouch LCD menu is present, Stow and Deploy are working properly.
  4. :heavy_check_mark: Z-endstop switch is monitored when moving Z axis down via LCD menu or G0.

Option 3

/* pins_BTT_SKR_MINI_E3_V1_2.h */
#define Z_STOP_PIN         PC2
#define Z_MIN_PROBE_PIN    PC14
/* Configuration.h */
#define BLTOUCH
#define Z_SAFE_HOMING
#define Z_MIN_PROBE_USES_Z_MIN_ENDSTOP_PIN
/* Conditionals_LCD.h */
  #define HAS_CUSTOM_PROBE_PIN  DISABLED(Z_MIN_PROBE_USES_Z_MIN_ENDSTOP_PIN)
  #define HOMING_Z_WITH_PROBE   (Z_HOME_DIR < 0 && !HAS_CUSTOM_PROBE_PIN)
  1. :heavy_check_mark: Z-endstop switch is monitored while homing Z.
  2. :heavy_check_mark: BLTouch is deployed while homing Z.
  3. :heavy_check_mark: BLTouch is not monitored while homing Z. This is indeed :heavy_exclamation_mark:, however with Z_MIN_PROBE_USES_Z_MIN_ENDSTOP_PIN we specified that the BLTouch is connected to the Z-endstop switch pin, therefore it is :heavy_check_mark: that Marlin only monitors Z-endstop switch because it thinks it is actually the BLTouch.
  4. :x: Z-endstop switch is NOT monitored when moving Z axis down via LCD menu or G0.

Option 4

/* pins_BTT_SKR_MINI_E3_V1_2.h */
#define Z_STOP_PIN         PC14 // PC2
//#define Z_MIN_PROBE_PIN    PC14
/* Configuration.h */
#define BLTOUCH
#define Z_SAFE_HOMING
#define Z_MIN_PROBE_USES_Z_MIN_ENDSTOP_PIN
/* Conditionals_LCD.h */
  #define HAS_CUSTOM_PROBE_PIN  DISABLED(Z_MIN_PROBE_USES_Z_MIN_ENDSTOP_PIN)
  #define HOMING_Z_WITH_PROBE   (Z_HOME_DIR < 0 && !HAS_CUSTOM_PROBE_PIN)
  1. :heavy_check_mark: Z-endstop switch is NOT monitored while homing Z. This is indeed :heavy_exclamation_mark:, however from the FW standpoint the Z-endstop switch hardware connection does not even exist.
  2. :heavy_check_mark: BLTouch is deployed while homing Z.
  3. :heavy_check_mark: BLTouch is monitored while homing Z.
  4. :heavy_check_mark: Z-endstop switch is NOT monitored when moving Z axis down via LCD menu or G0. This is indeed :x: from a mechanical standpoint, however as said in point 1, the Z-endpoint switch does not even exist from the FW standpoint.

:x: overall despite all :heavy_check_mark:, because we lost the Z-endstop switch.

Option 5

/* pins_BTT_SKR_MINI_E3_V1_2.h */
#define Z_STOP_PIN         PC2
#define Z_MIN_PROBE_PIN    PC14
/* Configuration.h */
#define BLTOUCH
#define Z_SAFE_HOMING
#define Z_MIN_PROBE_USES_Z_MIN_ENDSTOP_PIN
/* Conditionals_LCD.h */
  #define HAS_CUSTOM_PROBE_PIN  true // DISABLED(Z_MIN_PROBE_USES_Z_MIN_ENDSTOP_PIN)
  #define HOMING_Z_WITH_PROBE   (Z_HOME_DIR < 0 && !HAS_CUSTOM_PROBE_PIN)

This was accidentally tested as I forgot to comment #define Z_MIN_PROBE_USES_Z_MIN_ENDSTOP_PIN.

  1. :x: Z-endstop switch is NOT monitored while homing Z.
  2. :x: BLTouch is NOT deployed while homing Z.
  3. :heavy_check_mark: BLTouch is not monitored while homing Z. This is not :x: because of the reason described in Option 3 point 3.
  4. :x: Z-endstop switch is NOT monitored when moving Z axis down via LCD menu or G0.

Effectively printer is unstoppable when homing Z and will smash to the bed.

Option 6

/* pins_BTT_SKR_MINI_E3_V1_2.h */
#define Z_STOP_PIN         PC2
#define Z_MIN_PROBE_PIN    PC14
/* Configuration.h */
#define BLTOUCH
#define Z_SAFE_HOMING
//#define Z_MIN_PROBE_USES_Z_MIN_ENDSTOP_PIN
/* Conditionals_LCD.h */
  #define HAS_CUSTOM_PROBE_PIN  true // DISABLED(Z_MIN_PROBE_USES_Z_MIN_ENDSTOP_PIN)
  #define HOMING_Z_WITH_PROBE   (Z_HOME_DIR < 0 && !HAS_CUSTOM_PROBE_PIN)
  1. :heavy_check_mark: Z-endstop switch is monitored while homing Z.
  2. :x: BLTouch is NOT deployed while homing Z.
  3. :x: BLTouch is NOT monitored while homing Z.
  4. :heavy_check_mark: Z-endstop switch is monitored when moving Z axis down via LCD menu or G0.

Option 7

/* pins_BTT_SKR_MINI_E3_V1_2.h */
#define Z_STOP_PIN         PC2
#define Z_MIN_PROBE_PIN    PC14
/* Configuration.h */
#define BLTOUCH
#define Z_SAFE_HOMING
//#define Z_MIN_PROBE_USES_Z_MIN_ENDSTOP_PIN
/* Conditionals_LCD.h */
  #define HAS_CUSTOM_PROBE_PIN  true // DISABLED(Z_MIN_PROBE_USES_Z_MIN_ENDSTOP_PIN)
  #define HOMING_Z_WITH_PROBE   (Z_HOME_DIR < 0)
  1. :x: Z-endstop switch is NOT monitored while homing Z.
  2. :heavy_check_mark: BLTouch is deployed while homing Z.
  3. :heavy_check_mark: BLTouch is monitored while homing Z.
  4. :heavy_check_mark: Z-endstop switch is monitored when moving Z axis down via LCD menu or G0.

Option ?

I have run out of ideas. Maybe the solution would be:

/* Conditionals_LCD.h */
  #define HAS_CUSTOM_PROBE_PIN  (defined(Z_STOP_PIN) && defined(Z_MIN_PROBE_PIN) && (Z_STOP_PIN != Z_MIN_PROBE_PIN))
  #define HOMING_Z_WITH_PROBE   (Z_HOME_DIR < 0)

and some fix for Option 7 point 1.

That's a useful answer
Without any help

Hmm, is the other thing more of a bug

BLTouch is not used if using separate pin (that is if Z_MIN_PROBE_USES_Z_MIN_ENDSTOP_PIN is disabled)"

because of the HOMING_Z_WITH_PROBE logic in Conditionals_LCD.h,or a feature request

Cofiguration option to use Z-endstop switch and BLTouch probe simultaneously

? Reading this again I do not understand the HOMING_Z_WITH_PROBE logic - shouldn't the normal operation of the Z-endstop switch be retained (unless configured otherwise, e.g. with Z_MIN_PROBE_USES_Z_MIN_ENDSTOP_PIN or commenting #define Z_STOP_PIN) and BLTouch probe just used in conjunction if the BLTOUCH is defined?