使用脚本:
#!/usr/bin/env bash
SOURCE=/usr/share/openocd/
INTERFACE_CFG=${SOURCE}scripts/interface/cmsis-dap.cfg
TARGET_CFG=${SOURCE}scripts/target/stm32f1x.cfg
PWD=$(dirname "$(readlink -f "$0")")
echo "开始连接"
openocd -f ${INTERFACE_CFG} \
-f ${TARGET_CFG} \
-c "init" \
-c "halt" \
-c "stm32f1x unlock 0" \
-c "reset halt" \
-c "exit"
效果如下:
lizigarden@leeds-ThinkPad ~/p/S/HelloWorld> sudo ./unlock.sh
开始连接
Open On-Chip Debugger 0.11.0
Licensed under GNU GPL v2
For bug reports, read
http://openocd.org/doc/doxygen/bugs.html
Info : auto-selecting first available session transport "swd". To override use 'transport select <transport>'.
Info : CMSIS-DAP: SWD Supported
Info : CMSIS-DAP: FW Version = 2.0.0
Info : CMSIS-DAP: Interface Initialised (SWD)
Info : SWCLK/TCK = 1 SWDIO/TMS = 1 TDI = 0 TDO = 1 nTRST = 0 nRESET = 1
Info : CMSIS-DAP: Interface ready
Info : clock speed 1000 kHz
Info : SWD DPIDR 0x1ba01477
Info : stm32f1x.cpu: hardware has 6 breakpoints, 4 watchpoints
Info : starting gdb server for stm32f1x.cpu on 3333
Info : Listening on port 3333 for gdb connections
target halted due to debug-request, current mode: Thread
xPSR: 0x01000000 pc: 0x08000234 msp: 0x2000fff8
Info : device id = 0x10036414
Info : flash size = 512kbytes
stm32x unlocked.
INFO: a reset or power cycle is required for the new settings to take effect.
target halted due to debug-request, current mode: Thread
xPSR: 0x61000000 pc: 0x2000003a msp: 0x2000fff8
开学到现在一个半月,终于解决了,呜呜呜。
差点就买了ST-LINK,我甚至加入了购物车。
于是,我得出一个结论:CSDN是**
参考链接:
- https://techoverflow.net/2022/02/12/how-to-unlock-stm32f0x-using-openocd/
- https://stackoverflow.com/questions/32509747/stm32-read-out-protection-via-openocd
- 搜索关键词:"openocd unlock stm32"