Getting Started With Embedded Programming: Internet of Things Course
Getting Started With Embedded Programming: Internet of Things Course
tn
LAB 1
Getting Started with Embedded
Programming
Issue 1.0
Contents
1 Introduction ............................................................................................. 1
1.1 Lab overview ........................................................................................................................... 1
2 Requirements .......................................................................................... 1
3 Updating board firmware (optional) ........................................................ 4
4 Creating your first Mbed online project ................................................... 4
5 Mbed Studio Setup .................................................................................. 9
5.1 Mbed Studio............................................................................................................................ 9
5.1.1 Preparing a workspace .................................................................................................... 9
5.1.2 Creating or importing programs ..................................................................................... 9
5.1.3 Build and running a program ........................................................................................ 11
8 Exercise.................................................................................................. 13
1 Introduction
1.1 Lab overview
In this lab, we will introduce the Arm Mbed compiler and learn how to set up a local environment for
developing embedded applications.
At the end of the lab, you should know how to create a new Mbed project, import code example,
compile, and execute applications for embedded devices.
2 Requirements
In this lab, we will be using the following hardware:
Board Features
64-Mbit Quad-SPI (Macronix) Flash memory
Bluetooth® V4.1 module (SPBTLE-RF)
Sub-GHz (868 or 915MHz) low-power-programmable RF module (SPSGRF-868 or SPSGRF-915)
Wi-Fi® module Inventek ISM43362-M3G-L44 (802.11 b/g/n compliant)
Dynamic Near-field Communication (NFC) tag based on M24SR with its printed NFC antenna
Two digital omnidirectional microphones (MP34DT01)
Capacitive digital sensor for relative humidity and temperature (HTS221)
High-performance 3-axis magnetometer (LIS3MDL)
3D accelerometer and 3D gyroscope (LSM6DSL)
260-1260hPa absolute digital output barometer (LPS22HB)
Copyright © 2021 Arm Limited (or its affiliates). All rights reserved.
Page 1
Time-of-Flight and gesture-detection sensor (VL53L0X)
Two push-buttons (user and reset)
USB OTG FS with Micro-AB connector
Expansion connectors:
o Arduino™ Uno V3
o PMOD
Flexible power-supply options: ST LINK USB VBUS or external sources
On-board ST-LINK/V2-1 debugger/programmer with USB re-enumeration capability: mass
storage, virtual COM port, and debug port
Board Pinout
Copyright © 2021 Arm Limited (or its affiliates). All rights reserved.
Page 2
Arduino Compatible Headers:
Copyright © 2021 Arm Limited (or its affiliates). All rights reserved.
Page 3
3 Updating board firmware (optional)
Download the latest Mbed interface firmware from
https://armmbed.github.io/DAPLink/?board=MTB_STM32L475
Press and hold down the reset button, while connecting the USB cable between the board
and the computer.
It should now enumerate as “CRP DISABLD” (you can open a file browser to see if such a
drive has been recognized).
Delete the file named firmware.bin, then drag and drop or copy the new bin file.
Wait for the file copy operation to complete.
Power-cycle the board. It should now enumerate and mount as DAPLINK or the name of
the board.
Copyright © 2021 Arm Limited (or its affiliates). All rights reserved.
Page 4
3. Open the Compiler. The main Mbed IDE will be displayed. Here you can manage your projects,
create new ones, import program from the mbed.org community…
4. Select the board on the top-right corner you are currently working with. If it’s the first time using
this board press “Add a new platform.”
user
Copyright © 2021 Arm Limited (or its affiliates). All rights reserved.
Page 5
Browse for your device among all the Mbed enabled platforms. You can filter by manufacturer
(STMicroelectronics) to find the DISCO-475VG-IOT01A board faster.
Copyright © 2021 Arm Limited (or its affiliates). All rights reserved.
Page 6
Select the target board, then click “Add to your Mbed Compiler.”
Go back to the Compiler interface. You should now be able to select this platform.
Copyright © 2021 Arm Limited (or its affiliates). All rights reserved.
Page 7
5. Create a helloworld project (blinky LED program).
6. Compile the program file which will be generate a binary file that will be downloaded to your
default download directory (set by your web browser).
7. Connect the board to your PC via an USB cable; the Mbed board will appear as a removable
storage device.
8. Copy the downloaded program file to the Mbed board’s root directory.
9. Reset the Mbed board; the latest copied program file will be the default program to run.
Copyright © 2021 Arm Limited (or its affiliates). All rights reserved.
Page 8
5 Mbed Studio Setup
5.1 Mbed Studio
Mbed Studio is a free IDE that allows developers to create Mbed OS 5 applications and libraries. This
will provide the functionality we require for completing the further labs.
Ensure that you have installed Mbed Studio from the following link: https://os.mbed.com/studio/.
You will also need to register an account and use it to sign in when launching the IDE.
You can change this workspace by clicking “File” and then selecting “Open Workspace”. Navigate to
the folder you wish to make the new workspace and select it.
Copyright © 2021 Arm Limited (or its affiliates). All rights reserved.
Page 9
In order to create a new program:
Let’s repeat the process, but this time, we will import a project called “mbed-os-example-blinky”.
Copyright © 2021 Arm Limited (or its affiliates). All rights reserved.
Page 10
5.1.3 Build and running a program
Now you can plug in your Mbed enabled board and select it from the list of targets, in this case we
will be using the Disco-L475VG-IOT01A:
Once the board is selected, ensure that “mbed-os-example-blinky” is the current active program and
then select the “Build program” button:
As a result of the build process, Mbed will create a .bin file, which will contain result of compiling
your program into machine code for whichever device you are using. Copying this file to your boards
internal storage will have the effect of loading the program onto your board, at which point the
program (for instance a blinking LED) should run!
Alternatively, pressing “Run program” should automatically build and load the program to your
board. You may need to press the reset switch on the board in order for the new program to run.
Copyright © 2021 Arm Limited (or its affiliates). All rights reserved.
Page 11
6 Setting up a Local Development Environment
You may often wish to develop embedded code locally to speed up deployment and avoid relying on
the internet connectivity at all times. Follow the steps below if you wish to set up a development
environment on your own machine.
Copyright © 2021 Arm Limited (or its affiliates). All rights reserved.
Page 12
This should produce an output that indicates which serial port the board is using. You should see an
identifier of the form /dev/ttyXYZ0. To connect to that port and inspect the embedded system
reporting, you can use the following command:
screen /dev/ttyXYZ0 9600
Remember to modify ttyXYZ0 to the actual identifier on your system. Here 9600 is the port’s Baud
rate.
8 Exercise
Starting from the example above, write an embedded application that executes a continuous loop in
which each LED, 1 and 2 on the board, blink once every second consecutively, then all of them flash
simultaneously for a second, and the process repeats.
Copyright © 2021 Arm Limited (or its affiliates). All rights reserved.
Page 13