HW setup with an LPC-Link2 in CMSIS-DAP mode
#1
If you have an LPC-Link2 lying around, you can use it to debug/develop on the PineTime dev kit.

First, you need to flash a CMSIS-DAP firmware on the LPC-Link2. NXP has these.

If you're using the wires provided with the PineTime, then you will need to populate the J6 location on the LPC-Link2; it's the only one which expects a pin header. I fitted a 9-pin right-angle header.

Then you have to properly match the PineTime SWD pinout to the J6 header pins. Gnd goes to pin 8, Vcc to pin 1, SWDIO to pin 2 and SWDCLK to pin 3.

Last, you have to put jumpers on both JP1 and JP2 of the LPC-Link2. JP1 will make it boot on its internal firmware and thus act as a CMSIS-DAP probe; JP2 will power the SWD signal buffers. If you forget JP2, OpenOCD will recodgnize the probe but not the PineTime.

Then you need a configuration file for OpenOCD. This file should contain the following:


Code:
source [find interface/cmsis-dap.cfg]
source [find target/nrf52.cfg]
telnet_port 4444

Name this file appropriately -- I named mine pinetime-lpc-link2-cmsis-dap.cfg.

Now run OpenOCD. In Linux, I run

Code:
openocd -f pinetime-lpc-link2-cmsis-dap.cfg -c init

At this point, if your PineTime still contains the factory firmware, it will be access-protected, i.e. you cannot read from it or write to it yet. You'll know it's the case if OpenOCD says "Error: Could not find MEM-AP to control the core".

If your PineTime is access-protected, you'll have to unprotect it before you can program it. This will remove the factory firmware, but it will have to go at some point, right? So open a second terminal, connect to OpenOCD using for instance

Code:
telnet localhost 4444

Now issue the following command:

Code:
dap apreg 1 0x0c

If the value displayed is 0x00000000 then your PineTime is indeed access-protected, and you can unprotect it by issuing

Code:
dap apreg 1 0x04 0x01

then

Code:
reset


to which OpenOCD should eventually display

Code:
nrf52.cpu: hardware has 6 breakpoints, 4 watchpoints

... and that is the sign that your PineTime is unprotected and now ready to be reprogrammed!
#2
Good post @aaribaud !

I'd like to comment that any 8-dollar Daplink from AliXpress is also a good option and it comes ready-to-use with PineTime (and other nRF52 boards). It can be managed with OpenOCD (and pyocd).

For the first time, nRF5x microcontrollers usually need to be erased. This step can be done with the next script (tested with OpenOCD 0.10), save it as 'flash_erase.cfg':

Code:
# flash_erase.cfg

source [find interface/cmsis-dap.cfg]
source [find target/nrf52.cfg]

init
nrf52.dap apreg 1 0x04 0x01
sleep 100
shutdown


Connect the Daplink to the PineTime (GND, CLK, SWD, 3V3)  and simply execute from the command line:

Code:
openocd -f flash_erase.cfg

Disconnect the 3V3 (or the USB cable from computer) and connect again. Now, your PineTime is ready to be flashed with a fresh firmware.

I've tested pyocd runner with Zephyr:

Code:
cd $ZEPHYR_BASE/samples/basic/blinky
west flash --runner pyocd

Happy flashing!
#3
Feel free to add this information to the Wiki article as well: https://wiki.pine64.org/index.php?title=...e_PineTime

It'd be a lot more accessible there.


Forum Jump:


Users browsing this thread: 1 Guest(s)