From f3b55a748a71fa4a7444bbf71b041eb89592e6fe Mon Sep 17 00:00:00 2001 From: ellensp <530024+ellensp@users.noreply.github.com> Date: Sun, 26 Sep 2021 16:39:36 +1300 Subject: [PATCH 1/3] add BLTOUCH_SET_5V_MODE sanity test --- Marlin/src/inc/SanityCheck.h | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/Marlin/src/inc/SanityCheck.h b/Marlin/src/inc/SanityCheck.h index 720a04c50223..2db1c18bbb43 100644 --- a/Marlin/src/inc/SanityCheck.h +++ b/Marlin/src/inc/SanityCheck.h @@ -1529,11 +1529,42 @@ static_assert(Y_MAX_LENGTH >= Y_BED_SIZE, "Movement bounds (Y_MIN_POS, Y_MAX_POS #endif #if ENABLED(BLTOUCH) + //Check for coltrollers that we know about. + #define ENABLE_FT_CHECK ENABLED(STM32F1) + + //What pin does probe use? + #if ENABLED(Z_MIN_PROBE_USES_Z_MIN_ENDSTOP_PIN) + #define PROBE_ON_PIN Z_MIN_PIN + #else + #define PROBE_ON_PIN Z_MIN_PROBE_PIN + #endif + + #if ENABLED(STM32F1) + // List of pins that are 5 volt tolerant for stm32f103 + #define CHECK_FT_PIN(FT) (\ + FT == PA8 || FT == PA9 || FT == PA10 || FT == PA11 || FT == PA12 || FT == PA13 || FT == PA14 || FT == PA15 || \ + FT == PB2 || FT == PB3 || FT == PB4 || FT == PB5 || FT == PB6 || FT == PB7 || FT == PB8 || FT == PB9 || FT == PB10 || FT == PB11 || FT == PB12 || FT == PB13 || FT == PB14 || FT == PB15 || \ + FT == PC6 || FT == PC7 || FT == PC8 || FT == PC9 || FT == PC10 || FT == PC11 || FT == PC12 || \ + FT == PD0 || FT == PD1 || FT == PD2 || FT == PD3 || FT == PD4 || FT == PD5 || FT == PD6 || FT == PD7 || FT == PD8 || FT == PD9 || FT == PD10 || FT == PD11 || FT == PD12 || FT == PD13 || FT == PD14 || FT == PD15 || \ + FT == PE0 || FT == PE1 || FT == PE2 || FT == PE3 || FT == PE4 || FT == PE5 || FT == PE6 || FT == PE7 || FT == PE8 || FT == PE9 || FT == PE10 || FT == PE11 || FT == PE12 || FT == PE13 || FT == PE14 || FT == PE15 || \ + FT == PF0 || FT == PF1 || FT == PF2 || FT == PF3 || FT == PF4 || FT == PF5 || FT == PF11 || FT == PF12 || FT == PF13 || FT == PF14 || FT == PF15 \ + ) + #endif + + #if ENABLE_FT_CHECK + #define CHECK_BLTOUCH_PIN_IS_FIVE_VOLT_TOLERNT CHECK_FT_PIN(PROBE_ON_PIN) + #else + #define CHECK_BLTOUCH_PIN_IS_FIVE_VOLT_TOLERNT 1 + #endif + #if BLTOUCH_DELAY < 200 #error "BLTOUCH_DELAY less than 200 is unsafe and is not supported." #elif DISABLED(BLTOUCH_SET_5V_MODE) && NONE(ONBOARD_ENDSTOPPULLUPS, ENDSTOPPULLUPS, ENDSTOPPULLUP_ZMIN, ENDSTOPPULLUP_ZMIN_PROBE) #error "BLTOUCH without BLTOUCH_SET_5V_MODE requires ENDSTOPPULLUPS, ENDSTOPPULLUP_ZMIN or ENDSTOPPULLUP_ZMIN_PROBE." #endif + #if ENABLED(BLTOUCH_SET_5V_MODE) && !CHECK_BLTOUCH_PIN_IS_FIVE_VOLT_TOLERNT + #error "BLTOUCH_SET_5V_MODE is active but the pin is not 5V tolerant. Disable BLTOUCH_SET_5V_MODE" + #endif #endif #if ENABLED(RACK_AND_PINION_PROBE) && !(defined(Z_PROBE_DEPLOY_X) && defined(Z_PROBE_RETRACT_X)) From 9a2d2181b5a3c4bd38c49e99cf33298db9d1de0d Mon Sep 17 00:00:00 2001 From: Scott Lahteine Date: Sun, 26 Sep 2021 20:22:42 -0500 Subject: [PATCH 2/3] Condense 5V pins list --- Marlin/src/inc/SanityCheck.h | 43 +++++++++++++----------------------- 1 file changed, 15 insertions(+), 28 deletions(-) diff --git a/Marlin/src/inc/SanityCheck.h b/Marlin/src/inc/SanityCheck.h index 2db1c18bbb43..813a56104dd5 100644 --- a/Marlin/src/inc/SanityCheck.h +++ b/Marlin/src/inc/SanityCheck.h @@ -1529,42 +1529,29 @@ static_assert(Y_MAX_LENGTH >= Y_BED_SIZE, "Movement bounds (Y_MIN_POS, Y_MAX_POS #endif #if ENABLED(BLTOUCH) - //Check for coltrollers that we know about. - #define ENABLE_FT_CHECK ENABLED(STM32F1) - - //What pin does probe use? - #if ENABLED(Z_MIN_PROBE_USES_Z_MIN_ENDSTOP_PIN) - #define PROBE_ON_PIN Z_MIN_PIN - #else - #define PROBE_ON_PIN Z_MIN_PROBE_PIN - #endif - - #if ENABLED(STM32F1) - // List of pins that are 5 volt tolerant for stm32f103 - #define CHECK_FT_PIN(FT) (\ - FT == PA8 || FT == PA9 || FT == PA10 || FT == PA11 || FT == PA12 || FT == PA13 || FT == PA14 || FT == PA15 || \ - FT == PB2 || FT == PB3 || FT == PB4 || FT == PB5 || FT == PB6 || FT == PB7 || FT == PB8 || FT == PB9 || FT == PB10 || FT == PB11 || FT == PB12 || FT == PB13 || FT == PB14 || FT == PB15 || \ - FT == PC6 || FT == PC7 || FT == PC8 || FT == PC9 || FT == PC10 || FT == PC11 || FT == PC12 || \ - FT == PD0 || FT == PD1 || FT == PD2 || FT == PD3 || FT == PD4 || FT == PD5 || FT == PD6 || FT == PD7 || FT == PD8 || FT == PD9 || FT == PD10 || FT == PD11 || FT == PD12 || FT == PD13 || FT == PD14 || FT == PD15 || \ - FT == PE0 || FT == PE1 || FT == PE2 || FT == PE3 || FT == PE4 || FT == PE5 || FT == PE6 || FT == PE7 || FT == PE8 || FT == PE9 || FT == PE10 || FT == PE11 || FT == PE12 || FT == PE13 || FT == PE14 || FT == PE15 || \ - FT == PF0 || FT == PF1 || FT == PF2 || FT == PF3 || FT == PF4 || FT == PF5 || FT == PF11 || FT == PF12 || FT == PF13 || FT == PF14 || FT == PF15 \ - ) + #if ENABLED(BLTOUCH_SET_5V_MODE) + #define _5V(A,B) !WITHIN(FT,A,B) + #ifdef STM32F1 // STM32F103 5V-tolerant pins + #define _NOT_5V_PIN(FT) (_5V(PA8, PA15) && _5V(PB2, PB15) && _5V(PC6, PC12) && _5V(PD0, PD15) && _5V(PE0, PE15) && _5V(PF0, PF5) && _5V(PF11, PF15)) + #else + #define _NOT_5V_PIN(FT) 0 // No more known controllers + #endif + #if USES_Z_MIN_PROBE_PIN && _NOT_5V_PIN(Z_MIN_PROBE_PIN) + #error "BLTOUCH_SET_5V_MODE is not compatible with the Z_MIN_PROBE_PIN." + #elif _NOT_5V_PIN(Z_MIN_PIN) + #error "BLTOUCH_SET_5V_MODE is not compatible with the Z_MIN_PIN." + #endif + #undef _NOT_5V_PIN + #undef _5V #endif - #if ENABLE_FT_CHECK - #define CHECK_BLTOUCH_PIN_IS_FIVE_VOLT_TOLERNT CHECK_FT_PIN(PROBE_ON_PIN) - #else - #define CHECK_BLTOUCH_PIN_IS_FIVE_VOLT_TOLERNT 1 - #endif + #undef _DO_FT_CHECK #if BLTOUCH_DELAY < 200 #error "BLTOUCH_DELAY less than 200 is unsafe and is not supported." #elif DISABLED(BLTOUCH_SET_5V_MODE) && NONE(ONBOARD_ENDSTOPPULLUPS, ENDSTOPPULLUPS, ENDSTOPPULLUP_ZMIN, ENDSTOPPULLUP_ZMIN_PROBE) #error "BLTOUCH without BLTOUCH_SET_5V_MODE requires ENDSTOPPULLUPS, ENDSTOPPULLUP_ZMIN or ENDSTOPPULLUP_ZMIN_PROBE." #endif - #if ENABLED(BLTOUCH_SET_5V_MODE) && !CHECK_BLTOUCH_PIN_IS_FIVE_VOLT_TOLERNT - #error "BLTOUCH_SET_5V_MODE is active but the pin is not 5V tolerant. Disable BLTOUCH_SET_5V_MODE" - #endif #endif #if ENABLED(RACK_AND_PINION_PROBE) && !(defined(Z_PROBE_DEPLOY_X) && defined(Z_PROBE_RETRACT_X)) From 467810572947076fe2bcef10c9d8f2c1e048bc6c Mon Sep 17 00:00:00 2001 From: Scott Lahteine Date: Mon, 27 Sep 2021 08:54:54 -0500 Subject: [PATCH 3/3] clarify --- Marlin/src/inc/SanityCheck.h | 26 ++++++++++++++++---------- 1 file changed, 16 insertions(+), 10 deletions(-) diff --git a/Marlin/src/inc/SanityCheck.h b/Marlin/src/inc/SanityCheck.h index 813a56104dd5..68542ec9e1a7 100644 --- a/Marlin/src/inc/SanityCheck.h +++ b/Marlin/src/inc/SanityCheck.h @@ -1529,28 +1529,34 @@ static_assert(Y_MAX_LENGTH >= Y_BED_SIZE, "Movement bounds (Y_MIN_POS, Y_MAX_POS #endif #if ENABLED(BLTOUCH) + + // BLTouch can't run in 5V mode with a 3.3V probe pin #if ENABLED(BLTOUCH_SET_5V_MODE) - #define _5V(A,B) !WITHIN(FT,A,B) + #define _5V(P,A,B) WITHIN(P,A,B) #ifdef STM32F1 // STM32F103 5V-tolerant pins - #define _NOT_5V_PIN(FT) (_5V(PA8, PA15) && _5V(PB2, PB15) && _5V(PC6, PC12) && _5V(PD0, PD15) && _5V(PE0, PE15) && _5V(PF0, PF5) && _5V(PF11, PF15)) + #define _IS_5V_TOLERANT(P) (_5V(P,PA8,PA15) || _5V(P,PB2,PB15) || _5V(P,PC6,PC12) || _5V(P,PD0,PD15) || _5V(P,PE0,PE15) || _5V(P,PF0,PF5) || _5V(P,PF11,PF15)) + #elif defined(ARDUINO_ARCH_SAM) + #define _IS_5V_TOLERANT(P) 0 // Assume no 5V tolerance #else - #define _NOT_5V_PIN(FT) 0 // No more known controllers + #define _IS_5V_TOLERANT(P) 1 // Assume 5V tolerance #endif - #if USES_Z_MIN_PROBE_PIN && _NOT_5V_PIN(Z_MIN_PROBE_PIN) + #if USES_Z_MIN_PROBE_PIN && !_IS_5V_TOLERANT(Z_MIN_PROBE_PIN) #error "BLTOUCH_SET_5V_MODE is not compatible with the Z_MIN_PROBE_PIN." - #elif _NOT_5V_PIN(Z_MIN_PIN) + #elif !_IS_5V_TOLERANT(Z_MIN_PIN) #error "BLTOUCH_SET_5V_MODE is not compatible with the Z_MIN_PIN." #endif - #undef _NOT_5V_PIN + #undef _IS_5V_TOLERANT #undef _5V + #elif NONE(ONBOARD_ENDSTOPPULLUPS, ENDSTOPPULLUPS, ENDSTOPPULLUP_ZMIN, ENDSTOPPULLUP_ZMIN_PROBE) + #if USES_Z_MIN_PROBE_PIN + #error "BLTOUCH on Z_MIN_PROBE_PIN requires ENDSTOPPULLUP_ZMIN_PROBE, ENDSTOPPULLUPS, or BLTOUCH_SET_5V_MODE." + #else + #error "BLTOUCH on Z_MIN_PIN requires ENDSTOPPULLUP_ZMIN, ENDSTOPPULLUPS, or BLTOUCH_SET_5V_MODE." + #endif #endif - #undef _DO_FT_CHECK - #if BLTOUCH_DELAY < 200 #error "BLTOUCH_DELAY less than 200 is unsafe and is not supported." - #elif DISABLED(BLTOUCH_SET_5V_MODE) && NONE(ONBOARD_ENDSTOPPULLUPS, ENDSTOPPULLUPS, ENDSTOPPULLUP_ZMIN, ENDSTOPPULLUP_ZMIN_PROBE) - #error "BLTOUCH without BLTOUCH_SET_5V_MODE requires ENDSTOPPULLUPS, ENDSTOPPULLUP_ZMIN or ENDSTOPPULLUP_ZMIN_PROBE." #endif #endif