# NRF51 Firmware Development Notes # Documentation nRF51-specific documentation: * [nRF51822 Product Specification](http://www.nordicsemi.com/eng/nordic/Products/nRF51822/nRF51822-PS/20339) * [nRF51822 Reference Manual](http://www.nordicsemi.com/eng/nordic/Products/nRF51822/nRF51-RM/20337) Generic ARM documentation: * [Cortex™-M0 Devices Generic User Guide](http://infocenter.arm.com/help/topic/com.arm.doc.dui0497a/DUI0497A_cortex_m0_r0p0_generic_ug.pdf) * [Cortex™-M0 Technical Reference Manual](http://infocenter.arm.com/help/topic/com.arm.doc.ddi0432c/DDI0432C_cortex_m0_r0p0_trm.pdf) # Chip Details ## Address Map 0xE000 0000 Private Peripherals Bus ... ... 0x5000 0000 ABH Peripherals ... 0x4000 0000 APB Peripherals ... 0x2000 0000 Data RAM ... 0x1000 1000 UICR ... 0x1000 0000 FICR ... 0x0000 0000 Code FLASH ### Flash and RAM Areas | Device | Flash ||| RAM ||| Device | Size | Start | End | Size | Start | End | ------- | ------ | ----------- | ----------- | ------ | ----------- | ----------- | `xxAA` | 256kB | 0x0000 0000 | 0x0002 0000 | 16kB | 0x2000 0000 | 0x2000 4000 | `xxAB` | 128kB | 0x0000 0000 | 0x0001 0000 | 16kB | 0x2000 0000 | 0x2000 4000 | `xxAC` | 256kB | 0x0000 0000 | 0x0002 0000 | 32kB | 0x2000 0000 | 0x2000 8000 | [Available resources for chip variants] # Debugging When using the nRF51-DK or the dongle you'll talk to the nRF chip through the Segger chip. It will only listen for traffic when a terminal is connected to /dev/ttyACM0. The terminal must use the DTR (data terminal ready) signal for the Segger to disable the tristating of the uart pins and start listening. screen /dev/ttyACM0 115200,ixon,ixoff ## GDB (gdb) print (gdb) info registers ## Remote Debugging * `target remote localhost:2331` * `disconnect` or `detach` * the generic `monitor` commands sends jlink-specific commands. `monitor reset` When using GDB, make sure you use the version for arm: arm-none-eabi-gdb I often start GDB like this: arm-none-eabi-gdb -ex "file build/*.out" -ex "target remote localhost:2331" -ex "monitor reset" This select the correct image so you can say `break main`, connects to the JLink remote GDB server and performs a reset of the board. # The JLink tools ## JLinkGDBServer This program is normally executed as JLinkGDBServer -if SWD It should find the target and wait for an TCP connection on port 2331. Sometimes it will refuse to listen to the socket, just waiting (around 10 seconds) for a while seems to fix the problem. Example output: $ JLinkGDBServer -if SWD SEGGER J-Link GDB Server V4.98e Command Line Version JLinkARM.dll V4.98e (DLL compiled May 5 2015 11:49:35) -----GDB Server start settings----- GDBInit file: none GDB Server Listening port: 2331 SWO raw output listening port: 2332 Terminal I/O port: 2333 Accept remote connection: yes Generate logfile: off Verify download: off Init regs on start: off Silent mode: off Single run mode: off Target connection timeout: 0 ms ------J-Link related settings------ J-Link Host interface: USB J-Link script: none J-Link settings file: none ------Target related settings------ Target device: unspecified Target interface: SWD Target interface speed: 1000kHz Target endian: little Connecting to J-Link... J-Link is connected. Firmware: J-Link OB-SAM3U128-V2-NordicSemi compiled May 4 2015 13:48:48 Hardware: V1.00 S/N: 681084376 Checking target voltage... Target voltage: 3.30 V Listening on TCP/IP port 2331 Connecting to target...WARNING: T-bit of XPSR is 0 but should be 1. Changed to 1. Connected to target Waiting for GDB connection...