Skip to content

paul-szczepanek-arm/mbed-os-example-ble

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

BLE Examples

This repo contains a collection of BLE example applications based on Mbed OS. Each example subdirectory contains a separate Mbed OS project, along with a description of the example and additional instructions for running it.

You can build each project with all supported Mbed OS build tools. However, this file specifically refers to the command-line interface tools, Arm Mbed CLI 1 and Mbed CLI 2.

The BLE documentation describes the BLE APIs on Mbed OS.

Mbed OS build tools

Mbed CLI 2

Starting with version 6.5, Mbed OS uses Mbed CLI 2. It uses Ninja as a build system, and CMake to generate the build environment and manage the build process in a compiler-independent manner. If you are working with Mbed OS version prior to 6.5 then check the section Mbed CLI 1.

Install Mbed CLI 2.

Mbed CLI 1

Install Mbed CLI 1.

Pre-Requisites

In order to use BLE in Mbed OS you need one of the following hardware combinations:

The BLE documentation describes the BLE APIs on mbed OS.

Targets for BLE

The following targets have been tested and work with these examples:

  • Targets with an ST BLE expansion board plugged in:

    • NUCLEO_F401RE
    • NUCLEO_L476RG
    • NUCLEO_L446RE
    • K64F
  • ST boards with embedded SPBTLE-RF module (BlueNRG-MS):

    • DISCO_L475VG_IOT01A (ref B-L475E-IOT01A)
    • DISCO_L562QE (ref STM32L562E-DK)
  • Board with wireless STM32WB microcontrollers:

    • NUCLEO_WB55RG
  • Nordic:

    • NRF52_DK
    • NRF52840_DK
  • Embedded Planet:

    • EP_AGORA

Important: If an ST BLE expansion is used with the K64F board, a hardware patch is required. Check out X-NUCLEO-BNRG2A1 or X-NUCLEO-IDB05A1 for more information.

The following board is currently not supported as it doesn't yet support the Cordio stack: * NRF51_DK

Using ST BLE expansion board on other targets

It is possible to use the ST BLE expansion on boards not directly supported by these examples as long as the board has an Arduino UNO R3 connector.

To make the board compatible with the ST BLE expansion three things are required:

  • Add the BLE feature to your target.
  • Add the BLE implementation for the ST BLE expansion to the list of modules which have to be compiled.
  • Indicate to the BLE implementation that your board uses an Arduino connector.

All these operations can be done in the file mbed_app.json present in every example.

In the section target_overrides, add a new object named after your target with the following three fields:

  • "target.components_add": ["BlueNRG_2"] Add the BlueNRG-2 component to the target.
  • "target.features_add": ["BLE"] Add the BLE feature to the target.
  • "target.extra_labels_add": ["CORDIO"]: Add the BLE implementation of the ST BLE expansion to the list of the application modules.

Below is an example of the JSON to be added in the target_overrides section of mbed_app.json, with the NUCLEO_F401RE board.

        "NUCLEO_F401RE": {
            "target.components_add": ["BlueNRG_2"],
            "target.features_add": ["BLE"],
            "target.extra_labels_add": ["CORDIO"]
        },

Note: Further information about the configuration system is available in the documentation.

Important: It is required to apply an hardware patch to the ST BLE expansion if it is used on a board with an Arduino connector. Check out X-NUCLEO-BNRG2A1 or X-NUCLEO-IDB05A1 for more information.

Building the examples

  1. Clone the repository containing the collection of examples:

    $ git clone https://github.com/ARMmbed/mbed-os-example-ble.git

    Tip: If you don't have git installed, you can download a zip file of the repository.

  2. Using a command-line tool, navigate to any of the example directories, like BLE_Advertising:

    $ cd mbed-os-example-ble
    $ cd BLE_Advertising
  3. Update the source tree:

    • Mbed CLI 2
    $ mbed-tools deploy
    • Mbed CLI 1
    $ mbed deploy
  4. Connect a USB cable between the USB port on the board and the host computer.

  5. Run the following command: this will build the example project, program the microcontroller flash memory, and then open a serial terminal to the device.

    • Mbed CLI 2
    $ mbed-tools compile -m <TARGET> -t <TOOLCHAIN> --flash --sterm --baudrate 115200
    • Mbed CLI 1
    $ mbed compile -m <TARGET> -t <TOOLCHAIN> --flash --sterm --baudrate 115200

Your PC may take a few minutes to compile your code.

The binary will be located in the following directory:

  • Mbed CLI 2 - ./cmake_build/<TARGET>/<PROFILE>/<TOOLCHAIN>/
  • Mbed CLI 1 - ./BUILD/<TARGET>/<TOOLCHAIN>/

You can manually copy the binary to the target, which gets mounted on the host computer through USB, rather than using the --flash option.

You can also open a serial terminal separately, as explained below, rather than using the --sterm and --baudrate options.

Running the examples

When example application is running, information about activity is printed over the serial connection. The default serial baudrate has been set to 115200 for these examples.

If not using the --sterm and --baudrate options when flashing, have a client open and connected to the board. You may use:

  • Mbed CLI 2

    $ mbed-tools sterm -b 115200
  • Mbed CLI 1

    $ mbed sterm -b 115200
  • Tera Term for Windows

  • screen or minicom for Linux

    screen /dev/serial/<your board> 115200

To observe and/or interact with example applications please use any BLE scanner on a smartphone. If you don't have a scanner on your phone, please install:

License and contributions

The software is provided under Apache-2.0 license. Contributions to this project are accepted under the same license. Please see CONTRIBUTING.md for more info.

This project contains code from other projects. The original license text is included in those source files. They must comply with our license guide.

Branches

Master branch is for releases only. Please target the development branch for all your PRs.

About

BLE demos using mbed OS and mbed cli

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • C++ 92.2%
  • CMake 7.8%