Install OpenOCD
- Install openocd following instructions:
git clone https://github.com/ntfreak/openocd
cd openocd
sudo apt-get install build-essential pkg-config autoconf automake libtool libusb-dev libusb-1.0-0-dev libhidapi-dev libftdi-dev
./bootstrap
./configure
make -j 4
sudo make install
- Clone stlink:
git clone https://github.com/texane/stlink
- Add rules:
sudo cp ./stlink/etc/udev/rules.d/49-stlinkv2.rules /etc/udev/rules.d/
sudo cp ./contrib/60-openocd.rules /etc/udev/rules.d/
sudo udevadm control --reload-rules
sudo udevadm trigger
- Create openocd.cfg file in ./tcl with following content:
source [find interface/stlink.cfg]
set WORKAREASIZE 0x0
transport select "hla_swd"
source [find target/nrf51.cfg]
reset_config srst_only srst_nogate
Based on tutorial in blog post and youtube video
- Download SDK
- Install ARM compiler:
sudo add-apt-repository ppa:team-gcc-arm-embedded/ppa
sudo apt-get update
sudo apt-get install gcc-arm-embedded
- Change <nRF5_SDK>/components/toolchain/gcc/Makefile.posix::
GNU_INSTALL_ROOT := /usr/
GNU_PREFIX := arm-none-eabi
- Compile blinky example:
cd <nRF5_SDK>/examples/peripheral/blinky/pca10028/s130/armgcc
make
// binary file for flashing will be stored in _build/nrf51422_xxac.hex
Ensure that memory adresses in file ./blinky_gcc_nrf51.ld corresponds to adresses from file ./components/softdevice/s130/toolchain/armgcc/armgcc_s130_nrf51422_xxaa.ld
MEMORY
{
FLASH (rx) : ORIGIN = 0x1b000, LENGTH = 0x25000
RAM (rwx) : ORIGIN = 0x200013c8, LENGTH = 0x2c38
}
- Flash device:
cd <path_to_openocd>/tcl
set file=<nRF5_SDK>/components/softdevice/s130/hex/s130_nrf51_1.0.0_softdevice.hex
openocd -f interface/stlink.cfg -f target/nrf51.cfg -c init -c "reset halt" -c "nrf51 mass_erase 0" -c "flash write_image %file%" -c reset -c exit
set file=<PATH_TO_HEX>
openocd -f interface/stlink.cfg -f target/nrf51.cfg -c init -c "reset halt" -c "flash write_image %file% 0" -c reset -c exit