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