Skip to content

Commit fa1bf57

Browse files
committed
Enable export to uvision5 + armc6
1 parent 546dafb commit fa1bf57

File tree

3 files changed

+81
-36
lines changed

3 files changed

+81
-36
lines changed

tools/export/__init__.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,8 @@
3434
cdt, vscode, gnuarmeclipse, qtcreator, cmake, nb, cces, codeblocks)
3535

3636
EXPORTERS = {
37-
u'uvision5': uvision.Uvision,
37+
u'uvision6': uvision.UvisionArmc6,
38+
u'uvision5': uvision.UvisionArmc5,
3839
u'make_gcc_arm': makefile.GccArm,
3940
u'make_armc5': makefile.Armc5,
4041
u'make_armc6': makefile.Armc6,

tools/export/uvision/__init__.py

Lines changed: 71 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -118,8 +118,6 @@ class Uvision(Exporter):
118118
project file (.uvprojx).
119119
The needed information can be viewed in uvision.tmpl
120120
"""
121-
NAME = 'uvision5'
122-
TOOLCHAIN = 'ARM'
123121

124122
POST_BINARY_WHITELIST = set([
125123
"MCU_NRF51Code.binary_hook",
@@ -131,22 +129,6 @@ class Uvision(Exporter):
131129
"NCS36510TargetCode.ncs36510_addfib"
132130
])
133131

134-
@classmethod
135-
def is_target_supported(cls, target_name):
136-
target = TARGET_MAP[target_name]
137-
if not (set(target.supported_toolchains).intersection(
138-
set(["ARM", "uARM"]))):
139-
return False
140-
if not DeviceCMSIS.check_supported(target_name):
141-
return False
142-
if "Cortex-A" in target.core:
143-
return False
144-
if not hasattr(target, "post_binary_hook"):
145-
return True
146-
if target.post_binary_hook['function'] in cls.POST_BINARY_WHITELIST:
147-
return True
148-
else:
149-
return False
150132

151133
#File associations within .uvprojx file
152134
file_types = {'.cpp': 8, '.c': 1, '.s': 2,
@@ -177,22 +159,28 @@ def uv_files(self, files):
177159
def format_flags(self):
178160
"""Format toolchain flags for Uvision"""
179161
flags = copy.deepcopy(self.flags)
180-
# to be preprocessed with armcc
181162
asm_flag_string = (
182163
'--cpreproc --cpreproc_opts=-D__ASSERT_MSG,' +
183164
",".join(filter(lambda f: f.startswith("-D"), flags['asm_flags'])))
184165
flags['asm_flags'] = asm_flag_string
185-
# All non-asm flags are in one template field
186-
c_flags = list(set(flags['c_flags'] + flags['cxx_flags'] +flags['common_flags']))
187-
ld_flags = list(set(flags['ld_flags'] ))
188-
# These flags are in template to be set by user i n IDE
189-
template = ["--no_vla", "--cpp", "--c99"]
190-
# Flag is invalid if set in template
191-
# Optimizations are also set in the template
192-
invalid_flag = lambda x: x in template or re.match("-O(\d|time)", x)
193-
flags['c_flags'] = [flag.replace('"','\\"') for flag in c_flags if not invalid_flag(flag)]
194-
flags['c_flags'] = " ".join(flags['c_flags'])
195-
flags['ld_flags'] = " ".join(flags['ld_flags'])
166+
167+
c_flags = set(
168+
flags['c_flags'] + flags['cxx_flags'] + flags['common_flags']
169+
)
170+
in_template = set(
171+
["--no_vla", "--cpp", "--c99", "-std=gnu99", "-std=g++98"]
172+
)
173+
174+
def valid_flag(x):
175+
return x not in in_template or not x.startswith("-O")
176+
177+
def is_define(s):
178+
return s.startswith("-D")
179+
180+
flags['c_flags'] = " ".join(f.replace('"', '\\"') for f in c_flags
181+
if (valid_flag(f) and not is_define(f)))
182+
flags['c_defines'] = " ".join(f[2:] for f in c_flags if is_define(f))
183+
flags['ld_flags'] = " ".join(set(flags['ld_flags']))
196184
return flags
197185

198186
def format_src(self, srcs):
@@ -244,6 +232,8 @@ def generate(self):
244232
else:
245233
ctx['fpu_setting'] = 1
246234
ctx['fputype'] = self.format_fpu(core)
235+
ctx['armc6'] = int(self.TOOLCHAIN is 'ARMC6')
236+
ctx['toolchain_name'] = self.TOOLCHAIN_NAME
247237
ctx.update(self.format_flags())
248238
self.gen_file('uvision/uvision.tmpl', ctx, self.project_name+".uvprojx")
249239
self.gen_file('uvision/uvision_debug.tmpl', ctx, self.project_name + ".uvoptx")
@@ -285,3 +275,54 @@ def build(project_name, log_name='build_log.txt', cleanup=True):
285275
return -1
286276
else:
287277
return 0
278+
279+
class UvisionArmc5(Uvision):
280+
NAME = 'uvision5-armc5'
281+
TOOLCHAIN = 'ARM'
282+
TOOLCHAIN_NAME = ''
283+
284+
@classmethod
285+
def is_target_supported(cls, target_name):
286+
target = TARGET_MAP[target_name]
287+
if not (set(target.supported_toolchains).intersection(
288+
set(["ARM", "uARM"]))):
289+
return False
290+
if not DeviceCMSIS.check_supported(target_name):
291+
return False
292+
if "Cortex-A" in target.core:
293+
return False
294+
if not hasattr(target, "post_binary_hook"):
295+
return True
296+
if target.post_binary_hook['function'] in cls.POST_BINARY_WHITELIST:
297+
return True
298+
else:
299+
return False
300+
301+
@classmethod
302+
def is_target_supported(cls, target_name):
303+
target = TARGET_MAP[target_name]
304+
return apply_supported_whitelist(
305+
cls.TOOLCHAIN, cls.POST_BINARY_WHITELIST, target) and\
306+
DeviceCMSIS.check_supported(target_name)
307+
308+
class UvisionArmc6(Uvision):
309+
NAME = 'uvision5-armc6'
310+
TOOLCHAIN = 'ARMC6'
311+
TOOLCHAIN_NAME = '6070000::V6.7::.\ARMCLANG'
312+
313+
@classmethod
314+
def is_target_supported(cls, target_name):
315+
target = TARGET_MAP[target_name]
316+
if not (set(target.supported_toolchains).intersection(
317+
set(["ARMC6"]))):
318+
return False
319+
if not DeviceCMSIS.check_supported(target_name):
320+
return False
321+
if "Cortex-A" in target.core:
322+
return False
323+
if not hasattr(target, "post_binary_hook"):
324+
return True
325+
if target.post_binary_hook['function'] in cls.POST_BINARY_WHITELIST:
326+
return True
327+
else:
328+
return False

tools/export/uvision/uvision.tmpl

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,10 @@
1010
<TargetName>{{name}}</TargetName>
1111
<ToolsetNumber>0x4</ToolsetNumber>
1212
<ToolsetName>ARM-ADS</ToolsetName>
13+
{% if toolchain_name %}
14+
<pCCUsed>{{toolchain_name}}</pCCUsed>
15+
{% endif %}
16+
<uAC6>{{armc6}}</uAC6>
1317
<TargetOption>
1418
<TargetCommonOption>
1519
<Device>{{device.dname}}</Device>
@@ -354,7 +358,7 @@
354358
<Optim>1</Optim>
355359
<oTime>0</oTime>
356360
<SplitLS>0</SplitLS>
357-
<OneElfS>0</OneElfS>
361+
<OneElfS>1</OneElfS>
358362
<Strict>0</Strict>
359363
<EnumInt>0</EnumInt>
360364
<PlainCh>0</PlainCh>
@@ -365,16 +369,16 @@
365369
<uSurpInc>0</uSurpInc>
366370
<uC99>1</uC99>
367371
<useXO>0</useXO>
368-
<v6Lang>1</v6Lang>
369-
<v6LangP>1</v6LangP>
372+
<v6Lang>4</v6Lang>
373+
<v6LangP>2</v6LangP>
370374
<vShortEn>1</vShortEn>
371375
<vShortWch>1</vShortWch>
372376
<v6Lto>0</v6Lto>
373377
<v6WtE>0</v6WtE>
374378
<v6Rtti>0</v6Rtti>
375379
<VariousControls>
376380
<MiscControls>{{c_flags}}</MiscControls>
377-
<Define></Define>
381+
<Define>{{c_defines}}</Define>
378382
<Undefine></Undefine>
379383
<IncludePath>{{include_paths}}</IncludePath>
380384
</VariousControls>
@@ -434,5 +438,4 @@
434438
</Groups>
435439
</Target>
436440
</Targets>
437-
438441
</Project>

0 commit comments

Comments
 (0)