I would like to automate flashing process for my Infineon XC886 devices.
Currently, I use ULINK2 and I connect to my board via JTAGhttps://developer.arm.com/documentation/101407/0540/Command-Line/Program-Flash-Exampleand then I call the UV4.exe via command line. This command opens up Keil uVision5 and flashes the application to my MCU. This process works but is not convenient for production since it opens up Keil application everytime I flash my devices.Can I use uv4.exe in headless mode (not opening application) or should I use different tool/method to flash my devices? Perhaps someone could suggest an alternative?
I have been able to achieve this by simply running the command via Python and reading the log file in real time as the log file is being written to.
from subprocess import Popen, PIPE, STDOUT import os import re import time import threading def log_subprocess_output(pipe): for line in iter(pipe.readline, b''): # b'\n'-separated lines print(line) KEIL_EXE_path = 'C:/Keil_v5/UV4/UV4.exe' LOG_FILE_PATH = 'test_log.txt' def tail_f(filename): with open(filename, 'r') as f: while True: line = f.readline() if line: print(line, end='') # Print the new line else: time.sleep(0.1) # Wait a bit before checking for new data process = Popen([KEIL_EXE_path, '-f', 'test.uvproj', '-j0', '-l', LOG_FILE_PATH], stdout=PIPE, stderr=STDOUT) # Run tail_f in a separate thread to print log file in real-time log_thread = threading.Thread(target=tail_f, args=(LOG_FILE_PATH,)) log_thread.start() # Wait for the process to finish process.wait() # Join the log thread log_thread.join()
Thanks for sharing your solution, Lukas