Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BTT SKR V2.0 (STM32F407VGT6) & Stepper Driver Anti-SNAFU Protection #21503

Merged
merged 38 commits into from
Apr 27, 2021
Merged
Show file tree
Hide file tree
Changes from 14 commits
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
3f0d219
Driver Anti-Reverse Protection
thisiskeithb Apr 1, 2021
dc277d2
SKR V2.0 Support
thisiskeithb Apr 1, 2021
8df14d3
Merge remote-tracking branch 'MarlinFirmware/bugfix-2.0.x' into pr/bt…
thisiskeithb Apr 3, 2021
9a710a8
Merge remote-tracking branch 'MarlinFirmware/bugfix-2.0.x' into pr/bt…
thisiskeithb Apr 3, 2021
f0117e7
Mass production of pin. Avoid sharing TMC SPI with SD SPI
Msq001 Apr 3, 2021
d7f816a
Enable anti-reverse protection in default if SAFE_POWER_PIN is defined
Msq001 Apr 3, 2021
bc62981
Merge pull request #5 from bigtreetech/pr/btt_skr_v2_pin
thisiskeithb Apr 3, 2021
fac7451
Fix merge
thisiskeithb Apr 3, 2021
16bcc2c
Temporarily add generic SKR V2 variant
thisiskeithb Apr 3, 2021
1a55086
Merge remote-tracking branch 'MarlinFirmware/bugfix-2.0.x' into pr/bt…
thisiskeithb Apr 4, 2021
3ee454c
Merge remote-tracking branch 'MarlinFirmware/bugfix-2.0.x' into pr/bt…
thisiskeithb Apr 6, 2021
f932ed3
Merge remote-tracking branch 'MarlinFirmware/bugfix-2.0.x' into pr/bt…
thisiskeithb Apr 9, 2021
7d146f8
Update generic SKR V2 usb env
thisiskeithb Apr 9, 2021
7055c1b
Remove generic SKR V2 env
thisiskeithb Apr 12, 2021
a9ec119
Merge remote-tracking branch 'MarlinFirmware/bugfix-2.0.x' into pr/bt…
thisiskeithb Apr 12, 2021
2d83294
Merge remote-tracking branch 'MarlinFirmware/bugfix-2.0.x' into pr/bt…
thisiskeithb Apr 14, 2021
1261428
fix flash drive env
rhapsodyv Apr 14, 2021
8c3c936
Check pin_exists after pins include
thinkyhead Apr 14, 2021
2e7c870
fix SanityCheck
Msq001 Apr 14, 2021
b2fa246
Merge pull request #6 from bigtreetech/pr/btt_skr_v2
thisiskeithb Apr 14, 2021
1445098
adjustments
thinkyhead Apr 14, 2021
13738b0
Merge remote-tracking branch 'MarlinFirmware/bugfix-2.0.x' into pr/bt…
thisiskeithb Apr 17, 2021
e030030
Merge remote-tracking branch 'MarlinFirmware/bugfix-2.0.x' into pr/bt…
thisiskeithb Apr 17, 2021
db70fb8
variants
Msq001 Apr 19, 2021
339173f
Merge pull request #7 from bigtreetech/pr/btt_skr_v2
thisiskeithb Apr 19, 2021
8126432
Merge remote-tracking branch 'MarlinFirmware/bugfix-2.0.x' into pr/bt…
thisiskeithb Apr 19, 2021
cb7d2c3
Remove SKR_2 variant
thisiskeithb Apr 19, 2021
1c0005e
Some cleanup
thisiskeithb Apr 19, 2021
890f741
Translatable on-screen error message
thisiskeithb Apr 19, 2021
ddfa4e1
Merge remote-tracking branch 'MarlinFirmware/bugfix-2.0.x' into pr/bt…
thisiskeithb Apr 23, 2021
6c3027d
delete onboard sd detect pin
Msq001 Apr 24, 2021
e58af41
Remove onboard sd detect pin
thisiskeithb Apr 24, 2021
d7d8496
Merge remote-tracking branch 'MarlinFirmware/bugfix-2.0.x' into pr/bt…
thisiskeithb Apr 24, 2021
6286e9d
no enabled()
thisiskeithb Apr 24, 2021
422fb20
Merge remote-tracking branch 'MarlinFirmware/bugfix-2.0.x' into pr/bt…
thisiskeithb Apr 24, 2021
2d1dc8f
Merge remote-tracking branch 'MarlinFirmware/bugfix-2.0.x' into pr/bt…
thisiskeithb Apr 24, 2021
2647594
Merge remote-tracking branch 'MarlinFirmware/bugfix-2.0.x' into pr/bt…
thisiskeithb Apr 25, 2021
88b7791
Merge remote-tracking branch 'MarlinFirmware/bugfix-2.0.x' into pr/bt…
thisiskeithb Apr 26, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions Marlin/Configuration_adv.h
Original file line number Diff line number Diff line change
Expand Up @@ -3310,6 +3310,15 @@
#define POWER_MONITOR_FIXED_VOLTAGE 13.6 // Voltage for a current sensor with no voltage sensor (for power display)
#endif

/**
* Disable Stepper Driver Anti-Reverse Protection
*
* Check driver orientation before supplying power to prevent damage if "SAFE_POWER_PIN" is defined.
* However, some new stepper drivers may not support similar detection in the future
* So a disable option is provided. The driver will be powered directly without detection during initialization if disable
*/
//#define DISABLE_DRIVER_SAFE_POWER_PROTECT

/**
* CNC Coordinate Systems
*
Expand Down
12 changes: 12 additions & 0 deletions Marlin/src/MarlinCore.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,10 @@
#include "lcd/extui/lib/dgus/DGUSScreenHandler.h"
#endif

#if DRIVER_SAFE_POWER_PROTECT
#include "feature/driver_anti_reverse_protection.h"
#endif

PGMSTR(M112_KILL_STR, "M112 Shutdown");

MarlinState marlin_state = MF_INITIALIZING;
Expand Down Expand Up @@ -1218,6 +1222,10 @@ void setup() {
SETUP_RUN(ui.reset_status()); // Load welcome message early. (Retained if no errors exist.)
#endif

#if PIN_EXISTS(SAFE_POWER)
SETUP_RUN(TERN(DRIVER_SAFE_POWER_PROTECT, stepper_driver_anti_plug_detect(), OUT_WRITE(SAFE_POWER_PIN, HIGH)));
#endif

#if ENABLED(PROBE_TARE)
SETUP_RUN(probe.tare_init());
#endif
Expand Down Expand Up @@ -1462,6 +1470,10 @@ void setup() {
SETUP_RUN(test_tmc_connection(true, true, true, true));
#endif

#if DRIVER_SAFE_POWER_PROTECT
SETUP_RUN(test_anti_plug());
#endif

#if HAS_PRUSA_MMU2
SETUP_RUN(mmu2.init());
#endif
Expand Down
29 changes: 15 additions & 14 deletions Marlin/src/core/boards.h
Original file line number Diff line number Diff line change
Expand Up @@ -367,20 +367,21 @@
#define BOARD_BTT_SKR_PRO_V1_2 4208 // BigTreeTech SKR Pro v1.2 (STM32F407ZG)
#define BOARD_BTT_BTT002_V1_0 4209 // BigTreeTech BTT002 v1.0 (STM32F407VG)
#define BOARD_BTT_GTR_V1_0 4210 // BigTreeTech GTR v1.0 (STM32F407IGT)
#define BOARD_LERDGE_K 4211 // Lerdge K (STM32F407ZG)
#define BOARD_LERDGE_S 4212 // Lerdge S (STM32F407VE)
#define BOARD_LERDGE_X 4213 // Lerdge X (STM32F407VE)
#define BOARD_VAKE403D 4214 // VAkE 403D (STM32F446VET6)
#define BOARD_FYSETC_S6 4215 // FYSETC S6 (STM32F446VET6)
#define BOARD_FYSETC_S6_V2_0 4216 // FYSETC S6 v2.0 (STM32F446VET6)
#define BOARD_FYSETC_SPIDER 4217 // FYSETC Spider (STM32F446VET6)
#define BOARD_FLYF407ZG 4218 // FLYF407ZG (STM32F407ZG)
#define BOARD_MKS_ROBIN2 4219 // MKS_ROBIN2 (STM32F407ZE)
#define BOARD_MKS_ROBIN_PRO_V2 4220 // MKS Robin Pro V2 (STM32F407VE)
#define BOARD_MKS_ROBIN_NANO_V3 4221 // MKS Robin Nano V3 (STM32F407VG)
#define BOARD_ANET_ET4 4222 // ANET ET4 V1.x (STM32F407VGT6)
#define BOARD_ANET_ET4P 4223 // ANET ET4P V1.x (STM32F407VGT6)
#define BOARD_FYSETC_CHEETAH_V20 4224 // FYSETC Cheetah V2.0
#define BOARD_BTT_SKR_V2_0 4211 // BigTreeTech SKR v2.0 (STM32F407VG)
#define BOARD_LERDGE_K 4212 // Lerdge K (STM32F407ZG)
#define BOARD_LERDGE_S 4213 // Lerdge S (STM32F407VE)
#define BOARD_LERDGE_X 4214 // Lerdge X (STM32F407VE)
#define BOARD_VAKE403D 4215 // VAkE 403D (STM32F446VET6)
#define BOARD_FYSETC_S6 4216 // FYSETC S6 (STM32F446VET6)
#define BOARD_FYSETC_S6_V2_0 4217 // FYSETC S6 v2.0 (STM32F446VET6)
#define BOARD_FYSETC_SPIDER 4218 // FYSETC Spider (STM32F446VET6)
#define BOARD_FLYF407ZG 4219 // FLYF407ZG (STM32F407ZG)
#define BOARD_MKS_ROBIN2 4220 // MKS_ROBIN2 (STM32F407ZE)
#define BOARD_MKS_ROBIN_PRO_V2 4221 // MKS Robin Pro V2 (STM32F407VE)
#define BOARD_MKS_ROBIN_NANO_V3 4222 // MKS Robin Nano V3 (STM32F407VG)
#define BOARD_ANET_ET4 4223 // ANET ET4 V1.x (STM32F407VGT6)
#define BOARD_ANET_ET4P 4224 // ANET ET4P V1.x (STM32F407VGT6)
#define BOARD_FYSETC_CHEETAH_V20 4225 // FYSETC Cheetah V2.0

//
// ARM Cortex M7
Expand Down
166 changes: 166 additions & 0 deletions Marlin/src/feature/driver_anti_reverse_protection.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,166 @@
/**
* Marlin 3D Printer Firmware
* Copyright (c) 2021 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
*
* Based on Sprinter and grbl.
* Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*
*/
#include "../inc/MarlinConfig.h"
#include "../lcd/marlinui.h"

#if DRIVER_SAFE_POWER_PROTECT

#include "driver_anti_reverse_protection.h"

#define MSG_ERROR_ANTI(axis) #axis"-Axis anti pluged"

#define ANTI_PLUG_DETECT(axis, bit) do {\
SET_INPUT(axis##_ENABLE_PIN);\
OUT_WRITE(axis##_STEP_PIN, false);\
delay(20);\
if (READ(axis##_ENABLE_PIN) == false) {\
SBI(axis_anti_pluged, bit);\
SERIAL_ERROR_MSG(MSG_ERROR_ANTI(axis));\
}\
}while(0)

#define TEST_ANTI_PLUG(axis, bit) if (TEST(axis_anti_pluged, bit)) {\
SERIAL_ERROR_MSG(MSG_ERROR_ANTI(axis));\
LCD_MESSAGEPGM_P(MSG_ERROR_ANTI(axis));\
}


static uint32_t axis_anti_pluged = 0;

void stepper_driver_anti_plug_detect() {

OUT_WRITE(SAFE_POWER_PIN, LOW);

#if HAS_X_ENABLE
ANTI_PLUG_DETECT(X, 0);
#endif
#if HAS_X2_ENABLE
ANTI_PLUG_DETECT(X2, 1);
#endif

#if HAS_Y_ENABLE
ANTI_PLUG_DETECT(Y, 2);
#endif
#if HAS_Y2_ENABLE
ANTI_PLUG_DETECT(Y2, 3);
#endif

#if HAS_Z_ENABLE
ANTI_PLUG_DETECT(Z, 4);
#endif
#if HAS_Z2_ENABLE
ANTI_PLUG_DETECT(Z2, 5);
#endif
#if HAS_Z3_ENABLE
ANTI_PLUG_DETECT(Z3, 6);
#endif
#if HAS_Z4_ENABLE
ANTI_PLUG_DETECT(Z4, 7);
#endif

#if HAS_E0_ENABLE
ANTI_PLUG_DETECT(E0, 8);
#endif
#if HAS_E1_ENABLE
ANTI_PLUG_DETECT(E1, 9);
#endif
#if HAS_E2_ENABLE
ANTI_PLUG_DETECT(E2, 10);
#endif
#if HAS_E3_ENABLE
ANTI_PLUG_DETECT(E3, 11);
#endif
#if HAS_E4_ENABLE
ANTI_PLUG_DETECT(E4, 12);
#endif
#if HAS_E5_ENABLE
ANTI_PLUG_DETECT(E5, 13);
#endif
#if HAS_E6_ENABLE
ANTI_PLUG_DETECT(E6, 14);
#endif
#if HAS_E7_ENABLE
ANTI_PLUG_DETECT(E7, 15);
#endif

if (axis_anti_pluged == 0) {
WRITE(SAFE_POWER_PIN, HIGH);
}
}

void test_anti_plug() {
if (axis_anti_pluged == 0) return;

#if HAS_X_ENABLE
TEST_ANTI_PLUG(X, 0);
#endif
#if HAS_X2_ENABLE
TEST_ANTI_PLUG(X2, 1);
#endif

#if HAS_Y_ENABLE
TEST_ANTI_PLUG(Y, 2);
#endif
#if HAS_Y2_ENABLE
TEST_ANTI_PLUG(Y2, 3);
#endif

#if HAS_Z_ENABLE
TEST_ANTI_PLUG(Z, 4);
#endif
#if HAS_Z2_ENABLE
TEST_ANTI_PLUG(Z2, 5);
#endif
#if HAS_Z3_ENABLE
TEST_ANTI_PLUG(Z3, 6);
#endif
#if HAS_Z4_ENABLE
TEST_ANTI_PLUG(Z4, 7);
#endif

#if HAS_E0_ENABLE
TEST_ANTI_PLUG(E0, 8);
#endif
#if HAS_E1_ENABLE
TEST_ANTI_PLUG(E1, 9);
#endif
#if HAS_E2_ENABLE
TEST_ANTI_PLUG(E2, 10);
#endif
#if HAS_E3_ENABLE
TEST_ANTI_PLUG(E3, 11);
#endif
#if HAS_E4_ENABLE
TEST_ANTI_PLUG(E4, 12);
#endif
#if HAS_E5_ENABLE
TEST_ANTI_PLUG(E5, 13);
#endif
#if HAS_E6_ENABLE
TEST_ANTI_PLUG(E6, 14);
#endif
#if HAS_E7_ENABLE
TEST_ANTI_PLUG(E7, 15);
#endif
}

#endif // DRIVER_SAFE_POWER_PROTECT
28 changes: 28 additions & 0 deletions Marlin/src/feature/driver_anti_reverse_protection.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/**
* Marlin 3D Printer Firmware
* Copyright (c) 2021 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
*
* Based on Sprinter and grbl.
* Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*
*/
#pragma once


#include "../inc/MarlinConfigPre.h"

void stepper_driver_anti_plug_detect();
void test_anti_plug();
4 changes: 4 additions & 0 deletions Marlin/src/inc/Conditionals_adv.h
Original file line number Diff line number Diff line change
Expand Up @@ -543,3 +543,7 @@
#if EITHER(MEATPACK_ON_SERIAL_PORT_1, MEATPACK_ON_SERIAL_PORT_2)
#define HAS_MEATPACK 1
#endif

#if DISABLED(DISABLE_DRIVER_SAFE_POWER_PROTECT) && PIN_EXISTS(SAFE_POWER)
thinkyhead marked this conversation as resolved.
Show resolved Hide resolved
#define DRIVER_SAFE_POWER_PROTECT 1
#endif
7 changes: 7 additions & 0 deletions Marlin/src/inc/SanityCheck.h
Original file line number Diff line number Diff line change
Expand Up @@ -1628,6 +1628,13 @@ static_assert(hbm[Z_AXIS] >= 0, "HOMING_BUMP_MM.Z must be greater than or equal
#error "POWER_MONITOR_CURRENT_PIN and POWER_MONITOR_VOLTAGE_PIN must be different."
#endif

/**
* Stepper Driver Anti-Reverse Protection
*/
#if ENABLED(DRIVER_SAFE_POWER_PROTECT) && !PIN_EXISTS(SAFE_POWER)
thinkyhead marked this conversation as resolved.
Show resolved Hide resolved
#error "DRIVER_SAFE_POWER_PROTECT requires a valid SAFE_POWER_PIN."
#endif

/**
* Volumetric Extruder Limit
*/
Expand Down
2 changes: 2 additions & 0 deletions Marlin/src/pins/pins.h
Original file line number Diff line number Diff line change
Expand Up @@ -594,6 +594,8 @@
#include "stm32f4/pins_BTT_GTR_V1_0.h" // STM32F4 env:BIGTREE_GTR_V1_0 env:BIGTREE_GTR_V1_0_usb_flash_drive
#elif MB(BTT_BTT002_V1_0)
#include "stm32f4/pins_BTT_BTT002_V1_0.h" // STM32F4 env:BIGTREE_BTT002
#elif MB(BTT_SKR_V2_0)
#include "stm32f4/pins_BTT_SKR_V2_0.h" // STM32F4 env:BIGTREE_SKR_2 env:BIGTREE_SKR_2_usb_flash_drive env:BIGTREE_SKR_2_generic env:BIGTREE_SKR_2_generic_usb_flash_drive
#elif MB(LERDGE_K)
#include "stm32f4/pins_LERDGE_K.h" // STM32F4 env:LERDGEK env:LERDGEK_usb_flash_drive
#elif MB(LERDGE_S)
Expand Down
Loading