When I was first handled with the task of building a Bluetooth and NB-IoT gateway, I was a bit overwhelmed by the messy and complex documentation on the manufacturer’s website. So I decide to do a write guide to start off a hello world example as I learn discover that Thingy 91 module is all about.
Start up hardware
Thingy 91 (from Nordic)
Thingy 91 is a prototyping kit which consist of the IC chip nRF9160 (for NB-IoT communication), and nRF52840 (Bluetooth Low Energy BLE 4.0, 5.0 communication). Simple battery powered electronic hardware to get engineer start up with working on nRF9160.
nRF9160-DK (from Nordic)
nRF9160-DK is similar to Thingy91, an development kit for learning nRF9160 IC chip. That why the it is named “-DK”. It consist of the same IC chip nRF9160 and nRF52840.
Check out this video introduction of nRF9160-DK development kit board.
and a quick introduction to nRF Connect SDK.
An additional big chip is found on this kit. This chip is there for the programming of the IC nRF9160 or nRF52840. A switch SW5 near this big chip is used for selecting the chip that you want to program. You can select nRF52 (for nRF52840 chip) or nRF91 (for nRF9160 chip).
Beside able to program the IC chip on its own board, this development kit can also act as a programmer to program nRF52xxx or nRF91xxx chips on other boards. You can use nRF9160 as a programmer device to program the chips (nRF52840 or nRF9160) on the Thingy91 board via the JTAG cable (10pins ribbon cable).
How to get started?
This was one big question on my head. I done many installations until I also don’t know what I was doing. Here I want to start off by learning how to program a “Hello World” firmware into nRF52840 chip first.
I decided not to rush into things and do things step by step from the basis fundamental first.
What do you need?
- Development Kit nRF9160-DK
- USB micro cable
- A computer with a Windows Operating System
Ways to program Nordic nRF52840 chip
There are a number of ways to program the Nordic chip nRF52840.
- Debug header
- USB Bootloader (Wired)
- USB Mass Storage
- Bluetooth Firmware Loader (Wireless)
Getting start with nRF9160-DK
You can refer to the reference from this webpage.
- Install the software nRF Connect on your desktop computer.
- Open up this software nRF Connect.
- Go to Getting Started Assistant, click <Install>
- Open and execute the program Getting Started Assistant to guide you with the steps to take.
Summary from Getting Started Assistant
- Install the toolchain
- Clone the nRF Connect SDK
- Download SEGGER Embedded Studio
- Set up a project in SEGGER Embedded Studio
Install the toolchain
The whole installation experience is a pain. Please ensure there is no space in the name of your folders. It will not be recognized by the software tools.
- Install toolchain Chocolatey. Chocolatey tool makes software installation on WinOS looks easy. It will be like typically how we do software installation on Linux OS system. Helps you to automate and create software deployment package for Windows. Learn about Chocolatey here.
The subsequent steps, we will be doing installation and configuring of Chocolatey from WinOS command prompt.
- Open a command prompt as an Administrator on your WinOS computer. Press on your keyboard Windows+X. Click on the pop-up menu “Command Prompt (Admin)” or “Windows PowerShell (Admin)”. A command prompt should pops up.
- Paste the following command text into the PowerShell,
> Set-ExecutionPolicy Bypass -Scope Process -Force; [System.Net.ServicePointManager]::SecurityProtocol = [System.Net.ServicePointManager]::SecurityProtocol -bor 3072; iex ((New-Object System.Net.WebClient).DownloadString(‘https://chocolatey.org/install.ps1’))
This will download and install Chocalatey onto your computer system.
- Enter the following command text into the PowerShell to check if Chocolatey is installed.
You should receive the following message when Chocolatey is properly installed.
Please run ‘choco -?’ or ‘choco -?’ for help menu.
- Enter the following command texts, and click verify button on Getting Started Assistant. The Assistant should highlight green which indicates that the task is done properly. Do the same for the subsequent command.
> choco feature enable -n allowGlobalConfirmation
- Enter the following command texts, and click on verify button.
> choco install -y cmake –installargs ‘ADD_CMAKE_TO_PATH=System’
- > choco install git
- > choco install python
- > choco install ninja
- > choco install dtc-msys2
- > choco install gperf
- Download and install ONLY the recommended version of GNU ARM Embedded toolchain so that able to cross-compile for ARM microcontroller chips. Follow what nRF Connect assistant tells you to download.
which is version
8-2019-q3-updateof the GNU ARM Embedded toolchain.
Install the software to the root directory c:
The installed folder is probably c:\8 2019-q9-update
Change the folder name to c:\gnuarmemb
Ensure that there is a bin folder under c:\gnuarmemb\bin.
Use the Verify button to confirmed that you have done it correctly.
Please ignore the following test…..
Open up “Command Prompt” and key in the following command to check if GNU toolchain is installed.
> arm-none-eabi-gcc –version
Please ignore the following test…..
Install onto “C:\gnuarmemb” directory. (recommended by nRF Connect)
example: “C:\gnuarmemb\GNU Tools Arm Embedded\9 2019-q4-major“
Click verify on your Assistant when this is done.
Clone the nRF Connect SDK from Nordic Repository.
Nordic has developed SDK specially for their nRF chip products (only for nRF9160 or nRF5340). These source code are in Nordic repository. The following commands are to copy/update that source code onto our own local computer system.
Enter the following command texts in Windows PowerShell, and click on Verify button.
- Install West (Zephyr’s meta-tool), a swiss-army knife command-line tool .
Use pip3 to install west.
> pip3 install west
- Create your own directory to store nRF Connect SDK, and create a directory (no spaces in the directory name) ncs under it.
> cd ‘e:\nRFConnectSDK’
> mkdir ncs
> cd ncs
- Initialise West meta-tool, and update it
> west init -m https://github.com/NordicPlayground/fw-nrfconnect-nrf
> west update
- Visit the webpage nRF Connect SDK Release Notes to look for the version that you want to clone onto your computer system. Look for the Release Tag to use. In this example, I am looking at “nRF Connect SDK v1.2.0 Release Notes”. The Release Tag that I see from this release is “v1.2.0“. Use this tag for git checkout as shown below. This will fetch the release version v1.2.0 from the repository.
> cd ‘e:\nRF Connect SDK\ncs\nrf’
> git checkout v1.2.0
> west update
If you want the latest version (may not be a stable version from Nordic), use the command “git fetch origin” instead of “git checkout v1.2.0”. The command “west update” simply update the files to that version.
- Install a list of required Python modules.
> cd ‘f:\nRF Connect SDK\ncs’
> pip3 install -r zephyr\scripts\requirements.txt
> pip3 install -r nrf\scripts\requirements.txt
> pip3 install -r bootloader\mcuboot\scripts\requirements.txt
Download SEGGER Embedded Studio
Download and install SEGGER Embedded Studio.
Set up a project in SEGGER Embedded Studio
Execute the SEGGER Embedded Studio software.
- Use command prompt to navigate to the folder where SEGGER Embedded Studio is located. In this example, it is located at “e:\nRF Connect SDK\arm_segger_embedded_studio_v442a_win_x64_nordic\bin\”
- Execute the file emStudio.exe to launch the software.
- A pop up screen may appeared indicating “No commercial-use license detected”. Activate your free license.
Setup the path of the Zephyr Base (the location of your cloned Zephyr repository, path ncs/zephyr), and the path where GNU ARM Embedded Toolchain is installed.
In the software go to Tools > Options, and select the nRF Connect tab.
In our example, the path for
- Zephyr Base, “e:\nRFConnectSDK\ncs\zephyr“
- GNU ARM Embedded Toolchain, “c:\gnuarmemb“
You can now start opening your nRF Connect project. Select File > Open nRF Connect SDK Project.
Follow the setting of the screenshot on the right.
For the board name, remember to select the name ending with xxxxxxns. Which means Non-Secure version.
- CMakeLists.txt (location of the project makelist. Typically located at ../ncs/nrf/samples/nrf9160/lte_ble_gateway/CMakeLists.txt)
- Board Directory (location of the board used for the project. Typically located at ../ncs/zephyr/boards/arm/nrf9160_pca10090 )
- Board Name (names for the board will be automatically generated when the board directory is selected). Always choose the board name with xxxxns at the end of the name. ns means Non-Secure.
- Build Directory (the folder of where the output build will be located, will be automatically generated when the CMakeLists.txt is selected. The build… will be generated in the same directory of the CMakeLists.txt)
- Check the box “Clean Build Directory” so that the outdated build is not cache.
- Issue installing Chocolatey due to outdated software. TLS 1.2 at a minimum version.
Error message “DownloadString” with “1” argument(s): “The request was aborted: Could not create SSL/TLS secure channel.”
- When verifying “choco install -y cmake –installargs ‘ADD_CMAKE_TO_PATH=System'”, an error message occurred.
Error message is ” ‘cmake’ is not recognized as an internal or external command, operable program or batch file.”
Solution 1: is to download and install cmake software. https://cmake.org/install/
It is found that cmake is already installed, just that it needs some repair only. You may need to install and uninstall.
Remember also that you may need to go to Tools > Options > nRF Connect > Executables > CMake Executable, to set the location of the newly installed cmake program.
Solution 2: set environment path in the command prompt.
$env:path += “;C:\Program Files\cmake\bin”
After this, key in cmake in the command prompt. It should work.
- SEGGER software keep asking me to activate license.
Solution: Close Segger Embedded Studio and open any SES project from Nordic SDK.
Example of such a SDK project file is “nRF5_SDK_15.2.0_9412b96”
Open a *.emProject files using the SEGGER program.
The file can be found under the folders “examples\peripheral\blinky\pca10056\blank\ses”
There will no longer be a license problem the next time you open the SEGGER.
- What I learned is Zephyr is a OS is based on a small-footprint kernel designed for use on resource-constrainted systems.
- Don’t give name to a directory that have space inside.
- Error message while opening a nRF Connect SDK project.
“warning: BSD_LIBRARY (defined at…….. has direct dependencies TRUSTED_EXECUTION_NONSECURE with value n, but is currently being y-selected by the following symbols: -MODEM_INFO (defined at…….”
Solution: When choosing the board name, choose one with name ending with xxxxxxns. Reason: bsdlib can only be used from a non-secure application and you need bsdlib to use the modem.
Other good tutorial resources
- nRF Connect SDK Tutorial – Part 1
- nRF Connect SDK video introduction
Updating the Modem firmware on nRF9160
Remember to put the switch to nRF9160 (instead of nRF52840) before the programming. You can switch and click on the “Read” button from the nRF Programmer software to check which chip the nRF9160-DK board is connected to.
The following tutorial is a good reference to show us how to update the modem firmware to the nRF9160 chip on the nRF9160-DK board.
Update Thingy91 with the latest firmware
You can download the latest “precompiled application and modem firmware” from this URL
Inside this package, you will see 4 folder,
- images_dfu_bin (programming nRF52840 nRF9160 chip via bin format using ???)
- images_dfu_hex (programming nRF52840 nRF9160 chip via hex format using bootloader method)
- images_full (full firmware image, programming nRF52840 nRF9160 chip firmware via J-Link debug probe/development kit)
- mfwnrf9160110.zip (modem firmware)
Let’s use the full firmware image method. Inside the folder images_full, you will see,
- thingy91_at_client_2019-11-29_d3130d77.hex (flash nRF9160 with only AT Client application)
- thingy91_ltem_2019-11-29_d3130d77.hex (flash nRF9160 with Asset Tracking Demo (connect to nRF Cloud Server for Demo purpose) using LTE-M network)
- thingy91_nbiot_2019-11-29_d3130d77.hex (flash nRF9160 with Asset Tracking Demo (connect to nRF Cloud Server for Demo purpose) using NB-Iot network)
- thingy91_nbiot_legacy_pco_2019-11-29_d3130d77.hex (???)
- thingy91_nrf52_usb_uart_bridge_2019-11-29_d3130d77.hex (flash nRF52840 to act as a USB-UART converter chip)
There are 3 firmware that needs to be updated.
- mfwnrf9160110.zip (modem firmware)
They can be loaded via the nRF Cloud Programmer software.
For modem firmware, after going into the programmer software, go to the lower right side of the screen and load in the *.zip file (modem firmware). Remember to slide the switch on the Thingy91 to select for the nRF9160 chip.
For the thingy91_at_client firmware, in the programmer software load up the hex file. Then click “erase & write” to begin flashing. Remember to slide the switch on the Thingy91 to select for the nRF9160 chip.
For the thingy91_nrf52_usb_uart_bridge firmware, in the programmer software load up the hex file. Then click “erase & write” to begin flashing. Remember to slide the switch on the Thingy91 to select for the nRF52840 chip.
Playing with the nRF9160 modem
Everytime the board is plugged in, there will be 3 COM port that appears. 2x COM belongs to the nRF9160 chip, one maybe for the AT command, and the other maybe the logging messages from the modem module. 1x COM belongs to the nRF52840 chip.
Using the software LTE Link Monitor to initialise the modem and send AT command.
First connect the device, communication port by selecting the connected Thingy91 or nRF9160 device.
Some console text will starts to appear. If not, can also press the reset button on the hardware board. Key in the command “AT” to check if the board is responding to this AT command.
Key in “AT+CGMR” to check the modem firmware version.
Key on the modem command “AT+CGMR” to initalise and start the module. The indicator on the software Modem, UICC, LTE, PDN will all start to turn green.
Network will display, Singapore Telecom
For more information on AT commands for NB-IoT, refer to this page.
Flashing with AT firmware only
AT+CFUN=1 (connect to LTE network)