So, the main goal here is to set up OpenOCD to flash firmware using an STLinkV2 debugger.
The text suggests building OpenOCD from source because packaged versions in Linux distributions might be outdated and lack support for NRF52. Here are the steps:
-
Install dependency:
sudo apt-get update sudo apt install make sudo apt-get install git sudo apt install openocd sudo apt-get install pkg-config autoconf automake libtool make
git clone https://git.code.sf.net/p/openocd/code openocd-code
-
Change directory:
cd openocd-code -
Prepare the build environment:
./bootstrap
-
Configure the build:
./configure --enable-stlink
-
Build the project:
make -j4
-
Install it:
sudo make install
After installation, it's necessary to configure UDEV to allow OpenOCD to access the STLinkV2 via USB:
-
Copy the UDEV rule:
sudo cp contrib/60-openocd.rules /etc/udev/rules.d/
-
Reload the UDEV rules:
sudo udevadm control --reload-rules
Once that's done, you can plug in the STLinkV2 and run OpenOCD to test the connection:
openocd -f interface/stlink.cfg -f target/nrf52.cfgThe output should show that OpenOCD is running and detects the STLinkV2. However, it might give an error about not being able to connect to the target if the STLinkV2 isn't connected to the PineTime yet.
OpenOCD uses configuration files to specify how it should interact with the debugger and the target device. The text mentions two types of configuration files:
-
Common configuration file:
openocd-stlink.ocdThis file includes:
-
interface/stlink.cfg: Specifies the STLink interface. -
target/nrf52.cfg: Specifies the NRF52 target.
Additionally, it enables flashing via GDB and overrides breakpoints to be hard.
-
-
User files for specific flashing operations:
-
flash_bootloader_app.ocd: Flashes the bootloader and the application firmware. -
flash_graphics.ocd: Flashes the graphics flasher.
-
These files contain commands to initialize the debugger, program specific binary files to memory addresses, and reset the target.
Jtag for RK3566 using STLinkV2: stlink.cfg rk3566.cfg
~/openocd-code/tcl$ openocd -f interface/stlink.cfg -f target/rk3566.cfgThe text provides examples of how to use these configuration files:
-
Flashing bootloader and application:
openocd -f ./openocd-stlink.cfg -f ./flash_bootloader_app.ocd
-
Flashing graphics flasher:
openocd -f ./openocd-stlink.cfg -f ./flash_graphics.ocd
There's a mention of using pogo pins to connect the STLinkV2 to the PineTime, along with images showing the SWD pinout and the pogo pins. It also refers to additional wiring information on a wiki page.
Overall, this text provides a detailed guide on how to set up and use OpenOCD with an STLinkV2 debugger to flash firmware onto the PineTime device. It covers installation, configuration, and practical examples of flashing different components of the firmware.
-
Building from source: This is often necessary for up-to-date features, especially with rapidly evolving hardware like the NRF52.
-
UDEV rules: Important for permissions when accessing USB devices from non-root users.
-
Configuration files: Key to telling OpenOCD what to do. Need to make sure the paths to the binary files are correct.
-
Pogo pins: A convenient way to make SWD connections without soldering, though they might require steady hands or some form of jig to hold everything in place.
-
Error handling: The initial error about not connecting to the target is expected if the STLinkV2 isn't properly connected to the PineTime.
-
Safety precautions: When working with hardware, always ensure that the device is powered off and handled carefully to avoid damage.