3 Copyright (c) 2011-2016 ARM Limited
5 Licensed under the Apache License, Version 2.0 (the "License");
6 you may not use this file except in compliance with the License.
7 You may obtain a copy of the License at
9 http://www.apache.org/licenses/LICENSE-2.0
11 Unless required by applicable law or agreed to in writing, software
12 distributed under the License is distributed on an "AS IS" BASIS,
13 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 See the License for the specific language governing permissions and
15 limitations under the License.
17 Author: Przemyslaw Wirkus <Przemyslaw.Wirkus@arm.com>
22 from time
import sleep
23 from serial
import Serial, SerialException
24 from mbed_host_tests
import host_tests_plugins, DEFAULT_BAUD_RATE
29 copy_method='default',
32 """! Flash device using pythonic interface
33 @param disk Switch -d <disk>
34 @param image_path Switch -f <image_path>
35 @param copy_method Switch -c <copy_method> (default: shell)
36 @param port Switch -p <port>
38 if copy_method ==
'default':
41 result = host_tests_plugins.call_plugin(
'CopyMethod',
43 image_path=image_path,
45 destination_disk=disk)
46 sleep(program_cycle_s)
54 baudrate=DEFAULT_BAUD_RATE,
57 """! Reset device using pythonic interface
58 @param port Switch -p <port>
59 @param disk Switch -d <disk>
60 @param reset_type Switch -r <reset_type>
61 @param reset_timeout Switch -R <reset_timeout>
62 @param serial_port Serial port handler, set to None if you want this function to open serial
64 @param baudrate Serial port baudrate
65 @param timeout Serial port timeout
66 @param verbose Verbose mode
72 with Serial(port, baudrate=baudrate, timeout=timeout)
as serial_port:
73 result = host_tests_plugins.call_plugin(
'ResetMethod',
78 except SerialException
as e:
80 print(
"%s" % (str(e)))
90 """! Resets platforms and prints serial port output
91 @detail Mix with switch -r RESET_TYPE and -p PORT for versatility
94 reset_type =
'default'
96 port_config = port.split(
':')
97 if len(port_config) == 2:
100 baudrate = int(port_config[1])
if not baudrate
else baudrate
101 elif len(port_config) == 3:
103 port = port_config[0]
104 baudrate = int(port_config[1])
if not baudrate
else baudrate
105 timeout = float(port_config[2])
109 baudrate = DEFAULT_BAUD_RATE
112 print(
"mbedhtrun: serial port configuration: %s:%s:%s"% (port, str(baudrate), str(timeout)))
115 serial_port = Serial(port, baudrate=baudrate, timeout=timeout)
116 except Exception
as e:
117 print(
"mbedhtrun: %s" % (str(e)))
121 "baudrate" : baudrate,
123 "reset_type" : reset_type,
129 result = host_tests_plugins.call_plugin(
'ResetMethod', reset_type, serial=serial_port, disk=disk)
131 print(
"mbedhtrun: reset plugin failed")
135 "baudrate" : baudrate,
137 "reset_type" : reset_type
141 print(
"mbedhtrun: serial dump started (use ctrl+c to break)")
144 test_output = serial_port.read(512)
146 sys.stdout.write(
'%s'% test_output)
147 if "{end}" in test_output:
150 print(
"mbedhtrun: stopped (found '{end}' terminator)")
152 except KeyboardInterrupt:
153 print(
"ctrl+c break")