Creation of a MBED project
If you want to use MBED Studio, see MBED Studio first project.
Keil Studio Cloud
Note
In this section, we assume that you have a MBED account or an Arm® account. See Keil Studio Cloud account.
You can access to this platform by following this link: https://www.keil.arm.com/.
Then click
, to access to the login page. Log into the Keil Studio Cloud platform with your personal informations.Keil Studio Cloud IDE
You will access to the main window of the IDE.
This interface is divided in a classical manner with a project management area (on the left side of the interface), a text editor area (in the top-right part of the interface) and an output information area (in the bottom-right part of the interface).
During your first access, no projects appear in the project management part. In this section, you can access to :
your personal informations (icons surrounded by an orange border);
the list of the projects you develop (icon surrounded by a pink border).
Create your first project
To create a new project, you can click
(icon surrounded by a red border on the previous figure) or click .Then select
.Warning
To avoid any compilation conflicts with other libraries, make sure to select the baremetal project in the MBED 6 version of MBED-OS.
When the type of project is selected, you can change the project name. Give a specific name corresponding to the content of the project.
You can uncheck the
option if you are not using Git with your project.Click
. Your first project is created.You can check in the
tab (in the bottom-right part of the interface) the version of MBED that it is used (in this example: MBED version 6.13).Now it’s time to test your first application, go to the Compile and test section.
MBED Studio
Note
In this section, we assume that you have a MBED account and that MBED Studio is installed on your computer. See Keil Studio Cloud account.
Start
.MBED Studio IDE
You will access to the main window of the IDE.
This interface is divided in a classical manner with a project management area (on the left side of the interface), a text editor area (in the top-right part of the interface) and an output information area (in the bottom-right part of the interface).
During your first access, no projects appear in the project management part. In this section, you can access to the list of the projects you develop (icon surrounded by a pink border).
Define your workspace
Before creating your first project, you need to specify where you want to store your projects.
Click
. Then select the directory where you want to store your projects.Create your first project
To create a new project, you can click
(icon surrounded by a red border on the previous figure) or click .Then select
.Warning
To avoid any compilation conflicts with other libraries, make sure to select the baremetal project in the MBED 6 version of MBED-OS.
When the type of project is selected, you can change the project name. Give a specific name corresponding to the content of the project.
Warning
In the MBED OS Location section, make sure to select the Link to an existing shared Mbed OS instance option, and select the directory where an instance of the last MBED-OS is installed.
Note
On the LEnsE labwork computers, the last version of MBED-OS is installed in S:\mbed-os
and C:\mbed-os
.
Click
. Your first project is created.Now it’s time to test your first application.
Compile and test
MBED-OS primarily uses C++ as the programming language for developing applications and firmware.
Note
If you are not familiar with the C++ language, tutorials are available at the following address: C++ - Basics and Object-Oriented Programming.
Note
Most of the following steps are the same in Keil Studio Cloud and MBED Studio. Otherwise, a note will specify the differences.
Main file
On the left side of the interface, click on your project (here
to display its contents.Projects basically contain about ten files and directories. They are useful at various stages of the project realization.
But the most essential is the main.cpp
file. It contains the main()
function that serves as the entry point of the program.
Click
file to open it on the top-right side of the interface.We will see later its content.
Select a target
Although the MBED-OS operating system is designed for a wide range of microcontrollers from the STM32 family, it is necessary to specify to the compiler for which target the program is being developed.
Note
At LEnsE, we mainly use Nucleo-L476RG and Nucleo-G431KB boards.
If you don’t select a target, the compilation button is not enabled. When you select a target, some options of the compilation process are automatically set up.
Compile
The C++ program is not understandable by the microcontroller. A compilation step is necessary to translate your code to native language of the microcontroller: a list of basic instructions.
Click on the build button (the blue one with a hammer) to compile your code. In the bottom-right side of the interface, the list of the files being compiled is display.
Note
In the MBED Studio version, you can choose the Build profile. In Debug mode, you have access to inline debugging tools but it tooks more spaces in the memory contrary to the Release mode.
After a few moment, and if no error occured during the compilation process, you obtain the same type of informations as displayed in the next figure:
Depending on the development environment you used, you have two options.
Keil Studio Cloud
A binary file is generated and downloaded on your computer (depending on your browser options).
MBED Studio
A binary file is created in a sub-directory of your project directory. Depending on the target you specified, the binary file is stored in the project_dir\BUILD\NUCLEO_target\ARM6\
directory, where target is the name of the target (for example: G431KB) and project_dir the name of the directory where you stored your project.
Flash the program
The final step, before enjoying to play with your new system, is to flash the binary file into the microcontroller. STMicroelectronics, through the design of their Nucleo boards, facilitates the code uploading step into the microcontroller.
Note
Make sure that your board is connected to your computer via a USB cable.
The Nucleo boards are recognized on computers as USB storage devices. But you can only store binary files as the previously generated by MBED compiler.
You just have to copy and paste the binary file (bin extension) from your computer to the Nucleo device. After few seconds, the Nucleo device flashes the internal memory of the onboard-microcontroller.
During the transfer of the file, the LD1 (or COM) led is blinking in red and green. At the end of the transfer, this led stops blinking.
Duplicate a project
Note
It is recommended to create a new project each time you develop a new application.
Instead of entirely creating a new project each time, you can also duplicate an existing project.
Right-click on the project you want to duplicate and click
.A second project with the same name following by the term copy is generated.
You can change its name by right-click on the new project and then click
.You can also set this new project as the active one by right-click on the project and then click
.Pre-compiler informations
A specific file, called mbed_app.json
, allows developers to specify configuration options and parameters for their Mbed applications.
This JSON file is typically used to configure various aspects of the application, such as: target configuration, feature configuration, peripheral configuration or library configuration.
Baremetal option
Baremetal refers to programming directly on hardware without the use of an operating system. In baremetal programming, developers have direct control over the hardware resources and can write code that interacts directly with the hardware peripherals and registers.
{
"requires": [ "bare-metal"],
"target_overrides": {
"*": {
"target.printf_lib": "minimal-printf",
"platform.minimal-printf-enable-floating-point": true,
"platform.stdio-baud-rate": 115200
}
}
}
In this example, the baremetal modules are required.
The other options, specified in the target_overrides part, allow the use of the printf()
function (linked to the virtual serial port of the USB connection) and set the baudrate of the transmission to 115200 bauds.
SD card, FAT filesystem options
If you want to use a SD card and a FAT filesystem, other options are required. For example:
{
"requires": [ "bare-metal", "rtos-api", "sd","filesystem","fat_chan"],
"target_overrides": {
"*": {
"target.components_add": [ "SD" ]
}
}
}
CMSIS-DSP library
{
"requires": ["bare-metal","cmsis-dsp"]
}