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