- These notes are glued from other tutorials found.
- I use mac OS Catalina, so some commands are relevant. However installing needed packages is simple on Linux dists.
- Feel free to improve.
- hardware: STM32F103C8T6 + ST-Link V2 Mini STM8 (I have this one)
- software:
- Black Magic Probe - https://github.com/blacksphere/blackmagic
- OpenOCD -
brew install open-ocd - ST-Link -
brew install stlink - GNU Arm Embedded Toolchain:
brew cask install gcc-arm-embedded
Note that Mac OS Catalina has security feature that blocks unverified apps.
Cannot be opened because the developer cannot be verified.
You can fix your gcc-arm-embedded binaries using:
xattr -d com.apple.quarantine <path to binary>
I glued information mainly from these tutorials:
- http://blog.linuxbits.io/2016/02/15/cheap-chinese-st-link-v-2-programmer-converted-to-black-magic-probe-debugger/
- https://buger.dread.cz/tag/black-magic-probe.html
git clone https://github.com/blacksphere/blackmagic.git
cd blackmagic
make
cd src
make clean && make PROBE_HOST=swlink
According to buger swlink is not typo (many tutorials mention stlink), it maps SWDIO/SWCLK to already soldered pins near 3.3V and GND.
Connect ST-Link V2 (with aluminum cover) to STM32F103C8T6 board (3.3V<->3.3V, GND<->GND, SWDIO<->SWDIO, SWCLK<->SWCLK), we will use ST-Link to flash BMP into STM board.
My openocd files were in /usr/local/opt/openocd/share/openocd/scripts/ so I change directory in.
openocd -f interface/stlink-v2.cfg -f target/stm32f1x.cfg -c "init" -c "halt" -c "stm32f1x unlock 0" -c "shutdown"
st-flash erase
st-flash --flash=0x20000 --reset write blackmagic.bin 0x8002000
st-flash --flash=0x20000 --reset write blackmagic_dfu.bin 0x8000000
Flashing .hex or .elf file is easy. Run arm-none-eabi-gdb and then enter following commands. Plugging Black Magic Probe to USB created two devices. Name consist of serial number (e.g. E0CD9EC7) which can be obtained in mac OS system profiler (for Linux use lsusb or something similar).
(gdb) target extended-remote /dev/tty.usbmodemE0CD9EC71
Remote debugging using /dev/tty.usbmodemE0CD9EC71
(gdb) mon swdp_scan
Target voltage: ABSENT!
Available Targets:
No. Att Driver
1 Nordic nRF52 M3/M4
2 Nordic nRF52 Access Port
(gdb) att 1
Attaching to Remote target
...
(gdb) file apps/pinetime/bin/pinetime/PineTime.elf
A program is being debugged already.
Are you sure you want to change the file? (y or n) y
Reading symbols from apps/pinetime/bin/pinetime/PineTime.elf...
(gdb) load
Loading section .text, size 0x34f70 lma 0x0
Loading section .ARM.exidx, size 0x8 lma 0x34f70
Loading section .relocate, size 0x418 lma 0x34f78
Start address 0x480, load size 218000
Transfer rate: 44 KB/sec, 968 bytes/write.
(gdb) detach
Detaching from program: ..../apps/pinetime/bin/pinetime/PineTime.elf, Remote target
[Inferior 1 (Remote target) detached]
(gdb) quit
See also page already mentioned in PineTime wiki FAQ) https://devzone.nordicsemi.com/nordic/nordic-blog/b/blog/posts/flashing-and-debugging-nrf5152-with-a-cheap-blackm