Difference between revisions of "Reprogramming the PineTime"

From PINE64
Jump to navigation Jump to search
Line 96: Line 96:
     0x00000001
     0x00000001


== Flashing a new piece of software ==
==== Flashing a new piece of software ====


Just issue this command, replace ''code.hex'' with your own.
Just issue this command, replace ''code.hex'' with your own.


   openocd -s ./tcl -c 'source [find interface/cmsis-dap.cfg]; transport select swd; source [find target/nrf52.cfg]' -c init -c 'nrf5 mass_erase' -c "program code.hex verify" -c reset -c exit
   openocd -s ./tcl -c 'source [find interface/cmsis-dap.cfg]; transport select swd; source [find target/nrf52.cfg]' -c init -c 'nrf5 mass_erase' -c "program code.hex verify" -c reset -c exit

Revision as of 23:54, 6 February 2020

Programming the PineTime

Using JLink programmer and nrfjprog tools

The following steps have been tested with the Segger JLink embedded in the NRF52-DK development board.

1. Connect the Pinetime SWD pins to the debugger (P20 on NRF52-DK)

Pintime JLink
GND GND
SWDCLK SWDCLK
SWDIO SWDIO
VCC (3.3V) VTG (target detect)

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! :

nrfjprog -f NRF52 --recover

3. Program the BLE softdevice (if needed by the firmware). Replace PATH_TO_NRF_SDK by the path where you unzipped the NRF52 SDK :

nrfjprog -f NRF52 --program /PATH_TO_NRF_SDK/components/softdevice/s132/hex/s132_nrf52_6.1.1_softdevice.hex --sectorerase

4. Program the firmware (replace firmware.hex by the actual filename of the firmware):

nrfjprog -f NRF52 --program firmware.hex --sectorerase

5. Reset and run the new firmware:

nrfjprog -f NRF52 --reset

Using OpenOCD and a Raspberry Pi

Instructions in Medium post, subsequently updated with a more reliable method under development, so may be a bit of a moving target.

Using OpenOCD and a JLink

Start OpenOCD:

openocd \
   -c 'interface jlink; transport select swd; source [find target/nrf52.cfg]' \
   -c 'init'

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

BlackMagic Probe

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

Using STM32 (Blue Pill) as BlackMagic Probe

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 forum post or 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 this link for more detals.

Using BlackMagic Probe to debug PineTime

Refer to the BMP wiki for the full description of commands. 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:

 target extended-remote /dev/ttyBmpGdb
 monitor swdp_scan
 attach 1
 file %firmware file%

Then one may use load command to flash the firmware, compare-sections to verify the upload, or monitor erase_mass to erase the firmware. Then, proceed with debugging as normal.

Using OpenOCD and a CMSIS-DAP dongle

Copied from this article.

Issue this command to initialize a connection to the devkit:

 openocd -d2 -c 'source [find interface/cmsis-dap.cfg]; transport select swd; source [find target/nrf52.cfg]'
 

After that command you can connect to localhost and execute unlock commands. Full wipe after this is required to do further flashing.

 telnet localhost 4444
   Trying 127.0.0.1...
   Connected to localhost.
   Escape character is '^]'.
   Open On-Chip Debugger
   > nrf52.dap apreg 1 0x04
   0x00000000
   > nrf52.dap apreg 1 0x04 0x01
   > nrf52.dap apreg 1 0x04
   0x00000001

Flashing a new piece of software

Just issue this command, replace code.hex with your own.

 openocd -s ./tcl -c 'source [find interface/cmsis-dap.cfg]; transport select swd; source [find target/nrf52.cfg]' -c init -c 'nrf5 mass_erase' -c "program code.hex verify" -c reset -c exit