From 1d3f28da2e9e7ecbecc4a25fffb120645a5b6ae1 Mon Sep 17 00:00:00 2001
From: George Fu <nailao_5918@163.com>
Date: Mon, 29 Mar 2021 17:38:28 +0800
Subject: [PATCH] FYSETC Spider board (#21458)

---
 Marlin/src/core/boards.h                     |  19 ++--
 Marlin/src/pins/pins.h                       |   2 +
 Marlin/src/pins/stm32f4/pins_FYSETC_S6.h     |  18 ++-
 Marlin/src/pins/stm32f4/pins_FYSETC_SPIDER.h | 110 +++++++++++++++++++
 4 files changed, 135 insertions(+), 14 deletions(-)
 create mode 100644 Marlin/src/pins/stm32f4/pins_FYSETC_SPIDER.h

diff --git a/Marlin/src/core/boards.h b/Marlin/src/core/boards.h
index 46c198a0ed..a7ee18d6eb 100644
--- a/Marlin/src/core/boards.h
+++ b/Marlin/src/core/boards.h
@@ -368,15 +368,16 @@
 #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 board
-#define BOARD_FYSETC_S6_V2_0          4216  // FYSETC S6 v2.0 board
-#define BOARD_FLYF407ZG               4217  // FLYF407ZG board (STM32F407ZG)
-#define BOARD_MKS_ROBIN2              4218  // MKS_ROBIN2 (STM32F407ZE)
-#define BOARD_MKS_ROBIN_PRO_V2        4219  // MKS Robin Pro V2 (STM32F407VE)
-#define BOARD_MKS_ROBIN_NANO_V3       4220  // MKS Robin Nano V3 (STM32F407VG)
-#define BOARD_ANET_ET4                4221  // ANET ET4 V1.x (STM32F407VGT6)
-#define BOARD_ANET_ET4P               4222  // ANET ET4P V1.x (STM32F407VGT6)
-#define BOARD_FYSETC_CHEETAH_V20      4223  // FYSETC Cheetah V2.0
+#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
 
 //
 // ARM Cortex M7
diff --git a/Marlin/src/pins/pins.h b/Marlin/src/pins/pins.h
index 58a87f2313..8eecce2c17 100644
--- a/Marlin/src/pins/pins.h
+++ b/Marlin/src/pins/pins.h
@@ -600,6 +600,8 @@
   #include "stm32f4/pins_FYSETC_S6.h"           // STM32F4                                env:FYSETC_S6
 #elif MB(FYSETC_S6_V2_0)
   #include "stm32f4/pins_FYSETC_S6_V2_0.h"      // STM32F4                                env:FYSETC_S6
+#elif MB(FYSETC_SPIDER)
+  #include "stm32f4/pins_FYSETC_SPIDER.h"       // STM32F4                                env:FYSETC_S6
 #elif MB(FLYF407ZG)
   #include "stm32f4/pins_FLYF407ZG.h"           // STM32F4                                env:FLYF407ZG
 #elif MB(MKS_ROBIN2)
diff --git a/Marlin/src/pins/stm32f4/pins_FYSETC_S6.h b/Marlin/src/pins/stm32f4/pins_FYSETC_S6.h
index d617087e9d..e6420dc238 100644
--- a/Marlin/src/pins/stm32f4/pins_FYSETC_S6.h
+++ b/Marlin/src/pins/stm32f4/pins_FYSETC_S6.h
@@ -24,7 +24,7 @@
 #include "env_validate.h"
 
 #if HOTENDS > 3 || E_STEPPERS > 3
-  #error "RUMBA32 supports up to 3 hotends / E-steppers."
+  #error "FYSETC S6 supports up to 3 hotends / E-steppers."
 #endif
 
 #ifndef BOARD_INFO_NAME
@@ -168,10 +168,18 @@
 //
 // Heaters / Fans
 //
-#define HEATER_0_PIN                        PB3
-#define HEATER_1_PIN                        PB4
-#define HEATER_2_PIN                        PB15
-#define HEATER_BED_PIN                      PC8
+#ifndef HEATER_0_PIN
+  #define HEATER_0_PIN                      PB3
+#endif
+#ifndef HEATER_0_PIN
+  #define HEATER_1_PIN                      PB4
+#endif
+#ifndef HEATER_0_PIN
+  #define HEATER_2_PIN                      PB15
+#endif
+#ifndef HEATER_0_PIN
+  #define HEATER_BED_PIN                    PC8
+#endif
 
 #define FAN_PIN                             PB0
 #define FAN1_PIN                            PB1
diff --git a/Marlin/src/pins/stm32f4/pins_FYSETC_SPIDER.h b/Marlin/src/pins/stm32f4/pins_FYSETC_SPIDER.h
new file mode 100644
index 0000000000..a33f35bd55
--- /dev/null
+++ b/Marlin/src/pins/stm32f4/pins_FYSETC_SPIDER.h
@@ -0,0 +1,110 @@
+/**
+ * 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
+
+#ifndef BOARD_INFO_NAME
+  #define BOARD_INFO_NAME "FYSETC SPIDER"
+#endif
+#ifndef DEFAULT_MACHINE_NAME
+  #define DEFAULT_MACHINE_NAME BOARD_INFO_NAME
+#endif
+
+//
+// EEPROM Emulation
+//
+#if NO_EEPROM_SELECTED
+  #undef NO_EEPROM_SELECTED
+  //#define FLASH_EEPROM_EMULATION
+  //#define SRAM_EEPROM_EMULATION
+  #define I2C_EEPROM
+#endif
+
+#if ENABLED(I2C_EEPROM)
+  #define MARLIN_EEPROM_SIZE              0x1000  // 4KB
+#endif
+
+//
+// Steppers
+//
+#define X2_STEP_PIN                         PD12
+#define X2_DIR_PIN                          PC4
+#define X2_ENABLE_PIN                       PE8
+#define X2_CS_PIN                           PA15
+
+#define Z2_STEP_PIN                         PE1
+#define Z2_DIR_PIN                          PE0
+#define Z2_ENABLE_PIN                       PC5
+#define Z2_CS_PIN                           PD11
+
+//
+// Heaters / Fans
+//
+#define HEATER_0_PIN                        PB15
+#define HEATER_1_PIN                        PC8
+#define HEATER_2_PIN                        PB3
+#define HEATER_BED_PIN                      PB4
+
+//
+// Steppers
+//
+#define X_ENABLE_PIN                        PE9
+
+#if HAS_TMC_UART
+  #define X_SERIAL_TX_PIN                   PE7
+  #define X_SERIAL_RX_PIN                   PE7
+  #define Y_SERIAL_TX_PIN                   PE15
+  #define Y_SERIAL_RX_PIN                   PE15
+  #define Z_SERIAL_TX_PIN                   PD10
+  #define Z_SERIAL_RX_PIN                   PD10
+  #define E0_SERIAL_TX_PIN                  PD7
+  #define E0_SERIAL_RX_PIN                  PD7
+  #define E1_SERIAL_TX_PIN                  PC14
+  #define E1_SERIAL_RX_PIN                  PC14
+  #define E2_SERIAL_TX_PIN                  PC15
+  #define E2_SERIAL_RX_PIN                  PC15
+  #define X2_SERIAL_TX_PIN                  PA15
+  #define X2_SERIAL_RX_PIN                  PA15
+  #define Z2_SERIAL_TX_PIN                  PD11
+  #define Z2_SERIAL_RX_PIN                  PD11
+#endif
+
+//
+// Software SPI pins for TMC2130 stepper drivers
+//
+#define TMC_USE_SW_SPI
+#if ENABLED(TMC_USE_SW_SPI)
+  #ifndef TMC_SW_MOSI
+    #define TMC_SW_MOSI                     PE14
+  #endif
+  #ifndef TMC_SW_MISO
+    #define TMC_SW_MISO                     PE13
+  #endif
+  #ifndef TMC_SW_SCK
+    #define TMC_SW_SCK                      PE12
+  #endif
+#endif
+
+#if HOTENDS > 3 || E_STEPPERS > 3
+  #error "FYSETC SPIDER supports up to 3 hotends / E-steppers."
+#else
+  #include "pins_FYSETC_S6.h"
+#endif