#
# Marlin Firmware
# PlatformIO Configuration File
#

#################################
#
# HC32F460 Architecture with unified HC32 HAL
#
# Naming Example: HC32F460JEUA
#
# |- Xiaohua Semiconductor
# |  |- CPU bit width (32: 32-bit)
# |  |  |- Product Type (F: Universal MCU)
# |  |  | |- Core Type (4: Cortex-M4)
# |  |  | | |- Performance (6: High Performance)
# |  |  | | | |- Configuration (0: Configuration 1)
# |  |  | | | | |- Pin Count (J: 48, K: 60/64, P: 100)
# |  |  | | | | | |- Flash Capacity (C: 256KB, E: 512KB)
# |  |  | | | | | | |- Package (T: LQFP, U: QFN, H:VFBGA)
# |  |  | | | | | | | |- Temperature range (A: -40-85°C, B: -40-105°C)
# HC 32 F 4 6 0 J E U A
#
#################################

#
# Base Environment for all HC32F460 variants
#
[HC32F460_base]
platform         = https://github.com/shadow578/platform-hc32f46x/archive/1.0.0.zip
board            = generic_hc32f460
build_src_filter = ${common.default_src_filter} +<src/HAL/HC32> +<src/HAL/shared/backtrace>
build_type       = release
build_flags      =
  -D ARDUINO_ARCH_HC32
  -D PLATFORM_M997_SUPPORT  # Enable M997 command
                            # note: ddl and arduino debug mode are
                            # automatically enabled with MARLIN_DEV_MODE
  #-D __DEBUG               # force DDL debug mode
  #-D __CORE_DEBUG          # force Arduino core debug mode

# hc32 app configuration file
board_build.app_config = Marlin/src/HAL/HC32/app_config.h

# Drivers and Middleware required by the HC32 HAL
board_build.ddl.ots    = true
board_build.ddl.sdioc  = true
board_build.ddl.wdt    = true
board_build.ddl.timer0 = true
board_build.ddl.timera = true
board_build.mw.sd_card = true

# extra build flags
board_build.flags.common =
  -g3                     # Force emit debug symbols to elf. this does not affect the final binary size
  -fno-signed-char        # Force unsigned chars. this is required for meatpack to work

# Additional flags to reduce binary size
board_build.flags.cpp =
  -fno-threadsafe-statics # Disable thread-safe statics (only one core anyway)
  -fno-exceptions         # Disable exceptions (not used by marlin)
  -fno-rtti               # Disable RTTI (not used by marlin)

#
# Base HC32F460xCxx (256K Flash)
#
[HC32F460C_base]
extends = HC32F460_base
board_build.ld_args.flash_size = 256K

#
# Base HC32F460xExx (512K Flash)
#
[HC32F460E_base]
extends = HC32F460_base
board_build.ld_args.flash_size = 512K

#
# Voxelab Aquila V1.0.0/V1.0.1/V1.0.2/V1.0.3 as found in the Voxelab Aquila X2 & C2
#
[env:HC32F460C_aquila_101]
extends = HC32F460C_base
board_build.ld_args.flash_start = 0xC000    # Bootloader start address, as logged by the bootloader on boot
board_build.ld_args.boot_mode = secondary   # Save ~1.4k of flash by compiling as secondary firmware

#
# Creality Ender 2 Pro v2.4.S4_170 (HC32f460kcta) (256K Flash, 192K RAM).
#
[env:HC32F460C_e2p24s4]
extends = HC32F460C_base
board_build.ld_args.flash_start = 0x8000