Welcome to the Getting Started Guide for the STM32-F103RB Nucleo Board! This guide will walk you through the essential steps to begin your journey with this powerful microcontroller board. Whether you're a beginner or an experienced developer, this guide will provide you with the necessary knowledge to get up and running with the STM32-F103RB Nucleo Board.
The objective of this project is to familiarize oneself with the STM32 Cube IDE and the STM32-F103RB Nucleo Board by implementing a basic blinking functionality for both the built-in LED and an external LED
To successfully complete this project, you will need the following components:
Nucleo-F103RB board
LED
Resistor (220–330 ohms)
Jumper wires
Breadboard
Follow the circuit diagram below to connect the LED to the Nucleo board:
Connect the anode (long leg) of the LED to PA5 of the Nucleo board.
Connect the cathode (short leg) of the LED to a resistor (220 ohms).
Now connect the other end of the resistor to the ground (GND) pin of the board.
Follow these steps to configure the .IOC file and set up GPIOs and Clock :
Open the STM32 Cube IDE and start by creating a new STM32 project. Click on the board selector tab in the target selection window.
Enter "NUCLEO-F103RB" as the commercial part number and click on "Next" after selecting the board.
3. Enter the Project Name "blink_led", keep everything else to default, and click on "Finish". After that, click on "Yes" to initialize all the peripherals in default mode.
Pinout & Configuration: To configure the built-in LED (PA5) on the STM32-F103RB Nucleo Board, navigate to the "Pinout & Configuration" tab. Select the "GPIO" tab in the System Core section.
To configure the GPIO pin PA5 for output, click on the GPIO pin in the Pinout & Configuration tab. Select the "GPIO_Output" option from the available options. To add a user label, right-click on the GPIO pin PA5 and select the "User Label" option and enter the desired name for the label, in this case "LD2".
Configure the PA5 pin as follows:
Select "Output level" as Low (This will keep the GPIO Low initially).
Choose push-pull GPIO mode.
Keep the GPIO Pull-Up/Pull-Down as "No Pull-up or Pull-down".
Set the maximum output speed as "High".
8. After finishing the Pinout Configuration, go to the Clock Configuration menu. In the HCLK field, enter "72 MHz" as the desired frequency for the HCLK (system clock). The Integrated Development Environment (IDE) will automatically search for the necessary clock sources and prescalers based on this configuration.
9. Next, locate the gear-like icon on the toolbar and click on it. This will add the configuration settings we did in the GUI to the code.
Now, let's proceed to understand and write the C code to blink the LED. Follow the steps below:
The Device Configuration Tool will automatically open the main.c file for you. In the project, you will find all the necessary pin and port names defined in the Core ⇾ Inc ⇾ main.h file. These definitions will help us easily reference the pins and ports in our code.
Navigate to the main function in the main.c file and paste the following code, two methods are shown to blink the LED:
Note: You can download the full project code from this link.
int main(void)
{
HAL_Init();
SystemClock_Config();
MX_GPIO_Init();
MX_USART2_UART_Init();
/* Infinite loop */
/* USER CODE BEGIN WHILE */
while (1)
{
/*USER CODE BEGIN 3 */
/*Normal toggle
HAL_GPIO_WritePin(LD2_GPIO_Port, LD2_Pin, GPIO_PIN_RESET); (0)
HAL_Delay(1000);
HAL_GPIO_WritePin(LD2_GPIO_Port, LD2_Pin, GPIO_PIN_SET); (1)
HAL_Delay(1000);
* /
// Toggle function
HAL_GPIO_TogglePin(LD2_GPIO_Port, LD2_Pin);
HAL_Delay(1000);
}
/* USER CODE END 3 */
}
After pasting the above code, ensure that you have connected your STM32-F103RB Nucleo Board to your PC/Laptop using a USB cable.
Next, click on the "Run and Debug" icon in the toolbar menu of the IDE (Refer to image below ). This will initiate the build process for your project. The IDE will compile the code. Once the build process is successful, the IDE will start flashing the compiled project to the STM32-F103RB Nucleo Board.
Upon successfully running the project, the built-in LED and external LED connected to PA5 on the STM32-F103RB Nucleo Board will blink at a rate of 1 Hz. The blinking pattern demonstrates successful code execution and showcases the functionality of the board.
By completing this guide, you have gained hands-on experience with the STM32 Cube IDE and the STM32-F103RB Nucleo Board. You have successfully implemented basic blinking functionality for LEDs, setting the foundation for future projects. Continue exploring advanced features and resources to further enhance your microcontroller development skills.