<?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=Jlukanc</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=Jlukanc"/>
	<link rel="alternate" type="text/html" href="https://wiki.pine64.org/wiki/Special:Contributions/Jlukanc"/>
	<updated>2026-05-06T16:09:42Z</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=5597</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=5597"/>
		<updated>2020-05-15T22:30:13Z</updated>

		<summary type="html">&lt;p&gt;Jlukanc: /* Raspberry Pi */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;= Introduction =&lt;br /&gt;
&lt;br /&gt;
The PineTime Dev Kit comes with the back not glued down to allow it to be easily reprogramed but the kit does not include an hardware programmer. There are a bewildering variaty of different hardware programmers available but whatever programmer you have there are only a few tasks you will have to learn about:&lt;br /&gt;
&lt;br /&gt;
* Unlock the device&lt;br /&gt;
* Upload new software&lt;br /&gt;
* Run a debugger&lt;br /&gt;
&lt;br /&gt;
Unlocking the device is a one-time action that is needed to enable to debug port and provide full access to the device. Unlocking the device will erase all existing software from the internal flash.&lt;br /&gt;
&lt;br /&gt;
= Black Magic 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;
== Adapters ==&lt;br /&gt;
&lt;br /&gt;
=== Native adapters ===&lt;br /&gt;
&lt;br /&gt;
The native adapters are the official Black Magic family of debug adapters, including the original Black Magic Probe and the Black Magic Probe Mini. By buying the official hardware you are supporting the continued development of the Black Magic Probe software.&lt;br /&gt;
&lt;br /&gt;
Providing your native adapter is running up-to-date firmware then it can be used to program your PineTime.&lt;br /&gt;
&lt;br /&gt;
=== STM32 (Blue Pill) ===&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;
=== Other hardware ===&lt;br /&gt;
&lt;br /&gt;
The Black Magic Probe firmware can be run on a variety of host devices. See [https://github.com/blacksphere/blackmagic/wiki/Debugger-Hardware BMP Debugger Hardware] for more information.&lt;br /&gt;
&lt;br /&gt;
== Uploading new software ==&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;
= nrfjprog =&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;
== Hookup ==&lt;br /&gt;
&lt;br /&gt;
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;
== Unlocking the FLASH ==&lt;br /&gt;
&lt;br /&gt;
Unlocking 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 &lt;br /&gt;
flash memory of the MCU!''' :&lt;br /&gt;
 &lt;br /&gt;
 nrfjprog -f NRF52 --recover&lt;br /&gt;
&lt;br /&gt;
== Uploading new software ==&lt;br /&gt;
&lt;br /&gt;
1. 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;
2. 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;
3. Reset and run the new firmware:&lt;br /&gt;
 &lt;br /&gt;
 nrfjprog -f NRF52 --reset&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
= OpenOCD =&lt;br /&gt;
&lt;br /&gt;
== Adapters ==&lt;br /&gt;
&lt;br /&gt;
=== CMSIS-DAP ===&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;
=== 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;
=== 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;
Additionally, look at [https://github.com/jlukanc1/pinetime-boot-flasher this Github repo] for a script that aims to simplify the bootloader install process by using a modified version of the above scripts.&lt;br /&gt;
&lt;br /&gt;
=== STLink ===&lt;br /&gt;
&lt;br /&gt;
TODO&lt;br /&gt;
&lt;br /&gt;
== Unlocking the device ==&lt;br /&gt;
&lt;br /&gt;
Once you have connected to the device then the OpenOCD command console is accessable via a network socket. If you need to disable access port protection then you can do this using the following commands below.&lt;br /&gt;
&lt;br /&gt;
Note: ''Unlocking the device to remove access port protection will erase the contents of flash.''&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;br /&gt;
&lt;br /&gt;
== Uploading new software ==&lt;br /&gt;
&lt;br /&gt;
Just issue this command, replace ''code.hex'' with your own (and cmsis-dap.cfg with an approprate adapter).&lt;br /&gt;
&lt;br /&gt;
  openocd -c 'source [find interface/cmsis-dap.cfg]; transport select swd; source [find target/nrf52.cfg]' \&lt;br /&gt;
      -c init \&lt;br /&gt;
      -c 'nrf5 mass_erase' \&lt;br /&gt;
      -c 'program code.hex verify' \&lt;br /&gt;
      -c reset \&lt;br /&gt;
      -c exit&lt;/div&gt;</summary>
		<author><name>Jlukanc</name></author>
	</entry>
</feed>