Skip to content

Instantly share code, notes, and snippets.

@NickShargan
Created December 14, 2019 09:42
Show Gist options
  • Save NickShargan/2413e252775f1ff5bef5c566284822ea to your computer and use it in GitHub Desktop.
Save NickShargan/2413e252775f1ff5bef5c566284822ea to your computer and use it in GitHub Desktop.

Install OpenOCD

  1. 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
  1. Clone stlink:
git clone https://github.com/texane/stlink
  1. 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
  1. 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

Setup environment for running example from SDK(tested on v12.3)

Based on tutorial in blog post and youtube video

  1. Download SDK
  2. Install ARM compiler:
sudo add-apt-repository ppa:team-gcc-arm-embedded/ppa
sudo apt-get update
sudo apt-get install gcc-arm-embedded
  1. Change <nRF5_SDK>/components/toolchain/gcc/Makefile.posix::
GNU_INSTALL_ROOT := /usr/
GNU_PREFIX := arm-none-eabi
  1. 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
}
  1. 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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment