From e8a7a00ddbd67a7e737519d9b7b684ede67c6aa8 Mon Sep 17 00:00:00 2001 From: EmanuelFeru Date: Fri, 7 Feb 2020 18:08:15 +0100 Subject: [PATCH] How to unlock the MCU flash --- unlock_MCU_flash.md | 44 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 unlock_MCU_flash.md diff --git a/unlock_MCU_flash.md b/unlock_MCU_flash.md new file mode 100644 index 0000000..d5c2c37 --- /dev/null +++ b/unlock_MCU_flash.md @@ -0,0 +1,44 @@ +This wiki page explains how to unlock the flash of an STM32 or a GD32 to allow re-flashing with a custom firmware. + +### WARNING: This procedure can erase the MCU firmware irreversibly! Perform these steps at your own risk! + +# Method 1: Using ST-Link Utility + +* Step 1: Download and install the [ST-Link Utility](https://www.st.com/en/development-tools/stsw-link004.html) +* Step 2: Connect the ST-Link programmer to the MCU programming pins GND, SWDIO, SWCLK. Connect the 3V3 pin only if your MCU is not powered externally. +* Step 3: Open the ST-Link utility and press Connect to target + +![unlock1](https://raw.githubusercontent.com/EmanuelFeru/hoverboard-firmware-hack-FOC/master/docs/pictures/unlock_mcu_1.png) + +* Step 4: If you get the message "Can not read memory!" the MCU is most probably locked +* Step 5: Go to Target and click Option Bytes + +![unlock2](https://raw.githubusercontent.com/EmanuelFeru/hoverboard-firmware-hack-FOC/master/docs/pictures/unlock_mcu_2.png) + +* Step 6: Select Disable in Read Out Protection drop-down menu + +![unlock3](https://raw.githubusercontent.com/EmanuelFeru/hoverboard-firmware-hack-FOC/master/docs/pictures/unlock_mcu_3.png) + +* Step 7: Click Connect to target + +![unlock4](https://raw.githubusercontent.com/EmanuelFeru/hoverboard-firmware-hack-FOC/master/docs/pictures/unlock_mcu_4.png) + +* Step 8: If you see the window above, then you have successfully unlocked your MCU. You can now flash the MCU. + +# Method 2: Using Ubuntu + +* Step 1: Install the [ST-Flash Utility](https://github.com/texane/stlink) +* Step 2: Install [OpenOCD](https://zoomadmin.com/HowToInstall/UbuntuPackage/openocd) +* Step 2: Connect the ST-Link programmer to the MCU programming pins GND, SWDIO, SWCLK. Connect the 3V3 pin only if your MCU is not powered externally. +* Step 3a: Open a terminal and send the following OpenOCD command: +``` +openocd -f interface/stlink-v2.cfg -f target/stm32f1x.cfg -c init -c "reset halt" -c "stm32f1x unlock 0" +``` +* Step 3b: If that does not work. Try: +``` +openocd -f interface/stlink-v2.cfg -f target/stm32f1x.cfg -c init -c "reset halt" -c "mww 0x40022004 0x45670123" -c "mww 0x40022004 0xCDEF89AB" -c "mww 0x40022008 0x45670123" -c "mww 0x40022008 0xCDEF89AB" -c "mww 0x40022010 0x220" -c "mww 0x40022010 0x260" -c "sleep 100" -c "mww 0x40022010 0x230" -c "mwh 0x1ffff800 0x5AA5" -c "sleep 1000" -c "mww 0x40022010 0x2220" -c "sleep 100" -c "mdw 0x40022010" -c "mdw 0x4002201c" -c "mdw 0x1ffff800" -c targets -c "halt" -c "stm32f1x unlock 0" +``` +``` +openocd -f interface/stlink-v2.cfg -f target/stm32f1x.cfg -c init -c "reset halt" -c "mww 0x40022004 0x45670123" -c "mww 0x40022004 0xCDEF89AB" -c "mww 0x40022008 0x45670123" -c "mww 0x40022008 0xCDEF89AB" -c targets -c "halt" -c "stm32f1x unlock 0" +``` +