ARM mbed

SimplePublish for ARM mbed

A SimplePublish example has been created on the mbed OS developer site. This is a free, online code editor and compiler that allows you to write code for the mbed OS. This makes it very easy to port code to the different supported platforms.

Like the other SimlePublish examples, the program uses the QSL to make the mote connect with the default network ID and join key. When connected, it starts periodically publishing random data, while also printing any downstream user data that arrives between each transmission. An on-board LED is used to indicate whether the mote has connected to a network or not.

The example code is written and tested on the NUCLEO-L053R8, but you should be able to compile it for any mbed supported platform that has an avalilable UART by defining the correct pins (see the Adaptations section below).

Prepare Your Platform

Log into your mbed account (or signup for one if you haven't already) and get started by selecting your platform on the mbed developer page: https://developer.mbed.org/platforms/.

Add Platform to Compiler

Click the big yellow button on the right side of the platform page to add it to your list of platforms in the online Compiler:

Setup for mbed

The page for your platform should include instructions on how to set it up and install any necessary drivers.
For our example, the page for NUCLEO-L058R8 informs us that we need to:

The ST-LINK/V2 driver is included with installer for the System Workbench for STM32.

Once you have everything set, your platform should appear as a storage device on your computer.

Connect to Mote

For the Nucleo boards you can follow the instructions on the SMT32 example page for the NUCLEO-L053R8 (the relevant pins are all the same).

Otherwise you should refer to the general instructions and the pinout of your platform.

Open Debug Terminal

The SimplePublish example program will send all standard output (e.g. debug prints) through the mbed default serial port (defined by SERIAL_TX, SERIAL_RX). For most platforms this will be a serial port that is spawned via USB: If you are using a Nucleo board you can see the instructions on the SMT32 example page on how to identify the correct portname; for other boards you should consult the mbed SerialPC page.

Open your favourite serial terminal (e.g. Putty or Minicom) and connect to the serial port you identified with the following configuration:

  • Baudrate: 115200
  • Data Bits: 8
  • Parity: None
  • Stop Bits: 1
You can (de)activate debug and log messages with the NDEBUG and NLOG defines in dn_debug.h (located in sm_qsl/).

Note that there appears to be an issue with the serial output from the ST-LINK/V2 on the Nucleo boards.


Compile and Run the Program

Import to Your Compiler Workspace

  1. Head to the Code page for the SimplePublish program and press the big yellow button:
  2. This should open the Import Program window in the Compiler online IDE:
    Source URL: https://developer.mbed.org/teams/QSL/code/QSL_SimplePublish/
    Import As: Select Program
    Import Name: Rename the program if you want to
    Update: Check to update the libraries that the program depends on (only the main mbed library)
  3. Press Import.
  4. You should now see the program listed under My Programs.

Select Platform

  1. Select the program in the Program Workspace window on the left side.
  2. Click the platform selection option in the top right corner:
  3. The platform you added to the Compiler earlier should appear in the window that pops up. Click on it and press Select Platform

Make Necessary Adaptations

The program mainly uses code that is universal to all mbed supported platforms, but if you use another platform than the NUCLEO-L053R8 you might have to make a few changes:

  • dn_uart.cpp: Change the UART_MOTE_TX and UART_MOTE_RX defines to the correct pins for your platform.
  • main.cpp: Change the LED define passed to DigitalOut myled() to the correct one for your platform.
  • dn_endianness.c: These functions are implemented for a little-endian platform, hence you need to change them if your platform is big-endian.

You can find the correct names of relevant pins for your platform on its mbed platform page (the labels written in blue/white or green/white).

Build

To only build the program, select it in the Program Workspace window and press Compile > Build Only (Ctrl+B).
This will build the program for the platform you selected, and any errors/warnings should appear in the bottom Compile Output window. You will probably get some warnings about some depreciated declarations in the sm_clib (which you can safely ignore), but if you get any errors you should consult the previous section.

Compile and Flash

Again, with the program selected, press Compile > Compile (Ctrl+D).
This will build the program and compile it to a binary that is downloaded via your browser. To flash the binary to your platform, simply save it directly to the device. You can also save it somewhere on your computer and simply copy/drag it to your device afterwards.

For the Nucleo boards, the big LD1 LED will flash green/red alternately during the transfer, ending in solid green upon completion.

For some devices, you might have to press the reset button when the transfer completes (consult its mbed platform page).