mirror of
https://github.com/RIOT-OS/RIOT.git
synced 2024-12-29 04:50:03 +01:00
dist/tools/bmp: revisit probe detection
The tool would always exit if no probes are detected, even if `--port` was provided. By making this assertion conditional, it becomes possible to override the port in any case. Use cases for this is running the BMP externally, and connecto to it via ser2net, for example.
This commit is contained in:
parent
e55da6ad82
commit
96dbd33507
15
dist/tools/bmp/README.md
vendored
15
dist/tools/bmp/README.md
vendored
@ -21,20 +21,21 @@ positional arguments:
|
||||
choose a task to perform
|
||||
file file to load to target (hex or elf)
|
||||
|
||||
optional arguments:
|
||||
options:
|
||||
-h, --help show this help message and exit
|
||||
--jtag use JTAG transport
|
||||
--swd use SWD transport (default)
|
||||
--connect-srst reset target while connecting
|
||||
--tpwr enable target power
|
||||
--serial SERIAL choose specific probe by serial number
|
||||
--port PORT choose specific probe by port
|
||||
--port PORT choose specific probe by port (overrides auto
|
||||
selection)
|
||||
--attach ATTACH choose specific target by number
|
||||
--gdb-path GDB_PATH path to GDB
|
||||
--term-cmd TERM_CMD serial terminal command
|
||||
```
|
||||
|
||||
## Available Actions
|
||||
## Available actions
|
||||
* `list` lists connected targets (default action)
|
||||
* `flash` load file to target
|
||||
* `erase` erase target flash
|
||||
@ -42,6 +43,14 @@ optional arguments:
|
||||
* `term` start TTY emulator program to look into connected UART
|
||||
* `reset` reset target (using RST line)
|
||||
|
||||
## Probe selection
|
||||
The probe is auto discovered based on the USB VID (0x1D50) and PID (0x6018,
|
||||
0x6017). The first discovered probe will be selected, unless `--port` or
|
||||
`--serial` is provided.
|
||||
|
||||
If `--port` is provided, then that port will be used as the GDB port for all
|
||||
actions, except for the `term` action.
|
||||
|
||||
## Examples (tested with BluePill STM32F103F8C6)
|
||||
* test connection:
|
||||
```
|
||||
|
54
dist/tools/bmp/bmp.py
vendored
54
dist/tools/bmp/bmp.py
vendored
@ -56,6 +56,18 @@ def detect_probes():
|
||||
return gdb_ports, uart_ports
|
||||
|
||||
|
||||
# print all found ports to console.
|
||||
def enumerate_probes(ports):
|
||||
print("found following Black Magic GDB servers:")
|
||||
for i, s in enumerate(ports):
|
||||
print("\t[%s]" % s.device, end=' ')
|
||||
if len(s.serial_number) > 1:
|
||||
print("Serial:", s.serial_number, end=' ')
|
||||
if i == 0:
|
||||
print("<- default", end=' ')
|
||||
print('')
|
||||
|
||||
|
||||
# search device with specific serial number <snr> in a list of ports <ports>
|
||||
def search_serial(snr, ports):
|
||||
for port in ports:
|
||||
@ -155,34 +167,25 @@ def check_flash(gdbmi):
|
||||
res = gdbmi.get_gdb_response(timeout_sec=TIMEOUT)
|
||||
|
||||
|
||||
def choose_bmp_port(args, gdb_ports):
|
||||
print("found following Black Magic GDB servers:")
|
||||
for i, s in enumerate(gdb_ports):
|
||||
print("\t[%s]" % s.device, end=' ')
|
||||
if len(s.serial_number) > 1:
|
||||
print("Serial:", s.serial_number, end=' ')
|
||||
if i == 0:
|
||||
print("<- default", end=' ')
|
||||
print('')
|
||||
port = gdb_ports[0].device
|
||||
# choose GDB or UART port, based on available ports and application arguments
|
||||
def choose_port(args, ports):
|
||||
if args.port:
|
||||
port = args.port
|
||||
elif args.serial:
|
||||
port = search_serial(args.serial, gdb_ports)
|
||||
assert port, "no BMP with this serial found"
|
||||
else:
|
||||
enumerate_probes(ports)
|
||||
if args.serial:
|
||||
port = search_serial(args.serial, ports)
|
||||
assert port, "no BMP with this serial found"
|
||||
else:
|
||||
assert len(ports) > 0, "no ports found"
|
||||
port = ports[0].device
|
||||
print('connecting to [%s]...' % port)
|
||||
return port
|
||||
|
||||
|
||||
# terminal mode, opens TTY program
|
||||
def term_mode(args, uart_ports):
|
||||
port = uart_ports[0].device
|
||||
if args.port:
|
||||
port = args.port
|
||||
elif args.serial:
|
||||
port = search_serial(args.serial, uart_ports)
|
||||
assert port, "no BMP with this serial found"
|
||||
os.system(args.term_cmd % port)
|
||||
def term_mode(args, uart_port):
|
||||
os.system(args.term_cmd % uart_port)
|
||||
sys.exit(0)
|
||||
|
||||
|
||||
@ -240,7 +243,7 @@ def parse_args():
|
||||
parser.add_argument('--connect-srst', action='store_true', help='reset target while connecting')
|
||||
parser.add_argument('--tpwr', action='store_true', help='enable target power')
|
||||
parser.add_argument('--serial', help='choose specific probe by serial number')
|
||||
parser.add_argument('--port', help='choose specific probe by port')
|
||||
parser.add_argument('--port', help='choose specific probe by port (overrides auto selection)')
|
||||
parser.add_argument('--attach', help='choose specific target by number', default='1')
|
||||
parser.add_argument('--gdb-path', help='path to GDB', default='gdb-multiarch')
|
||||
parser.add_argument('--term-cmd', help='serial terminal command',
|
||||
@ -259,12 +262,13 @@ def main():
|
||||
assert not (args.swd and args.jtag), "you may only choose one protocol"
|
||||
assert not (args.serial and args.port), "you may only specify the probe by port or by serial"
|
||||
g, u = detect_probes()
|
||||
assert len(g) > 0, "no Black Magic Probes found 😔"
|
||||
|
||||
if args.action == 'term':
|
||||
term_mode(args, u)
|
||||
port = choose_port(args, u)
|
||||
|
||||
term_mode(args, port)
|
||||
else:
|
||||
port = choose_bmp_port(args, g)
|
||||
port = choose_port(args, g)
|
||||
|
||||
args.file = args.file if args.file else ''
|
||||
args.gdb_path = find_suitable_gdb(args.gdb_path)
|
||||
|
Loading…
Reference in New Issue
Block a user