-
Notifications
You must be signed in to change notification settings - Fork 0
/
config.nims
73 lines (54 loc) · 2.48 KB
/
config.nims
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
import std/os
import std/strformat
import std/strutils
const
samd21Variant* = "SAMD21G18A"
samd21Family* = "samd21" & samd21Variant[^1].toLowerAscii
switch("outdir", "./build")
# For Mac OSX, where gcc is not the default C compiler for Nim
switch("cc", "gcc")
# Cross-compiler toolchain set-up
switch("arm.any.gcc.exe", "arm-none-eabi-gcc")
switch("arm.any.gcc.linkerexe", "arm-none-eabi-gcc")
switch("arm.any.gcc.options.always", "-w -fmax-errors=3 -mthumb -mcpu=cortex-m0plus")
switch("arm.any.gcc.options.linker", "-mthumb -mcpu=cortex-m0plus --specs=nano.specs --specs=nosys.specs")
task build, "Build for MCU target":
switch("os", "any")
switch("cpu", "arm")
switch("threads", "off")
switch("define", "danger")
switch("define", "useMalloc")
switch("define", "noSignalHandler")
switch("opt", "size")
switch("mm", "arc")
# Place each function in its own section, which allows the linker to
# eliminate unused sections. See --gc-sections link flag
switch("passC", "-ffunction-sections -fdata-sections")
# This is used by the startup.nim module to emit a {.compile.} pragma in order
# to compile the startup_{device}.c file. The startup file requires setting a C
# define for the MCU variant.
const startupFile = joinPath("lib", "atmel", samd21Family, "gcc", "gcc", "startup_samd21.c")
switch("define", "startupFile:" & startupFile)
# Required by samd21.h to select the device-specific header.
# samd21.h is included by the startup_{device}.c file, which is required for
# initialization.
switch("passC", "-D__" & samd21Variant.toUpperAscii & "__")
# Specific to samd21g18a.h header, prevents including system header
switch("passC", "-DDONT_USE_CMSIS_INIT")
# Include dirs so that CMSIS and atmel headers are found
switch("passC", "-I./lib/CMSIS/Core/Include")
switch("passC", "-I" & joinPath("lib", "atmel", samd21Family, "include"))
# Eliminate unused code sections at link time
switch("passL", "-Wl,--gc-sections")
# Generate linker map file with cross-references
switch("passL", "-Wl,-Map=build/main.map -Wl,--cref")
# Linker script
const linkerScript = &"./lib/linker/{samd21Variant.toLowerAscii}.ld"
switch("passL", "-T" & linkerScript)
setCommand "c", "src/main.nim"
task objcopy, "Convert build output to .bin image for flashing":
exec "arm-none-eabi-objcopy -O binary build/main build/main.bin"
exec "arm-none-eabi-size -G build/main"
task bin, "Compile and create .bin image for flashing":
selfExec "build"
selfExec "objcopy"