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