2025-09-04 11:04 PM
How to add a python script to introduce build errors during compilation process when some of the GPIO settings are modified from the below ones. PFB the python script
import sys
import re
# :white_heavy_check_mark: Define the locked GPIO settings here
LOCKED_SETTINGS = {
# Format: "PinName.Property": "ExpectedValue"
"PA0.GPIO_Label": "Button1",
"PA0.GPIO_Mode": "GPIO_MODE_INPUT",
"PA0.GPIO_PuPd": "GPIO_NOPULL",
"PB5.GPIO_Label": "LED1",
"PB5.GPIO_Mode": "GPIO_MODE_OUTPUT_PP",
"PB5.GPIO_PuPd": "GPIO_NOPULL",
"PB5.GPIO_Speed": "GPIO_SPEED_FREQ_LOW",
}
def check_ioc_file(ioc_path):
try:
with open(ioc_path, "r", encoding="utf-8") as f:
lines = f.readlines()
except FileNotFoundError:
print(f":cross_mark: ERROR: File not found: {ioc_path}")
sys.exit(1)
errors = []
for key, expected_value in LOCKED_SETTINGS.items():
found = False
for line in lines:
if line.startswith(key + "="):
found = True
actual_value = line.strip().split("=")[1]
if actual_value != expected_value:
errors.append(f"{key} changed! Expected '{expected_value}', found '{actual_value}'")
break
if not found:
errors.append(f"{key} missing from {ioc_path}")
if errors:
print(":cross_mark: GPIO lock check failed:")
for err in errors:
print(" - " + err)
sys.exit(1)
else:
print(":white_heavy_check_mark: GPIO lock check passed.")
if __name__ == "__main__":
if len(sys.argv) != 2:
print("Usage: python check_ioc_lock.py Temp-STM32H743VIHX.ioc")
sys.exit(1)
check_ioc_file(sys.argv[1])