Clone of official tools

Committer:
Anders Blomdell
Date:
Thu Feb 04 17:17:13 2021 +0100
Revision:
47:21ae3e5a7128
Parent:
43:2a7da56ebd24
Add a few normpath calls

Who changed what in which revision?

UserRevisionLine numberNew contents of line
theotherjimmy 43:2a7da56ebd24 1 from __future__ import print_function, absolute_import
theotherjimmy 43:2a7da56ebd24 2 from builtins import str
theotherjimmy 43:2a7da56ebd24 3
The Other Jimmy 31:8ea194f6145b 4 import os
theotherjimmy 43:2a7da56ebd24 5 from os.path import normpath, exists, dirname
The Other Jimmy 31:8ea194f6145b 6 import ntpath
The Other Jimmy 31:8ea194f6145b 7 import copy
The Other Jimmy 31:8ea194f6145b 8 from collections import namedtuple
The Other Jimmy 31:8ea194f6145b 9 import shutil
The Other Jimmy 31:8ea194f6145b 10 from subprocess import Popen, PIPE
The Other Jimmy 31:8ea194f6145b 11 import re
The Other Jimmy 31:8ea194f6145b 12
theotherjimmy 43:2a7da56ebd24 13 from tools.resources import FileType
The Other Jimmy 31:8ea194f6145b 14 from tools.targets import TARGET_MAP
theotherjimmy 43:2a7da56ebd24 15 from tools.export.exporters import Exporter
The Other Jimmy 31:8ea194f6145b 16 from tools.export.cmsis import DeviceCMSIS
The Other Jimmy 31:8ea194f6145b 17
The Other Jimmy 31:8ea194f6145b 18
The Other Jimmy 31:8ea194f6145b 19 class DeviceUvision(DeviceCMSIS):
The Other Jimmy 31:8ea194f6145b 20 """Uvision Device class, inherits CMSIS Device class
The Other Jimmy 31:8ea194f6145b 21
The Other Jimmy 31:8ea194f6145b 22 Encapsulates information necessary for uvision project targets"""
The Other Jimmy 31:8ea194f6145b 23 def __init__(self, target):
The Other Jimmy 31:8ea194f6145b 24 DeviceCMSIS.__init__(self, target)
The Other Jimmy 31:8ea194f6145b 25 dev_format = "$$Device:{0}${1}"
The Other Jimmy 31:8ea194f6145b 26 self.svd = ''
The Other Jimmy 31:8ea194f6145b 27 if self.debug_svd:
The Other Jimmy 31:8ea194f6145b 28 self.svd = dev_format.format(self.dname, self.debug_svd)
The Other Jimmy 31:8ea194f6145b 29 self.reg_file = dev_format.format(self.dname, self.compile_header)
The Other Jimmy 31:8ea194f6145b 30 self.debug_interface = self.uv_debug()
The Other Jimmy 31:8ea194f6145b 31 self.flash_dll = self.generate_flash_dll()
The Other Jimmy 31:8ea194f6145b 32
The Other Jimmy 31:8ea194f6145b 33 def uv_debug(self):
The Other Jimmy 31:8ea194f6145b 34 """Return a namedtuple of information about uvision debug settings"""
theotherjimmy 43:2a7da56ebd24 35 UVDebug = namedtuple('UVDebug', ['bin_loc', 'core_flag', 'key'])
The Other Jimmy 31:8ea194f6145b 36
The Other Jimmy 31:8ea194f6145b 37 # CortexMXn => pCMX
The Other Jimmy 31:8ea194f6145b 38 cpu = self.core.replace("Cortex-", "C")
The Other Jimmy 31:8ea194f6145b 39 cpu = cpu.replace("+", "")
The Other Jimmy 31:8ea194f6145b 40 cpu = cpu.replace("F", "")
theotherjimmy 43:2a7da56ebd24 41 cpu = cpu.replace("-NS", "")
The Other Jimmy 31:8ea194f6145b 42 cpu_flag = "p"+cpu
The Other Jimmy 31:8ea194f6145b 43
The Other Jimmy 31:8ea194f6145b 44 # Locations found in Keil_v5/TOOLS.INI
theotherjimmy 43:2a7da56ebd24 45 debuggers = {
theotherjimmy 43:2a7da56ebd24 46 "st-link": ('STLink\\ST-LINKIII-KEIL_SWO.dll',
theotherjimmy 43:2a7da56ebd24 47 'ST-LINKIII-KEIL_SWO'),
theotherjimmy 43:2a7da56ebd24 48 "j-link": ('Segger\\JL2CM3.dll', 'JL2CM3'),
theotherjimmy 43:2a7da56ebd24 49 "cmsis-dap": ('BIN\\CMSIS_AGDI.dll', 'CMSIS_AGDI'),
theotherjimmy 43:2a7da56ebd24 50 "nulink": ('NULink\\Nu_Link.dll', 'Nu_Link')
theotherjimmy 43:2a7da56ebd24 51 }
The Other Jimmy 31:8ea194f6145b 52 res = debuggers[self.debug.lower()]
The Other Jimmy 31:8ea194f6145b 53 binary = res[0]
The Other Jimmy 31:8ea194f6145b 54 key = res[1]
The Other Jimmy 31:8ea194f6145b 55
The Other Jimmy 31:8ea194f6145b 56 return UVDebug(binary, cpu_flag, key)
The Other Jimmy 31:8ea194f6145b 57
The Other Jimmy 31:8ea194f6145b 58 def generate_flash_dll(self):
The Other Jimmy 31:8ea194f6145b 59 '''Flash DLL string from uvision
The Other Jimmy 31:8ea194f6145b 60 S = SW/JTAG Clock ID
The Other Jimmy 31:8ea194f6145b 61 C = CPU index in JTAG chain
The Other Jimmy 31:8ea194f6145b 62 P = Access Port
theotherjimmy 43:2a7da56ebd24 63 For the Options for Target -> Debug -> settings -> "Flash" dialog:
The Other Jimmy 31:8ea194f6145b 64 FD = RAM Start for Flash Functions
The Other Jimmy 31:8ea194f6145b 65 FC = RAM Size for Flash Functions
The Other Jimmy 31:8ea194f6145b 66 FN = Number of Flash types
The Other Jimmy 31:8ea194f6145b 67 FF = Flash File Name (without an extension)
The Other Jimmy 31:8ea194f6145b 68 FS = Start Address of the Flash Device
The Other Jimmy 31:8ea194f6145b 69 FL = Size of the Flash Device
The Other Jimmy 31:8ea194f6145b 70 FP = Full path to the Device algorithm (RTE)
The Other Jimmy 31:8ea194f6145b 71
theotherjimmy 43:2a7da56ebd24 72 Necessary to flash some targets.
The Other Jimmy 31:8ea194f6145b 73 '''
The Other Jimmy 31:8ea194f6145b 74 fl_count = 0
theotherjimmy 43:2a7da56ebd24 75
The Other Jimmy 31:8ea194f6145b 76 def get_mem_no_x(mem_str):
The Other Jimmy 31:8ea194f6145b 77 mem_reg = "\dx(\w+)"
The Other Jimmy 31:8ea194f6145b 78 m = re.search(mem_reg, mem_str)
The Other Jimmy 31:8ea194f6145b 79 return m.group(1) if m else None
The Other Jimmy 31:8ea194f6145b 80
theotherjimmy 43:2a7da56ebd24 81 RAMS = [
theotherjimmy 43:2a7da56ebd24 82 (get_mem_no_x(info["start"]), get_mem_no_x(info["size"]))
theotherjimmy 43:2a7da56ebd24 83 for mem, info in self.target_info["memory"].items() if "RAM" in mem
theotherjimmy 43:2a7da56ebd24 84 ]
theotherjimmy 43:2a7da56ebd24 85 format_str = (
theotherjimmy 43:2a7da56ebd24 86 "UL2CM3(-S0 -C0 -P0 -FD{ramstart}"
theotherjimmy 43:2a7da56ebd24 87 " -FC{ramsize} -FN{num_algos} {extra_flags})"
theotherjimmy 43:2a7da56ebd24 88 )
The Other Jimmy 31:8ea194f6145b 89 ramstart = ''
theotherjimmy 43:2a7da56ebd24 90 # Default according to Keil developer
The Other Jimmy 31:8ea194f6145b 91 ramsize = '1000'
theotherjimmy 43:2a7da56ebd24 92 if len(RAMS) >= 1:
The Other Jimmy 31:8ea194f6145b 93 ramstart = RAMS[0][0]
The Other Jimmy 31:8ea194f6145b 94 extra_flags = []
The Other Jimmy 31:8ea194f6145b 95 for name, info in self.target_info["algorithm"].items():
The Other Jimmy 31:8ea194f6145b 96 if not name or not info:
The Other Jimmy 31:8ea194f6145b 97 continue
theotherjimmy 43:2a7da56ebd24 98 if int(info["default"]) == 0:
The Other Jimmy 31:8ea194f6145b 99 continue
The Other Jimmy 31:8ea194f6145b 100 name_reg = "\w*/([\w_]+)\.flm"
The Other Jimmy 31:8ea194f6145b 101 m = re.search(name_reg, name.lower())
The Other Jimmy 31:8ea194f6145b 102 fl_name = m.group(1) if m else None
The Other Jimmy 31:8ea194f6145b 103 name_flag = "-FF" + str(fl_count) + fl_name
The Other Jimmy 31:8ea194f6145b 104
theotherjimmy 43:2a7da56ebd24 105 start = get_mem_no_x(info["start"])
theotherjimmy 43:2a7da56ebd24 106 size = get_mem_no_x(info["size"])
theotherjimmy 43:2a7da56ebd24 107 rom_start_flag = "-FS" + str(fl_count) + str(start)
The Other Jimmy 31:8ea194f6145b 108 rom_size_flag = "-FL" + str(fl_count) + str(size)
The Other Jimmy 31:8ea194f6145b 109
The Other Jimmy 31:8ea194f6145b 110 if info["ramstart"] is not None and info["ramsize"] is not None:
The Other Jimmy 31:8ea194f6145b 111 ramstart = get_mem_no_x(info["ramstart"])
The Other Jimmy 31:8ea194f6145b 112 ramsize = get_mem_no_x(info["ramsize"])
The Other Jimmy 31:8ea194f6145b 113
theotherjimmy 43:2a7da56ebd24 114 path_flag = "-FP{}($$Device:{}${})".format(
theotherjimmy 43:2a7da56ebd24 115 str(fl_count), self.dname, name
theotherjimmy 43:2a7da56ebd24 116 )
The Other Jimmy 31:8ea194f6145b 117
theotherjimmy 43:2a7da56ebd24 118 extra_flags.extend([
theotherjimmy 43:2a7da56ebd24 119 name_flag, rom_start_flag, rom_size_flag, path_flag
theotherjimmy 43:2a7da56ebd24 120 ])
The Other Jimmy 31:8ea194f6145b 121 fl_count += 1
The Other Jimmy 31:8ea194f6145b 122
The Other Jimmy 31:8ea194f6145b 123 extra = " ".join(extra_flags)
The Other Jimmy 31:8ea194f6145b 124 return format_str.format(ramstart=ramstart,
The Other Jimmy 31:8ea194f6145b 125 ramsize=ramsize,
The Other Jimmy 31:8ea194f6145b 126 extra_flags=extra, num_algos=fl_count)
The Other Jimmy 31:8ea194f6145b 127
The Other Jimmy 31:8ea194f6145b 128
The Other Jimmy 31:8ea194f6145b 129 class Uvision(Exporter):
The Other Jimmy 31:8ea194f6145b 130 """Keil Uvision class
The Other Jimmy 31:8ea194f6145b 131
The Other Jimmy 31:8ea194f6145b 132 This class encapsulates information to be contained in a Uvision
The Other Jimmy 31:8ea194f6145b 133 project file (.uvprojx).
The Other Jimmy 31:8ea194f6145b 134 The needed information can be viewed in uvision.tmpl
The Other Jimmy 31:8ea194f6145b 135 """
The Other Jimmy 36:96847d42f010 136
The Other Jimmy 36:96847d42f010 137 POST_BINARY_WHITELIST = set([
The Other Jimmy 36:96847d42f010 138 "MCU_NRF51Code.binary_hook",
The Other Jimmy 36:96847d42f010 139 "TEENSY3_1Code.binary_hook",
The Other Jimmy 36:96847d42f010 140 "LPCTargetCode.lpc_patch",
The Other Jimmy 36:96847d42f010 141 "LPC4088Code.binary_hook",
The Other Jimmy 36:96847d42f010 142 "MTSCode.combine_bins_mts_dot",
The Other Jimmy 36:96847d42f010 143 "MTSCode.combine_bins_mts_dragonfly",
The Other Jimmy 36:96847d42f010 144 "NCS36510TargetCode.ncs36510_addfib"
The Other Jimmy 36:96847d42f010 145 ])
theotherjimmy 40:7d3fa6b99b2b 146
theotherjimmy 43:2a7da56ebd24 147 # File associations within .uvprojx file
The Other Jimmy 31:8ea194f6145b 148 file_types = {'.cpp': 8, '.c': 1, '.s': 2,
The Other Jimmy 31:8ea194f6145b 149 '.obj': 3, '.o': 3, '.lib': 4,
The Other Jimmy 31:8ea194f6145b 150 '.ar': 4, '.h': 5, '.hpp': 5, '.sct': 4}
The Other Jimmy 31:8ea194f6145b 151
The Other Jimmy 31:8ea194f6145b 152 def uv_files(self, files):
The Other Jimmy 31:8ea194f6145b 153 """An generator containing Uvision specific information about project files
The Other Jimmy 31:8ea194f6145b 154 Positional Arguments:
The Other Jimmy 31:8ea194f6145b 155 files - the location of source files
The Other Jimmy 31:8ea194f6145b 156
The Other Jimmy 31:8ea194f6145b 157 .uvprojx XML for project file:
The Other Jimmy 31:8ea194f6145b 158 <File>
The Other Jimmy 31:8ea194f6145b 159 <FileType>{{file.type}}</FileType>
The Other Jimmy 31:8ea194f6145b 160 <FileName>{{file.name}}</FileName>
The Other Jimmy 31:8ea194f6145b 161 <FilePath>{{file.loc}}</FilePath>
The Other Jimmy 31:8ea194f6145b 162 </File>
The Other Jimmy 31:8ea194f6145b 163 """
The Other Jimmy 31:8ea194f6145b 164 for loc in files:
theotherjimmy 43:2a7da56ebd24 165 # Encapsulates the information necessary for template entry above
theotherjimmy 43:2a7da56ebd24 166 UVFile = namedtuple('UVFile', ['type', 'loc', 'name'])
The Other Jimmy 31:8ea194f6145b 167 _, ext = os.path.splitext(loc)
The Other Jimmy 31:8ea194f6145b 168 if ext.lower() in self.file_types:
The Other Jimmy 31:8ea194f6145b 169 type = self.file_types[ext.lower()]
The Other Jimmy 31:8ea194f6145b 170 name = ntpath.basename(normpath(loc))
The Other Jimmy 31:8ea194f6145b 171 yield UVFile(type, loc, name)
The Other Jimmy 31:8ea194f6145b 172
The Other Jimmy 31:8ea194f6145b 173 def format_flags(self):
The Other Jimmy 31:8ea194f6145b 174 """Format toolchain flags for Uvision"""
The Other Jimmy 31:8ea194f6145b 175 flags = copy.deepcopy(self.flags)
theotherjimmy 40:7d3fa6b99b2b 176 asm_flag_string = (
theotherjimmy 40:7d3fa6b99b2b 177 '--cpreproc --cpreproc_opts=-D__ASSERT_MSG,' +
theotherjimmy 43:2a7da56ebd24 178 ",".join("-D{}".format(s) for s in
theotherjimmy 43:2a7da56ebd24 179 self.toolchain.get_symbols(for_asm=True)))
The Other Jimmy 31:8ea194f6145b 180 flags['asm_flags'] = asm_flag_string
theotherjimmy 43:2a7da56ebd24 181
theotherjimmy 43:2a7da56ebd24 182 config_header = self.config_header_ref
theotherjimmy 43:2a7da56ebd24 183 config_option = self.toolchain.get_config_option(config_header.name)
theotherjimmy 43:2a7da56ebd24 184 c_flags = set(
theotherjimmy 43:2a7da56ebd24 185 flags['c_flags'] + flags['cxx_flags'] + flags['common_flags']
theotherjimmy 43:2a7da56ebd24 186 )
theotherjimmy 43:2a7da56ebd24 187 in_template = set(
theotherjimmy 43:2a7da56ebd24 188 ["--no_vla", "--cpp", "--c99", "-MMD"] + config_option
theotherjimmy 43:2a7da56ebd24 189 )
theotherjimmy 43:2a7da56ebd24 190
theotherjimmy 43:2a7da56ebd24 191 def valid_flag(x):
theotherjimmy 43:2a7da56ebd24 192 return (
theotherjimmy 43:2a7da56ebd24 193 x not in in_template and
theotherjimmy 43:2a7da56ebd24 194 not x.startswith("-O") and
theotherjimmy 43:2a7da56ebd24 195 not x.startswith("-std") and
theotherjimmy 43:2a7da56ebd24 196 not x.startswith("-D")
theotherjimmy 43:2a7da56ebd24 197 )
theotherjimmy 43:2a7da56ebd24 198
theotherjimmy 43:2a7da56ebd24 199 def is_define(s):
theotherjimmy 43:2a7da56ebd24 200 return s.startswith("-D") and "(" not in s
theotherjimmy 43:2a7da56ebd24 201
theotherjimmy 43:2a7da56ebd24 202 flags['c_flags'] = " ".join(
theotherjimmy 43:2a7da56ebd24 203 f.replace('"', '\\"') for f in c_flags if valid_flag(f)
theotherjimmy 43:2a7da56ebd24 204 )
theotherjimmy 43:2a7da56ebd24 205 flags['c_flags'] += " "
theotherjimmy 43:2a7da56ebd24 206 flags['c_flags'] += " ".join(config_option)
theotherjimmy 43:2a7da56ebd24 207 flags['c_defines'] = " ".join(f[2:].replace('"', '\\"')
theotherjimmy 43:2a7da56ebd24 208 for f in c_flags if is_define(f))
theotherjimmy 43:2a7da56ebd24 209 flags['ld_flags'] = " ".join(set(flags['ld_flags']))
The Other Jimmy 31:8ea194f6145b 210 return flags
The Other Jimmy 31:8ea194f6145b 211
The Other Jimmy 31:8ea194f6145b 212 def format_src(self, srcs):
The Other Jimmy 31:8ea194f6145b 213 """Make sources into the named tuple for use in the template"""
The Other Jimmy 31:8ea194f6145b 214 grouped = self.group_project_files(srcs)
The Other Jimmy 31:8ea194f6145b 215 for group, files in grouped.items():
The Other Jimmy 35:da9c89f8be7d 216 grouped[group] = sorted(list(self.uv_files(files)),
theotherjimmy 43:2a7da56ebd24 217 key=lambda tuple: tuple[2].lower())
The Other Jimmy 31:8ea194f6145b 218 return grouped
The Other Jimmy 31:8ea194f6145b 219
The Other Jimmy 36:96847d42f010 220 @staticmethod
The Other Jimmy 36:96847d42f010 221 def format_fpu(core):
The Other Jimmy 36:96847d42f010 222 """Generate a core's FPU string"""
The Other Jimmy 36:96847d42f010 223 if core.endswith("FD"):
The Other Jimmy 36:96847d42f010 224 return "FPU3(DFPU)"
The Other Jimmy 36:96847d42f010 225 elif core.endswith("F"):
The Other Jimmy 36:96847d42f010 226 return "FPU2"
The Other Jimmy 36:96847d42f010 227 else:
The Other Jimmy 36:96847d42f010 228 return ""
The Other Jimmy 36:96847d42f010 229
The Other Jimmy 31:8ea194f6145b 230 def generate(self):
The Other Jimmy 31:8ea194f6145b 231 """Generate the .uvproj file"""
theotherjimmy 43:2a7da56ebd24 232 srcs = (
theotherjimmy 43:2a7da56ebd24 233 self.resources.headers + self.resources.s_sources +
theotherjimmy 43:2a7da56ebd24 234 self.resources.c_sources + self.resources.cpp_sources +
theotherjimmy 43:2a7da56ebd24 235 self.resources.objects + self.libraries
theotherjimmy 43:2a7da56ebd24 236 )
The Other Jimmy 31:8ea194f6145b 237 ctx = {
The Other Jimmy 31:8ea194f6145b 238 'name': self.project_name,
The Other Jimmy 31:8ea194f6145b 239 # project_files => dict of generators - file group to generator of
The Other Jimmy 31:8ea194f6145b 240 # UVFile tuples defined above
theotherjimmy 43:2a7da56ebd24 241 'project_files': sorted(list(self.format_src(srcs).items()),
theotherjimmy 43:2a7da56ebd24 242 key=lambda tuple: tuple[0].lower()),
theotherjimmy 43:2a7da56ebd24 243 'include_paths': ';'.join(self.filter_dot(d) for d in
theotherjimmy 43:2a7da56ebd24 244 self.resources.inc_dirs).encode('utf-8'),
The Other Jimmy 31:8ea194f6145b 245 'device': DeviceUvision(self.target),
The Other Jimmy 31:8ea194f6145b 246 }
theotherjimmy 43:2a7da56ebd24 247 sct_name, sct_path = self.resources.get_file_refs(
theotherjimmy 43:2a7da56ebd24 248 FileType.LD_SCRIPT)[0]
theotherjimmy 43:2a7da56ebd24 249 ctx['linker_script'] = self.toolchain.correct_scatter_shebang(
theotherjimmy 43:2a7da56ebd24 250 sct_path, dirname(sct_name))
theotherjimmy 43:2a7da56ebd24 251 if ctx['linker_script'] != sct_path:
theotherjimmy 41:2a77626a4c21 252 self.generated_files.append(ctx['linker_script'])
theotherjimmy 43:2a7da56ebd24 253 ctx['cputype'] = ctx['device'].core.rstrip("FD").replace("-NS", "")
theotherjimmy 43:2a7da56ebd24 254 if ctx['device'].core.endswith("FD"):
The Other Jimmy 36:96847d42f010 255 ctx['fpu_setting'] = 3
theotherjimmy 43:2a7da56ebd24 256 elif ctx['device'].core.endswith("F"):
The Other Jimmy 36:96847d42f010 257 ctx['fpu_setting'] = 2
The Other Jimmy 36:96847d42f010 258 else:
The Other Jimmy 36:96847d42f010 259 ctx['fpu_setting'] = 1
theotherjimmy 43:2a7da56ebd24 260 ctx['fputype'] = self.format_fpu(ctx['device'].core)
theotherjimmy 43:2a7da56ebd24 261 ctx['armc6'] = int(self.TOOLCHAIN is 'ARMC6')
theotherjimmy 43:2a7da56ebd24 262 ctx['toolchain_name'] = self.TOOLCHAIN_NAME
The Other Jimmy 31:8ea194f6145b 263 ctx.update(self.format_flags())
theotherjimmy 43:2a7da56ebd24 264 self.gen_file(
theotherjimmy 43:2a7da56ebd24 265 'uvision/uvision.tmpl', ctx, self.project_name + ".uvprojx"
theotherjimmy 43:2a7da56ebd24 266 )
theotherjimmy 43:2a7da56ebd24 267 self.gen_file(
theotherjimmy 43:2a7da56ebd24 268 'uvision/uvision_debug.tmpl', ctx, self.project_name + ".uvoptx"
theotherjimmy 43:2a7da56ebd24 269 )
theotherjimmy 43:2a7da56ebd24 270
theotherjimmy 43:2a7da56ebd24 271 @staticmethod
theotherjimmy 43:2a7da56ebd24 272 def clean(project_name):
theotherjimmy 43:2a7da56ebd24 273 os.remove(project_name + ".uvprojx")
theotherjimmy 43:2a7da56ebd24 274 os.remove(project_name + ".uvoptx")
theotherjimmy 43:2a7da56ebd24 275 # legacy .build directory cleaned if exists
theotherjimmy 43:2a7da56ebd24 276 if exists('.build'):
theotherjimmy 43:2a7da56ebd24 277 shutil.rmtree('.build')
theotherjimmy 43:2a7da56ebd24 278 if exists('BUILD'):
theotherjimmy 43:2a7da56ebd24 279 shutil.rmtree('BUILD')
The Other Jimmy 31:8ea194f6145b 280
The Other Jimmy 31:8ea194f6145b 281 @staticmethod
The Other Jimmy 31:8ea194f6145b 282 def build(project_name, log_name='build_log.txt', cleanup=True):
The Other Jimmy 31:8ea194f6145b 283 """ Build Uvision project """
The Other Jimmy 31:8ea194f6145b 284 # > UV4 -r -j0 -o [log_name] [project_name].uvprojx
The Other Jimmy 31:8ea194f6145b 285 proj_file = project_name + ".uvprojx"
The Other Jimmy 31:8ea194f6145b 286 cmd = ['UV4', '-r', '-j0', '-o', log_name, proj_file]
The Other Jimmy 31:8ea194f6145b 287
The Other Jimmy 31:8ea194f6145b 288 # Build the project
The Other Jimmy 31:8ea194f6145b 289 p = Popen(cmd, stdout=PIPE, stderr=PIPE)
The Other Jimmy 31:8ea194f6145b 290 out, err = p.communicate()
The Other Jimmy 31:8ea194f6145b 291 ret_code = p.returncode
The Other Jimmy 31:8ea194f6145b 292
The Other Jimmy 31:8ea194f6145b 293 # Print the log file to stdout
The Other Jimmy 31:8ea194f6145b 294 with open(log_name, 'r') as f:
theotherjimmy 43:2a7da56ebd24 295 print(f.read())
The Other Jimmy 31:8ea194f6145b 296
The Other Jimmy 31:8ea194f6145b 297 # Cleanup the exported and built files
The Other Jimmy 31:8ea194f6145b 298 if cleanup:
The Other Jimmy 31:8ea194f6145b 299 os.remove(log_name)
theotherjimmy 43:2a7da56ebd24 300 Uvision.clean(project_name)
The Other Jimmy 31:8ea194f6145b 301
The Other Jimmy 31:8ea194f6145b 302 # Returns 0 upon success, 1 upon a warning, and neither upon an error
The Other Jimmy 31:8ea194f6145b 303 if ret_code != 0 and ret_code != 1:
The Other Jimmy 31:8ea194f6145b 304 # Seems like something went wrong.
The Other Jimmy 31:8ea194f6145b 305 return -1
The Other Jimmy 31:8ea194f6145b 306 else:
The Other Jimmy 31:8ea194f6145b 307 return 0
theotherjimmy 43:2a7da56ebd24 308
theotherjimmy 43:2a7da56ebd24 309
theotherjimmy 43:2a7da56ebd24 310 class UvisionArmc5(Uvision):
theotherjimmy 43:2a7da56ebd24 311 NAME = 'uvision5-armc5'
theotherjimmy 43:2a7da56ebd24 312 TOOLCHAIN = 'ARM'
theotherjimmy 43:2a7da56ebd24 313 TOOLCHAIN_NAME = ''
theotherjimmy 43:2a7da56ebd24 314
theotherjimmy 43:2a7da56ebd24 315 @classmethod
theotherjimmy 43:2a7da56ebd24 316 def is_target_supported(cls, target_name):
theotherjimmy 43:2a7da56ebd24 317 target = TARGET_MAP[target_name]
theotherjimmy 43:2a7da56ebd24 318 if not (set(target.supported_toolchains).intersection(
theotherjimmy 43:2a7da56ebd24 319 set(["ARM", "uARM"]))):
theotherjimmy 43:2a7da56ebd24 320 return False
theotherjimmy 43:2a7da56ebd24 321 if not DeviceCMSIS.check_supported(target_name):
theotherjimmy 43:2a7da56ebd24 322 return False
theotherjimmy 43:2a7da56ebd24 323 if "Cortex-A" in target.core:
theotherjimmy 43:2a7da56ebd24 324 return False
theotherjimmy 43:2a7da56ebd24 325 if not hasattr(target, "post_binary_hook"):
theotherjimmy 43:2a7da56ebd24 326 return True
theotherjimmy 43:2a7da56ebd24 327 if target.post_binary_hook['function'] in cls.POST_BINARY_WHITELIST:
theotherjimmy 43:2a7da56ebd24 328 return True
theotherjimmy 43:2a7da56ebd24 329 else:
theotherjimmy 43:2a7da56ebd24 330 return False
theotherjimmy 43:2a7da56ebd24 331
theotherjimmy 43:2a7da56ebd24 332
theotherjimmy 43:2a7da56ebd24 333 class UvisionArmc6(Uvision):
theotherjimmy 43:2a7da56ebd24 334 NAME = 'uvision5-armc6'
theotherjimmy 43:2a7da56ebd24 335 TOOLCHAIN = 'ARMC6'
theotherjimmy 43:2a7da56ebd24 336 TOOLCHAIN_NAME = '6070000::V6.7::.\ARMCLANG'
theotherjimmy 43:2a7da56ebd24 337
theotherjimmy 43:2a7da56ebd24 338 @classmethod
theotherjimmy 43:2a7da56ebd24 339 def is_target_supported(cls, target_name):
theotherjimmy 43:2a7da56ebd24 340 target = TARGET_MAP[target_name]
theotherjimmy 43:2a7da56ebd24 341 if not (set(target.supported_toolchains).intersection(
theotherjimmy 43:2a7da56ebd24 342 set(["ARMC6"]))):
theotherjimmy 43:2a7da56ebd24 343 return False
theotherjimmy 43:2a7da56ebd24 344 if not DeviceCMSIS.check_supported(target_name):
theotherjimmy 43:2a7da56ebd24 345 return False
theotherjimmy 43:2a7da56ebd24 346 if "Cortex-A" in target.core:
theotherjimmy 43:2a7da56ebd24 347 return False
theotherjimmy 43:2a7da56ebd24 348 if not hasattr(target, "post_binary_hook"):
theotherjimmy 43:2a7da56ebd24 349 return True
theotherjimmy 43:2a7da56ebd24 350 if target.post_binary_hook['function'] in cls.POST_BINARY_WHITELIST:
theotherjimmy 43:2a7da56ebd24 351 return True
theotherjimmy 43:2a7da56ebd24 352 else:
theotherjimmy 43:2a7da56ebd24 353 return False