Tag: #mbed

STMicro DISCO-L072CZ-LRWAN1 quickstart with mbed-os

There is a great article on the ARM mbed website about their support of LoRaWAN.

Their code has improved a lot this year. Previously, it was a little tricky to work with – there is now a clean install available on github that can be built locally from the command line on Mac, Windows or linux. using the GNU ARM embedded toolchain and mbed-os.

I describe below a simple recipe to use this code with the STMicro DISCO-L072CZ-LRWAN1 evaluation board (pictured). The code can be simply adapted to run with the sx1272 mbed shield on STMicro Nucleo boards and there is also support for the RAKWireless RAK811 node.

I am assuming that you have already registered your device in your application in your TTN console:
https://console.thethingsnetwork.org/applications/[your application name]/devices

1. Setup the GNU ARM embedded toolchain and install mbed-cli:

On a Windows 10 PC – just use the installer that you can download from here:
mbed-cli installer

The Windows installer for Mbed CLI includes the following components:

  • Python – Mbed CLI is a Python script, so you need Python to use it. The installer installs version 2.7.13 of Python. It is not compatible with Python 3
  • Mbed CLI version 1.2.2 – Mbed CLI
  • Git and Mercurial – Mbed CLI supports both Git and Mercurial repositories. Both Git and Mercurial are being installed. git and hg are added to system’s PATH
  • GNU Arm Embedded Toolchain – GNU Embedded Toolchain for Arm
  • Mbed Windows serial port driver – serial port driver

Note that the Windows installer sets all paths and even configures some MBED variables
Check the path to the gcc compiler:
mbed config -L

On a Mac – use homebrew – remember to brew update && brew upgrade before installing
If you need to install homebrew first, then
/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
Otherwise, just:

brew tap ArmMbed/homebrew-formulae
brew install arm-none-eabi-gcc
brew install python@2
brew install mercurial
brew install git
git clone https://github.com/ARMmbed/mbed-cli
cd mbed-cli
python setup.py install

Check the version of mbed-cli and that it is installed OK – version should be =>1.8.2
mbed-cli --version
Check the install location of arm-none-eabi-gcc with
which arm-none-eabi-gcc
Set path for mbed
mbed config -G GCC_ARM_PATH "/usr/local/bin"

On a linux machine, here is a typical install (I used ubuntu xenial)

sudo apt-get install software-properties-common
sudo add-apt-repository ppa:team-gcc-arm-embedded/ppa
sudo apt-get update
sudo apt-get install gcc-arm-embedded
sudo apt-get install build-essential libssl-dev libffi-dev libxml2-dev libxslt1-dev
sudo apt-get install mercurial git python-dev python-pip
pip install mbed-cli
mbed-cli --version
which arm-none-eabi-gcc
mbed config -G GCC_ARM_PATH "/usr/bin"

2. Pull the example code from the mbed github and create the local mbed-os environment in the folder, using mbed-cli (note that ‘mbed-cli’ also works using just ‘mbed’)

mbed import mbed-os-example-lorawan
cd mbed-os-example-lorawan/

3. Configure for your node
edit mbed_app.json to configure lora.device-eui, lora.application-eui, lora.application-key

4. compile and send to evaluation board (assumes there is only one ST-Link/Nucleo/DISCO board connected)
mbed compile -m DISCO_L072CZ_LRWAN1 -t GCC_ARM --flash

5. use mbed as your terminal emulator:
mbed sterm --baudrate 115200

Note that on linux, it may be necessary to change user permissions for the serial port, similar to:
sudo chmod 666 /dev/ttyACM0

6. press the black reset button on the DISCO board
You should see this:

 Mbed LoRaWANStack initialized
 CONFIRMED message retries : 3
 Adaptive data  rate (ADR) - Enabled
 Connection - In Progress ...

After a few seconds, this should appear:

 Connection - Successful
 Dummy Sensor Value = 2.1
 25 bytes scheduled for transmission
 Message Sent to Network Server

Any questions? Please get in touch…