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