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 27 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 @@ -3378,6 +3378,15 @@
#define POWER_MONITOR_VOLTAGE_OFFSET 0 // Offset (in volts) applied to the calculated voltage
#endif

/**
* Stepper Driver Anti-SNAFU Protection
*
* If the SAFE_POWER_PIN is defined for your board, Marlin will check
* that stepper drivers are properly plugged in before applying power.
* Disable protection if your stepper drivers don't support the feature.
*/
//#define DISABLE_DRIVER_SAFE_POWER_PROTECT

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

#if HAS_DRIVER_SAFE_POWER_PROTECT
#include "feature/stepper_driver_safety.h"
#endif

PGMSTR(M112_KILL_STR, "M112 Shutdown");

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

#if PIN_EXISTS(SAFE_POWER)
#if ENABLED(HAS_DRIVER_SAFE_POWER_PROTECT)
thisiskeithb marked this conversation as resolved.
Show resolved Hide resolved
SETUP_RUN(stepper_driver_backward_check());
#else
SETUP_LOG("SAFE_POWER");
OUT_WRITE(SAFE_POWER_PIN, HIGH);
#endif
#endif

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

#if HAS_DRIVER_SAFE_POWER_PROTECT
SETUP_RUN(stepper_driver_backward_report());
#endif

#if HAS_PRUSA_MMU2
SETUP_RUN(mmu2.init());
#endif
Expand Down
38 changes: 20 additions & 18 deletions Marlin/src/core/boards.h
Original file line number Diff line number Diff line change
Expand Up @@ -363,25 +363,27 @@
#define BOARD_BLACK_STM32F407VE 4204 // BLACK_STM32F407VE
#define BOARD_BLACK_STM32F407ZE 4205 // BLACK_STM32F407ZE
#define BOARD_STEVAL_3DP001V1 4206 // STEVAL-3DP001V1 3D PRINTER BOARD
#define BOARD_BTT_SKR_PRO_V1_1 4207 // BigTreeTech SKR Pro v1.1 (STM32F407ZG)
#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_SKR_PRO_V1_1 4207 // BigTreeTech SKR Pro v1.1 (STM32F407VGT6)
thisiskeithb marked this conversation as resolved.
Show resolved Hide resolved
#define BOARD_BTT_SKR_PRO_V1_2 4208 // BigTreeTech SKR Pro v1.2 (STM32F407VGT6)
#define BOARD_BTT_BTT002_V1_0 4209 // BigTreeTech BTT002 v1.0 (STM32F407VGT6)
#define BOARD_BTT_E3_RRF 4210 // BigTreeTech E3 RRF (STM32F407VGT6)
#define BOARD_BTT_GTR_V1_0 4211 // BigTreeTech GTR v1.0 (STM32F407IGT)
#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
#define BOARD_BTT_SKR_V2_0 4211 // BigTreeTech SKR v2.0 (STM32F407VGT6)
#define BOARD_BTT_GTR_V1_0 4212 // BigTreeTech GTR v1.0 (STM32F407IGT)
#define BOARD_LERDGE_K 4213 // Lerdge K (STM32F407ZG)
#define BOARD_LERDGE_S 4214 // Lerdge S (STM32F407VE)
#define BOARD_LERDGE_X 4215 // Lerdge X (STM32F407VE)
#define BOARD_VAKE403D 4216 // VAkE 403D (STM32F446VET6)
#define BOARD_FYSETC_S6 4217 // FYSETC S6 (STM32F446VET6)
#define BOARD_FYSETC_S6_V2_0 4218 // FYSETC S6 v2.0 (STM32F446VET6)
#define BOARD_FYSETC_SPIDER 4219 // FYSETC Spider (STM32F446VET6)
#define BOARD_FLYF407ZG 4220 // FLYF407ZG (STM32F407ZG)
#define BOARD_MKS_ROBIN2 4221 // MKS_ROBIN2 (STM32F407ZE)
#define BOARD_MKS_ROBIN_PRO_V2 4222 // MKS Robin Pro V2 (STM32F407VE)
#define BOARD_MKS_ROBIN_NANO_V3 4223 // MKS Robin Nano V3 (STM32F407VG)
#define BOARD_ANET_ET4 4224 // ANET ET4 V1.x (STM32F407VGT6)
#define BOARD_ANET_ET4P 4225 // ANET ET4P V1.x (STM32F407VGT6)
#define BOARD_FYSETC_CHEETAH_V20 4226 // FYSETC Cheetah V2.0


//
// ARM Cortex M7
Expand Down
171 changes: 171 additions & 0 deletions Marlin/src/feature/stepper_driver_safety.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,171 @@
/**
* 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 HAS_DRIVER_SAFE_POWER_PROTECT

#include "stepper_driver_safety.h"

static uint32_t axis_plug_backward = 0;

void stepper_driver_backward_error(PGM_P str) {
SERIAL_ERROR_START();
SERIAL_ECHOPGM_P(str);
SERIAL_ECHOLNPGM(" driver is backward!");
ui.status_printf_P(2, PSTR(S_FMT " driver backward"), str);
}

void stepper_driver_backward_check() {

OUT_WRITE(SAFE_POWER_PIN, LOW);

#define TEST_BACKWARD(AXIS, BIT) do { \
SET_INPUT(AXIS##_ENABLE_PIN); \
OUT_WRITE(AXIS##_STEP_PIN, false); \
delay(20); \
if (READ(AXIS##_ENABLE_PIN) == false) { \
SBI(axis_plug_backward, BIT); \
stepper_driver_backward_error(PSTR(STRINGIFY(AXIS))); \
} \
}while(0)

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

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

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

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

if (!axis_plug_backward)
WRITE(SAFE_POWER_PIN, HIGH);
}

void stepper_driver_backward_report() {
if (!axis_plug_backward) return;

auto _report_if_backward = [](PGM_P axis, uint8_t bit) {
if (TEST(axis_plug_backward, bit))
stepper_driver_backward_error(axis);
};

#define REPORT_BACKWARD(axis, bit) _report_if_backward(PSTR(STRINGIFY(axis)), bit)

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

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

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

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

#endif // HAS_DRIVER_SAFE_POWER_PROTECT
28 changes: 28 additions & 0 deletions Marlin/src/feature/stepper_driver_safety.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_backward_check();
void stepper_driver_backward_report();
4 changes: 4 additions & 0 deletions Marlin/src/inc/Conditionals_post.h
Original file line number Diff line number Diff line change
Expand Up @@ -3026,3 +3026,7 @@
#if BUTTONS_EXIST(EN1, EN2, ENC)
#define HAS_ROTARY_ENCODER 1
#endif

#if PIN_EXISTS(SAFE_POWER) && DISABLED(DISABLE_DRIVER_SAFE_POWER_PROTECT)
#define HAS_DRIVER_SAFE_POWER_PROTECT 1
#endif
2 changes: 2 additions & 0 deletions Marlin/src/pins/pins.h
Original file line number Diff line number Diff line change
Expand Up @@ -596,6 +596,8 @@
#include "stm32f4/pins_BTT_BTT002_V1_0.h" // STM32F4 env:BIGTREE_BTT002
#elif MB(BTT_E3_RRF)
#include "stm32f4/pins_BTT_E3_RRF.h" // STM32F4 env:BIGTREE_E3_RRF
#elif MB(BTT_SKR_V2_0)
#include "stm32f4/pins_BTT_SKR_V2_0.h" // STM32F4 env:BIGTREE_SKR_2
#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