From 6131d2c5a6285da849fbb8d3e592f89518b02b24 Mon Sep 17 00:00:00 2001 From: ldursw <37294448+ldursw@users.noreply.github.com> Date: Fri, 4 Jun 2021 00:38:10 -0300 Subject: [PATCH] =?UTF-8?q?=F0=9F=94=A8=20MKS=20Robin=20E3=20for=20HAL/STM?= =?UTF-8?q?32=20(#21927)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Marlin/src/pins/pins.h | 2 +- .../pins/stm32f1/pins_MKS_ROBIN_E3_common.h | 11 ++++++- .../PlatformIO/scripts/stm32_serialbuffer.py | 23 ++++++++++++++ ini/stm32f1-maple.ini | 2 +- ini/stm32f1.ini | 30 +++++++++++++++---- 5 files changed, 60 insertions(+), 8 deletions(-) create mode 100644 buildroot/share/PlatformIO/scripts/stm32_serialbuffer.py diff --git a/Marlin/src/pins/pins.h b/Marlin/src/pins/pins.h index 49d91e493a..fa6c5208f9 100644 --- a/Marlin/src/pins/pins.h +++ b/Marlin/src/pins/pins.h @@ -503,7 +503,7 @@ #elif MB(MKS_ROBIN_PRO) #include "stm32f1/pins_MKS_ROBIN_PRO.h" // STM32F1 env:mks_robin_pro #elif MB(MKS_ROBIN_E3) - #include "stm32f1/pins_MKS_ROBIN_E3.h" // STM32F1 env:mks_robin_e3 + #include "stm32f1/pins_MKS_ROBIN_E3.h" // STM32F1 env:mks_robin_e3 env:mks_robin_e3_maple #elif MB(MKS_ROBIN_E3_V1_1) #include "stm32f1/pins_MKS_ROBIN_E3_V1_1.h" // STM32F1 env:mks_robin_e3 #elif MB(MKS_ROBIN_E3D) diff --git a/Marlin/src/pins/stm32f1/pins_MKS_ROBIN_E3_common.h b/Marlin/src/pins/stm32f1/pins_MKS_ROBIN_E3_common.h index da7bdc79e5..6369fcd31b 100644 --- a/Marlin/src/pins/stm32f1/pins_MKS_ROBIN_E3_common.h +++ b/Marlin/src/pins/stm32f1/pins_MKS_ROBIN_E3_common.h @@ -176,8 +176,17 @@ // // SD Card // -#define SPI_DEVICE 2 +#define SPI_DEVICE 2 +#define ONBOARD_SPI_DEVICE 2 +#define SDSS SD_SS_PIN +#define SDCARD_CONNECTION ONBOARD #define SD_DETECT_PIN PC10 +#define ONBOARD_SD_CS_PIN SD_SS_PIN +#define NO_SD_HOST_DRIVE + +// TODO: This is the only way to set SPI for SD on STM32 (for now) +#define ENABLE_SPI2 +#define CUSTOM_SPI_PINS #define SD_SCK_PIN PB13 #define SD_MISO_PIN PB14 #define SD_MOSI_PIN PB15 diff --git a/buildroot/share/PlatformIO/scripts/stm32_serialbuffer.py b/buildroot/share/PlatformIO/scripts/stm32_serialbuffer.py new file mode 100644 index 0000000000..2be5a202ef --- /dev/null +++ b/buildroot/share/PlatformIO/scripts/stm32_serialbuffer.py @@ -0,0 +1,23 @@ +# +# stm32_serialbuffer.py +# +Import("env") + +# Marlin has `RX_BUFFER_SIZE` and `TX_BUFFER_SIZE` to configure the +# buffer size for receiving and transmitting data respectively. +# Stm32duino uses another set of defines for the same purpose, +# so we get the values from the Marlin configuration and set +# them in `SERIAL_RX_BUFFER_SIZE` and `SERIAL_TX_BUFFER_SIZE`. +# It is not possible to change the values at runtime, they must +# be set with build flags. +# +# The script will set the value as the default one (64 bytes) +# or the user-configured one, whichever is higher. +mf = env["MARLIN_FEATURES"] +rxBuf = str(max(64, int(mf["RX_BUFFER_SIZE"]) if "RX_BUFFER_SIZE" in mf else 0)) +txBuf = str(max(64, int(mf["TX_BUFFER_SIZE"]) if "TX_BUFFER_SIZE" in mf else 0)) + +build_flags = env.get('BUILD_FLAGS') +build_flags.append("-DSERIAL_RX_BUFFER_SIZE=" + rxBuf) +build_flags.append("-DSERIAL_TX_BUFFER_SIZE=" + txBuf) +env.Replace(BUILD_FLAGS=build_flags) diff --git a/ini/stm32f1-maple.ini b/ini/stm32f1-maple.ini index b7869fd949..ec72e89831 100644 --- a/ini/stm32f1-maple.ini +++ b/ini/stm32f1-maple.ini @@ -268,7 +268,7 @@ extra_scripts = ${common_stm32f1.extra_scripts} # MKS Robin E3D (STM32F103RCT6) and # MKS Robin E3 with TMC2209 # -[env:mks_robin_e3] +[env:mks_robin_e3_maple] platform = ${common_stm32f1.platform} extends = common_stm32f1 board = genericSTM32F103RC diff --git a/ini/stm32f1.ini b/ini/stm32f1.ini index a0dd38fcd4..bbd2038479 100644 --- a/ini/stm32f1.ini +++ b/ini/stm32f1.ini @@ -31,6 +31,8 @@ build_flags = ${common.build_flags} -DADC_RESOLUTION=12 build_unflags = -std=gnu++11 src_filter = ${common.default_src_filter} + + +extra_scripts = ${common.extra_scripts} + pre:buildroot/share/PlatformIO/scripts/stm32_serialbuffer.py # # BigTree SKR Mini V1.1 / SKR mini E3 / SKR E3 DIP (STM32F103RCT6 ARM Cortex-M3) @@ -53,7 +55,7 @@ monitor_speed = 115200 board_build.core = stm32 board_build.variant = MARLIN_F103Rx board_build.ldscript = ldscript.ld -extra_scripts = ${common.extra_scripts} +extra_scripts = ${common_stm32.extra_scripts} pre:buildroot/share/PlatformIO/scripts/generic_create_variant.py buildroot/share/PlatformIO/scripts/stm32_bootloader.py @@ -136,12 +138,30 @@ build_flags = ${common_stm32.build_flags} -DENABLE_HWSERIAL3 -DTIMER_SERIAL=TIM5 build_unflags = ${common_stm32.build_unflags} -DUSBCON -DUSBD_USE_CDC -extra_scripts = ${common.extra_scripts} +extra_scripts = ${common_stm32.extra_scripts} pre:buildroot/share/PlatformIO/scripts/generic_create_variant.py buildroot/share/PlatformIO/scripts/stm32_bootloader.py buildroot/share/PlatformIO/scripts/mks_encrypt.py lib_deps = +# +# MKS Robin E3/E3D (STM32F103RCT6) with TMC2209 +# +[env:mks_robin_e3] +platform = ${common_stm32.platform} +extends = common_STM32F103RC +build_flags = ${common_stm32.build_flags} + -DDEBUG_LEVEL=0 -DTIMER_SERVO=TIM5 +build_unflags = ${common_stm32.build_unflags} -DUSBCON -DUSBD_USE_CDC +monitor_speed = 115200 +board_build.offset = 0x5000 +board_build.encrypt = Yes +board_build.firmware = Robin_e3.bin +board_upload.offset_address = 0x08005000 +debug_tool = stlink +extra_scripts = ${env:STM32F103RC.extra_scripts} + buildroot/share/PlatformIO/scripts/mks_encrypt.py + # # Creality (STM32F103RET6) # @@ -181,7 +201,7 @@ board_build.firmware = Robin_mini.bin board_build.encrypt = Yes board_upload.offset_address = 0x08007000 build_unflags = ${common_stm32.build_unflags} -DUSBCON -DUSBD_USE_CDC -extra_scripts = ${common.extra_scripts} +extra_scripts = ${common_stm32.extra_scripts} pre:buildroot/share/PlatformIO/scripts/generic_create_variant.py buildroot/share/PlatformIO/scripts/stm32_bootloader.py buildroot/share/PlatformIO/scripts/mks_encrypt.py @@ -204,7 +224,7 @@ board_upload.offset_address = 0x08007000 build_unflags = ${common_stm32.build_unflags} -DUSBCON -DUSBD_USE_CDC debug_tool = jlink upload_protocol = jlink -extra_scripts = ${common.extra_scripts} +extra_scripts = ${common_stm32.extra_scripts} pre:buildroot/share/PlatformIO/scripts/generic_create_variant.py buildroot/share/PlatformIO/scripts/stm32_bootloader.py buildroot/share/PlatformIO/scripts/mks_encrypt.py @@ -222,6 +242,6 @@ board_build.ldscript = ldscript.ld board_build.offset = 0x10000 build_flags = ${common_stm32.build_flags} -DENABLE_HWSERIAL3 -DTIMER_SERIAL=TIM5 build_unflags = ${common_stm32.build_unflags} -DUSBCON -DUSBD_USE_CDC -extra_scripts = ${common.extra_scripts} +extra_scripts = ${common_stm32.extra_scripts} pre:buildroot/share/PlatformIO/scripts/generic_create_variant.py buildroot/share/PlatformIO/scripts/stm32_bootloader.py