diff --git a/examples/knx-demo/platformio.ini b/examples/knx-demo/platformio.ini index b5cdfe5..1924630 100644 --- a/examples/knx-demo/platformio.ini +++ b/examples/knx-demo/platformio.ini @@ -123,6 +123,8 @@ build_flags = -DMASK_VERSION=0x07B0 -Wno-unknown-pragmas +extra_scripts = ../scripts/stm32rdu.py + [env:h8c09] platform = ststm32 board = genericSTM32F103CB @@ -143,3 +145,5 @@ build_flags = -DKNX_LED=PB5 -DMASK_VERSION=0x07B0 -Wno-unknown-pragmas + +extra_scripts = ../scripts/stm32rdu.py diff --git a/examples/scripts/stm32rdu.py b/examples/scripts/stm32rdu.py new file mode 100755 index 0000000..d0c5400 --- /dev/null +++ b/examples/scripts/stm32rdu.py @@ -0,0 +1,34 @@ +#!/usr/bin/env python +from subprocess import run +from datetime import datetime, timedelta +from os.path import expanduser + +ocddir = expanduser("~/.platformio/packages/tool-openocd/") +chip = "stm32f1x" + +def unlock(*args, **kwargs): + print("Please connect the board within the next two minutes.") + endtime = datetime.now() + timedelta(minutes = 1) + ret = 1 + while ret != 0 and datetime.now() < endtime: + ret = run(["bin/openocd", "-f", "interface/stlink.cfg", "-f", "target/" + chip + ".cfg", "-c", "init", "-c", "reset halt", "-c", chip + " unlock 0", "-c", "reset halt", "-c", "exit"], cwd = ocddir).returncode + if ret != 0: + print("Timeout") + return ret + +try: + Import("env") +except NameError: + import sys + if len(sys.argv) > 1: + chip = sys.argv[1] + if len(sys.argv) > 2: + ocddir = sys.argv[2] + unlock(None, None) +else: + ocddir = env.PioPlatform().get_package_dir("tool-openocd") + options = env.GetProjectOptions() + for option in options: + if "unlock_chip" == option[0]: + chip = option[1] + env.AddCustomTarget("unlock", None, unlock)