1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
|
#!/usr/bin/python3
import argparse
import subprocess
import time
HELP = """This script can be used to debug an issue where the Zephyr-based
firmware of a target microcontroller is not able to communicate via the network
after roughly every second boot process. The Ethernet-capable microcontroller
has to be connected directly to the Linux-based host PC via an Ethernet cable
and a ST-Link. Reboots are triggered via the Open Source st-utils tool
(https://github.com/stlink-org/stlink). Connectivity is checked with ping."""
def main():
args = parse_args()
ok = 0
not_ok = 0
for i in range(args.iterations):
print(f"Iteration #{i+1}")
subprocess.run(["st-info", "--connect-under-reset"], check=True)
time.sleep(args.delay)
try:
subprocess.run(
["ping", "-c", "1", args.address], check=True, stdout=subprocess.DEVNULL
)
print("ok")
ok += 1
except:
print("not ok")
not_ok += 1
print(
f"Success rate is {round(100 * ok / (ok + not_ok))} % ({ok} ok and {not_ok} failed)"
)
def parse_args():
parser = argparse.ArgumentParser(description=HELP)
parser.add_argument(
"-i",
"--iterations",
default=100,
help="how often the test should be executed",
type=int,
)
parser.add_argument(
"-d",
"--delay",
default=10,
help="how long to wait after reset for the ICMP request",
type=int,
)
parser.add_argument(
"-a",
"--address",
default="192.0.2.1",
help="address of the microcontroller / target of ICMP request",
type=str,
)
return parser.parse_args()
if __name__ == "__main__":
main()
|