コード番人 (Kodobannin) or “code keeper” is the code repository for Hello products based on the Nordic nRF51822 chipset.
Kodobannin has the concept of a hardware platform (or platform), an app, and a build.
IMU_SPI_MOSI constant, which is a GPIO pin number that an app uses to talk to the accelerometer (IMU) via SPI. A hardware platform may also define any other functions or constants specific to that platform.It’s easiest to understand these with examples. Some examples of hardware platforms are:
band, the name of the app).Some examples of apps are:
A build is a combination of an app paired with a hardware platform. (An app must be paired with a hardware platform to run.) For example, band+band_EVT3 is the band app paired with the band_EVT3 hardware platform, while hello_world+EK is the Hello World app designed to run on the Evaluation Kit.
Hardware platform and apps share the same namespace (because the build system uses the root directory of the code repository for both these things), so you cannot call an app the same name as a platform, and vice versa. In other words, having an app named “morpheus” and a platform named “morpheus” is invalid, but an app named “morpheus” and a platform named “morpheus_PVT” is OK. This will likely be good for your own sanity, too.
We use GNU make to build the firmware. To build a firmware binary, do:
make app+platform
For example:
make band+band_EVT3
make bootloader+band_EVT3
make hello_world+EK
Building a binary will put the resulting binary in the build/app+platform/ directory.
To build & upload (or program) some hardware, do:
make p-app+platform # p- prefix is for "program"
For example:
make p-band+band_EVT3
make p-hello_world+EK
Programming the hardware will upload the binary from the build/app+platform/ directory to the hardware via the J-Link tools. You can also program both the app and the bootloader for the platform adding -bootloader to the app name, e.g.
make p-band+bootloader+band_EVT3
make p-hello_world+bootloader+EK
To debug some hardware (without building and uploading), do:
make g-app+platform # g- prefix mirrors gcc's -g debug flag
For example:
make g-band+band_EVT3
make g-bootloader+EK
All build products get put into the build/ directory.
Each build product will get put into its own app+platform directory inside the build directory, and each source file will have its corresponding .o (object) and .d (dependency) file. This implies that there are no object files shared between any app+platform combination, by design.
The build is designed to be parallelized by default, so you should run make -j8 where possible. (I’d recommend adding export MAKEFLAGS=-j8 to your ~/.profile for default parallel builds with Make. This will break some builds, but you can easily run those with make -j1.)
Every .c and .s (Assembly) file from each app directory and platform directory will be compiled.
Decide on a name for your app, e.g. myapp.
Create a directory for your app: mkdir myapp.
Add at least one .c file to your app directory that has a void _start() function, which is the entry point for your app. By convention, we call this file main.c, but you can call it whatever you want. You can also add whatever other other .c and .s your app needs to your app directory for it to function, e.g. the band app has both a main.c and a peak_detect.c file.
Add a startup/myapp.ld file, which is the linker script for your app. In most cases, you can probably symlink this to the app.ld script, unless your app is unusual: ln -s app.ld startup/myapp.ld
To enable programming via make p-myapp+platform, add a prog/myapp+platform.jlink.in file. This is a file that gets fed directly to the JLinkExe tool, and should have some commands to upload your code to the hardware device. See the other prog/*.jlink.in files for examples. You can use the $PWD and $BUILD_DIR variables in your script.
A platform is nothing special; it’s just a directory where:
.c and .s files in the directory are treated as source code and compiled, and-I flag to gcc).So it’s really up to the app to define whatever you need from the platform. By convention, the app typically does #include "platform.h", which implies that each platform has a platform.h file. You can put a myapp/ directory inside the platform directory and do #include "myapp/platform.h"; it’s entirely up to you. See the other platform directories (EK, band_EVT3) for examples.
Typing in the above make commands to build, upload/program and debug firmware should automatically download all the required dependencies. The Makefile is the authoritative place to check dependencies since that is always up to date, but here are some of them:
GCC for ARM. A direct link to the current version we use is https://launchpad.net/gcc-arm-embedded/4.7/4.7-2013-q3-update/+download/gcc-arm-none-eabi-4_7-2013q3-20130916-mac.tar.bz2. There are also more recent versions (e.g. GCC 4.8) that are available for other platforms (Windows, Linux), if you’d like to be enterprising.
The J-Link toolchain. The direct link to the current version we use is http://www.segger.com/jlink-software.html?step=1&file=JLinkMacOSX_474. (You will need to enter in the serial number on your J-Link to download it.)
micro-ecc, for elliptic curve cryptography support.
Of course, Nordic’s SoftDevice and nRF51 SDK libraries to provide a Bluetooth Low Energy stack.
The Band has serial port output. You will want the serial port set to 38400 8N1. (8 stop bits, no parity, 1 stop bit.) Plugging in a USB serial port should add a new device at /dev/cu.usbserial-SOMETHING.
Here are a few ways to get OS X to talk to serial ports. Take your pick of what you prefer. On pre-Mavericks (OS X 10.8 and below) machines, you’ll need the FTDI serial driver from FTDI to make the serial port appear.
Run tools/serial_cat, which will automatically try to figure out the serial port that appeared at /dev and start echoing its contents to the console.
screen /dev/cu.usbserial-* 38400. Unless you know GNU screen voodoo, screen may or may not override your Terminal scrollback buffer, which you may or may not want.
brew install minicom && minicom -D /dev/cu.usbserial-* -b 38400. Minicom is a fairly old Unix program that was popular back in the warez^H^H^H^H^Hmodem days. You may want to disable the status line by pressing Esc -> O -> Screen and keyboard -> C.
If you are 31337 like Andre and like to use cat:
exec 3<> /dev/cu.usbserial-* # attach file descriptor 3 to serial port
stty -f /dev/cu.usbserial-* speed 38400 # set serial port to 38400 baud
cat <&3 # run cat with stdin attached to file descriptor 3