Skip to content

Commit c51467e

Browse files
committed
Flake8 of uvision exporter python code
1 parent 11702d1 commit c51467e

File tree

1 file changed

+51
-38
lines changed

1 file changed

+51
-38
lines changed

tools/export/uvision/__init__.py

Lines changed: 51 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
from builtins import str
33

44
import os
5-
from os.path import sep, normpath, join, exists, dirname
5+
from os.path import normpath, exists, dirname
66
import ntpath
77
import copy
88
from collections import namedtuple
@@ -11,11 +11,11 @@
1111
import re
1212

1313
from tools.resources import FileType
14-
from tools.arm_pack_manager import Cache
1514
from tools.targets import TARGET_MAP
16-
from tools.export.exporters import Exporter, apply_supported_whitelist
15+
from tools.export.exporters import Exporter
1716
from tools.export.cmsis import DeviceCMSIS
1817

18+
1919
class DeviceUvision(DeviceCMSIS):
2020
"""Uvision Device class, inherits CMSIS Device class
2121
@@ -32,7 +32,7 @@ def __init__(self, target):
3232

3333
def uv_debug(self):
3434
"""Return a namedtuple of information about uvision debug settings"""
35-
UVDebug = namedtuple('UVDebug',['bin_loc','core_flag', 'key'])
35+
UVDebug = namedtuple('UVDebug', ['bin_loc', 'core_flag', 'key'])
3636

3737
# CortexMXn => pCMX
3838
cpu = self.core.replace("Cortex-", "C")
@@ -42,10 +42,13 @@ def uv_debug(self):
4242
cpu_flag = "p"+cpu
4343

4444
# Locations found in Keil_v5/TOOLS.INI
45-
debuggers = {"st-link": ('STLink\\ST-LINKIII-KEIL_SWO.dll', 'ST-LINKIII-KEIL_SWO'),
46-
"j-link":('Segger\\JL2CM3.dll', 'JL2CM3'),
47-
"cmsis-dap":('BIN\\CMSIS_AGDI.dll', 'CMSIS_AGDI'),
48-
"nulink":('NULink\\Nu_Link.dll','Nu_Link')}
45+
debuggers = {
46+
"st-link": ('STLink\\ST-LINKIII-KEIL_SWO.dll',
47+
'ST-LINKIII-KEIL_SWO'),
48+
"j-link": ('Segger\\JL2CM3.dll', 'JL2CM3'),
49+
"cmsis-dap": ('BIN\\CMSIS_AGDI.dll', 'CMSIS_AGDI'),
50+
"nulink": ('NULink\\Nu_Link.dll', 'Nu_Link')
51+
}
4952
res = debuggers[self.debug.lower()]
5053
binary = res[0]
5154
key = res[1]
@@ -57,7 +60,7 @@ def generate_flash_dll(self):
5760
S = SW/JTAG Clock ID
5861
C = CPU index in JTAG chain
5962
P = Access Port
60-
For the Options for Target -> Debug tab -> settings -> "Flash" tab in the dialog:
63+
For the Options for Target -> Debug -> settings -> "Flash" dialog:
6164
FD = RAM Start for Flash Functions
6265
FC = RAM Size for Flash Functions
6366
FN = Number of Flash types
@@ -66,44 +69,55 @@ def generate_flash_dll(self):
6669
FL = Size of the Flash Device
6770
FP = Full path to the Device algorithm (RTE)
6871
69-
Necessary to flash some targets. Info gathered from algorithms field of pdsc file.
72+
Necessary to flash some targets.
7073
'''
7174
fl_count = 0
75+
7276
def get_mem_no_x(mem_str):
7377
mem_reg = "\dx(\w+)"
7478
m = re.search(mem_reg, mem_str)
7579
return m.group(1) if m else None
7680

77-
RAMS = [(get_mem_no_x(info["start"]), get_mem_no_x(info["size"]))
78-
for mem, info in self.target_info["memory"].items() if "RAM" in mem]
79-
format_str = "UL2CM3(-S0 -C0 -P0 -FD{ramstart}"+" -FC{ramsize} "+"-FN{num_algos} {extra_flags})"
81+
RAMS = [
82+
(get_mem_no_x(info["start"]), get_mem_no_x(info["size"]))
83+
for mem, info in self.target_info["memory"].items() if "RAM" in mem
84+
]
85+
format_str = (
86+
"UL2CM3(-S0 -C0 -P0 -FD{ramstart}"
87+
" -FC{ramsize} -FN{num_algos} {extra_flags})"
88+
)
8089
ramstart = ''
81-
#Default according to Keil developer
90+
# Default according to Keil developer
8291
ramsize = '1000'
83-
if len(RAMS)>=1:
92+
if len(RAMS) >= 1:
8493
ramstart = RAMS[0][0]
8594
extra_flags = []
8695
for name, info in self.target_info["algorithm"].items():
8796
if not name or not info:
8897
continue
89-
if int(info["default"])==0:
98+
if int(info["default"]) == 0:
9099
continue
91100
name_reg = "\w*/([\w_]+)\.flm"
92101
m = re.search(name_reg, name.lower())
93102
fl_name = m.group(1) if m else None
94103
name_flag = "-FF" + str(fl_count) + fl_name
95104

96-
start, size = get_mem_no_x(info["start"]), get_mem_no_x(info["size"])
97-
rom_start_flag = "-FS"+str(fl_count)+str(start)
105+
start = get_mem_no_x(info["start"])
106+
size = get_mem_no_x(info["size"])
107+
rom_start_flag = "-FS" + str(fl_count) + str(start)
98108
rom_size_flag = "-FL" + str(fl_count) + str(size)
99109

100110
if info["ramstart"] is not None and info["ramsize"] is not None:
101111
ramstart = get_mem_no_x(info["ramstart"])
102112
ramsize = get_mem_no_x(info["ramsize"])
103113

104-
path_flag = "-FP" + str(fl_count) + "($$Device:"+self.dname+"$"+name+")"
114+
path_flag = "-FP{}($$Device:{}${})".format(
115+
str(fl_count), self.dname, name
116+
)
105117

106-
extra_flags.extend([name_flag, rom_start_flag, rom_size_flag, path_flag])
118+
extra_flags.extend([
119+
name_flag, rom_start_flag, rom_size_flag, path_flag
120+
])
107121
fl_count += 1
108122

109123
extra = " ".join(extra_flags)
@@ -130,8 +144,7 @@ class Uvision(Exporter):
130144
"NCS36510TargetCode.ncs36510_addfib"
131145
])
132146

133-
134-
#File associations within .uvprojx file
147+
# File associations within .uvprojx file
135148
file_types = {'.cpp': 8, '.c': 1, '.s': 2,
136149
'.obj': 3, '.o': 3, '.lib': 4,
137150
'.ar': 4, '.h': 5, '.hpp': 5, '.sct': 4}
@@ -149,8 +162,8 @@ def uv_files(self, files):
149162
</File>
150163
"""
151164
for loc in files:
152-
#Encapsulates the information necessary for template entry above
153-
UVFile = namedtuple('UVFile', ['type','loc','name'])
165+
# Encapsulates the information necessary for template entry above
166+
UVFile = namedtuple('UVFile', ['type', 'loc', 'name'])
154167
_, ext = os.path.splitext(loc)
155168
if ext.lower() in self.file_types:
156169
type = self.file_types[ext.lower()]
@@ -212,11 +225,11 @@ def format_fpu(core):
212225

213226
def generate(self):
214227
"""Generate the .uvproj file"""
215-
cache = Cache(True, False)
216-
217-
srcs = self.resources.headers + self.resources.s_sources + \
218-
self.resources.c_sources + self.resources.cpp_sources + \
219-
self.resources.objects + self.libraries
228+
srcs = (
229+
self.resources.headers + self.resources.s_sources +
230+
self.resources.c_sources + self.resources.cpp_sources +
231+
self.resources.objects + self.libraries
232+
)
220233
ctx = {
221234
'name': self.project_name,
222235
# project_files => dict of generators - file group to generator of
@@ -227,7 +240,8 @@ def generate(self):
227240
self.resources.inc_dirs).encode('utf-8'),
228241
'device': DeviceUvision(self.target),
229242
}
230-
sct_name, sct_path = self.resources.get_file_refs(FileType.LD_SCRIPT)[0]
243+
sct_name, sct_path = self.resources.get_file_refs(
244+
FileType.LD_SCRIPT)[0]
231245
ctx['linker_script'] = self.toolchain.correct_scatter_shebang(
232246
sct_path, dirname(sct_name))
233247
if ctx['linker_script'] != sct_path:
@@ -243,8 +257,12 @@ def generate(self):
243257
ctx['armc6'] = int(self.TOOLCHAIN is 'ARMC6')
244258
ctx['toolchain_name'] = self.TOOLCHAIN_NAME
245259
ctx.update(self.format_flags())
246-
self.gen_file('uvision/uvision.tmpl', ctx, self.project_name+".uvprojx")
247-
self.gen_file('uvision/uvision_debug.tmpl', ctx, self.project_name + ".uvoptx")
260+
self.gen_file(
261+
'uvision/uvision.tmpl', ctx, self.project_name + ".uvprojx"
262+
)
263+
self.gen_file(
264+
'uvision/uvision_debug.tmpl', ctx, self.project_name + ".uvoptx"
265+
)
248266

249267
@staticmethod
250268
def clean(project_name):
@@ -284,6 +302,7 @@ def build(project_name, log_name='build_log.txt', cleanup=True):
284302
else:
285303
return 0
286304

305+
287306
class UvisionArmc5(Uvision):
288307
NAME = 'uvision5-armc5'
289308
TOOLCHAIN = 'ARM'
@@ -306,12 +325,6 @@ def is_target_supported(cls, target_name):
306325
else:
307326
return False
308327

309-
@classmethod
310-
def is_target_supported(cls, target_name):
311-
target = TARGET_MAP[target_name]
312-
return apply_supported_whitelist(
313-
cls.TOOLCHAIN, cls.POST_BINARY_WHITELIST, target) and\
314-
DeviceCMSIS.check_supported(target_name)
315328

316329
class UvisionArmc6(Uvision):
317330
NAME = 'uvision5-armc6'

0 commit comments

Comments
 (0)