Reprogramming the PineTime

From PINE64
Jump to navigation Jump to search

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

Using STM32 bluepill as blackmagic probe

Instructions in forum post or gist (mac os)

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