BA
/
BaBoRo_test2
Backup 1
mbed-os/tools/make.py@0:02dd72d1d465, 2018-04-24 (annotated)
- Committer:
- borlanic
- Date:
- Tue Apr 24 11:45:18 2018 +0000
- Revision:
- 0:02dd72d1d465
BaBoRo_test2 - backup 1
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
borlanic | 0:02dd72d1d465 | 1 | #! /usr/bin/env python2 |
borlanic | 0:02dd72d1d465 | 2 | """ |
borlanic | 0:02dd72d1d465 | 3 | mbed SDK |
borlanic | 0:02dd72d1d465 | 4 | Copyright (c) 2011-2013 ARM Limited |
borlanic | 0:02dd72d1d465 | 5 | |
borlanic | 0:02dd72d1d465 | 6 | Licensed under the Apache License, Version 2.0 (the "License"); |
borlanic | 0:02dd72d1d465 | 7 | you may not use this file except in compliance with the License. |
borlanic | 0:02dd72d1d465 | 8 | You may obtain a copy of the License at |
borlanic | 0:02dd72d1d465 | 9 | |
borlanic | 0:02dd72d1d465 | 10 | http://www.apache.org/licenses/LICENSE-2.0 |
borlanic | 0:02dd72d1d465 | 11 | |
borlanic | 0:02dd72d1d465 | 12 | Unless required by applicable law or agreed to in writing, software |
borlanic | 0:02dd72d1d465 | 13 | distributed under the License is distributed on an "AS IS" BASIS, |
borlanic | 0:02dd72d1d465 | 14 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
borlanic | 0:02dd72d1d465 | 15 | See the License for the specific language governing permissions and |
borlanic | 0:02dd72d1d465 | 16 | limitations under the License. |
borlanic | 0:02dd72d1d465 | 17 | |
borlanic | 0:02dd72d1d465 | 18 | |
borlanic | 0:02dd72d1d465 | 19 | TEST BUILD & RUN |
borlanic | 0:02dd72d1d465 | 20 | """ |
borlanic | 0:02dd72d1d465 | 21 | from __future__ import print_function |
borlanic | 0:02dd72d1d465 | 22 | from builtins import str |
borlanic | 0:02dd72d1d465 | 23 | import sys |
borlanic | 0:02dd72d1d465 | 24 | import json |
borlanic | 0:02dd72d1d465 | 25 | from time import sleep |
borlanic | 0:02dd72d1d465 | 26 | from shutil import copy |
borlanic | 0:02dd72d1d465 | 27 | from os.path import join, abspath, dirname |
borlanic | 0:02dd72d1d465 | 28 | from json import load, dump |
borlanic | 0:02dd72d1d465 | 29 | |
borlanic | 0:02dd72d1d465 | 30 | # Be sure that the tools directory is in the search path |
borlanic | 0:02dd72d1d465 | 31 | ROOT = abspath(join(dirname(__file__), "..")) |
borlanic | 0:02dd72d1d465 | 32 | sys.path.insert(0, ROOT) |
borlanic | 0:02dd72d1d465 | 33 | |
borlanic | 0:02dd72d1d465 | 34 | from tools.utils import args_error |
borlanic | 0:02dd72d1d465 | 35 | from tools.utils import NotSupportedException |
borlanic | 0:02dd72d1d465 | 36 | from tools.paths import BUILD_DIR |
borlanic | 0:02dd72d1d465 | 37 | from tools.paths import MBED_LIBRARIES |
borlanic | 0:02dd72d1d465 | 38 | from tools.paths import RPC_LIBRARY |
borlanic | 0:02dd72d1d465 | 39 | from tools.paths import USB_LIBRARIES |
borlanic | 0:02dd72d1d465 | 40 | from tools.paths import DSP_LIBRARIES |
borlanic | 0:02dd72d1d465 | 41 | from tools.tests import TESTS, Test, TEST_MAP |
borlanic | 0:02dd72d1d465 | 42 | from tools.tests import TEST_MBED_LIB |
borlanic | 0:02dd72d1d465 | 43 | from tools.tests import test_known, test_name_known |
borlanic | 0:02dd72d1d465 | 44 | from tools.targets import TARGET_MAP |
borlanic | 0:02dd72d1d465 | 45 | from tools.options import get_default_options_parser |
borlanic | 0:02dd72d1d465 | 46 | from tools.options import extract_profile |
borlanic | 0:02dd72d1d465 | 47 | from tools.options import extract_mcus |
borlanic | 0:02dd72d1d465 | 48 | from tools.build_api import build_project |
borlanic | 0:02dd72d1d465 | 49 | from tools.build_api import mcu_toolchain_matrix |
borlanic | 0:02dd72d1d465 | 50 | from tools.build_api import mcu_toolchain_list |
borlanic | 0:02dd72d1d465 | 51 | from tools.build_api import mcu_target_list |
borlanic | 0:02dd72d1d465 | 52 | from tools.build_api import merge_build_data |
borlanic | 0:02dd72d1d465 | 53 | from utils import argparse_filestring_type |
borlanic | 0:02dd72d1d465 | 54 | from utils import argparse_many |
borlanic | 0:02dd72d1d465 | 55 | from utils import argparse_dir_not_parent |
borlanic | 0:02dd72d1d465 | 56 | from tools.toolchains import mbedToolchain, TOOLCHAIN_CLASSES, TOOLCHAIN_PATHS |
borlanic | 0:02dd72d1d465 | 57 | from tools.settings import CLI_COLOR_MAP |
borlanic | 0:02dd72d1d465 | 58 | |
borlanic | 0:02dd72d1d465 | 59 | if __name__ == '__main__': |
borlanic | 0:02dd72d1d465 | 60 | # Parse Options |
borlanic | 0:02dd72d1d465 | 61 | parser = get_default_options_parser(add_app_config=True) |
borlanic | 0:02dd72d1d465 | 62 | group = parser.add_mutually_exclusive_group(required=False) |
borlanic | 0:02dd72d1d465 | 63 | group.add_argument( |
borlanic | 0:02dd72d1d465 | 64 | "-p", |
borlanic | 0:02dd72d1d465 | 65 | type=argparse_many(test_known), |
borlanic | 0:02dd72d1d465 | 66 | dest="program", |
borlanic | 0:02dd72d1d465 | 67 | help="The index of the desired test program: [0-%d]" % (len(TESTS)-1)) |
borlanic | 0:02dd72d1d465 | 68 | |
borlanic | 0:02dd72d1d465 | 69 | group.add_argument( |
borlanic | 0:02dd72d1d465 | 70 | "-n", |
borlanic | 0:02dd72d1d465 | 71 | type=argparse_many(test_name_known), |
borlanic | 0:02dd72d1d465 | 72 | dest="program", |
borlanic | 0:02dd72d1d465 | 73 | help="The name of the desired test program") |
borlanic | 0:02dd72d1d465 | 74 | |
borlanic | 0:02dd72d1d465 | 75 | parser.add_argument( |
borlanic | 0:02dd72d1d465 | 76 | "-j", "--jobs", |
borlanic | 0:02dd72d1d465 | 77 | type=int, |
borlanic | 0:02dd72d1d465 | 78 | dest="jobs", |
borlanic | 0:02dd72d1d465 | 79 | default=0, |
borlanic | 0:02dd72d1d465 | 80 | help="Number of concurrent jobs. Default: 0/auto (based on host machine's number of CPUs)") |
borlanic | 0:02dd72d1d465 | 81 | |
borlanic | 0:02dd72d1d465 | 82 | parser.add_argument( |
borlanic | 0:02dd72d1d465 | 83 | "-v", "--verbose", |
borlanic | 0:02dd72d1d465 | 84 | action="store_true", |
borlanic | 0:02dd72d1d465 | 85 | dest="verbose", |
borlanic | 0:02dd72d1d465 | 86 | default=False, |
borlanic | 0:02dd72d1d465 | 87 | help="Verbose diagnostic output") |
borlanic | 0:02dd72d1d465 | 88 | |
borlanic | 0:02dd72d1d465 | 89 | parser.add_argument( |
borlanic | 0:02dd72d1d465 | 90 | "--silent", |
borlanic | 0:02dd72d1d465 | 91 | action="store_true", |
borlanic | 0:02dd72d1d465 | 92 | dest="silent", |
borlanic | 0:02dd72d1d465 | 93 | default=False, |
borlanic | 0:02dd72d1d465 | 94 | help="Silent diagnostic output (no copy, compile notification)") |
borlanic | 0:02dd72d1d465 | 95 | |
borlanic | 0:02dd72d1d465 | 96 | parser.add_argument( |
borlanic | 0:02dd72d1d465 | 97 | "-D", |
borlanic | 0:02dd72d1d465 | 98 | action="append", |
borlanic | 0:02dd72d1d465 | 99 | dest="macros", |
borlanic | 0:02dd72d1d465 | 100 | help="Add a macro definition") |
borlanic | 0:02dd72d1d465 | 101 | |
borlanic | 0:02dd72d1d465 | 102 | group.add_argument( |
borlanic | 0:02dd72d1d465 | 103 | "-S", "--supported-toolchains", |
borlanic | 0:02dd72d1d465 | 104 | dest="supported_toolchains", |
borlanic | 0:02dd72d1d465 | 105 | default=False, |
borlanic | 0:02dd72d1d465 | 106 | const="matrix", |
borlanic | 0:02dd72d1d465 | 107 | choices=["matrix", "toolchains", "targets"], |
borlanic | 0:02dd72d1d465 | 108 | nargs="?", |
borlanic | 0:02dd72d1d465 | 109 | help="Displays supported matrix of MCUs and toolchains") |
borlanic | 0:02dd72d1d465 | 110 | |
borlanic | 0:02dd72d1d465 | 111 | parser.add_argument( |
borlanic | 0:02dd72d1d465 | 112 | '-f', '--filter', |
borlanic | 0:02dd72d1d465 | 113 | dest='general_filter_regex', |
borlanic | 0:02dd72d1d465 | 114 | default=None, |
borlanic | 0:02dd72d1d465 | 115 | help='For some commands you can use filter to filter out results') |
borlanic | 0:02dd72d1d465 | 116 | |
borlanic | 0:02dd72d1d465 | 117 | parser.add_argument( |
borlanic | 0:02dd72d1d465 | 118 | "--stats-depth", |
borlanic | 0:02dd72d1d465 | 119 | type=int, |
borlanic | 0:02dd72d1d465 | 120 | dest="stats_depth", |
borlanic | 0:02dd72d1d465 | 121 | default=2, |
borlanic | 0:02dd72d1d465 | 122 | help="Depth level for static memory report") |
borlanic | 0:02dd72d1d465 | 123 | |
borlanic | 0:02dd72d1d465 | 124 | # Local run |
borlanic | 0:02dd72d1d465 | 125 | parser.add_argument("--automated", action="store_true", dest="automated", |
borlanic | 0:02dd72d1d465 | 126 | default=False, help="Automated test") |
borlanic | 0:02dd72d1d465 | 127 | parser.add_argument("--host", dest="host_test", |
borlanic | 0:02dd72d1d465 | 128 | default=None, help="Host test") |
borlanic | 0:02dd72d1d465 | 129 | parser.add_argument("--extra", dest="extra", |
borlanic | 0:02dd72d1d465 | 130 | default=None, help="Extra files") |
borlanic | 0:02dd72d1d465 | 131 | parser.add_argument("--peripherals", dest="peripherals", |
borlanic | 0:02dd72d1d465 | 132 | default=None, help="Required peripherals") |
borlanic | 0:02dd72d1d465 | 133 | parser.add_argument("--dep", dest="dependencies", |
borlanic | 0:02dd72d1d465 | 134 | default=None, help="Dependencies") |
borlanic | 0:02dd72d1d465 | 135 | parser.add_argument("--source", dest="source_dir", type=argparse_filestring_type, |
borlanic | 0:02dd72d1d465 | 136 | default=None, help="The source (input) directory", action="append") |
borlanic | 0:02dd72d1d465 | 137 | parser.add_argument("--duration", type=int, dest="duration", |
borlanic | 0:02dd72d1d465 | 138 | default=None, help="Duration of the test") |
borlanic | 0:02dd72d1d465 | 139 | parser.add_argument("--build", dest="build_dir", type=argparse_dir_not_parent(ROOT), |
borlanic | 0:02dd72d1d465 | 140 | default=None, help="The build (output) directory") |
borlanic | 0:02dd72d1d465 | 141 | parser.add_argument("-N", "--artifact-name", dest="artifact_name", |
borlanic | 0:02dd72d1d465 | 142 | default=None, help="The built project's name") |
borlanic | 0:02dd72d1d465 | 143 | parser.add_argument("-d", "--disk", dest="disk", |
borlanic | 0:02dd72d1d465 | 144 | default=None, help="The mbed disk") |
borlanic | 0:02dd72d1d465 | 145 | parser.add_argument("-s", "--serial", dest="serial", |
borlanic | 0:02dd72d1d465 | 146 | default=None, help="The mbed serial port") |
borlanic | 0:02dd72d1d465 | 147 | parser.add_argument("-b", "--baud", type=int, dest="baud", |
borlanic | 0:02dd72d1d465 | 148 | default=None, help="The mbed serial baud rate") |
borlanic | 0:02dd72d1d465 | 149 | group.add_argument("-L", "--list-tests", action="store_true", dest="list_tests", |
borlanic | 0:02dd72d1d465 | 150 | default=False, help="List available tests in order and exit") |
borlanic | 0:02dd72d1d465 | 151 | |
borlanic | 0:02dd72d1d465 | 152 | # Ideally, all the tests with a single "main" thread can be run with, or |
borlanic | 0:02dd72d1d465 | 153 | # without the usb, dsp |
borlanic | 0:02dd72d1d465 | 154 | parser.add_argument("--rpc", |
borlanic | 0:02dd72d1d465 | 155 | action="store_true", dest="rpc", |
borlanic | 0:02dd72d1d465 | 156 | default=False, help="Link with RPC library") |
borlanic | 0:02dd72d1d465 | 157 | |
borlanic | 0:02dd72d1d465 | 158 | parser.add_argument("--usb", |
borlanic | 0:02dd72d1d465 | 159 | action="store_true", |
borlanic | 0:02dd72d1d465 | 160 | dest="usb", |
borlanic | 0:02dd72d1d465 | 161 | default=False, |
borlanic | 0:02dd72d1d465 | 162 | help="Link with USB Device library") |
borlanic | 0:02dd72d1d465 | 163 | |
borlanic | 0:02dd72d1d465 | 164 | parser.add_argument("--dsp", |
borlanic | 0:02dd72d1d465 | 165 | action="store_true", |
borlanic | 0:02dd72d1d465 | 166 | dest="dsp", |
borlanic | 0:02dd72d1d465 | 167 | default=False, |
borlanic | 0:02dd72d1d465 | 168 | help="Link with DSP library") |
borlanic | 0:02dd72d1d465 | 169 | |
borlanic | 0:02dd72d1d465 | 170 | parser.add_argument("--testlib", |
borlanic | 0:02dd72d1d465 | 171 | action="store_true", |
borlanic | 0:02dd72d1d465 | 172 | dest="testlib", |
borlanic | 0:02dd72d1d465 | 173 | default=False, |
borlanic | 0:02dd72d1d465 | 174 | help="Link with mbed test library") |
borlanic | 0:02dd72d1d465 | 175 | |
borlanic | 0:02dd72d1d465 | 176 | parser.add_argument("--build-data", |
borlanic | 0:02dd72d1d465 | 177 | dest="build_data", |
borlanic | 0:02dd72d1d465 | 178 | default=None, |
borlanic | 0:02dd72d1d465 | 179 | help="Dump build_data to this file") |
borlanic | 0:02dd72d1d465 | 180 | |
borlanic | 0:02dd72d1d465 | 181 | # Specify a different linker script |
borlanic | 0:02dd72d1d465 | 182 | parser.add_argument("-l", "--linker", dest="linker_script", |
borlanic | 0:02dd72d1d465 | 183 | type=argparse_filestring_type, |
borlanic | 0:02dd72d1d465 | 184 | default=None, help="use the specified linker script") |
borlanic | 0:02dd72d1d465 | 185 | |
borlanic | 0:02dd72d1d465 | 186 | options = parser.parse_args() |
borlanic | 0:02dd72d1d465 | 187 | |
borlanic | 0:02dd72d1d465 | 188 | # Only prints matrix of supported toolchains |
borlanic | 0:02dd72d1d465 | 189 | if options.supported_toolchains: |
borlanic | 0:02dd72d1d465 | 190 | if options.supported_toolchains == "matrix": |
borlanic | 0:02dd72d1d465 | 191 | print(mcu_toolchain_matrix(platform_filter=options.general_filter_regex)) |
borlanic | 0:02dd72d1d465 | 192 | elif options.supported_toolchains == "toolchains": |
borlanic | 0:02dd72d1d465 | 193 | toolchain_list = mcu_toolchain_list() |
borlanic | 0:02dd72d1d465 | 194 | # Only print the lines that matter |
borlanic | 0:02dd72d1d465 | 195 | for line in toolchain_list.split("\n"): |
borlanic | 0:02dd72d1d465 | 196 | if not "mbed" in line: |
borlanic | 0:02dd72d1d465 | 197 | print(line) |
borlanic | 0:02dd72d1d465 | 198 | elif options.supported_toolchains == "targets": |
borlanic | 0:02dd72d1d465 | 199 | print(mcu_target_list()) |
borlanic | 0:02dd72d1d465 | 200 | exit(0) |
borlanic | 0:02dd72d1d465 | 201 | |
borlanic | 0:02dd72d1d465 | 202 | # Print available tests in order and exit |
borlanic | 0:02dd72d1d465 | 203 | if options.list_tests is True: |
borlanic | 0:02dd72d1d465 | 204 | print('\n'.join(map(str, sorted(TEST_MAP.values())))) |
borlanic | 0:02dd72d1d465 | 205 | sys.exit() |
borlanic | 0:02dd72d1d465 | 206 | |
borlanic | 0:02dd72d1d465 | 207 | # force program to "0" if a source dir is specified |
borlanic | 0:02dd72d1d465 | 208 | if options.source_dir is not None: |
borlanic | 0:02dd72d1d465 | 209 | p = 0 |
borlanic | 0:02dd72d1d465 | 210 | else: |
borlanic | 0:02dd72d1d465 | 211 | # Program Number or name |
borlanic | 0:02dd72d1d465 | 212 | p = options.program |
borlanic | 0:02dd72d1d465 | 213 | |
borlanic | 0:02dd72d1d465 | 214 | # If 'p' was set via -n to list of numbers make this a single element integer list |
borlanic | 0:02dd72d1d465 | 215 | if type(p) != type([]): |
borlanic | 0:02dd72d1d465 | 216 | p = [p] |
borlanic | 0:02dd72d1d465 | 217 | |
borlanic | 0:02dd72d1d465 | 218 | # Target |
borlanic | 0:02dd72d1d465 | 219 | if options.mcu is None : |
borlanic | 0:02dd72d1d465 | 220 | args_error(parser, "argument -m/--mcu is required") |
borlanic | 0:02dd72d1d465 | 221 | mcu = extract_mcus(parser, options)[0] |
borlanic | 0:02dd72d1d465 | 222 | |
borlanic | 0:02dd72d1d465 | 223 | # Toolchain |
borlanic | 0:02dd72d1d465 | 224 | if options.tool is None: |
borlanic | 0:02dd72d1d465 | 225 | args_error(parser, "argument -t/--tool is required") |
borlanic | 0:02dd72d1d465 | 226 | toolchain = options.tool[0] |
borlanic | 0:02dd72d1d465 | 227 | |
borlanic | 0:02dd72d1d465 | 228 | if (options.program is None) and (not options.source_dir): |
borlanic | 0:02dd72d1d465 | 229 | args_error(parser, "one of -p, -n, or --source is required") |
borlanic | 0:02dd72d1d465 | 230 | |
borlanic | 0:02dd72d1d465 | 231 | if options.source_dir and not options.build_dir: |
borlanic | 0:02dd72d1d465 | 232 | args_error(parser, "argument --build is required when argument --source is provided") |
borlanic | 0:02dd72d1d465 | 233 | |
borlanic | 0:02dd72d1d465 | 234 | |
borlanic | 0:02dd72d1d465 | 235 | if options.color: |
borlanic | 0:02dd72d1d465 | 236 | # This import happens late to prevent initializing colorization when we don't need it |
borlanic | 0:02dd72d1d465 | 237 | import colorize |
borlanic | 0:02dd72d1d465 | 238 | if options.verbose: |
borlanic | 0:02dd72d1d465 | 239 | notify = mbedToolchain.print_notify_verbose |
borlanic | 0:02dd72d1d465 | 240 | else: |
borlanic | 0:02dd72d1d465 | 241 | notify = mbedToolchain.print_notify |
borlanic | 0:02dd72d1d465 | 242 | notify = colorize.print_in_color_notifier(CLI_COLOR_MAP, notify) |
borlanic | 0:02dd72d1d465 | 243 | else: |
borlanic | 0:02dd72d1d465 | 244 | notify = None |
borlanic | 0:02dd72d1d465 | 245 | |
borlanic | 0:02dd72d1d465 | 246 | if not TOOLCHAIN_CLASSES[toolchain].check_executable(): |
borlanic | 0:02dd72d1d465 | 247 | search_path = TOOLCHAIN_PATHS[toolchain] or "No path set" |
borlanic | 0:02dd72d1d465 | 248 | args_error(parser, "Could not find executable for %s.\n" |
borlanic | 0:02dd72d1d465 | 249 | "Currently set search path: %s" |
borlanic | 0:02dd72d1d465 | 250 | %(toolchain, search_path)) |
borlanic | 0:02dd72d1d465 | 251 | |
borlanic | 0:02dd72d1d465 | 252 | # Test |
borlanic | 0:02dd72d1d465 | 253 | build_data_blob = {} if options.build_data else None |
borlanic | 0:02dd72d1d465 | 254 | for test_no in p: |
borlanic | 0:02dd72d1d465 | 255 | test = Test(test_no) |
borlanic | 0:02dd72d1d465 | 256 | if options.automated is not None: test.automated = options.automated |
borlanic | 0:02dd72d1d465 | 257 | if options.dependencies is not None: test.dependencies = options.dependencies |
borlanic | 0:02dd72d1d465 | 258 | if options.host_test is not None: test.host_test = options.host_test; |
borlanic | 0:02dd72d1d465 | 259 | if options.peripherals is not None: test.peripherals = options.peripherals; |
borlanic | 0:02dd72d1d465 | 260 | if options.duration is not None: test.duration = options.duration; |
borlanic | 0:02dd72d1d465 | 261 | if options.extra is not None: test.extra_files = options.extra |
borlanic | 0:02dd72d1d465 | 262 | |
borlanic | 0:02dd72d1d465 | 263 | if not test.is_supported(mcu, toolchain): |
borlanic | 0:02dd72d1d465 | 264 | print('The selected test is not supported on target %s with toolchain %s' % (mcu, toolchain)) |
borlanic | 0:02dd72d1d465 | 265 | sys.exit() |
borlanic | 0:02dd72d1d465 | 266 | |
borlanic | 0:02dd72d1d465 | 267 | # Linking with extra libraries |
borlanic | 0:02dd72d1d465 | 268 | if options.rpc: test.dependencies.append(RPC_LIBRARY) |
borlanic | 0:02dd72d1d465 | 269 | if options.usb: test.dependencies.append(USB_LIBRARIES) |
borlanic | 0:02dd72d1d465 | 270 | if options.dsp: test.dependencies.append(DSP_LIBRARIES) |
borlanic | 0:02dd72d1d465 | 271 | if options.testlib: test.dependencies.append(TEST_MBED_LIB) |
borlanic | 0:02dd72d1d465 | 272 | |
borlanic | 0:02dd72d1d465 | 273 | build_dir = join(BUILD_DIR, "test", mcu, toolchain, test.id) |
borlanic | 0:02dd72d1d465 | 274 | if options.source_dir is not None: |
borlanic | 0:02dd72d1d465 | 275 | test.source_dir = options.source_dir |
borlanic | 0:02dd72d1d465 | 276 | build_dir = options.source_dir |
borlanic | 0:02dd72d1d465 | 277 | |
borlanic | 0:02dd72d1d465 | 278 | if options.build_dir is not None: |
borlanic | 0:02dd72d1d465 | 279 | build_dir = options.build_dir |
borlanic | 0:02dd72d1d465 | 280 | |
borlanic | 0:02dd72d1d465 | 281 | try: |
borlanic | 0:02dd72d1d465 | 282 | bin_file = build_project(test.source_dir, build_dir, mcu, toolchain, |
borlanic | 0:02dd72d1d465 | 283 | set(test.dependencies), |
borlanic | 0:02dd72d1d465 | 284 | linker_script=options.linker_script, |
borlanic | 0:02dd72d1d465 | 285 | clean=options.clean, |
borlanic | 0:02dd72d1d465 | 286 | verbose=options.verbose, |
borlanic | 0:02dd72d1d465 | 287 | notify=notify, |
borlanic | 0:02dd72d1d465 | 288 | report=build_data_blob, |
borlanic | 0:02dd72d1d465 | 289 | silent=options.silent, |
borlanic | 0:02dd72d1d465 | 290 | macros=options.macros, |
borlanic | 0:02dd72d1d465 | 291 | jobs=options.jobs, |
borlanic | 0:02dd72d1d465 | 292 | name=options.artifact_name, |
borlanic | 0:02dd72d1d465 | 293 | app_config=options.app_config, |
borlanic | 0:02dd72d1d465 | 294 | inc_dirs=[dirname(MBED_LIBRARIES)], |
borlanic | 0:02dd72d1d465 | 295 | build_profile=extract_profile(parser, |
borlanic | 0:02dd72d1d465 | 296 | options, |
borlanic | 0:02dd72d1d465 | 297 | toolchain), |
borlanic | 0:02dd72d1d465 | 298 | stats_depth=options.stats_depth) |
borlanic | 0:02dd72d1d465 | 299 | print('Image: %s'% bin_file) |
borlanic | 0:02dd72d1d465 | 300 | |
borlanic | 0:02dd72d1d465 | 301 | if options.disk: |
borlanic | 0:02dd72d1d465 | 302 | # Simple copy to the mbed disk |
borlanic | 0:02dd72d1d465 | 303 | copy(bin_file, options.disk) |
borlanic | 0:02dd72d1d465 | 304 | |
borlanic | 0:02dd72d1d465 | 305 | if options.serial: |
borlanic | 0:02dd72d1d465 | 306 | # Import pyserial: https://pypi.python.org/pypi/pyserial |
borlanic | 0:02dd72d1d465 | 307 | from serial import Serial |
borlanic | 0:02dd72d1d465 | 308 | |
borlanic | 0:02dd72d1d465 | 309 | sleep(TARGET_MAP[mcu].program_cycle_s) |
borlanic | 0:02dd72d1d465 | 310 | |
borlanic | 0:02dd72d1d465 | 311 | serial = Serial(options.serial, timeout = 1) |
borlanic | 0:02dd72d1d465 | 312 | if options.baud: |
borlanic | 0:02dd72d1d465 | 313 | serial.setBaudrate(options.baud) |
borlanic | 0:02dd72d1d465 | 314 | |
borlanic | 0:02dd72d1d465 | 315 | serial.flushInput() |
borlanic | 0:02dd72d1d465 | 316 | serial.flushOutput() |
borlanic | 0:02dd72d1d465 | 317 | |
borlanic | 0:02dd72d1d465 | 318 | try: |
borlanic | 0:02dd72d1d465 | 319 | serial.sendBreak() |
borlanic | 0:02dd72d1d465 | 320 | except: |
borlanic | 0:02dd72d1d465 | 321 | # In linux a termios.error is raised in sendBreak and in setBreak. |
borlanic | 0:02dd72d1d465 | 322 | # The following setBreak() is needed to release the reset signal on the target mcu. |
borlanic | 0:02dd72d1d465 | 323 | try: |
borlanic | 0:02dd72d1d465 | 324 | serial.setBreak(False) |
borlanic | 0:02dd72d1d465 | 325 | except: |
borlanic | 0:02dd72d1d465 | 326 | pass |
borlanic | 0:02dd72d1d465 | 327 | |
borlanic | 0:02dd72d1d465 | 328 | while True: |
borlanic | 0:02dd72d1d465 | 329 | c = serial.read(512) |
borlanic | 0:02dd72d1d465 | 330 | sys.stdout.write(c) |
borlanic | 0:02dd72d1d465 | 331 | sys.stdout.flush() |
borlanic | 0:02dd72d1d465 | 332 | |
borlanic | 0:02dd72d1d465 | 333 | except KeyboardInterrupt as e: |
borlanic | 0:02dd72d1d465 | 334 | print("\n[CTRL+c] exit") |
borlanic | 0:02dd72d1d465 | 335 | except NotSupportedException as e: |
borlanic | 0:02dd72d1d465 | 336 | print("\nCould not compile for %s: %s" % (mcu, str(e))) |
borlanic | 0:02dd72d1d465 | 337 | except Exception as e: |
borlanic | 0:02dd72d1d465 | 338 | if options.verbose: |
borlanic | 0:02dd72d1d465 | 339 | import traceback |
borlanic | 0:02dd72d1d465 | 340 | traceback.print_exc(file=sys.stdout) |
borlanic | 0:02dd72d1d465 | 341 | else: |
borlanic | 0:02dd72d1d465 | 342 | print("[ERROR] %s" % str(e)) |
borlanic | 0:02dd72d1d465 | 343 | |
borlanic | 0:02dd72d1d465 | 344 | sys.exit(1) |
borlanic | 0:02dd72d1d465 | 345 | if options.build_data: |
borlanic | 0:02dd72d1d465 | 346 | merge_build_data(options.build_data, build_data_blob, "application") |