<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://wiki.pine64.org/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=SuperPrower</id>
	<title>PINE64 - User contributions [en]</title>
	<link rel="self" type="application/atom+xml" href="https://wiki.pine64.org/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=SuperPrower"/>
	<link rel="alternate" type="text/html" href="https://wiki.pine64.org/wiki/Special:Contributions/SuperPrower"/>
	<updated>2026-04-27T05:12:24Z</updated>
	<subtitle>User contributions</subtitle>
	<generator>MediaWiki 1.37.1</generator>
	<entry>
		<id>https://wiki.pine64.org/index.php?title=Reprogramming_the_PineTime&amp;diff=4894</id>
		<title>Reprogramming the PineTime</title>
		<link rel="alternate" type="text/html" href="https://wiki.pine64.org/index.php?title=Reprogramming_the_PineTime&amp;diff=4894"/>
		<updated>2020-02-04T17:49:43Z</updated>

		<summary type="html">&lt;p&gt;SuperPrower: /* Using STM32 bluepill as blackmagic probe */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Programming the PineTime ==&lt;br /&gt;
&lt;br /&gt;
=== Using JLink programmer and nrfjprog tools ===&lt;br /&gt;
&lt;br /&gt;
The following steps have been tested with the Segger JLink embedded in the [https://www.nordicsemi.com/Software-and-Tools/Development-Kits/nRF52-DK NRF52-DK development board].&lt;br /&gt;
&lt;br /&gt;
1. Connect the Pinetime SWD pins to the debugger (P20 on NRF52-DK)&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
!Pintime&lt;br /&gt;
!JLink&lt;br /&gt;
|-&lt;br /&gt;
|GND&lt;br /&gt;
|GND&lt;br /&gt;
|-&lt;br /&gt;
|SWDCLK&lt;br /&gt;
|SWDCLK&lt;br /&gt;
|-&lt;br /&gt;
|SWDIO&lt;br /&gt;
|SWDIO&lt;br /&gt;
|-&lt;br /&gt;
|VCC (3.3V)&lt;br /&gt;
|VTG (target detect)&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
2. Unlock the device and erase the memory. '''You need to execute this step only once, to remove the read protection on the memory. Note that it will erase the whole flash memory of the MCU!''' :&lt;br /&gt;
 &lt;br /&gt;
 nrfjprog -f NRF52 --recover&lt;br /&gt;
&lt;br /&gt;
3. Program the BLE softdevice (if needed by the firmware). Replace PATH_TO_NRF_SDK by the path where you unzipped the [https://www.nordicsemi.com/Software-and-Tools/Software/nRF5-SDK NRF52 SDK] :&lt;br /&gt;
&lt;br /&gt;
 nrfjprog -f NRF52 --program /PATH_TO_NRF_SDK/components/softdevice/s132/hex/s132_nrf52_6.1.1_softdevice.hex --sectorerase&lt;br /&gt;
&lt;br /&gt;
4. Program the firmware (replace firmware.hex by the actual filename of the firmware):&lt;br /&gt;
&lt;br /&gt;
 nrfjprog -f NRF52 --program firmware.hex --sectorerase&lt;br /&gt;
&lt;br /&gt;
5. Reset and run the new firmware:&lt;br /&gt;
 &lt;br /&gt;
 nrfjprog -f NRF52 --reset&lt;br /&gt;
&lt;br /&gt;
=== Using OpenOCD and a Raspberry Pi ===&lt;br /&gt;
&lt;br /&gt;
Instructions in [https://medium.com/@ly.lee/build-and-flash-rust-mynewt-firmware-for-pinetime-smart-watch-5e14259c55 Medium post], subsequently [https://medium.com/@ly.lee/openocd-on-raspberry-pi-better-with-swd-on-spi-7dea9caeb590 updated] with a more reliable method under development, so may be a bit of a moving target.&lt;br /&gt;
&lt;br /&gt;
=== Using OpenOCD and a JLink ===&lt;br /&gt;
&lt;br /&gt;
Start OpenOCD:&lt;br /&gt;
&lt;br /&gt;
 openocd \&lt;br /&gt;
    -c 'interface jlink; transport select swd; source [find target/nrf52.cfg]' \&lt;br /&gt;
    -c 'init'&lt;br /&gt;
&lt;br /&gt;
Now you can connect to `127.0.0.1` (`localhost`) port `4444` using telnet to invoke OpenOCD commands. GDB should be available on port `3333`.&lt;br /&gt;
&lt;br /&gt;
=== BlackMagic Probe ===&lt;br /&gt;
&lt;br /&gt;
BlackMagic Probe is an JTAG/SWD adapter with open-source firmware, allowing for it to be ported to a multitude of different boards. One of it's defining features is lack of need for intermediate software such as OpenOCD - one would just need to connect to the GDB server running on the chip and proceed with debugging. For more information, refer to [https://github.com/blacksphere/blackmagic/wiki wiki].&lt;br /&gt;
&lt;br /&gt;
==== Using STM32 (Blue Pill) as BlackMagic Probe ====&lt;br /&gt;
&lt;br /&gt;
It is possible to flash a popular development board based on STM32F103C8T6 microcontroller, known as Blue Pill, to make a BlackMagic Probe device. For example, one may follow instructions in [https://forum.pine64.org/showthread.php?tid=8816&amp;amp;pid=57095#pid57095 forum post] or [https://gist.github.com/darnel/dac1370d057e176386ca4026418abc2b gist] (mac os). Also, it is possible to use SWD pins on the board to flash other devices, instead using arbitrary pins on the board itself. See [https://buger.dread.cz/black-magic-probe-bmp-on-bluepill-stm32f103c8-minimum-system-development-board.html this link] for more detals.&lt;br /&gt;
&lt;br /&gt;
==== Using BlackMagic Probe to debug PineTime ====&lt;br /&gt;
&lt;br /&gt;
Refer to the BMP [https://github.com/blacksphere/blackmagic/wiki/Useful-GDB-commands wiki] for the full description of commands.&lt;br /&gt;
Overall, the process on Linux is like following. (/dev/ttyBmpGdb is a symlink created by the udev rule). It's useful to create a gdb script file (or .gdbinit) with following commands:&lt;br /&gt;
&lt;br /&gt;
  target extended-remote /dev/ttyBmpGdb&lt;br /&gt;
  monitor swdp_scan&lt;br /&gt;
  attach 1&lt;br /&gt;
  file %firmware file%&lt;br /&gt;
&lt;br /&gt;
Then one may use '''load''' command to flash the firmware, '''compare-sections''' to verify the upload, or '''monitor erase_mass''' to erase the firmware. &lt;br /&gt;
Then, proceed with debugging as normal.&lt;br /&gt;
&lt;br /&gt;
=== Using OpenOCD and a CMSIS-DAP dongle ===&lt;br /&gt;
&lt;br /&gt;
Copied from [https://blog.aegrel.ee/absniffer-cmsis-dap-sniffer.html this article]. &lt;br /&gt;
&lt;br /&gt;
Issue this command to initialize a connection to the devkit:&lt;br /&gt;
&lt;br /&gt;
  openocd -d2 -c 'source [find interface/cmsis-dap.cfg]; transport select swd; source [find target/nrf52.cfg]'&lt;br /&gt;
  &lt;br /&gt;
After that command you can connect to localhost and execute unlock commands. Full wipe after this is required to do further flashing.&lt;br /&gt;
&lt;br /&gt;
  telnet localhost 4444&lt;br /&gt;
    Trying 127.0.0.1...&lt;br /&gt;
    Connected to localhost.&lt;br /&gt;
    Escape character is '^]'.&lt;br /&gt;
    Open On-Chip Debugger&lt;br /&gt;
    &amp;gt; nrf52.dap apreg 1 0x04&lt;br /&gt;
    0x00000000&lt;br /&gt;
    &amp;gt; nrf52.dap apreg 1 0x04 0x01&lt;br /&gt;
    &amp;gt; nrf52.dap apreg 1 0x04&lt;br /&gt;
    0x00000001&lt;/div&gt;</summary>
		<author><name>SuperPrower</name></author>
	</entry>
</feed>