...
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.
...
Tip |
---|
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 UART RX/TX pins in dn_uart.cpppins (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/.
...
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.
...
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.
...
- 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.
Tip |
---|
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.
...
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.
...