{"id":20915794,"url":"https://github.com/brainelectronics/stm32-flash-lock","last_synced_at":"2025-04-11T09:44:03.760Z","repository":{"id":69601940,"uuid":"297960361","full_name":"brainelectronics/STM32-Flash-Lock","owner":"brainelectronics","description":"Flash a STM32F1 chip with some already compiled binary and optionally lock the chip with Readout protection level 1. Unlocking will erase the chip completly","archived":false,"fork":false,"pushed_at":"2021-06-07T14:10:22.000Z","size":40,"stargazers_count":6,"open_issues_count":0,"forks_count":3,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-03-25T06:41:34.221Z","etag":null,"topics":["bash-script","chip","flash","lock","openocd","stlink","stm32","stm32f103","telnet","unlock"],"latest_commit_sha":null,"homepage":"","language":"Shell","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/brainelectronics.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2020-09-23T12:19:52.000Z","updated_at":"2024-12-29T08:23:54.000Z","dependencies_parsed_at":"2023-05-31T12:15:52.509Z","dependency_job_id":null,"html_url":"https://github.com/brainelectronics/STM32-Flash-Lock","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/brainelectronics%2FSTM32-Flash-Lock","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/brainelectronics%2FSTM32-Flash-Lock/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/brainelectronics%2FSTM32-Flash-Lock/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/brainelectronics%2FSTM32-Flash-Lock/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/brainelectronics","download_url":"https://codeload.github.com/brainelectronics/STM32-Flash-Lock/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248369296,"owners_count":21092550,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["bash-script","chip","flash","lock","openocd","stlink","stm32","stm32f103","telnet","unlock"],"created_at":"2024-11-18T16:18:23.346Z","updated_at":"2025-04-11T09:44:03.731Z","avatar_url":"https://github.com/brainelectronics.png","language":"Shell","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Flash and Lock STM32 devices\n\nBare minimum scripts to lock or unlock STM32 devices\n\n---------------\n\n## Tools\n\nInstall the following tools on your system.\n\n### Openocd\n\n*used version 0.10.0*\n\n#### Linux\n\n```bash\nsudo apt-get install openocd\n```\n\n#### Mac\n\nSee [xpack OpenOCD Installation instructions](https://xpack.github.io/openocd/install/)\nor download latest released version, unzip it and change its rights.\n\n```bash\nwget https://github.com/xpack-dev-tools/openocd-xpack/releases/download/v0.10.0-14/xpack-openocd-0.10.0-14-darwin-x64.tar.gz\ntar -zxvf xpack-openocd-0.10.0-14-darwin-x64.tar.gz\nchmod -R -w xpack-openocd-0.10.0-14-darwin-x64\n```\n\nMove the files into your applications folder and create a symlink to use it\nwith the same commands as on linux\n\n```bash\nsudo ln -s /Volumes/Macintosh\\ HD/Applications/OpenOCD/ /usr/share/openocd\n```\n\n### telnet\n\n```bash\nsudo apt-get install telnet\n```\n\n## General\n\n### Run openocd with telnet\n\nCall this in first terminal\n\n```bash\nopenocd -d3 -f stlink-v2.cfg -c \"transport select hla_swd\" -f stm32f1x.cfg\n```\n\nopen second terminal\n\n```bash\ntelnet 127.0.0.1 4444\n```\n\n### Programming with scripts\n\nIf the chip is locked, it can't be programmed until it is unlocked.\n\nA power cycle is required after locking the chip to run the program.\n\nUnlocking the chip will erase it's content completly.\n\n#### Config\n\nConfig files for STLink are located at `/usr/share/openocd/scripts/interface/`,\nconfig for targets can be found at ` /usr/share/openocd/scripts/target/`.\n\nBe aware of different STLink versions, which only differ in one single char of VID.\n\n#### Flashing\n\n```bash\nsh flash.sh path/to/some/file.bin\n```\n\nFlash a file with debug level 1\n\n```bash\nsh flash.sh path/to/some/file.bin -d1\n```\n\n#### Locking\n\nLock a STM32F1 with a STLink V2\n\n```bash\nsh lock.sh\n```\n\nPerform lock with debug level 2 on a STM32F1 with a STLink V2\n\n```bash\nsh lock.sh -d2\n```\n\nUse `general_un_lock_st.sh` to lock or unlock a general STM32 device. The\nfollowing example is for an STM32F0 by using a STLink\n\n```bash\nsh un_lock_st.sh \\\n/Applications/OpenOCD/bin/openocd \\\n/Applications/OpenOCD/scripts \\\nstlink \\\nstm32f0x \\\nlock\n```\n\n#### Unlocking\n\nUnlock a STM32F1 with a STLink V2\n\n```bash\nsh unlock.sh\n```\n\nPerform unlock with debug level 1 on a STM32F1 with a STLink V2\n\n```bash\nsh unlock.sh -d1\n```\n\nUse `general_un_lock_st.sh` to lock or unlock a general STM32 device. The\nfollowing example is for an STM32F0 by using an STLink\n\n```bash\nsh un_lock_st.sh \\\n/Applications/OpenOCD/bin/openocd \\\n/Applications/OpenOCD/scripts \\\nstlink \\\nstm32f0x \\\nunlock\n```\n\n#### Power cycle (only on raspberry)\nPower cycle the target by using a raspberry pi pin.\n\nConnect VCC of the debug interface via a transistor or mosfet to VCC.\nThe mosfet or transistor is controlled by the raspberry pi pin.\n\nYou have to run this script once to configure the pin and turn it on.\n\n```bash\npython power_cycle.py\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbrainelectronics%2Fstm32-flash-lock","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbrainelectronics%2Fstm32-flash-lock","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbrainelectronics%2Fstm32-flash-lock/lists"}