In this Tutorial, I will be showing you detailed steps to BLINK LED on your STM32F103 Board.
This Tutorial is divided into 4 Steps:
Step 1: Creating Project
1-1: Creating Project using STM32CubeMX
1-2: Setting Up LED in STM32CubeMX
Step 2: Programming to Blink LED
Step 3: Burning/Compiling/Building onto STM32 Board
Step 4: Visualizing the output
Note: If you haven't installed softwares required for STM32F103 Development, Have a look at this Instructable:
Start STM32CubeMX. A window like this will appear: {See Image[1]}
Click on “New Project”. A list like this will appear: {See Image[2]}
From Series Click on “STM32F1”: {See Image[3]}
From “Lines” Click on “STM32F103”. {See Image[4]}
Now, From list Select “STM32F103RBTx” and Click “OK”. {See Image[5]}
A window like this will appear: {See Image[6]}
There is an LED mounted onto your STM32 Board. We will use that. This LED is connected to D13 (as labeled on STM32 board) pin of your Board. This D13 Pin corresponds to “PA5” pin on your microcontroller. So, we will configure this “PA5” pin.
So, click on “PA5” pin on microcontroller shown in your STM32CubeMX window: {See Image[7]}
And Select “GPIO_Output”. And it will turn to like this: {see Image[8]}
Now, Click on “Configuration”. {See Image[9]}
Now under the “System”, click on “GPIO”: {See Image[10]}
A window like this will appear. Select row containing “PA5” {See Image[11]}
In User Label textbox, type “Ld2” (‘L’ capital,‘d’ small, no spaces) {See Image[12]}
Click “APPLY” and then Click “OK”. Now, Click on “Generate Code” button as Shown Below: {See Image[13]}
A window like this will appear: {See Image[14]}
Enter Project Name: {See Image[15]}
Then Click On “Browse” button to locate where to save Project: {See Image[16]}
And Most Important, Click on “toolchain / IDE” and select “MDK-ARM v5” as shown below: {See Image[17]}
Click “OK” Button. If a warning appears,“Click Download”.And Downloading will start as shown below: {See Img[18]}
After Download is complete it will start generating the code. And then will ask: {See Image[19]}
Click on “Open Project”. After that it will open keil: {See Image[20]}
And a window like this will appear: {See Image[21]}
Now, Click on “+” sign before you Project Configuration Folder in this case, “ARK1 Configuration”, then click on “Application/User” Folder’s “+” sign, the Double Click on “main.c”. {See Image[22]}
This will open main.c file: {See Image[23]}
Now, Scroll Down until you find “While(1)”: {See Image[24]}
This is where you will write your Code.
Now, go into while loop and enter following line of code:
//Ld2 pin refers to "PA5" pin, which is D13 pin to which led is connectedHAL_GPIO_TogglePin(Ld2_GPIO_Port,Ld2_Pin); //Toggle LED
HAL_Delay(1000); //Delay 1 Seconds
After Writing these line of code Press “F7” or click on “Build” Button as shown Below: {See Image[25]}
And it will build compile your code as shown in the “Build Output” Window: {See Image[26]}
Make Sure, you get “0 Error(s)”.
Make sure that your STM32 Board is connected. Press “F8” or Click on “LOAD” button. {See Image[27]}
This will start loading code onto your STM32 Board. And following lines will be added to your Build output:
{See Image[28]}
Verify that “Verify OK”.
Now Press that “Black Button” (RESET Button) on your STM32 Board and you will see a led blinking on your STM32 Board.