Rtos API example

Committer:
marcozecchini
Date:
Sat Feb 23 12:13:36 2019 +0000
Revision:
0:9fca2b23d0ba
final commit

Who changed what in which revision?

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