From 9d545f1231cd8405dce65eba04c461e205f814b7 Mon Sep 17 00:00:00 2001
From: Eric Ptak <trouch@trouch.com>
Date: Mon, 11 May 2020 08:07:19 +0200
Subject: [PATCH] Fysetc S6 direct DFU upload (#17943)

---
 .../PlatformIO/scripts/fysetc_STM32S6.py      | 22 -------------------
 platformio.ini                                |  4 ++--
 2 files changed, 2 insertions(+), 24 deletions(-)

diff --git a/buildroot/share/PlatformIO/scripts/fysetc_STM32S6.py b/buildroot/share/PlatformIO/scripts/fysetc_STM32S6.py
index be010b10fe..f6598ede65 100644
--- a/buildroot/share/PlatformIO/scripts/fysetc_STM32S6.py
+++ b/buildroot/share/PlatformIO/scripts/fysetc_STM32S6.py
@@ -31,25 +31,3 @@ for file_name in os.listdir(source_dir):
     full_file_name = os.path.join(source_dir, file_name)
     if os.path.isfile(full_file_name):
         shutil.copy(full_file_name, variant_dir)
-
-# Relocate firmware from 0x08000000 to 0x08002000
-#env['CPPDEFINES'].remove(("VECT_TAB_ADDR", 134217728))
-#env['CPPDEFINES'].append(("VECT_TAB_ADDR", "0x08010000"))
-#env.Replace(LDSCRIPT_PATH="buildroot/share/PlatformIO/ldscripts/fysetc_aio_ii.ld")
-
-# Custom HEX from ELF
-env.AddPostAction(
-	"$BUILD_DIR/${PROGNAME}.elf",
-	env.VerboseAction(" ".join([
-				"$OBJCOPY",
-				"-O",
-				"ihex",
-				"$BUILD_DIR/${PROGNAME}.elf",
-				"$BUILD_DIR/${PROGNAME}.hex"
-			]), "Building $TARGET"))
-
-# In-line command with arguments
-env.Replace(
-	UPLOADER=platform.get_package_dir("tool-stm32duino") + '/stm32flash/stm32flash',
-	UPLOADCMD='"${UPLOADER}" -v -i rts,-dtr,dtr,-rts -R -b 115200 -g 0x8000000 -w "${BUILD_DIR}/${PROGNAME}.hex" ${UPLOAD_PORT}'
-)
diff --git a/platformio.ini b/platformio.ini
index aca4b55297..81855b3030 100644
--- a/platformio.ini
+++ b/platformio.ini
@@ -729,8 +729,8 @@ extra_scripts     = pre:buildroot/share/PlatformIO/scripts/fysetc_STM32S6.py
 src_filter        = ${common.default_src_filter} +<src/HAL/STM32>
 lib_ignore        = Arduino-L6470, SoftwareSerial
 debug_tool        = stlink
-#upload_protocol   = stlink
-upload_protocol   = serial
+upload_protocol   = dfu
+upload_command    = dfu-util -a 0 -s 0x08010000:leave -D "$SOURCE"
 
 #
 # STM32F407VET6 with RAMPS-like shield