Day: April 3, 2018

How to install NuttX on Nordic nRF52832

Today I tested NuttX on Nordic nRF52832 and it worked fine!!!

I used this low cost nRF52832 module:

https://www.ebay.com/itm/nRF52832-Bluetooth-4-1-BLE-Module-M4-Transparent-Transmission-CORTEX-M4-512KB-/332270581440

First you need to clone, compile and install a recent OpenOCD.

I used this mirror from github because I was facing issue with main repository:

$ git clone https://github.com/ntfreak/openocd
$ cd openocd
$ ./configure --enable-aice --enable-amtjtagaccel --enable-armjtagew --enable-cmsis-dap --enable-dummy --enable-ftdi --enable-gw16012 --enable-jlink --enable-jtag_vpi --enable-opendous --enable-openjtag_ftdi --enable-osbdm --enable-legacy-ft2232_libftdi --enable-parport --disable-parport-ppdev --enable-parport-giveio --enable-presto_libftdi --enable-remote-bitbang --enable-rlink --enable-stlink --enable-ti-icdi --enable-ulink --enable-usb-blaster-2 --enable-usb_blaster_libftdi --enable-usbprog --enable-vsllink
$ make
$ sudo make install

Now we can clone, configure and compile NuttX on nRF52832:

$ git clone https://bitbucket.org/nuttx/nuttx
$ git clone https://bitbucket.org/nuttx/apps
$ cd nuttx
$ ./tools/configure.sh nrf52-pca10040/nsh
$ make menuconfig
$ make

$ ls -l nuttx.bin 
-rwxrwxr-x 1 alan alan 61016 Abr  3 20:07 nuttx.bin

$ arm-none-eabi-size nuttx
   text	   data	    bss	    dec	    hex	filename
  60793	    220	   1972	  62985	   f609	nuttx

Now we can flash nuttx.bin in the board.

To program this board I used a stlink-v2 clone. I connected the SWDIO (board pin 33), SWDCLK (board pin 32), GND (pin 9) and VCC (pin 10) to respective pins of ST-LINK V2 programmer. Note: I connected VCC to 3.3V.

$ sudo openocd -f interface/stlink-v2.cfg -f target/nrf52.cfg -c init -c "reset init" -c halt -c "nrf5 mass_erase" -c "program nuttx.bin verify" -c reset -c exit
Open On-Chip Debugger 0.10.0+dev-00376-g3d3b45a (2018-04-03-20:18)
Licensed under GNU GPL v2
For bug reports, read
	http://openocd.org/doc/doxygen/bugs.html
WARNING: interface/stlink-v2.cfg is deprecated, please switch to interface/stlink.cfg
Info : auto-selecting first available session transport "hla_swd". To override use 'transport select '.
Info : The selected transport took over low-level target control. The results might differ compared to plain JTAG/SWD
adapter speed: 1000 kHz
Info : Unable to match requested speed 1000 kHz, using 950 kHz
Info : Unable to match requested speed 1000 kHz, using 950 kHz
Info : clock speed 950 kHz
Info : STLINK v2 JTAG v17 API v2 SWIM v4 VID 0x0483 PID 0x3748
Info : using stlink api v2
Info : Target voltage: 3.225739
Info : nrf52.cpu: hardware has 6 breakpoints, 4 watchpoints
Info : Listening on port 3333 for gdb connections
target halted due to debug-request, current mode: Thread 
xPSR: 0x01000000 pc: 0x000009f4 msp: 0x20000400
Info : nRF52832-QFAA(build code: B0) 512kB Flash
target halted due to debug-request, current mode: Thread 
xPSR: 0x01000000 pc: 0xfffffffe msp: 0xfffffffc
** Programming Started **
auto erase enabled
Warn : using fast async flash loader. This is currently supported
Warn : only with ST-Link and CMSIS-DAP. If you have issues, add
Warn : "set WORKAREASIZE 0" before sourcing nrf51.cfg/nrf52.cfg to disable it
target halted due to breakpoint, current mode: Thread 
xPSR: 0x61000000 pc: 0x2000001e msp: 0xfffffffc
wrote 61440 bytes from file nuttx.bin in 1.536207s (39.057 KiB/s)
** Programming Finished **
** Verify Started **
target halted due to breakpoint, current mode: Thread 
xPSR: 0x61000000 pc: 0x2000002e msp: 0xfffffffc
verified 61016 bytes in 0.165886s (359.198 KiB/s)
** Verified OK **
Warn : Flash driver of nrf52.flash does not support free_driver_priv()
Warn : Flash driver of nrf52.uicr does not support free_driver_priv()

You can see the NuttX starting in the serial console configured to 115200 8n1, just use a USB/Serial of 3.3V connecting P0.24 (board pin 36) to RXD, the P0.23 (pin 35) to TXD and the GND (pin 9) to USB/Serial’s GND.