Skip to content

Instantly share code, notes, and snippets.

@darnel
Last active January 27, 2020 06:59
Show Gist options
  • Save darnel/dac1370d057e176386ca4026418abc2b to your computer and use it in GitHub Desktop.
Save darnel/dac1370d057e176386ca4026418abc2b to your computer and use it in GitHub Desktop.

Flashing PineTime with Black Magic Probe (based on ST-Link V2)

  • 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.

Converting STM32F103C8T6 to Black Magic Probe

  • hardware: STM32F103C8T6 + ST-Link V2 Mini STM8 (I have this one)
  • software:

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:

Black Magic Probe

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.

Flashing BMP to ST-Link V2

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 PineTime

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment