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