Skip to content

Commit cfa4d0c

Browse files
authored
Merge pull request #1938 from 0xc0170/fix_iar
Fix iar exporter - flags duplication and consolidations
2 parents bbb5070 + 69c3da5 commit cfa4d0c

File tree

3 files changed

+23
-15
lines changed

3 files changed

+23
-15
lines changed

tools/export/iar.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020

2121
from tools.export.exporters import Exporter
2222
from tools.targets import TARGET_MAP, TARGET_NAMES
23+
from tools.settings import IAR_PATH
2324

2425
# If you wish to add a new target, add it to project_generator_definitions, and then
2526
# define progen_target name in the target class (`` self.progen_target = 'my_target_name' ``)
@@ -70,6 +71,15 @@ def generate(self):
7071
project_data['tool_specific']['iar'].setdefault("misc", {})
7172
project_data['tool_specific']['iar'].update(tool_specific['iar'])
7273
project_data['tool_specific']['iar']['misc'].update(self.progen_flags)
74+
# progen does not have common flags, expand c flags by common one
75+
project_data['tool_specific']['iar']['misc']['c_flags'] += self.progen_flags['common_flags']
76+
# template sets full dlib, this would produce the error as it's duplicate
77+
project_data['tool_specific']['iar']['misc']['c_flags'].remove("--dlib_config")
78+
project_data['tool_specific']['iar']['misc']['c_flags'].remove(os.path.join(IAR_PATH, "inc", "c", "DLib_Config_Full.h"))
79+
# these c++ flags are set by template - c++, no rtti, no exceptions
80+
project_data['tool_specific']['iar']['misc']['cxx_flags'].remove("--c++")
81+
project_data['tool_specific']['iar']['misc']['cxx_flags'].remove("--no_rtti")
82+
project_data['tool_specific']['iar']['misc']['cxx_flags'].remove("--no_exceptions")
7383
project_data['common']['build_dir'] = os.path.join(project_data['common']['build_dir'], 'iar_arm')
7484
self.progen_gen_file('iar_arm', project_data)
7585

tools/export/iar_template.ewp.tmpl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -622,8 +622,8 @@
622622
<debug>1</debug>
623623
<option>
624624
<name>OOCOutputFormat</name>
625-
<version>2</version>
626-
<state>2</state>
625+
<version>3</version>
626+
<state>3</state>
627627
</option>
628628
<option>
629629
<name>OCOutputOverride</name>

tools/toolchains/iar.py

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,11 @@ class IAR(mbedToolchain):
3838
# Pa093: Implicit conversion from float to integer (ie: wait_ms(85.4) -> wait_ms(85))
3939
# Pa082: Operation involving two values from two registers (ie: (float)(*obj->MR)/(float)(LPC_PWM1->MR0))
4040
"-e", # Enable IAR language extension
41-
"--diag_suppress=Pa050,Pa084,Pa093,Pa082"],
41+
"--diag_suppress=Pa050,Pa084,Pa093,Pa082",
42+
"--thumb",
43+
"--dlib_config", join(IAR_PATH, "inc", "c", "DLib_Config_Full.h")],
4244
'asm': [],
43-
'c': ["--vla"],
45+
'c': [],
4446
'cxx': ["--c++", "--no_rtti", "--no_exceptions", "--guard_calls"],
4547
'ld': ["--skip_dynamic_initialization", "--threaded_lib"],
4648
}
@@ -51,35 +53,31 @@ def __init__(self, target, options=None, notify=None, macros=None, silent=False,
5153
cpuchoice = "Cortex-M7"
5254
else:
5355
cpuchoice = target.core
54-
self.flags["common"] += [
55-
"--cpu=%s" % cpuchoice, "--thumb",
56-
"--dlib_config", join(IAR_PATH, "inc", "c", "DLib_Config_Full.h"),
57-
]
5856

5957
if target.core == "Cortex-M7F":
6058
self.flags["common"].append("--fpu=VFPv5_sp")
6159

60+
optimization = []
6261
if "debug-info" in self.options:
63-
self.flags["common"].append("-r")
64-
self.flags["common"].append("-On")
62+
optimization.append("-r")
63+
optimization.append("-On")
6564
else:
66-
self.flags["common"].append("-Oh")
65+
optimization.append("-Oh")
6766

6867
IAR_BIN = join(IAR_PATH, "bin")
6968
main_cc = join(IAR_BIN, "iccarm")
7069

71-
self.flags["asm"] += ["--cpu", cpuchoice]
7270
if target.core == "Cortex-M7F":
7371
self.flags["asm"] += ["--fpu", "VFPv5_sp"]
74-
self.asm = [join(IAR_BIN, "iasmarm")] + self.flags["asm"]
72+
self.asm = [join(IAR_BIN, "iasmarm")] + self.flags["asm"] + ["--cpu=%s" % cpuchoice]
7573
if not "analyze" in self.options:
7674
self.cc = [main_cc]
7775
self.cppc = [main_cc]
7876
else:
7977
self.cc = [join(GOANNA_PATH, "goannacc"), '--with-cc="%s"' % main_cc.replace('\\', '/'), "--dialect=iar-arm", '--output-format="%s"' % self.GOANNA_FORMAT]
8078
self.cppc = [join(GOANNA_PATH, "goannac++"), '--with-cxx="%s"' % main_cc.replace('\\', '/'), "--dialect=iar-arm", '--output-format="%s"' % self.GOANNA_FORMAT]
81-
self.cc += self.flags["common"] + self.flags["c"]
82-
self.cppc += self.flags["common"] + self.flags["cxx"]
79+
self.cc += self.flags["common"] + self.flags["c"] + ["--cpu=%s" % cpuchoice] + optimization
80+
self.cppc += self.flags["common"] + self.flags["cxx"] + ["--cpu=%s" % cpuchoice] + optimization
8381
self.ld = join(IAR_BIN, "ilinkarm")
8482
self.ar = join(IAR_BIN, "iarchive")
8583
self.elf2bin = join(IAR_BIN, "ielftool")

0 commit comments

Comments
 (0)