-
Notifications
You must be signed in to change notification settings - Fork 0
/
CompilerFlags.py
113 lines (103 loc) · 2.99 KB
/
CompilerFlags.py
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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
# This file sets additional flags that cannot be set from platformio.ini itself
# these can be for the compiler or for the linker
import configparser
import subprocess
import re
# load build environment
print("\n==================== CompilerFlags.py ====================")
l = lambda *args, **kwargs : print("[CompilerFlags.py]", *args, **kwargs)
Import("env")
# read settings from platform.ini to also include
conf = configparser.ConfigParser()
conf.read("platformio.ini")
env_name = "env:" + env.subst("$PIOENV")
opt = conf.get(env_name, "optimization")
git_branch_name = subprocess.check_output(['git', 'rev-parse', '--abbrev-ref', 'HEAD']).decode('ascii').strip()
git_commit_date = subprocess.check_output(['git', 'show', '-s', '--date=format:%d/%m/%Y', '--format=%cd', 'HEAD']).decode('ascii').strip()
git_commit_hash = subprocess.check_output(['git', 'show', '-s', '--format=%h', 'HEAD']).decode('ascii').strip()
git_commit_msg = subprocess.check_output(['git', 'show', '-s', '--format=%s', 'HEAD']).decode('ascii').strip()
git_string = f"{git_branch_name} {git_commit_hash} | {git_commit_date} | {git_commit_msg}"
git_string = re.sub('-', '_', git_string)
git_string = re.sub(r'[^a-zA-Z0-9 /_.]', '', git_string)
l(git_string)
#STMF767 microcontroller
if (env_name == "env:top_board"):
# compiler settings
env.Append(
CCFLAGS=[
f"-D__GIT_STRING__={git_string}",
f"-D__GIT_DEVELOPMENT__=\"{[0, 1][git_branch_name == 'main']}\"",
opt,
# "-std=c11",
# "-g3",
"-Wall",
# "-Wextra",
# "-Wconversion",
# "-pedantic",
"-mcpu=cortex-m7",
"-mfloat-abi=hard",
"-mfpu=fpv5-sp-d16",
"-D ARM_MATH_CM7",
"-DARM_MATH_MATRIX_CHECK",
"-D __FPU_PRESENT",
"-mthumb",
"-mthumb-interwork",
"-ffunction-sections",
"-fdata-sections",
"-fmessage-length=0",
"-specs=nosys.specs",
"-specs=nano.specs",
"-DUSE_HAL_DRIVER",
"-DSTM32F767xx",
]
)
# linker settings
env.Append(
LINKFLAGS=[
opt,
"-mfloat-abi=hard",
"-mfpu=fpv5-sp-d16",
"-Wl,-u,_printf_float,-u,_scanf_float"
]
)
#STMF303 microcontroller
else:
# compiler settings
env.Append(
CCFLAGS=[
f"-D__GIT_STRING__={git_string}",
f"-D__GIT_DEVELOPMENT__=\"{[0, 1][git_branch_name == 'main']}\"",
opt,
# "-std=c11",
# "-g3",
"-Wall",
# "-Wextra",
# "-Wconversion",
# "-pedantic",
"-mcpu=cortex-m4",
"-mfloat-abi=hard",
"-mfpu=fpv4-sp-d16",
"-D ARM_MATH_CM4",
"-DARM_MATH_MATRIX_CHECK",
"-D __FPU_PRESENT",
"-mthumb",
"-mthumb-interwork",
"-ffunction-sections",
"-fdata-sections",
"-fmessage-length=0",
"-specs=nosys.specs",
"-specs=nano.specs",
"-DUSE_HAL_DRIVER",
"-DSTM32F303x8",
]
)
# linker settings
env.Append(
LINKFLAGS=[
opt,
"-mfloat-abi=hard",
"-mfpu=fpv4-sp-d16",
"-Wl,-u,_printf_float,-u,_scanf_float"
]
)
print("\n")