#
# Marlin Firmware
# PlatformIO Configuration File
#

#################################
#
# STM32F4 Architecture
#
# Naming Example: STM32F401RGT6
#
#   F : Foundation (sometimes High Performance F2/F4)
#   4 : Cortex M4 core (0:M0, 1-2:M3, 3-4:M4, 7:M7)
#  01 : Line/Features
#   R : 64 or 66 pins  (T:36, C:48 or 49, M:81, V:100, Z:144, I:176)
#   G : 1024KB Flash-memory  (B:128KB, C:256KB, D:384KB, E:512KB)
#   T : LQFP package
#   6 : -40...85°C   (7: ...105°C)
#
#################################

#
# ARMED (STM32)
#
[env:ARMED]
extends       = common_stm32
board         = armed_v1
build_flags   = ${common_stm32.build_flags}
                -O2 -ffreestanding -fsigned-char -fno-move-loop-invariants -fno-strict-aliasing

#
# STM32F401RC
#
[env:FYSETC_CHEETAH_V20]
extends            = stm32_variant
board              = marlin_FYSETC_CHEETAH_V20
board_build.offset = 0x8000
build_flags        = ${stm32_variant.build_flags} -DSTM32F401xC
upload_command     = dfu-util -a 0 -s 0x08008000:leave -D "$SOURCE"

#
# STM32F446RC nobootloader
#
[env:FYSETC_CHEETAH_V30]
extends            = stm32_variant
board              = marlin_FYSETC_CHEETAH_V30
build_flags        = ${stm32_variant.build_flags} -DHAL_PCD_MODULE_ENABLED
debug_tool         = stlink
upload_protocol    = dfu
upload_command     = dfu-util -a 0 -s 0x08000000:leave -D "$SOURCE"

#
# FLYF407ZG
#
[env:FLYF407ZG]
extends             = stm32_variant
board               = marlin_STM32F407ZGT6
board_build.variant = MARLIN_FLY_F407ZG
board_build.offset  = 0x8000
upload_protocol     = dfu

#
# FYSETC S6 (STM32F446RET6 ARM Cortex-M4)
#
[env:FYSETC_S6]
extends                     = stm32_variant
board                       = marlin_fysetc_s6
board_build.offset          = 0x10000
board_upload.offset_address = 0x08010000
build_flags                 = ${stm32_variant.build_flags} -DHAL_PCD_MODULE_ENABLED
debug_tool                  = stlink
upload_protocol             = dfu
upload_command              = dfu-util -a 0 -s 0x08010000:leave -D "$SOURCE"

#
# FYSETC S6 new bootloader
#
[env:FYSETC_S6_8000]
extends                     = env:FYSETC_S6
board                       = marlin_fysetc_s6
board_build.offset          = 0x8000
board_upload.offset_address = 0x08008000
upload_command              = dfu-util -a 0 -s 0x08008000:leave -D "$SOURCE"

#
#  FYSETC SPIDER KING407 (STM32F407ZGT6 ARM Cortex-M4)
#
[env:FYSETC_SPIDER_KING407]
extends             = stm32_variant
board               = marlin_STM32F407ZGT6
board_build.variant = MARLIN_FYSETC_SPIDER_KING407
board_build.offset  = 0x8000
upload_protocol     = dfu

#
# STM32F407VET6 with RAMPS-like shield
# 'Black' STM32F407VET6 board - https://wiki.stm32duino.com/index.php?title=STM32F407
# Shield - https://github.com/jmz52/Hardware
#
[env:STM32F407VE_black]
extends           = stm32_variant
board             = marlin_blackSTM32F407VET6
build_flags       = ${stm32_variant.build_flags}
                    -DUSBD_USE_CDC_COMPOSITE -DUSE_USB_FS

#
# STM32F407VET6 Opulo Lumen REV3
#
[env:Opulo_Lumen_REV3]
extends           = stm32_variant
board             = marlin_opulo_lumen_rev3
build_flags       = ${stm32_variant.build_flags}
  -DARDUINO_BLACK_F407VE
  -DUSBD_USE_CDC_COMPOSITE -DUSE_USB_FS -DHAS_STM32_UID
extra_scripts     = ${stm32_variant.extra_scripts}

#
# STM32F407VET6 Opulo Lumen REV4
#
[env:Opulo_Lumen_REV4]
extends           = stm32_variant
board             = marlin_opulo_lumen_rev4
build_flags       = ${stm32_variant.build_flags}
  -DARDUINO_BLACK_F407VE
  -DUSBD_USE_CDC_COMPOSITE -DUSE_USB_FS -DHAS_STM32_UID
extra_scripts     = ${stm32_variant.extra_scripts}

#
# Anet ET4-MB_V1.x/ET4P-MB_V1.x (STM32F407VGT6 ARM Cortex-M4)
#
[Anet_ET4]
extends                     = stm32_variant
board                       = marlin_STM32F407VGT6_CCM
board_build.variant         = MARLIN_F4x7Vx
build_flags                 = ${stm32_variant.build_flags}
                              -DHAL_SD_MODULE_ENABLED -DHAL_SRAM_MODULE_ENABLED
build_unflags               = ${stm32_variant.build_unflags}
                              -DUSBCON -DUSBD_USE_CDC -DUSBD_VID=0x0483

#
# Anet ET4 directly flashed via ST-Link
#
[env:Anet_ET4_no_bootloader]
extends                     = Anet_ET4
debug_tool                  = stlink
upload_protocol             = stlink

#
# Anet ET4 with OpenBLT from https://github.com/davidtgbe/openblt/releases
#
[env:Anet_ET4_OpenBLT]
extends                     = Anet_ET4
board_build.encode          = firmware.srec
board_build.offset          = 0x10000
board_upload.offset_address = 0x08010000
extra_scripts               = ${stm32_variant.extra_scripts}
                              buildroot/share/PlatformIO/scripts/openblt.py

#
# BigTreeTech SKR Pro (STM32F407ZGT6 ARM Cortex-M4)
#
[env:BIGTREE_SKR_PRO]
extends            = stm32_variant
board              = marlin_BigTree_SKR_Pro
board_build.offset = 0x8000
build_flags        = ${stm32_variant.build_flags} -DSTM32F407_5ZX
debug_tool         = stlink
upload_protocol    = stlink

#
# BigTreeTech SKR Pro (STM32F407ZGT6 ARM Cortex-M4) with USB Flash Drive Support
#
[env:BIGTREE_SKR_PRO_usb_flash_drive]
extends           = env:BIGTREE_SKR_PRO
platform_packages = ${stm_flash_drive.platform_packages}
build_flags       = ${stm_flash_drive.build_flags} -DSTM32F407_5ZX
build_unflags     = ${env:BIGTREE_SKR_PRO.build_unflags} -DUSBCON -DUSBD_USE_CDC

#
# BigTreeTech E3 RRF (STM32F407VGT6 ARM Cortex-M4)
#
[env:BIGTREE_E3_RRF]
extends             = stm32_variant
board               = marlin_STM32F407VGT6_CCM
board_build.variant = MARLIN_BIGTREE_E3_RRF
board_build.offset  = 0x8000
build_flags         = ${stm32_variant.build_flags}
                      -DSTM32F407_5VX
                      -DMF_RX_BUFFER_SIZE=255
                      -DMF_TX_BUFFER_SIZE=255

#
# Bigtreetech GTR V1.0 (STM32F407IGT6 ARM Cortex-M4)
#
[env:BIGTREE_GTR_V1_0]
extends            = stm32_variant
board              = marlin_BigTree_GTR_v1
board_build.offset = 0x8000
build_flags        = ${stm32_variant.build_flags} -DSTM32F407IX

#
# Bigtreetech GTR V1.0 (STM32F407IGT6 ARM Cortex-M4) with USB Flash Drive Support
#
[env:BIGTREE_GTR_V1_0_usb_flash_drive]
extends           = env:BIGTREE_GTR_V1_0
platform_packages = ${stm_flash_drive.platform_packages}
build_flags       = ${stm_flash_drive.build_flags} -DSTM32F407IX
build_unflags     = ${env:BIGTREE_GTR_V1_0.build_unflags} -DUSBCON -DUSBD_USE_CDC

#
# BigTreeTech BTT002 V1.0 (STM32F407VGT6 ARM Cortex-M4)
#
[env:BIGTREE_BTT002]
extends            = stm32_variant
board              = marlin_BigTree_BTT002
board_build.offset = 0x8000
build_flags        = ${stm32_variant.build_flags}
                     -DSTM32F407_5VX
                     -DHAVE_HWSERIAL2
                     -DHAVE_HWSERIAL3
                     -DPIN_SERIAL2_RX=PD_6
                     -DPIN_SERIAL2_TX=PD_5

#
# BigTreeTech BTT002 V1.x with 512k of flash (STM32F407VET6 ARM Cortex-M4)
#
[env:BIGTREE_BTT002_VET6]
extends           = env:BIGTREE_BTT002
board             = marlin_BigTree_BTT002_VET6

#
# BigTreeTech SKR V2.0 (STM32F407VGT6 ARM Cortex-M4) with USB Flash Drive Support
#
[env:BIGTREE_SKR_2]
extends                     = stm32_variant
platform_packages           = ${stm_flash_drive.platform_packages}
board                       = marlin_STM32F407VGT6_CCM
board_build.variant         = MARLIN_F4x7Vx
board_build.offset          = 0x8000
board_upload.offset_address = 0x08008000
build_flags                 = ${stm_flash_drive.build_flags}
                              -DUSE_USBHOST_HS -DUSE_USB_HS_IN_FS
                              -DUSBD_IRQ_PRIO=5 -DUSBD_IRQ_SUBPRIO=6
                              -DHSE_VALUE=8000000U -DHAL_SD_MODULE_ENABLED
                              -DPIN_SERIAL3_RX=PD_9 -DPIN_SERIAL3_TX=PD_8
upload_protocol             = stlink

#
# BigTreeTech SKR V2.0 (STM32F407VGT6 ARM Cortex-M4) with USB Media Share Support
#
[env:BIGTREE_SKR_2_USB]
extends           = env:BIGTREE_SKR_2
build_flags       = ${env:BIGTREE_SKR_2.build_flags} -DUSBD_USE_CDC_MSC
build_unflags     = ${env:BIGTREE_SKR_2.build_unflags} -DUSBD_USE_CDC

[env:BIGTREE_SKR_2_USB_debug]
extends           = env:BIGTREE_SKR_2_USB
build_flags       = ${env:BIGTREE_SKR_2_USB.build_flags} -O0
build_unflags     = ${env:BIGTREE_SKR_2_USB.build_unflags} -Os -NDEBUG

#
# Bigtreetech SKR V2.0 F429 (STM32F429VGT6 ARM Cortex-M4) with USB Flash Drive Support
#
[env:BIGTREE_SKR_2_F429]
extends                     = env:BIGTREE_SKR_2
board                       = marlin_STM32F429VGT6

#
# BigTreeTech SKR V2.0 F429 (STM32F429VGT6 ARM Cortex-M4) with USB Media Share Support
#
[env:BIGTREE_SKR_2_F429_USB]
extends           = env:BIGTREE_SKR_2_F429
build_flags       = ${env:BIGTREE_SKR_2_F429.build_flags} -DUSBD_USE_CDC_MSC
build_unflags     = ${env:BIGTREE_SKR_2_F429.build_unflags} -DUSBD_USE_CDC

[env:BIGTREE_SKR_2_F429_USB_debug]
extends           = env:BIGTREE_SKR_2_F429_USB
build_flags       = ${env:BIGTREE_SKR_2_F429_USB.build_flags} -O0
build_unflags     = ${env:BIGTREE_SKR_2_F429_USB.build_unflags} -Os -NDEBUG

#
# BigTreeTech Octopus V1.0/1.1 / Octopus Pro V1.0 (STM32F446ZET6 ARM Cortex-M4)
#
[env:STM32F446ZE_btt]
extends                     = stm32_variant
board                       = marlin_BigTree_Octopus_v1
board_build.offset          = 0x8000
board_upload.offset_address = 0x08008000
debug_tool                  = stlink
upload_protocol             = stlink
build_flags                 = ${stm32_variant.build_flags}
                              -DSTM32F446_5VX -DUSE_USB_HS_IN_FS

#
# BigTreeTech Octopus V1.0/1.1 / Octopus Pro V1.0 (STM32F446ZET6 ARM Cortex-M4) with USB Flash Drive Support
#
[env:STM32F446ZE_btt_usb_flash_drive]
extends           = env:STM32F446ZE_btt
platform_packages = ${stm_flash_drive.platform_packages}
build_unflags     = -DUSBD_USE_CDC
build_flags       = ${stm_flash_drive.build_flags}
                    -DSTM32F446_5VX -DUSE_USB_HS_IN_FS
                    -DUSE_USBHOST_HS -DUSBD_IRQ_PRIO=5
                    -DUSBD_IRQ_SUBPRIO=6
                    -DUSBD_USE_CDC_MSC

#
# BigTreeTech Octopus V1.1 / Octopus Pro V1.0 (STM32F429ZGT6 ARM Cortex-M4)
#
[env:STM32F429ZG_btt]
extends                     = stm32_variant
board                       = marlin_BigTree_Octopus_Pro_v1_F429
board_build.offset          = 0x8000
board_upload.offset_address = 0x08008000
debug_tool                  = stlink
upload_protocol             = stlink
build_flags                 = ${stm32_variant.build_flags}
                              -DUSE_USB_HS_IN_FS

#
# BigTreeTech Octopus V1.1 / Octopus Pro V1.0 (STM32F429ZGT6 ARM Cortex-M4) with USB Flash Drive Support
#
[env:STM32F429ZG_btt_usb_flash_drive]
extends           = env:STM32F429ZG_btt
platform_packages = ${stm_flash_drive.platform_packages}
build_unflags     = -DUSBD_USE_CDC
build_flags       = ${stm_flash_drive.build_flags}
                    -DUSE_USB_HS_IN_FS -DUSE_USBHOST_HS
                    -DUSBD_IRQ_PRIO=5 -DUSBD_IRQ_SUBPRIO=6
                    -DUSBD_USE_CDC_MSC

#
# BigTreeTech Octopus / Octopus Pro (STM32F407ZET6 ARM Cortex-M4)
#
[env:STM32F407ZE_btt]
extends            = stm32_variant
board              = marlin_STM32F407ZE
board_build.offset = 0x8000
build_flags        = ${stm32_variant.build_flags}
                     -DUSE_USB_HS_IN_FS

#
# BigTreeTech Octopus / Octopus Pro (STM32F407ZET6 ARM Cortex-M4) with USB Flash Drive Support
#
[env:STM32F407ZE_btt_usb_flash_drive]
extends           = env:STM32F407ZE_btt
platform_packages = ${stm_flash_drive.platform_packages}
build_unflags     = -DUSBD_USE_CDC
build_flags       = ${stm_flash_drive.build_flags}
                    -DUSE_USB_HS_IN_FS -DUSE_USBHOST_HS
                    -DUSBD_IRQ_PRIO=5 -DUSBD_IRQ_SUBPRIO=6
                    -DUSBD_USE_CDC_MSC

#
# Lerdge base
#
[lerdge_common]
extends                  = stm32_variant
board                    = marlin_STM32F407ZGT6
board_build.variant      = MARLIN_LERDGE
board_build.crypt_lerdge = firmware.bin
board_build.offset       = 0x10000
build_flags              = ${stm32_variant.build_flags}
                           -DSTM32F4 -DSTM32F4xx -DTARGET_STM32F4
                           -DDISABLE_GENERIC_SERIALUSB -DARDUINO_ARCH_STM32 -DLERDGE_TFT35
build_unflags            = ${stm32_variant.build_unflags} -DUSBCON -DUSBD_USE_CDC -DUSBD_VID=0x0483
extra_scripts            = ${stm32_variant.extra_scripts}
                           buildroot/share/PlatformIO/scripts/lerdge.py

#
# Lerdge X (STM32F407VE)
#
[env:LERDGEX]
extends                  = lerdge_common
board_build.crypt_lerdge = Lerdge_X_firmware_force.bin

#
# Lerdge X with USB Flash Drive Support
#
[env:LERDGEX_usb_flash_drive]
extends           = env:LERDGEX
platform_packages = ${stm_flash_drive.platform_packages}
build_flags       = ${stm_flash_drive.build_flags} ${lerdge_common.build_flags}

#
# Lerdge S (STM32F407ZG)
#
[env:LERDGES]
extends                  = lerdge_common
board_build.crypt_lerdge = Lerdge_firmware_force.bin

#
# Lerdge S with USB Flash Drive Support
#
[env:LERDGES_usb_flash_drive]
extends           = env:LERDGES
platform_packages = ${stm_flash_drive.platform_packages}
build_flags       = ${stm_flash_drive.build_flags} ${lerdge_common.build_flags}

#
# Lerdge K (STM32F407ZG)
#
[env:LERDGEK]
extends                  = lerdge_common
board_build.crypt_lerdge = Lerdge_K_firmware_force.bin
build_flags              = ${lerdge_common.build_flags} -DLERDGEK

#
# Lerdge K with USB Flash Drive Support
#
[env:LERDGEK_usb_flash_drive]
extends           = env:LERDGEK
platform_packages = ${stm_flash_drive.platform_packages}
build_flags       = ${stm_flash_drive.build_flags} ${lerdge_common.build_flags}

#
# RUMBA32
#
[env:rumba32]
extends             = stm32_variant
board               = rumba32_f446ve
board_build.variant = MARLIN_F446VE
board_build.offset  = 0x0000
build_flags         = ${stm32_variant.build_flags}
                      -Os -DHAL_PCD_MODULE_ENABLED
                      -DDISABLE_GENERIC_SERIALUSB
                      -DHAL_UART_MODULE_ENABLED
                      -DTIMER_SERIAL=TIM9
monitor_speed       = 500000
upload_protocol     = dfu

#
# STM32F407ZET6 ARM Cortex-M4
#
[env:mks_robin2]
extends                     = stm32_variant
board                       = marlin_MKS_ROBIN2
board_build.offset          = 0xC000
board_upload.offset_address = 0x0800C000
board_build.encrypt_mks     = Robin2.bin
build_flags                 = ${stm32_variant.build_flags}
                              -DTARGET_STM32F4 -DSTM32F407_5ZX
                              -DUSBCON -DUSBD_USE_CDC -DUSBD_VID=0x0483 -DUSBD_PID=0x3748 -DUSB_PRODUCT=\"MKS_Robin2\"

#
# MKS Robin Pro V2 (No bootloader!)
#
[env:mks_robin_pro2]
extends                     = stm32_variant
platform_packages           = ${stm_flash_drive.platform_packages}
board                       = genericSTM32F407VET6
board_build.variant         = MARLIN_F4x7Vx
board_build.offset          = 0x0000
board_upload.offset_address = 0x08000000
build_flags                 = ${stm_flash_drive.build_flags}
build_unflags               = ${stm32_variant.build_unflags} -DUSBCON -DUSBD_USE_CDC
debug_tool                  = jlink
upload_protocol             = jlink

#
# This I2C1(PB6:I2C1_SCL PB7:I2C1_SDA) is used by Robin Nano V3
#
[stm32f4_I2C1]
build_flags = -DPIN_WIRE_SCL=PB6 -DPIN_WIRE_SDA=PB7

#
# MKS Robin Nano V3
#
[env:mks_robin_nano_v3]
extends                     = stm32_variant
board                       = marlin_STM32F407VGT6_CCM
board_build.variant         = MARLIN_F4x7Vx
board_build.offset          = 0xC000
board_upload.offset_address = 0x0800C000
board_build.rename          = Robin_nano_v3.bin
build_flags                 = ${stm32_variant.build_flags} ${stm32f4_I2C1.build_flags}
                              -DHAL_PCD_MODULE_ENABLED
debug_tool                  = jlink
upload_protocol             = jlink

#
# MKS Robin Nano V3 with USB Flash Drive Support
#
[env:mks_robin_nano_v3_usb_flash_drive]
extends           = env:mks_robin_nano_v3
platform_packages = ${stm_flash_drive.platform_packages}
build_flags       = ${stm_flash_drive.build_flags} ${stm32f4_I2C1.build_flags}
                    -DUSE_USBHOST_HS
                    -DUSBD_IRQ_PRIO=5
                    -DUSBD_IRQ_SUBPRIO=6
                    -DUSE_USB_HS_IN_FS

#
# MKS Robin Nano V3 with USB Flash Drive Support and Shared Media
#
[env:mks_robin_nano_v3_usb_flash_drive_msc]
extends           = env:mks_robin_nano_v3_usb_flash_drive
build_flags       = ${env:mks_robin_nano_v3_usb_flash_drive.build_flags}
                    -DUSBD_USE_CDC_MSC
build_unflags     = -DUSBD_USE_CDC

#
# MKS Robin Nano V3_1
#
[env:mks_robin_nano_v3_1]
extends           = env:mks_robin_nano_v3
board             = marlin_STM32F407VET6_CCM

#
# MKS Robin Nano V3.1 with USB Flash Drive Support
#
[env:mks_robin_nano_v3_1_usb_flash_drive]
extends           = env:mks_robin_nano_v3_usb_flash_drive
board             = marlin_STM32F407VET6_CCM

#
# MKS Robin Nano V3.1 with USB Flash Drive Support and Shared Media
#
[env:mks_robin_nano_v3_1_usb_flash_drive_msc]
extends           = env:mks_robin_nano_v3_usb_flash_drive_msc
board             = marlin_STM32F407VET6_CCM

#
# MKS Eagle
# 5 TMC2209 uart mode on board
#
[env:mks_eagle]
extends                     = stm32_variant
board                       = marlin_STM32F407VGT6_CCM
board_build.variant         = MARLIN_F4x7Vx
board_build.offset          = 0xC000
board_upload.offset_address = 0x0800C000
board_build.rename          = mks_eagle.bin
build_flags                 = ${stm32_variant.build_flags} ${stm32f4_I2C1.build_flags}
                              -DHAL_PCD_MODULE_ENABLED
                              -DSTM32_FLASH_SIZE=512
debug_tool                  = jlink
upload_protocol             = jlink

#
# MKS Eagle with USB Flash Drive Support
#
[env:mks_eagle_usb_flash_drive]
extends           = env:mks_eagle
platform_packages = ${stm_flash_drive.platform_packages}
build_flags       = ${stm_flash_drive.build_flags} ${stm32f4_I2C1.build_flags}
                    -DUSE_USBHOST_HS
                    -DUSBD_IRQ_PRIO=5
                    -DUSBD_IRQ_SUBPRIO=6
                    -DUSE_USB_HS_IN_FS

#
# MKS Eagle with USB Flash Drive Support and Shared Media
#
[env:mks_eagle_usb_flash_drive_msc]
extends           = env:mks_eagle_usb_flash_drive
build_flags       = ${env:mks_eagle_usb_flash_drive.build_flags}
                    -DUSBD_USE_CDC_MSC
build_unflags     = -DUSBD_USE_CDC

#
# This I2C1(PB8:I2C1_SCL PB9:I2C1_SDA) is used by MKS Monster8
#
[stm32f4_I2C1_CAN]
build_flags = -DPIN_WIRE_SCL=PB8 -DPIN_WIRE_SDA=PB9

#
# MKS Monster8 V1 / V2 (STM32F407VET6 ARM Cortex-M4)
#
[env:mks_monster8]
extends                     = stm32_variant
board                       = marlin_STM32F407VGT6_CCM
board_build.variant         = MARLIN_F4x7Vx
board_build.offset          = 0xC000
board_upload.offset_address = 0x0800C000
board_build.rename          = mks_monster8.bin
build_flags                 = ${stm32_variant.build_flags} ${stm32f4_I2C1_CAN.build_flags}
                              -DHAL_PCD_MODULE_ENABLED -DTIMER_SERIAL=TIM4
                              -DSTM32_FLASH_SIZE=512
debug_tool                  = jlink
upload_protocol             = jlink

#
# MKS Monster8 V1 / V2 (STM32F407VET6 ARM Cortex-M4) with USB Flash Drive Support
#
[env:mks_monster8_usb_flash_drive]
extends           = env:mks_monster8
platform_packages = ${stm_flash_drive.platform_packages}
build_flags       = ${stm_flash_drive.build_flags} ${stm32f4_I2C1_CAN.build_flags}
                    -DUSE_USBHOST_HS
                    -DUSBD_IRQ_PRIO=5
                    -DUSBD_IRQ_SUBPRIO=6
                    -DUSE_USB_HS_IN_FS

#
# MKS Monster8 V1 / V2 (STM32F407VET6 ARM Cortex-M4) with USB Flash Drive Support and Shared Media
#
[env:mks_monster8_usb_flash_drive_msc]
extends           = env:mks_monster8_usb_flash_drive
build_flags       = ${env:mks_monster8_usb_flash_drive.build_flags}
                    -DUSBD_USE_CDC_MSC
build_unflags     = -DUSBD_USE_CDC

#
# TH3D EZBoard v2.0 (STM32F405RGT6 ARM Cortex-M4)
#
[TH3D_EZBoard_V2]
extends                     = stm32_variant
board                       = genericSTM32F405RG
board_build.variant         = MARLIN_TH3D_EZBOARD_V2
build_flags                 = ${stm32_variant.build_flags} -DHSE_VALUE=12000000U -O0

#
# TH3D EZBoard v2.0 directly flashed via ST-Link
#
[env:TH3D_EZBoard_V2_no_bootloader]
extends                     = TH3D_EZBoard_V2
debug_tool                  = stlink
upload_protocol             = stlink

#
# TH3D EZBoard v2.0 with OpenBLT from https://github.com/rhapsodyv/OpenBLT-STM32
#
[env:TH3D_EZBoard_V2_OpenBLT]
extends                     = TH3D_EZBoard_V2
board_build.encode          = firmware.bin
board_build.offset          = 0xC000
board_upload.offset_address = 0x0800C000
extra_scripts               = ${stm32_variant.extra_scripts}
                              buildroot/share/PlatformIO/scripts/openblt.py

[mks_robin_nano_v1_3_f4_common]
extends                     = stm32_variant
board                       = marlin_STM32F407VGT6_CCM
board_build.variant         = MARLIN_F4x7Vx
board_build.offset          = 0x8000
board_upload.offset_address = 0x08008000
board_build.rename          = Robin_nano35.bin
debug_tool                  = jlink
upload_protocol             = jlink

#
# BOARD_MKS_ROBIN_NANO_V1_3_F4
#  - MKS Robin Nano   V1.3 (STM32F407VET6, 5 Pololu Plug)
#  - MKS Robin Nano-S V1.3 (STM32F407VET6, 4 TMC2225, 1 Pololu Plug)
#  - ZNP Robin Nano   V1.3 (STM32F407VET6, 2 TMC2208, 2 A4988, 1x Polulu plug)
#
[env:mks_robin_nano_v1_3_f4]
extends       = mks_robin_nano_v1_3_f4_common
build_flags   = ${stm32_variant.build_flags}
                -DMCU_STM32F407VE -DENABLE_HWSERIAL3 -DSTM32_FLASH_SIZE=512
                -DTIMER_SERVO=TIM2 -DTIMER_TONE=TIM3 -DSS_TIMER=4
                -DHAL_SD_MODULE_ENABLED -DHAL_SRAM_MODULE_ENABLED
build_unflags = ${stm32_variant.build_unflags}
                -DUSBCON -DUSBD_USE_CDC

#
#  MKS/ZNP Robin Nano V1.3 with native USB mod
#
[env:mks_robin_nano_v1_3_f4_usbmod]
extends       = mks_robin_nano_v1_3_f4_common
build_flags   = ${stm32_variant.build_flags}
                -DMCU_STM32F407VE -DSTM32_FLASH_SIZE=512
                -DTIMER_SERVO=TIM2 -DTIMER_TONE=TIM3 -DSS_TIMER=4
                -DHAL_SD_MODULE_ENABLED -DHAL_SRAM_MODULE_ENABLED

#
# Artillery Ruby
#
[env:Artillery_Ruby]
extends       = common_stm32
board         = marlin_Artillery_Ruby
build_flags   = ${common_stm32.build_flags}
                -DSTM32F401xC -DTARGET_STM32F4 -DDISABLE_GENERIC_SERIALUSB -DARDUINO_ARCH_STM32
                -DUSBD_USE_CDC_COMPOSITE -DUSE_USB_FS
                -DUSB_PRODUCT=\"Artillery_3D_Printer\"
                -DFLASH_DATA_SECTOR=1U -DFLASH_BASE_ADDRESS=0x08004000
extra_scripts = ${common_stm32.extra_scripts}
                pre:buildroot/share/PlatformIO/scripts/generic_create_variant.py

#
# Ender-3 S1 STM32F401RC_creality
#
[STM32F401RC_creality_base]
extends                     = stm32_variant
board                       = genericSTM32F401RC
board_build.variant         = MARLIN_CREALITY_STM32F401RC
build_flags                 = ${stm32_variant.build_flags} -DMCU_STM32F401RC -DSTM32F4
                              -DSS_TIMER=4 -DTIMER_SERVO=TIM5
                              -DENABLE_HWSERIAL3 -DTRANSFER_CLOCK_DIV=8
build_unflags               = ${stm32_variant.build_unflags} -DUSBCON -DUSBD_USE_CDC
monitor_speed               = 115200

[env:STM32F401RC_creality]
extends                     = STM32F401RC_creality_base
board_build.offset          = 0x10000
board_upload.offset_address = 0x08010000
board_build.rename          = firmware-{date}-{time}.bin

[env:STM32F401RC_creality_nobootloader]
extends                     = STM32F401RC_creality_base
board_build.offset          = 0x0000
board_upload.offset_address = 0x08000000
debug_tool                  = stlink
upload_protocol             = stlink

[env:STM32F401RC_creality_jlink]
extends         = env:STM32F401RC_creality
debug_tool      = jlink
upload_protocol = jlink

[env:STM32F401RC_creality_stlink]
extends         = env:STM32F401RC_creality
debug_tool      = stlink
upload_protocol = stlink

#
# Ender-5 S1 STM32F401RE_creality (CR4NS200141C13 with STM32F401RET6)
#
[env:STM32F401RE_creality]
extends                     = stm32_variant
board                       = marlin_CREALITY_STM32F401RE
board_build.offset          = 0x10000
board_upload.offset_address = 0x08010000
board_build.rename          = firmware-{date}-{time}.bin
build_flags                 = ${stm32_variant.build_flags} -DSTM32F401xE -DSTM32F4 -DSTM32F4_UPDATE_FOLDER
build_unflags               = ${stm32_variant.build_unflags} -DUSBCON -DUSBD_USE_CDC
monitor_speed               = 115200

[env:STM32F401RE_creality_jlink]
extends         = env:STM32F401RE_creality
debug_tool      = jlink
upload_protocol = jlink

[env:STM32F401RE_creality_stlink]
extends         = env:STM32F401RE_creality
debug_tool      = stlink
upload_protocol = stlink

#
# STM32F401RE_freeruns  Creality E3 Free-runs Silent Motherboard
#
[env:STM32F401RE_freeruns]
extends                     = stm32_variant
board                       = marlin_STM32F401RE_freeruns
board_build.offset          = 0x10000
board_upload.offset_address = 0x08010000
board_build.rename          = firmware-{date}-{time}.bin
build_flags                 = ${stm32_variant.build_flags} -DSTM32F401xE
                              -DSS_TIMER=4 -DTIMER_SERVO=TIM5
                              -DTRANSFER_CLOCK_DIV=8
build_unflags               = ${stm32_variant.build_unflags} -DUSBCON -DUSBD_USE_CDC
monitor_speed               = 115200

[env:STM32F401RE_freeruns_jlink]
extends                     = env:STM32F401RE_freeruns
debug_tool                  = jlink
upload_protocol             = jlink

[env:STM32F401RE_freeruns_stlink]
extends                     = env:STM32F401RE_freeruns
debug_tool                  = stlink
upload_protocol             = stlink

#
# BigTree SKR mini E3 V3.0.1 (STM32F401RCT6 ARM Cortex-M4)
#
[env:STM32F401RC_btt]
extends                     = stm32_variant
platform                    = ststm32@~14.1.0
platform_packages           = framework-arduinoststm32@~4.20600.231001
                              toolchain-gccarmnoneeabi@1.100301.220327
board                       = marlin_STM32F401RC
board_build.offset          = 0x4000
board_upload.offset_address = 0x08004000
build_flags                 = ${stm32_variant.build_flags}
                              -DPIN_SERIAL6_RX=PC_7 -DPIN_SERIAL6_TX=PC_6
                              -DSERIAL_RX_BUFFER_SIZE=1024 -DSERIAL_TX_BUFFER_SIZE=1024
                              -DTIMER_SERVO=TIM3 -DTIMER_TONE=TIM4
                              -DSTEP_TIMER_IRQ_PRIO=0
upload_protocol             = stlink
debug_tool                  = stlink

#
# BigTreeTech SKR Mini E3 V3.0.1 (STM32F401RCT6 ARM Cortex-M0+)
# Custom upload to SD via Marlin with Binary Protocol
# Requires Marlin with BINARY_FILE_TRANSFER already installed on the target board.
# If CUSTOM_FIRMWARE_UPLOAD is also installed, Marlin will reboot the board to install the firmware.
# Currently CUSTOM_FIRMWARE_UPLOAD must also be enabled to use 'xfer' build envs.
#
[env:STM32F401RC_btt_xfer]
extends         = env:STM32F401RC_btt
build_flags     = ${env:STM32F401RC_btt.build_flags} -DXFER_BUILD
extra_scripts   = ${env:STM32F401RC_btt.extra_scripts}
                  pre:buildroot/share/scripts/upload.py
upload_protocol = custom

#
# MKS SKIPR v1.0 all-in-one board (STM32F407VE)
#
[env:mks_skipr_v1]
extends                     = stm32_variant
board                       = marlin_MKS_SKIPR_V1
board_build.rename          = mks_skipr.bin

[env:mks_skipr_v1_nobootloader]
extends                     = env:mks_skipr_v1
board_build.rename          = firmware.bin
board_build.offset          = 0x0000
board_upload.offset_address = 0x08000000
upload_protocol             = dfu
upload_command              = dfu-util -a 0 -s 0x08000000:leave -D "$SOURCE"

#
# TRONXY_CXY_446_V10 (STM32F446ZET6 ARM Cortex-M4)
#
[env:TRONXY_CXY_446_V10]
extends              = stm32_variant
board                = marlin_STM32F446ZET_tronxy
board_build.ldscript = buildroot/share/PlatformIO/variants/MARLIN_F446Zx_TRONXY/ldscript.ld
board_build.offset   = 0x10000
board_build.rename   = fmw_tronxy.bin
build_flags          = ${stm32_variant.build_flags}
                       -DSTM32F4xx -DUSE_USB_HS
                       -DUSE_USB_HS_IN_FS
build_unflags        = ${stm32_variant.build_unflags} -fno-rtti
                       -fno-threadsafe-statics -fno-exceptions
                       -DUSBD_USE_CDC -DUSBCON
extra_scripts        = ${stm32_variant.extra_scripts}
                       buildroot/share/PlatformIO/scripts/tronxy_cxy_446_v10.py

#
# TRONXY_CXY_446_V10 (STM32F446ZET6 ARM Cortex-M4) with USB Flash Drive Support
#
[env:TRONXY_CXY_446_V10_usb_flash_drive]
extends           = env:TRONXY_CXY_446_V10
platform_packages = ${stm_flash_drive.platform_packages}

#
# Blackpill
#
[env:STM32F401CD_blackpill_stlink]
platform        = ${common_stm32.platform}
extends         = common_stm32
board           = blackpill_f401cc
upload_protocol = stlink
monitor_speed   = 115200

#
# I3Dbeez9 (STM32F407ZGT6 ARM Cortex-M4)
#
[env:I3DBEEZ9_V1]
extends            = stm32_variant
board              = marlin_I3DBEEZ9
board_build.offset = 0x8000
build_flags        = ${stm32_variant.build_flags} -DSTM32F407_5ZX
debug_tool         = stlink
upload_protocol    = stlink

#
# BlackBeezMini (blackpill_f401cc)
#
[env:BLACKBEEZMINI_V1]
platform           = ststm32
extends            = common_stm32
board              = blackpill_f401cc
board_build.offset = 0x0000
build_flags        = ${common_stm32.build_flags}
                     -Os -DHAL_PCD_MODULE_ENABLED
                     -DHAL_UART_MODULE_ENABLED
monitor_speed      = 250000
upload_protocol    = dfu

#
# Mellow Fly E3 V2 (STM32F407VGT6 ARM Cortex-M4)
#
[env:FLY_E3_V2]
extends                     = stm32_variant
board                       = marlin_STM32F407VGT6_CCM
board_build.variant         = MARLIN_F4x7Vx
board_build.offset          = 0x8000
board_upload.offset_address = 0x08008000
build_flags                 = ${stm32_variant.build_flags}
                              -DHAVE_HWSERIAL1 -DHAVE_HWSERIAL3
                              -DPIN_SERIAL1_RX=PA_10 -DPIN_SERIAL1_TX=PA_9
                              -DPIN_SERIAL3_RX=PD_9 -DPIN_SERIAL3_TX=PD_8
                              -DHAL_SD_MODULE_ENABLED
                              -DUSE_USBHOST_HS -DUSE_USB_HS_IN_FS
                              -DUSBD_IRQ_PRIO=5 -DUSBD_IRQ_SUBPRIO=6
                              -DHSE_VALUE=8000000U
upload_protocol             = stlink

#
# XTLW3D Climber-8th-F4 (STM32F407VGT6 ARM Cortex-M4)
#
[env:XTLW_CLIMBER_8TH]
platform                    = ${common_stm32.platform}
extends                     = stm32_variant
platform_packages           = ${stm_flash_drive.platform_packages}
board                       = marlin_STM32F407VGT6_CCM
board_build.variant         = MARLIN_F4x7Vx
board_build.offset          = 0x8000
board_upload.offset_address = 0x08008000
build_flags                 = ${stm_flash_drive.build_flags}
                              -DUSE_USBHOST_HS -DUSE_USB_HS_IN_FS
                              -DUSBD_IRQ_PRIO=5 -DUSBD_IRQ_SUBPRIO=6
                              -DHSE_VALUE=8000000U -DHAL_SD_MODULE_ENABLED
                              -DPIN_SERIAL3_RX=PD_9 -DPIN_SERIAL3_TX=PD_8
