Skip to content

atmark-techno/pc-ble-driver

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

pc-ble-driver

pc-ble-driver provides C/C++ libraries for Bluetooth Low Energy nRF5 SoftDevice serialization.


Overview

pc-ble-driver consists of a set of static and shared libraries that provide SoftDevice functionality to the application via serial port communication with an nRF5 connectivity chip running the SoftDevice and connectivity software, included as a single .hex file here. For more information on SoftDevice serialization see Serialization.

The C/C++ libraries can be interfaced with directly, but are also provided as higher-level bindings that ease development at the cost of reduced control (acceptable in most cases):


Architecture

Architecture

Where the 'Application chip' is just generic hardware (i.e. a Windows, Linux or macOS device), although it could also be an Arduino or Raspberry Pi for example.


Supported environments

Operating system

  • Windows 7, 8 and 10, 32 and 64-bit (tested on Windows 7)
  • Ubuntu Linux LTS 64-bit (tested on Ubuntu 18.04)
  • macOS 64-bit (tested on 10.14 Mojave)

SoftDevice and IC

To use pc-ble-driver, your Development Kit needs to have the correct firmware. The needed firmwares are found in the hex/sd_api_v<x> folder and contain the SoftDevice and connectivity firmware required to communicate with pc-ble-driver.

The generated libraries are compatible with the following SoftDevice API versions and nRF5x ICs:

  • SoftDevice s130 API version 2: connectivity_<version>_1m_with_s130_2.x.x (nRF51 and nRF52 series ICs)
  • SoftDevice s132 API version 3: connectivity_<version>_<1m|*usb>_with_s132_3.x.x (only for nRF52 series ICs)
  • SoftDevice s132 API version 5: connectivity_<version>_<1m|*usb>_with_s132_5.x.x (only for nRF52 series ICs)
  • SoftDevice s132 API version 6: connectivity_<version>_<1m|*usb>_with_s132_6.x.x (only for nRF52 series ICs)
  • SoftDevice s140 API version 6: connectivity_<version>_<1m|*usb>_with_s140_6.x.x (only for nRF52 series ICs)

*usb) only for nRF52 series ICs with USBD peripheral

Supported Development Kits
PCA Official name Article number Notes
PCA10028 nRF51 DEVELOPMENT KIT nRF6824
PCA10031 nRF51 DONGLE nRF6825
PCA10040 nRF52 DEVELOPMENT KIT nRF6827
PCA10056 nRF52840 { Development Kit } nRF6828 *)
PCA10059 nRF52840 { Dongle } nRF6829 Can only use connectivity firmware with Nordic USB CDC serial port support

*) Can use both Nordic USB CDC serial port version and SEGGER J-Link-OB (VCOM) version. Using Nordic USB CDC serial port version on PCA10056 requires that you connect pins P0.18 and P0.24. The pins to QSPI chip must also be in place (they are by default). The algorithm for detecting if it is PCA10056 or PCA10059 is to check if it is possible to communicate with the QSPI chip. PCA10059 does not have a QSPI chip. The detection is used by nRF Connect DFU trigger to determine what pin to use for resetting the device when changing between DFU and application mode.


Installing device drivers

Driver installation

This communication library works over any kind of serial port (UART), but it is most often used over a Segger J-Link USB CDC UART. To set up the required J-Link drivers simply download and install the version matching you operating system:

After you have installed the required drivers and connected a J-Link enabled board (such as the Nordic Development Kits) the port should be available.

In addition, you have to disable the Mass Storage Device in order to use pc-ble-driver to communicate with the device, see data corruption or drops issue.

Driver validation

Validating on Windows

The serial port will appear as COMxx. Simply check the "Ports (COM & LPT)" section in the Device Manager.

Validating on Ubuntu Linux

The serial port will appear as /dev/ttyACMx.

By default the port is not accessible to all users. Type the command below to add your user to the dialout group to give it access to the serial port. Note that re-login is required for this to take effect.

    $ sudo usermod -a -G dialout <username>

To prevent the modemmanager service from trying to connect to the CDC ACM serial port:

    $ systemctl stop ModemManager.service
    $ systemctl disable ModemManager.service

Validating on macOS

The serial port will appear as /dev/tty.usbmodemXXXX.

There is a known issue, check it here if you met any problems.


Installing tools

nRF5x Command-Line Tools

To program the connectivity firmware you will need nrfjprog which is bundled with the nRF5x Command-Line Tools, which can be downloaded from:

Add nrfjprog and mergehex to PATH on Linux and macOS.

nRF Connect Programmer (optional)

Alternatively, nRF Connect Programmer can help you to program the connectivty firmware with UI support.

Download nRF Connect Desktop and install nRF Connect Programmer there.


Installing dependencies

To compile pc-ble-driver you will need the following tools:

To compile connectivity HEX files you will need additional tools:

Follow the steps to install dependencies on a specific platform:

Installing dependencies on Windows

  1. Download Visual Studio 15 or later version and install.

  2. Install Chocolatey. Install with cmd.exe (Run as administrator)

    # Copy everything below
    @"%SystemRoot%\System32\WindowsPowerShell\v1.0\powershell.exe" -NoProfile -InputFormat None -ExecutionPolicy Bypass -Command "iex ((New-Object System.Net.WebClient).DownloadString('https://chocolatey.org/install.ps1'))" && SET "PATH=%PATH%;%ALLUSERSPROFILE%\chocolatey\bin"

    If Chocolatey has already been installed as described above but has not been added to PATH, run:

    $ SET "PATH=%PATH%;%ALLUSERSPROFILE%\chocolatey\bin"
  3. Install Git.

    $ choco install -y git
  4. Install CMake.

    $ choco install -y cmake
  5. Install vcpkg.

    $ git clone https://github.com/Microsoft/vcpkg.git
    $ cd vcpkg
    $ git checkout tags/2020.04
    $ .\bootstrap-vcpkg.bat

    Then add the vcpkg location to the PATH and set it as VCPKG_ROOT environment variable.

The following steps are needed only if you want to compile your own connectivity HEX files.

  1. Install ninja.

    $ choco install -y ninja
  2. Download and install GNU Embedded Toolchain for Arm version 7-2018q2

    Download from this location.

    Follow the install instructions.

    Set its installation path as GNUARMEMB_TOOLCHAIN_PATH in environment variables. For example:

    $ set GNUARMEMB_TOOLCHAIN_PATH=c:\gccarmemb
  3. Install Python and pip, and then install nrfutil

    $ pip install nrfutil
    
    # Reboot if installation succeeds but validation fails

Installing dependencies on Ubuntu Linux

  1. Install build-essential.

    $ sudo apt-get -y install build-essential
  2. Install Git

    $ sudo apt-get -y install git

    If the installed version of Git is lower than required, then:

    $ sudo add-apt-repository ppa:git-core/ppa
    $ sudo apt update
    $ sudo apt install git
  3. Install CMake.

    $ sudo apt-get -y install cmake

    Install CMake from source if the version is lower than required.

  4. Install vcpkg.

    $ git clone https://github.com/Microsoft/vcpkg.git
    $ cd vcpkg
    $ git checkout tags/2020.04
    $ ./bootstrap-vcpkg.sh

    Then add the vcpkg location to the PATH and VCPKG_ROOT environment variable.

The following steps are needed only if you want to compile your own connectivity HEX files.

  1. Install GNU Embedded Toolchain for Arm version 7-2018q2.

    • Download from here
    • Extract
    • Set its location as GNUARMEMB_TOOLCHAIN_PATH in environment variables.
  2. Install Python and pip, and then install nrfutil.

    $ pip install nrfutil
    
    # Reboot if installation succeeds but validation fails

Installing dependencies on macOS

  1. Install Xcode (>=10.1).

  2. Install gcc6 using HomeBrew.

    $ brew install gcc6
  3. Install CMake using HomeBrew.

    $ brew install cmake
    $ brew upgrade cmake

    Install CMake from source if the version is lower than required.

  4. Install vcpkg.

    $ git clone https://github.com/Microsoft/vcpkg/
    $ cd vcpkg
    $ git checkout tags/2020.04
    $ ./bootstrap-vcpkg.sh

    Then add the vcpkg location to the PATH and VCPKG_ROOT environment variable.

The following steps are needed only if you want to compile your own connectivity HEX files.

  1. Install GNU Embedded Toolchain for Arm version 7-2018q2.

    • Download from here
    • Extract
    • Set its location as GNUARMEMB_TOOLCHAIN_PATH in environment variables.
  2. Install Python and pip, and then install nrfutil

    $ pip install nrfutil
    
    # Reboot if installation succeeds but validation fails

Compiling pc-ble-driver from source

Go to install dependencies if you have not done that yet.

Compiling pc-ble-driver on Windows

  1. Install vcpkg dependencies.

    # cd <pc-ble-driver-root-folder>
    
    # Make sure %VCPKG_ROOT% is set and added to %PATH%
    $ mkdir build && cd build
    $ vcpkg install asio catch2 spdlog
  2. CMake Select the Visual Studio compiler to use according to this article: Build C/C++ code on the command line

    $ cmake -G Ninja ..
  3. Compile

    $ cmake --build .

    Optionally select the build configuration with the --config option. Typically Debug, Release, MinSizeRel and RelWithDebInfo are available. For example:

    $ cmake --build . --config Debug

Compiling pc-ble-driver on Ubuntu Linux or macOS

  1. Install vcpkg dependencies.

    # cd <pc-ble-driver-root-folder>
    
    # Make sure $VCPKG_ROOT is set and added to $PATH
    $ mkdir build && cd build
    $ vcpkg install asio catch2 spdlog
  2. CMake

    $ cmake \
        -G Ninja \
        ..

    Optionally Select the build configuration with the -DCMAKE_BUILD_TYPE option. Typically Debug, Release, MinSizeRel and RelWithDebInfo are available.

    Optionally select the target architecture (32 or 64-bit) using the -DARCH option. The values can be x86_32, x86_64, x86_32,x86_64. For example:

    $ cmake \
        -G Ninja \
        -DCMAKE_BUILD_TYPE=Debug \
        -DARCH=x86_32,x86_64 \
        ..
  3. Compile

    $ cmake --build .

Compiling connectivity HEX files

Go to install dependencies if you have not done that yet.
Go to compile pc-ble-driver from source if you have not done that yet.

Make sure the following environment variables are set:

  • VCPKG_ROOT
  • GNUARMEMB_TOOLCHAIN_PATH

Make sure the following paths have been added to PATH:

  • VCPKG_ROOT
  • mergehex

Follow the steps to install dependencies on a specific platform:

Compiling connectivity HEX files on Windows

  1. Set environment

    # cd <pc-ble-driver-root-folder>
    $ SET "PATH=%PATH%;%ALLUSERSPROFILE%\chocolatey\bin"
    
    # Make sure environment variables have been set
    # as described at beginning of this section
  2. CMake

    $ mkdir build && cd build
    
    # Modify -DCONNECTIVITY_VERSION=a.b.c
    $ cmake -G Ninja -DCOMPILE_CONNECTIVITY=1 -DCONNECTIVITY_VERSION=1.0.0 ..

    COMPILE_CONNECTIVITY is set to 1 to enable compiling connectivity firmware.

    CONNECTIVITY_VERSION defines a version for the compiled connectivity firmware.

    Check more options at compiling pc-ble-driver on Windows

  3. Compile

    $ cmake --build . --target compile_connectivity

    The HEX files are available in the hex/sd_api_v<x> folder after compilation. They include the SoftDevice and the connectivity application.

Compiling connectivity HEX files on Ubuntu Linux or macOS

  1. Set environment

    # cd <pc-ble-driver-root-folder>
    $ export TMP=/tmp
    
    # Make sure environment variables have been set
    # as described at beginning of this section
  2. CMake

    $ mkdir build && cd build
    
    # Modify -DCONNECTIVITY_VERSION=a.b.c
    $ cmake \
        -G Ninja \
        -DCOMPILE_CONNECTIVITY=1 \
        -DCONNECTIVITY_VERSION=1.0.0 \
        ..

    COMPILE_CONNECTIVITY is set to 1 to enable compiling connectivity firmware.

    CONNECTIVITY_VERSION defines a version for the compiled connectivity firmware.

    Check more options at compiling pc-ble-driver on Ubuntu Linux or macOS

  3. Compile

    $ cmake --build . --target compile_connectivity

    The HEX files are available in the hex/sd_api_v<x> folder after compilation. They include the SoftDevice and the connectivity application.


Programming connectivity HEX files

SEGGER J-Link-OB based kits

Go to install tools if the nRF5x Command-Line Tools have not been installed yet.

To use this library you will need to program the connectivity firmware on a nRF5x IC

Use nRF5x Command-Line Tools to erase and program the IC:

$ nrfjprog -f NRF5<x> -e
$ nrfjprog -f NRF5<x> --program hex/sd_api_v<x>/connectivity_<ver>_<baudrate>_with_s<x>_<a>.<b>.<c>.hex

Alternatively, use nRF Connect Programmer to erase and program the IC.

Nordic USB based kits

Installing drivers and tools

Some kits, like the pca10059 nRF52 dongle, do not have onboard debugger and will have to be programmed via serial DFU. On Windows, device drivers are required for the kits to be detected correctly by the operating system. To install the required drivers, please make sure you have the latest nRF Connect for Desktop installed.

Programming the connectivity firmware via serial DFU

Programming the connectivity firmware via serial DFU can be done from command line or from nRF Connect for Desktop.

Programming from command line with nrfutil

Device Firmware Upgrade with nrfutil is normally done in two steps: 1: generating the DFU zip package, and 2: performing the DFU procedure. A DFU zip package has been pre-made and is included in this repository. To run the DFU procedure with nrfutil with the pre-made DFU package:

nrfutil dfu usb-serial -pkg connectivity_x.x.x_usb_with_s<x>_<a>.<b>.<c>_dfu_pkg.zip -p <serial port>

Examples

The examples serve as a great starting point for development with pc-ble-driver. Examples include a heart rate monitor (BLE peripheral) and heart rate collector (BLE master) and show the basic structure of an application built on pc-ble-driver.

To quickly get the examples up and running, see examples/README.md.

Known issues

If you meet problems during installation of pc-ble-driver, please see Issues.md.

Contributions

Feel free to propose changes by creating a pull request.

If you plan to make any non-trivial changes, please start out small and ask seek an agreement before putting too much work in it. A pull request can be declined if it does not fit well within the current product roadmap.

In order to accept your pull request, we need you to sign our Contributor License Agreement (CLA). You will see instructions for doing this after having submitted your first pull request.

Feedback

If you find any bugs, or have questions or other feedback in general, please submit a post on the Nordic DevZone portal. Note that bug reports should describe in sufficient detail how to reproduce the bug.

License

See the license file for details.