STM32CubeIDE Guide
STM32CubeIDE Guide
Software Requirements
STM32Cube IDE
STM32CubeIDE
compiler.
After the selection of an empty STM32 MCU or MPU, the project is created and
STM32CubeMX
for STM32.
It uses the STM32 hardware abstraction layer (HAL) library to create the
microcontrollers if needed.
After the code is generated, everything should be ready to use the HAL library to
Lab Practice 1
In this example, we will create a simple circuit consisting of a switch, SW and an led, LED.
The led will be ON when the switch is pressed down. Otherwise it will remain OFF.
Step 1
First create a directory called LedBlink (1). Next open the STM32CubeIDE by double
Step 2
Browse and select the directory created in Step 1 as the workspace (1). Next click on the
Step 4
In the Part Number box, type stm32f103 and click on STM32F103C6 from the drop down
list.
Next click on the first row (package LQFP48) and click on the Next button.
Step 5
When the screen shown below pops up, click on the Yes button.
Step 7
An led, LED, will be connected to pin PB0 (1). Click on this pin and from the drop down
list , select GPIO_Output (2). Notice now pin PB0 is labelled as GPIO_Output. (3)
Step 8
Click on System Core and from the drop down menu, select GPIO.
Modify the output pin name as LED (1). The other configurations should be maintained. By
default the GPIO output level is Low (2). Do not change this default level.
NOTE : There is an alternative way to label the pin. Simply left click on the pin (1). Click on
Enter User Label (2) and change the pin accordingly (3).
Repeat the same proceduce for switch SW, which will be connected to pin PB4.
Step 9
We will use the stm32f103c6 8MHz internal oscillator (HSI). The external oscillators (HSE
need to be included for blinking the led is inside the infinite while loop.
Now we have the input pin, SW and the output pin, LED. These input and output pin
statements may be determined by typing the keyword hal_gpio followed by pressing the Ctrl
give :
GPIOx refers to the port we are using – in this case port B (PB0 and PB4). So, we change
GPIOx to GPIOB. For the switch input, the GPIO_Pin is SW_Pin. For the LED output, this
HAL_GPIO_ReadPin(GPIOB, SW_Pin)
Finally, we write the intended code - when SW is pressed down, LED will be ON. We know
that SW is pressed down when it reads 0 or LOW logic. To check this, we use the if
condition :
Also, LED will be ON when we write 0 or LOW logic to it. So, to ON LED, we write :
Note that GPIO_Pin_SET and GPIO_Pin_RESET means the pin has 1 and 0 logic
respectively.
Next, to generate the hex file to be used with Proteus, perform the following steps (click on
NOTE : For step 5, check on the second box and click on the Apply and Close
Step 12
NOTE:
Remodify the program such that LED will blink when switch SW is pressed down.