howstuffworks

Today: set up your toolchain

Setting up Firmware Toolchain

Intro

The aconno firmware codebase is highly configurable using the aconno Sensorics app.
Still, you might want to make some changes in it. For that, you will need some tools aka toolchain: compiler, editor, Nordic’s SDK (Software Development Kit,  the aconno codebase and something to transfer the code to your device, for example, a JLink or aconno programmer.

First things first: The Compiler

In order to translate the source code into a hex file (hex file is a special binary format that your microprocessor understands- zeros and ones), you need to use a special program – the compiler. More about compilers can be found here.

Here at aconno, we use GNU GCC arm-none-eabi-gcc compiler for the cross-compiling process. Since it’s cross-compiling, you can use either Windows, MacOS or Linux based operating system.

On Windows:

The installation process on Windows is easy. First download the software package for your platform here: Windows source and then execute the exe file and set the PATH variable.

On Linux:

Linux users are used to the apt-get tool for convenient installations of software packages but not here.

For the compiler needed it’s better not to use apt-get because the repository does not contain a stable version and it’s not updated. So you need to go for the old style way, manually.

You can find a stable version here.

And here is the detailed installation tutorial.

Basic installation steps are shown below:

  1. Open terminal
  2. Make “opt” folder and extract downloaded compiler there
    $ tar xjf ~/Downloads/gcc-arm-none-eabi-version
  3. Change access rights for the files
    $ chmod -R -w gcc-arm-none-eabi-version
  4. After that, you want to add the Toolchain path to system/user path so you can call it from the command line without having to export variables every time you want to develop 
    $ export PATH="$PATH:$HOME/opt/gcc-arm-none-eabi-VERSION/bin"


aconno codebase

The aconno codebase consists of many libraries developed by our programmers to support all the sensors that are used on our products. Together with libraries, there are also finished firmware projects related to our hardware products. For example, in our codebase, you can find firmware support for acnSENSA, acnRANGE etc. aconno products are based on Nordic Semiconductors nRF528xx chips thus we use their SDK (Software Development Kit) as a base point for our projects. More info, APIs and examples can be found here.

The Firmware of our products is based on the RTOS (Real Time Operating System) called freeRTOS thus some modifications are made on official Nordic SDK to fit our requirements. The modified version is part of our codebase and the source can be found here:

Source.

To make modification on any of our projects, you need to have a source code of aconno’s version of Nordic SDK located locally on your machine you are cross-compiling on. The location of the SDK root map is not arbitrary. The aconno SDK should be located in the same folder as a project you want to work on.

The following folder tree demonstrates that scenario:

|---acnProject
^---|---- Source
^-----------|---- main.cpp
^---|---- aconnoBLE
^---|---- aconnoConfig
---
|---nRF5_SDK_15.2.0
^---|---- Components
---

To clone our projects, acnSENSA for example, use to following commands:
git clone https://git.simvelop.de/acnSENSA/acnSENSAFW
cd acnSENSA
git submodule update --init --recursive


The build system, it’s all about make

To translate C/C++ source code to hex file for your microprocessor, you will need to compile it. You could do it manually file by file if you had a lot of time, but please do not do that. Let the machine do the boring job for you – use one of the build system programs. We use and recommend the ‘make’ program. You can find a good tutorial about it here. It basically is fed with an instruction set on what to compile, where to find it and where to put, like a cooking recipe for nerds, and it saves a lot of time.

To build aconno project:

  1. Navigate here:
    acnProject/build
  2. Run the following command to start a make script
    $ make
  3. Run the following command
    $ make merge_softdevice

The result is stored into acnProject/build/_build map. The first command will compile all the source files and make one single hex file from it. The second command will search for the SoftDevice (hex file that allows you to use BLE part of the nrf chip) and merge its hex with your application into one hex file. The result is file named nrf52832_xxaa_and_soft.hex.

All open sourced aconno projects and libraries can be found here.


Change the code, use an Editor

Now that you learn how to compile the source code into a usable hex you can compile yourself a firmware, great huh. It would be even cooler if we changed some of the code to fit the requirements.
To change the source we need any software that can change the source, so you could even do it with VI but then you would need to know how to exit it.
Today we have more comfortable tools then just a pure text editor, we have IDEs.

An IDE brings you the comfort of having a debugger, a C++ checker, automated build systems, automated flashing, faster code browsing, an overview function usage and tons of other useful functions.

We recommend the use of these IDEs: Visual Studio Code, free and light, CLion, a C++ monster, best you can get, Keil, old industry standard (we do not really recommend this, it’s just listed as everybody uses it without knowing why) and Embedded Studio by Segger.

Here we will showcase you the installation and configuration of the Visual Studio Code if you would like to use another IDE either RTFM or wait for somebody of us to find a free time to write a document about it, but seriously, the net is full of such docs, ask Mr. Google.

Visual Studio Code editor

At aconno, we use the VS Code editor. You could ask why we do not use the well known Keil editor… Well, VSCode editor is equipped with advanced features such as code completion, static code analysis, black background (dark theme is super important) and tons of other free add-ons available. Here’re configuration steps to install the editor together with ARM development support:

  1. Clone git@git.simvelop.de:aconnoLibs/nRF5_SDK_15.2.0.git (default to the same folder, where the projects will be loaded to)
  2. Set nRF5_SDK_”15.2.0/components/toolchain/gcc/MakeFile.posix” settings, it contains the path and prefix of the gcc arm compiler
  3. Install nRF5-Command-Line-Tools
  4. Install  J-Link Software and Documentation Pack
  5. Install Visual Studio Code
  6. Install Visual Studio Code Cortex-Debug from marus25 via Extensions
  7. Clone the FreeRTOS project
  8. Set SDK_ROOT in {projectDir}/build/Makefile to where you cloned nRF5_SDK_15.2.0 (should already be the proper relative path)
  9. Get nrf52 softdevice
  10. Create tasks.json and paste the code from below
  11. Create launch.json and paste and paste the code from below
  12. Start JLinkRTTClient for serial output, it will automatically connect with the debugger
  13. Press F5 in Visual Studio Code for debugging

tasks.json

{
// See https://go.microsoft.com/fwlink/?LinkId=733558
// for the documentation about the tasks.json format
"version": "2.0.0",
"tasks": [
{
"label": "compile",
"type": "shell",
"linux": {
"command": "cd ${workspaceFolder}/build/; make;"
},
"windows": {
"command": "cd ${workspaceFolder}\\build\\; make;"
}
},
{
"label": "compile_erase",
"dependsOn": "compile",
"type": "shell",
"linux": {
"command": "cd ${workspaceFolder}/build/; make erase;"
},
"windows": {
"command": "cd ${workspaceFolder}\\build\\; make erase;"
}
},
{
"label": "compile_erase_merge",
"dependsOn": "compile_erase",
"type": "shell",
"linux": {
"command": "cd ${workspaceFolder}/build/; make merge_soft;"
},
"windows": {
"command": "cd ${workspaceFolder}\\build\\; make merge_soft;"
}
},
{
"label": "compile_erase_merge_flash",
"dependsOn": "compile_erase_merge",
"type": "shell",
"linux": {
"command": "cd ${workspaceFolder}/build/; make flash_merged;"
},
"windows": {
"command": "cd ${workspaceFolder}\\build\\; make flash_merged;"
}
}
]
}

launch.json

{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "Cortex Debug",
"cwd": "${workspaceRoot}",
"windows": {
"executable": "\\build\\_build\\nrf52832_xxaa.out"
},
"linux": {
"executable": "./build/_build/nrf52832_xxaa.out"
},
"request": "launch",
"type": "cortex-debug",
"servertype": "jlink",
"device": "nRF52832_xxAA",
"interface": "swd",
"ipAddress": null,
"serialNumber": null,
"preLaunchTask": "compile_erase_merge_flash",
}
]
}