name=MIK32 Boards
version=0.1.0

# Compiler and tools
compiler.prefix=riscv-none-elf-
compiler.path={runtime.tools.riscv.path}/bin/
compiler.c.cmd={compiler.prefix}gcc
compiler.cpp.cmd={compiler.prefix}g++
compiler.S.cmd={compiler.prefix}gcc
compiler.c.elf.cmd={compiler.prefix}g++
compiler.ar.cmd={compiler.prefix}gcc-ar
compiler.size.cmd={compiler.prefix}size
compiler.objcopy.cmd={compiler.prefix}objcopy
compiler.elf2hex.cmd={compiler.prefix}objcopy

# Include directories and defines
compiler.MIK32_Amur.extra_include= "-I{build.core.path}/avr/" "-I{build.core.path}/mik32/shared/include/" "-I{build.core.path}/mik32/shared/periphery/" "-I{build.core.path}/mik32/shared/runtime/" "-I{build.core.path}/mik32/shared/libs/" "-I{build.core.path}/mik32/hal/core/Include/" "-I{build.core.path}/mik32/hal/peripherals/Include/" "-I{build.core.path}/mik32/hal/utilities/Include/"
compiler.define="-DMCU_{build.mcu}" "-DF_CPU={build.f_cpu}" "-DARDUINO={runtime.ide.version}" "-DARDUINO_{build.board}" "-DARDUINO_ARCH_{build.arch}" "-DMIK32V2" "-D__ARDUINO_ARC__" "-D__CPU_ARC__"

build.ldscript=spifi_cpp.ld

# Compiler flags
compiler.warning_flags=-Wunused -Wuninitialized
compiler.warning_flags.none=-w
compiler.warning_flags.default=
compiler.warning_flags.more=-Wall
compiler.warning_flags.all=-Wall -Wextra

# EXPERIMENTAL feature: optimization flags
#  - this is alpha and may be subject to change without notice
compiler.optimization_flags=-Os
compiler.optimization_flags.release=-Os
compiler.optimization_flags.debug=-Og -g3

compiler.extra_flags = -march=rv32imc_zicsr_zifencei -mabi=ilp32 -mcmodel=medlow -Wall -fsigned-char -ffunction-sections
compiler.S.flags     = {compiler.extra_flags} -x assembler-with-cpp {compiler.define} "-I{runtime.platform.path}/libraries/FreeRTOS/src" {compiler.optimization_flags} {compiler.warning_flags} {compiler.MIK32_Amur.extra_include}
compiler.c.flags     = -c -std=gnu11 -Werror=return-type {compiler.extra_flags} {compiler.define} {compiler.warning_flags} {compiler.optimization_flags} {compiler.MIK32_Amur.extra_include}
compiler.cpp.flags   = -c -std=gnu++17 -fabi-version=0 -fno-exceptions -fno-rtti -fno-use-cxa-atexit -fno-threadsafe-statics -Werror=return-type {compiler.extra_flags} {compiler.define} {compiler.warning_flags} {compiler.optimization_flags} {compiler.MIK32_Amur.extra_include}
compiler.c.elf.flags = -march=rv32imc_zicsr_zifencei -mabi=ilp32 -mcmodel=medlow -nostartfiles -Xlinker
compiler.ar.flags=rc
compiler.elf2bin.flags=-O binary
compiler.elf2hex.flags=-O ihex

# Compiler recipes
recipe.c.o.pattern=  "{compiler.path}{compiler.c.cmd}"   {compiler.c.flags}   {build.extra_flags} {includes} "{source_file}" -o "{object_file}"
recipe.cpp.o.pattern="{compiler.path}{compiler.cpp.cmd}" {compiler.cpp.flags} {build.extra_flags} {includes} "{source_file}" -o "{object_file}"
recipe.S.o.pattern=  "{compiler.path}{compiler.S.cmd}"   {compiler.S.flags}   {build.extra_flags} {includes} "{source_file}" -c -o "{object_file}"

# Archiving
archive_file_path={build.path}/{archive_file}
recipe.ar.pattern="{compiler.path}{compiler.ar.cmd}" {compiler.ar.flags} "{archive_file_path}" "{object_file}"

# Combine gc-sections, archives, and objects
recipe.c.combine.pattern= "{compiler.path}{compiler.c.elf.cmd}" -o "{build.path}/{build.project_name}.elf" -T "{build.core.path}/mik32/shared/ldscripts/{build.ldscript}" {compiler.c.elf.flags} "-Map={build.path}/{build.project_name}.map" -Wl,--gc-sections -Wl,--no-warn-rwx-segments "-L{build.path}" -Wl,--start-group {object_files} -Wl,--whole-archive "{archive_file_path}" -Wl,--no-whole-archive -lc -Wl,--end-group 

# Create output (.bin file)
recipe.objcopy.bin.pattern="{compiler.path}{compiler.objcopy.cmd}" {compiler.elf2bin.flags} "{build.path}/{build.project_name}.elf" "{build.path}/{build.project_name}.bin"

# Create output (.hex file)
recipe.objcopy.hex.pattern="{compiler.path}{compiler.objcopy.cmd}" {compiler.elf2hex.flags} "{build.path}/{build.project_name}.elf" "{build.path}/{build.project_name}.hex"

# Size calculation
recipe.size.pattern="{compiler.path}{compiler.size.cmd}" -A "{build.path}/{build.project_name}.elf"
recipe.size.regex=      ^(?:\.text|\.data|\.rodata)\s+([0-9]+).*
recipe.size.regex.data= ^(?:\.data|\.bss|\.noinit)\s+([0-9]+).*

# Debugger configuration (general options)
# ----------------------------------------
# EXPERIMENTAL feature:
#  - this is alpha and may be subject to change without notice

debug_config.mik32.cortex-debug.custom.name=Arduino on Mik32
debug_config.mik32.cortex-debug.custom.overrideLaunchCommands.0=set mem inaccessible-by-default off
debug_config.mik32.cortex-debug.custom.overrideLaunchCommands.1=mem 0x01000000 0x01002000 ro
debug_config.mik32.cortex-debug.custom.overrideLaunchCommands.2=mem 0x80000000 0xffffffff ro
debug_config.mik32.cortex-debug.custom.overrideLaunchCommands.3=set arch riscv:rv32
debug_config.mik32.cortex-debug.custom.overrideLaunchCommands.4=set remotetimeout 10
debug_config.mik32.cortex-debug.custom.overrideLaunchCommands.5=set remote hardware-breakpoint-limit 2
debug_config.mik32.cortex-debug.custom.overrideLaunchCommands.6=thb setup 
debug_config.mik32.cortex-debug.custom.overrideLaunchCommands.7=monitor reset
debug_config.mik32.cortex-debug.custom.overrideLaunchCommands.8=monitor halt
debug_config.mik32.cortex-debug.custom.overrideLaunchCommands.9=monitor gdb sync

debug_config.mik32.cortex-debug.custom.overrideRestartCommands.0=thb setup 
debug_config.mik32.cortex-debug.custom.overrideRestartCommands.1=monitor reset
debug_config.mik32.cortex-debug.custom.overrideRestartCommands.2=monitor halt
debug_config.mik32.cortex-debug.custom.overrideRestartCommands.3=monitor gdb sync

debug.executable={build.path}/{build.project_name}.elf
debug.svd_file={runtime.platform.path}/cores/arduino/mik32/shared/svd/mik32v2.svd

debug.toolchain=gcc
debug.toolchain.path={runtime.tools.riscv.path}/bin/
debug.toolchain.prefix=riscv-none-elf-

debug.server=openocd
debug.server.openocd.path={runtime.tools.openocd.path}/bin/openocd
debug.server.openocd.scripts_dir={runtime.tools.mik32_upload.path}/openocd-scripts/
debug.server.openocd.scripts.0={debug.server.openocd.scripts_dir}/interface/{bootloader.interface}
debug.server.openocd.scripts.1={debug.server.openocd.scripts_dir}/target/mik32.cfg

debug.additional_config=debug_config.mik32

# Uploader tool
tools.elbear_uploader.cmd=elbear_uploader
tools.elbear_uploader.cmd.windows=elbear_uploader.exe 
tools.elbear_uploader.path={runtime.tools.elbear_uploader.path}
tools.elbear_uploader.upload.pattern="{path}/{cmd}" "{build.path}/{build.project_name}.hex" --com={serial.port} --baudrate={upload.speed}
tools.elbear_uploader.upload.params.quiet=
tools.elbear_uploader.upload.params.verbose=

# Set elbear_uploader as programmer
programmers.elbear_uploader.name=Elbear Uploader
programmers.elbear_uploader.program.tool=elbear_uploader

# Bootloader tool
tools.mik32_upload.cmd=mik32_upload
tools.mik32_upload.cmd.windows=mik32_upload.exe 
tools.mik32_upload.cmd.extension=
tools.mik32_upload.cmd.extension.windows=.exe
tools.mik32_upload.path={runtime.tools.mik32_upload.path}

# Bootloader can not be burnt if there is no erase command, even if it's empty
tools.mik32_upload.erase.pattern=
tools.mik32_upload.erase.params.quiet=
tools.mik32_upload.erase.params.verbose=

# For Tools > Burn Bootloader 
tools.mik32_upload.bootloader.pattern="{path}/{cmd}" "{runtime.platform.path}/bootloaders/{bootloader.file}" --run-openocd --no-driver --openocd-exec "{runtime.tools.openocd.path}/bin/openocd{cmd.extension}" --openocd-interface "{path}/openocd-scripts/interface/{bootloader.interface}" --openocd-target "{path}/openocd-scripts/target/mik32.cfg"
tools.mik32_upload.bootloader.params.quiet=

# For Sketch > Upload Using Programmer
tools.mik32_upload.program.pattern="{path}/{cmd}" "{build.path}/{build.project_name}.hex" --run-openocd --no-driver --openocd-exec "{runtime.tools.openocd.path}/bin/openocd{cmd.extension}" --openocd-interface "{path}/openocd-scripts/interface/{bootloader.interface}" --openocd-target "{path}/openocd-scripts/target/mik32.cfg"
tools.mik32_upload.program.params.quiet=
tools.mik32_upload.program.params.verbose=