Comment on page
Using STM32 with the built-in IDE on Simuli Virtual Lab
First, log in to your Simuli account and navigate to the Simuli Virtual Lab. Here we will create a new emulated instance of the STM32. Click on the
Launchbutton under STM32 to get started.
This will open the configuration menu. First, provide a name for the project. Then, we will add the
SHT2XTemperature and Humidity Sensor by selecting it from the list of available components. Finally, review that the name for the project and the selected sensors are correct and click on the
Once we have clicked on the Launch button, a new instance of the STM32 will be created. It can take a few minutes, so be patient. Once the new instance is ready, an
Openbutton will be visible. Click on this button to open and start working with our STM32.
A new tab with the development environment opens upon clicking
Open. On the left side, we have the code editor window along with the terminal at the bottom. On the right side, we have our STM32 Nucleo board with a terminal for interacting with the board and the SHT2X sensor.
Let's work on our first program called
blink. This is the equivalent of a 'Hello World' program for Embedded programming. We will write a program that turns an LED on and off in a loop.
The STM32 instances come with support for Platform IO Core (CLI). We will be using it for working on our projects. To know more about Platform IO Core (CLI) and the different commands go to the Platform IO documentation.
First, we need to initialise a new project using Platform IO. Let's create a new folder called
STM32-blinkwhich will hold all our code related to the project. You can right-click anywhere in the File Explorer pane, select New Folder, name the folder and click on OK. Now that our Folder is ready, let's go to the terminal and open the newly created folder. Use the following command:
Now we will initialise a new project using Platform IO. Type the following command in the terminal:
pio project init --board nucleo_f411re --project-option "framework=stm32cube"
pio project initcommand is used to initialise the project. Then we need to specify the board which we want to use with the
--boardflag. Finally, Platform IO supports multiple different frameworks for the STM32 like STM32Cube, Arduino, Mbed and others. For a full list of supported frameworks, go here. For this project, we are using the STM32Cube framework.
Once the project init command has run successfully, we will see some new folders inside the
STM32-blinkfolder. We will store the files related to the project in the
After running the
project initcommand, if you can't see the new files, you may have to reload the project files by clicking on PROJECT in the File Explorer pane.
Create a new file called
srcfolder. This file will hold the code for the blink program. Click on the main.c file to open it up in our code editor. Now, paste the following code inside the main.c file.
#define LED_PIN GPIO_PIN_5
#define LED_GPIO_PORT GPIOA
#define LED_GPIO_CLK_ENABLE() __HAL_RCC_GPIOA_CLK_ENABLE()
GPIO_InitStruct.Pin = LED_PIN;
GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
GPIO_InitStruct.Pull = GPIO_PULLUP;
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_HIGH;
Save the main.c file. Now we need to compile this code. We will use Platform IO for the same. Go to your terminal and type the following command.
The first time this command is run, Platform IO will download and install the relevant framework and toolchains required for the STM32. This process will take a few seconds.
Now Platform IO will compile our code and output a firmware.bin file. We need to copy this firmware file from the
/workspace. Usually you would need to use the
cpcommand, but we have created a custom command called
load-firmwarefor ease of use. Just write the following command and the firmware.bin file will be copied to the workspace folder.
Once we have copied the firmware.bin file, all we need to do is to reset the STM32 by pressing the red button above the STM32. The new firmware will now be loaded and the LED at GPIO 5 will start blinking.
For working with Arduino based programs right in the online IDE, set the framework as
pio project initcommand. The Arduino sketches will go into the
srcfolder and the rest of the workflow is the same. Use
pio runfor compiling the sketches and
load-firmwarefor moving the firmware file to