STM32CubeIDE is an Integrated Development Environment (IDE) that provides a comprehensive and user-friendly platform for developing and debugging STM32 microcontroller applications. It provides a range of tools for code development, debugging, and testing, making it an ideal solution for embedded systems developers. If you’re new to STM32CubeIDE, you may be wondering how to get started with downloading and installing this software. In this article, we’ll provide a step-by-step guide to help you get started with STM32CubeIDE, including how to download and install the software on your computer. Whether you’re a beginner or an experienced developer, this guide will help you get started with STM32CubeIDE and start developing your next project.
Downloading STM32CubeIDE
In this section, we will first show you how to set up download STM32CubeIDE for Windows, Linux, and macOS.
Go to the following link:
Click the ‘Get latest’ block according to your operating system. We are using Windows.
The following form will open up. You will have to register your account. Give the following information and click the ‘Download’ button. If you already have an account on my.st.com then you can use that to login as well.
After specifying your personal information and clicking the download button your registration will be complete. You will be given a link in your email address to validate your email address after which the download will automatically start. Note that this email address is the one which you used for registration. The email will be sent by STMicroelectronics.
Installing STM32CubeIDE
A few moments later, after specifying the directory your download will start. After opening the .zip file you will be asked for your agreement. After accepting the agreement and choosing the desired location to install the IDE, the installation process will start. It will take some time for STM32CubeIDE to get installed.
After the installation is complete, click ‘Next’.
After the installation is completed, click ‘Finish’ to close the setup. Your desktop will now have a shortcut to STM32CubeIDE created.
Getting Started with STM32CubeIDE
In this section, we will see how to get started with STM32CubeIDE by creating our first project, For demonstration purposes, we will learn to use GPIO pins of STM32 Blue Pill as digital output pins and see how to configure GPIO pins as digital output in STM32CubeIDE.
For demonstration purposes, we will create a LED blinking example using STM32 Blue Pill. This board has an onboard LED connected to GPIO pin 13.
First, let’s see how to write your first program for STM32 Blue Pill in STM32CubeIDE.
Write your first STM32 Program in STM32CubeIDE
Now that we have already installed the STM32CubeIDE application in our system, let us learn how to use it to program our STM32 boards.
Open the application. You will be asked to specify the directory for the workplace. You can specify the directory and also tick the box below to keep this as the default directory. Next, click ‘Launch’ to start the application.
The STM32CubeIDE workspace will open.
Creating Project in STM32CubeIDE
Now click ‘Start new STM32 project’.
The Target Selection will open.
Select your device from the ‘Part Number.’ We are working with ‘STM32F103C8’.Then click any column entry and then click the ‘Next’ button to proceed further.
Give your project a name. As we are going to blink the on-board LED of our STM32 board hence we have named our project as ‘BLINK_LED.’ Then click ‘Finish.’
You will be asked to open associated perspective. Click ‘Yes’.
Device Configuration Tool
Now the Device Configuration Tool window will open up. We will be able to set pin specific functions here.
STM32 has an on-board LED connected at PC-13. Refer to the detailed pin out of the board above. Click on PC-13 pin on the Device configuration Tool.
A list of functions will appear associated with the pin. We will set this pin as a ‘GPIO Output.’
This is how it will look. Here you can see that we have attached GPIO_Output to PC-13.
Additionally, we have more options for pins as well. Go to System Core > GPIO > PC-13 and the pin configuration for PC-13 will open up. Here we have given the pin a user label of ‘LED.’ You can see in Device Configuration Tool, that now PC-13 has been given the label ‘LED.’
Apart from the label, there are several other options to choose from including GPIO output level, mode, pull-up/pull-down state, etc.
Now we will save our file. Press Ctrl + S. The following window will appear. Click ‘Yes.’ This will generate a template code for you.
Another window will appear that will ask if you want to open the perspective. Click ‘Yes.’
Code
Now the following page opens. On the right side, you will be able to view the Outline of the code. This happened because we opened our code with perspective.
In the center, you can view the main.c file and on the left you can view the Project Explorer.
If you want to go to the Device Configuration Tool, then click the BLINK_LED.ioc tab.
STM32 Blue Pill LED Blinking Code
Now let us modify the main.c file for our BLINK_LED project. Our aim is to blink the on-board LED indefinitely after a delay.
First, inside the main() function go to while(1) and insert the following lines of code. These will be responsible to blink the onboard LED infinitely.
while (1)
{
HAL_GPIO_WritePin(LED_GPIO_Port, LED_Pin, GPIO_PIN_RESET);
delay(500000);
HAL_GPIO_WritePin(LED_GPIO_Port, LED_Pin, GPIO_PIN_SET);
delay(500000);
}
Now what is happening is that the HAL_GPIO_WritePin() function takes in three parameters: the onboard LED port, the onboard LED pin, and the state of the pin. This function will be responsible for setting the onboard LED pin either HIGH or LOW.
Notice that we had labelled the onboard LED as ‘LED’ hence we have specified LABEL_GPIO_Port and LABEL_Pin : the first two parameters as LED_GPIO_Port and LED_Port. Remember to replace ‘LABEL’ with your own pin label.
The case where we are specifying the third parameter as GPIO_PIN_RESET, it sets the onboard LED pin to LOW whereas when we are specifying the third parameter as GPIO_PIN_SET, it sets the onboard LED pin to HIGH.
In between these two functions, we are calling the delay() function. It is not an in-built function therefore we will have to define it as well. Insert the following definition of the delay() function after Error_Handler().
void delay (int x)
{
volatile int i,j;
for (i=0 ; i < x ; i++)
{
j++;
}
return;
}
Additionally, add the prototype of the delay() function with the rest of the private function prototypes as shown below:
/* Private function prototypes -----------------------------------------------*/
void SystemClock_Config(void);
static void MX_GPIO_Init(void);
void delay (int x);
Save the main.c file after modifying it. Now we are ready to build our project.
Building Project STM32CubeIDE
To build our BLINK_LED project press Ctrl + B or go to Project > Build All.
Your project will start building. After a few moments, your project will be built if there are no errors.
Connecting ST-Link Programmer with STM32
Now as we have successfully built our BLINK_LED project let us move ahead and upload the code to our STM32 board. To do that, first we will have to connect our Blue Pill STM32 with a ST-Link programmer. We will be using ST-Link V2.
This will provide an interface between our computer and our STM32 board. It consists of 10 pins. We will be using pin2 SWDIO, pin6 SWCLK, pin4 GND, and pin8 3.3V to connect with our STM32 board. The SWDIO is the data input/output pin and the SWCLK is the clock pin. Follow the pin configuration given on the ST-LINK V2 to identify each pin.
Follow the table below to connect both devices correctly.
STM32 Blue Pill | ST-LINK V2 |
---|---|
VCC 3.3V pin | pin8 3.3V |
SWDIO pin | pin2 SWDIO |
SWCLK pin | pin6 SWCLK |
GND pin | pin4 GND |
Additionally move the BOOT jumper to the right to enable the microcontroller to go into programming mode.
Now connect your ST-LINK V2 with your computer via the USB port. Both the devices will power ON.
Next press the RUN button in the IDE. The following ‘Edit configuration’ window will open up. Click ‘OK’.
After a few moments, the code will be successfully sent to the STM32 board. You can view it in the Console terminal.
Otherwise, press the RESET button on your STM32 board.
Now to bring the Blue pill back to normal mode make sure you bring the BOOT jumper back at its place. After doing that press the RESET button on the board. Immediately, the onboard LED will start blinking.