Newer
Older
Nordic Radio's NRF52832 is a nice little chip -- It has a Cortex M4 running at 64 MHz, a 2.4 GHz RF transceiver, 512 kb of flash, a 12 bit 200 ksps ADC, 5x 32 bit timers, a flexible peripheral interconnect system with DMA, and lots of other bells and whistles.
In particular, the chip performs very well for its cost on tests measuring the speed of information transfer in and out of the CPU and over the RF channel. https://pub.pages.cba.mit.edu/ring/
## Programming the NRF52
Programming involves two steps: 1) compiling code, and 2) flashing the code to the chip.
Thanks to the folks at Adafruit, you can use the Arduino IDE to perform both steps. Instruction on installing the appropriate libraries can be found <a href='https://learn.adafruit.com/bluefruit-nrf52-feather-learning-guide'>here</a>.
To build the toolchain for compilation manually, you can follow the instructions on <a href='https://pcbreflux.blogspot.com/2016/09/nrf52832-first-steps-with-st-link-v2.html'>this page</a> (starting at heading "GNU ARM Compiler").
The steps for flashing your code depends on what board and programmer you have.
This is a great board; I would highly recommend it for NRF52 projects.
This board comes flashed with a Serial DFU bootloader and it has an onboard USB-to-Serial converter. This allows you to program it simply with a USB cable.
The Segger J-Link is a very helpful tool, but it's quite expensive. With it, we can use Nordic's command line utilities, including `nrfjprog`. I wrote a shell script with three commands to erase, flash the adafruit bootloader, and then start the chip running.
```
nrfjprog -f nrf52 --eraseall
nrfjprog -f nrf52 --program feather52_bootloader_v050_s132_v201.hex
nrfjprog -f nrf52 --run
```
<img src='jlink/jlink-wiring.jpg' width=22%>
<img src='jlink/flashing-bootloader.png' width=64%>
The J-Link requires a wire to ensure the target has power. In the image above, red is target power (3.3V), black is ground, green is SWDCLK, and blue is SWDIO.
You don't have to spend hundreds on a J-Link (even though it is very nice). Using <a href='openocd.org'>OpenOCD</a>, we can make a Raspberry Pi bit-bang the programming protocols.
<img src='openocd/bootloader-raspberrypi.jpg' width=53%>
<img src='openocd/flashing-bootloader.png' width=30%>
Support for the NRF52 is not in the stable release of OpenOCD as of V 0.10, but you can patch it following the instructions on <a href='https://primalcortex.wordpress.com/2017/06/10/setting-up-openocd-for-programming-the-nordic-nrf52832-chip/'>this page</a>. They worked for me, with the small addition that I needed to eliminate two duplicate variable definitions that broke my build.