init

Dependencies:   mbed

Committer:
Nathan Yonkee
Date:
Fri Mar 02 07:16:49 2018 -0700
Revision:
10:46a4cf51ee38
Parent:
9:d58e77ebd769
remove mbed-os

Who changed what in which revision?

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