Here's how to get applications for the nrf compiling on Windows. Linux and Mac users will require some small changes the home directory (%USERPROFILE% to ~), serial port (COM8 to /dev/ttyACM0), etc. I'm still working on some of these settings - I'll add it to a Github Wiki later for updating and versioning.
There are some quick start guides
And read Nordic's actual docs
The section "Application Notes > nAN36 - Creating Bluetooth Low Energy Applications Using nRF51822" is helpful for programming even though it's on an older SDK.
Read the specs for which SoftDevice version you're using. Mine is S130 V2.0
Acquiring / unpacking everything
Software we'll need:
- nrf5 SDK v12 (I may change to v10 or v11 later)
- nrf SoftDevice S130 (I may change to S110 later)
- nrf5x Command Tools (contains mergehex.exe)
- make v3.81
- gcc-arm-none-eabi v4.9
All theNRF downloads:
I'm calling my main directory "nrf" and placing it in my user directory. After unpacking everything it looks like this:
my nrf makefile location:
When I edited Makefile.windows I saw this line:
GNU_VERSION := 4.9.3
I assume that all makefiles are written for gcc 4.9.3 so I specifically got that version (4_9-2015q3).
I only needed to change my GNU_INSTALL_ROOT variable. I might change this later to match Eclipse, once that is finally configured.
GNU_INSTALL_ROOT := C:/Users/Maave/nrf/gcc-arm-none-eabi-4_9-2015q3-20150921-win32
PROGFILES lines were not needed. I didn't need to make any changes to Makefile.common
Configure makefile to match chip
I went to compile the example programs and found more directories such as "pca10028" etc. There are different types of nRF5* chips and these extra directories are the particular dev boards. The latest SDK should work for this chip, it's just not configured by default. So we make some tweaks.
Finding chip model
My two modules have chips:
to find your chip details, check the chip marking (source):
Then compare it to Nordic docs:
Packet variant and the first two digits in the build code can be read from markings on top of the nRF51 IC.
aka only "h0" and "h1" are actually written on the IC. The last digit is not written.
so now with the chart I know all my chip details
packet variant: qfaa
build code: h00 and h10
These specs match the pca10001 development board. The latest SDKs don't have samples for the pca10001 but they do have samples for the similar pca10028 (nrf51422). I still don't know exactly which SDK or SoftDevice is ideal for this project.
QFAAH1 is a rev 3 chip. To save yourself a lot of headache I recommend that you use the rev 3 chip, and the latest SDK and SoftDevice. SDK 11 and SoftDevice S132.
PCA10001 uses the nRF51822-QFAA, PCA10028 uses nRF51422-QFAC, Should be the same XTAL and LFCLK
PCA10028 has more RAM (32k instead of 16k in PCA10001), so you need to change the IRAM settings in your project. Flash seems same so IROM values should be same.
Copy one of board directories, eg pca10028, to pca10001, then go edit the makefile in there to change the board define to BOARD_PCA10001. You may also need to look at the linker script and ensure it matches your board.
The following boards are supported:
PCA10001 (part of nRF51822 Evaluation Kit) BOARD_PCA10001
Depending on the device on the legacy board, you might need to change the memory layout. For example, all nRF51 examples assume that you are using the 32 kB variant of nRF51, so if you are using a variant with 16 kB RAM, you must decrease the size of IRAM1 by 16 kB (0x4000 in hex) .... For GCC, change the linked *.ld file in the Makefile.
time to copy a pca10028 example. So I go into my examples dir I picked a simple one. Two notes
- pick a simple application like blinky, not the heartrate sensor (I ran out of memory trying to run that)
- our device is a peripheral so check /peripheral or /ble_peripheral
copy the pca10028 folder and name the new copy pca10001.
edit the makefile:
xxac with xxaa
These replacements appear optional:
51422 with 51822
10028 with 10001 (this will change features of the board like how many buttons are available)
The Softdevice reserves some amount of RAM and ROM on the chip depending on the features used. The linker decides what memory addresses to use. I'm using S130 SD v2:
Chapter 15 (p51)
SoftDevice memory usage
Required by the SoftDevice 104 kB
Required by the MBR 4 kB
APP_CODE_BASE address (absolute value) 0x0001B000
Required by the SoftDevice (in bytes):
0x1288 + Configurable Resources
Minimum: 0x13C8 (5064)
APP_RAM_BASE address (minimum required value):
0x20000000 + SoftDevice RAM consumption
in the linker file we adjust the memory values
The IROM number is correct for S130 V2.0.1
The IRAM varies depending on how you configure the SoftDevice, how many services/characteristics you add, etc. For experimental_ble_app_blinky the default IRAM base should be 0x20001fe8 in SDK 12.1, if you add something extra to the default example, you need to increase the number.
so depending on the application I'm making I'll have to change the RAM sizes. The pca10028 that I copied has 32kb RAM so I'll have to tweak it. The Windows calculator's programmer mode was handy here
RAM (rwx) : ORIGIN = 0x20001fe8, LENGTH = 0x6018
the RAM value starts at 0x20000000, so the SoftDevice is consuming 0x1fe8. Quick verification:
0x1fe8 -> 8168 (for soft device)
0x6018 -> 24600 (for application)
total: 32768 aka 32 KiB
now I tweak for the nrf51822's 16 KiB RAM
RAM (rwx) : ORIGIN = 0x20001fe8, LENGTH = 0x2018
0x1fe8 -> 8168 (for soft device)
0x2018 -> 8216 (for application)
total: 16384 aka 16 KiB
Here's another sample from the S110 softdevice on an nrf51822. S110 uses less RAM. This guy takes advantage of GNU ld's notation to make it much easier to read. I'll use this notation later.
The linker script defines the available memory of your chip, so it will be different for a 16k or 32k RAM IC, etc. It must be configured depending on the IC version you use and also depends on the SoftDevice you use because some memory is reserved for it.
Here is a linker script I use for my nRF51 (16k RAM, 256k FLASH with SoftDevice S110)
FLASH (rx) : ORIGIN = 0x0 + 96K, LENGTH = 256K - 96K
RAM (rwx) : ORIGIN = 0x20000000 + 8K, LENGTH = 16K - 8K
One more example of linker settings
Example .ld file for 256K/32K RAM variants running s110 v.8.0.0:
and same for 256K/16K:
FLASH (rx) : ORIGIN = 0x18000, LENGTH = 0x28000
RAM (rwx) : ORIGIN = 0x20002000, LENGTH = 0x2000
now that it's all configured it can be compiled
cd nRF5_SDK_12.3.0_d7731ad\examples\ble_peripheral\experimental_ble_app_blinky\pca10001\s130\armgcc\ make-3.81\bin\make.exe -f Makefile
that creates our binaries in _build. If the code utilizes the Softdevice (necessary for Bluetooth) then we merge the hex files. If it doesn't use Softdevice then we can skip this step.
cd %USERPROFILE%\nrf mergehex.exe --merge s130_nrf51_2.0.1_softdevice.hex .\nRF5_SDK_12.3.0_d7731ad\examples\ble_peripheral\ble_app_beacon\pca10001\s130\armgcc\_build\nrf51822_xxaa.hex --output blink.hex
arm-none-eabi-gdb.exe (gdb) target extended-remote COM8 (gdb) monitor swdp_scan (gdb) attach 1 (gdb) cd whatever/directory/_build (gdb) load blink.hex (gdb) run
My LED blinks!