#
# 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.1.1.zip
platform_packages = framework-hc32f46x-ddl@https://github.com/shadow578/framework-hc32f46x-ddl/archive/2.2.3.zip
                    framework-arduino-hc32f46x@https://github.com/shadow578/framework-arduino-hc32f46x/archive/1.2.0.zip
board             = generic_hc32f460
build_src_filter  = ${common.default_src_filter} +<src/HAL/HC32> +<src/HAL/shared/backtrace>
build_type        = release
build_flags       = -DARDUINO_ARCH_HC32
                    -DPLATFORM_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 char. 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_upload.maximum_size = 262144

#
# Base HC32F460xExx (512K Flash)
#
[HC32F460E_base]
extends = HC32F460_base
board_upload.maximum_size = 524288

#
# 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_upload.offset_address = 0xC000  # Bootloader start address, as logged by the bootloader on boot
board_build.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_upload.offset_address = 0x8000
