#!/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", required=True, help="address of the microcontroller / target of ICMP request", type=str, ) return parser.parse_args() if __name__ == "__main__": main()