Bare minimum scripts to lock or unlock STM32 devices
Install the following tools on your system.
used version 0.10.0
sudo apt-get install openocd
See xpack OpenOCD Installation instructions or download latest released version, unzip it and change its rights.
wget https://github.com/xpack-dev-tools/openocd-xpack/releases/download/v0.10.0-14/xpack-openocd-0.10.0-14-darwin-x64.tar.gz
tar -zxvf xpack-openocd-0.10.0-14-darwin-x64.tar.gz
chmod -R -w xpack-openocd-0.10.0-14-darwin-x64
Move the files into your applications folder and create a symlink to use it with the same commands as on linux
sudo ln -s /Volumes/Macintosh\ HD/Applications/OpenOCD/ /usr/share/openocd
sudo apt-get install telnet
Call this in first terminal
openocd -d3 -f stlink-v2.cfg -c "transport select hla_swd" -f stm32f1x.cfg
open second terminal
telnet 127.0.0.1 4444
If the chip is locked, it can't be programmed until it is unlocked.
A power cycle is required after locking the chip to run the program.
Unlocking the chip will erase it's content completly.
Config files for STLink are located at /usr/share/openocd/scripts/interface/
,
config for targets can be found at /usr/share/openocd/scripts/target/
.
Be aware of different STLink versions, which only differ in one single char of VID.
sh flash.sh path/to/some/file.bin
Flash a file with debug level 1
sh flash.sh path/to/some/file.bin -d1
Lock a STM32F1 with a STLink V2
sh lock.sh
Perform lock with debug level 2 on a STM32F1 with a STLink V2
sh lock.sh -d2
Use general_un_lock_st.sh
to lock or unlock a general STM32 device. The
following example is for an STM32F0 by using a STLink
sh un_lock_st.sh \
/Applications/OpenOCD/bin/openocd \
/Applications/OpenOCD/scripts \
stlink \
stm32f0x \
lock
Unlock a STM32F1 with a STLink V2
sh unlock.sh
Perform unlock with debug level 1 on a STM32F1 with a STLink V2
sh unlock.sh -d1
Use general_un_lock_st.sh
to lock or unlock a general STM32 device. The
following example is for an STM32F0 by using an STLink
sh un_lock_st.sh \
/Applications/OpenOCD/bin/openocd \
/Applications/OpenOCD/scripts \
stlink \
stm32f0x \
unlock
Power cycle the target by using a raspberry pi pin.
Connect VCC of the debug interface via a transistor or mosfet to VCC. The mosfet or transistor is controlled by the raspberry pi pin.
You have to run this script once to configure the pin and turn it on.
python power_cycle.py