Add STM32 unlock target

This copies the brute force unlock approach by @pavkriz into a custom target. With this commit, it is possible to automatically unlock e.g. a H8I8O board without leaving the PlatformIO IDE.

See #181
This commit is contained in:
M-Byte 2022-06-08 11:44:27 +02:00
parent 191d996e29
commit a629a5b0c7
2 changed files with 38 additions and 0 deletions

View File

@ -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

34
examples/scripts/stm32rdu.py Executable file
View File

@ -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)