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.flags.optimize=-Os
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

compiler.extra_flags = -march=rv32imc_zicsr_zifencei -mabi=ilp32 -mcmodel=medlow {build.flags.optimize} -g3 -Wall -fsigned-char -ffunction-sections
compiler.S.flags     = {compiler.extra_flags} -x assembler-with-cpp {compiler.define} {compiler.warning_flags} {compiler.MIK32_Amur.extra_include}
compiler.c.flags     = -c -std=gnu11 {compiler.extra_flags} {compiler.define} {compiler.warning_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 {compiler.extra_flags} {compiler.define} {compiler.warning_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]+).*

# 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=

# 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=

# For Tools > Burn Bootloader 
tools.mik32_upload.bootloader.pattern={path}/{cmd} {runtime.platform.path}/bootloaders/{bootloader.file} --run-openocd --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 --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=
