In our BCA143 Course, we tackled about microcontrollers. One of the microcontrollers Prof. Paul Rodolf Castor introduced in our class was the STM32. He also introduced to us the RT Spark 1 Development board, which utilizes the STM32F407ZGT6 microcontroller from ST Microelectronics. In this project, we are tasked to create a basic LED Blink Project for our First Laboratory Activity with the RT Spark Development board which consists the STM32F407ZGT6 microcontroller, using STM32CubeMx and STM32CubeIDE software.
Part 1: Gathering Materials & ResourcesFor our laboratory activity, first we will need the following software installed in our Windows computer:
- STM32CubeMX Download Link for Windows
- STM32CubeIDE Download Link for Windows
- Git for Windows
Also we will need to setup an account on the following platforms:
- Hackster.io (This platform)
- Github
Before we start, we will first know the objectives of this project. For our project objectives, we must:
- 1. Install STM32CubeIDE to Windows Operating System;
- 2. Install STM32CubeIDE to Windows Operating System;
- 3. Create a new project to blink an LED on an RT-Thread RT-Spark Development Board;
- 4. Upload the created working project to GitHub for beginners without a GitHub account; and
- 5. Create a HacksterIO project.
We will need to download 2 softwares for today's project. First, we download STM32CubeIDE to our Windows Computer
Go to the Download Link of the STM32CubeIDE and create an account. After creating an account, download the software designated for Windows as shown below
We must ensure we are downloading the most recent version.
After downloading, we will receive the file shown above. It is in.zip format so we will need to extract it and install the extracted.exe file.
After extracting, run the.exe file and follow the instructions on the screen until STM32CubeIDE is successfully installed.
After STM32CubeIDE Software is installed, head over to the STM32CubeMX Download Page and download the latest version for Windows.
The installation setup is the same with the STM32CubeIDE installation.
Now verify that both of the software are already installed on your computer
After that, we are ready to proceed to the next steps
Part 4: Creating a new STM32 ProjectTo create your first project, launch the STM32CubeMX Software
When you are in the homepage, go to File > New and wait for the initial resources to download.
Once the screen shown in Figure 8 appears, click on 'Comercial Part Number' field and search for STM32F407ZGT6
After you have searched for the exact part number, click on the exact part number shown on the table and then click the Start Project on the top right of the window.
Once we created our new project, we are ready to go to the next steps.
Part 5: Setup Hardware ConfigurationBefore we start coding, we will need to setup our hardware in order to make the blinking LED Project possible. First, we will need to configure the hardware pins that are connected to the LED in the RT Spark board. The exact pins used for the LED are shown in the sample schematic below
GPIO_LED_B and GPIO_LED_R will be our LED Connection. Take note that the exact pinout on the chip is not the GPIO name, but the chip pin name which will be PF11 and PF12.
In our STM32CubeMX Software, we will see a Chip with lots of pins.
In this screen, we can zoom in & out in the chip view. What we will need to do is set PF11 and PF12 as output pins. We can zoom on the chip and find it manually, or use the search bar on the bottom of the window to easily search.
Once we find PF11 and PF12 pins, we will set it to GPIO_Output.
Once we setup the hardware, we are now going to the coding part.
Part 6: Software CodingAfter the Hardware Configuration, we will continue to the Software Part. But first we will setup our STM32CubeMX Software for coding
First, Enter a Project Manager and write your Project Name. Mine will be of the format: Ambal_Jiandale_STM32_Blink_LED
You will also need to select a Project Location where your files will be saved
Don't forget to set the Toolchain / IDE to STM32CubeIDE
After that, click on the GENERATE CODE button on the top right corner of the window
If it asks for confirmation regarding missing dependencies, just click on yes and allow it to download all required firmware libraries and dependencies.
Once the Project Generation is done, click on Open Project
After opening your Project in STM32CubeIDE, your project should show the codes
Now go to Project > Build All
You should receive the message in the console if your Project Build was success
Now go to Project Explorer > Core > Src > main.c
And then write the blink code for the LED
The following code blinks the LED:
while (1)
{
/* USER CODE BEGIN WHILE */
/* USER CODE END WHILE */
/* USER CODE BEGIN 3 */
HAL_GPIO_TogglePin(GPIOF, GPIO_PIN_11);
HAL_GPIO_TogglePin(GPIOF, GPIO_PIN_12);
HAL_Delay(500);
/* USER CODE END 3 */
}This will be similar to the
void loop() {
}functions in Arduino MCUs.
Note: replace GPIO_PIN names based on the generated pin configuration by STM32CubeMX.
If needed, add
#include "main.h"at the top of main.c (it is usually already there).
Part 7: Build and flash to RT-SparkConnect the RT Spark Development Board to the USB Port of your computer and upload.
To upload the code, we will go to the toolbar section and press the green bug icon or Run > Debug or press F11 on the Keyboard
If the code works as expected, run the application as normal. Click the green Play Icon or go to Run > Run.
When the Program is deployed to our RT Thread Development board, we can see the LED Blink very fast.
You should notice the LED now blinks which means our program worked!
The LED Color blinks in RED + YELLOW Combination.
Take Note: Do not get confused by the LED circled in red below in Figure 24 when first uploading the code. I got confused and I thought that was the LED. It turns out it was the board uploader led indicator. Furthermore, the LED circled in Yellow is the LED Indicator for USB Function.
Now we have our basic blink output working on the RT Spark Development Board!
Part 9: Additional ChallengeI got slightly curious and researched more about the example code
The code uses the function
void HAL_GPIO_TogglePin(GPIO_TypeDef* GPIOx, uint16_t GPIO_Pin)I CTRL + Clicked the function definition and got this. I browsed the `stm32f4xx_hal_gpio.c` file and stumbled with this function:
void HAL_GPIO_WritePin(GPIO_TypeDef* GPIOx, uint16_t GPIO_Pin, GPIO_PinState PinState)I then tried using this. But I don't know what parameter to use in GPIO_PinState parameter. I did some research and found this on the forum:
Post: HAL_GPIO_WritePin and HAL_GPIO_ReadPin are not boolean compatible with c++ compiler.
I found out that:
GPIO_PIN_SET is = to HIGH
GPIO_PIN_RESET is = to LOWSo I modified my code to do this:
while (1)
{
HAL_GPIO_WritePin(GPIOF, GPIO_PIN_11, GPIO_PIN_SET);
HAL_GPIO_WritePin(GPIOF, GPIO_PIN_12, GPIO_PIN_SET);
HAL_Delay(500);
HAL_GPIO_WritePin(GPIOF, GPIO_PIN_11, GPIO_PIN_RESET);
HAL_GPIO_WritePin(GPIOF, GPIO_PIN_12, GPIO_PIN_RESET);
HAL_Delay(500);
}Instead of toggle, we now get manual control over the pins.
This is new knowledge!
Now I wanna have some fun. I will try to modify the code to change the behavior of the LED Blink. Since we have PF11 and PF12 pins, we can control 2 LED Color at the same time. What if we it like this:
- First iteration, both LED will flash alternate for 2 times with 500ms delay.
- Second iteration, first LED will turn on and off for 500ms delay then second LED will do the same. This will happen 2 times also
- Third iteration, we make them strobe alternating for 10times
- Finally we go back to the first iteration and rerun everything
So my loop code will be this:
while (1) {
/* First Iteration */
HAL_GPIO_WritePin(GPIOF, GPIO_PIN_11, GPIO_PIN_SET);
HAL_GPIO_WritePin(GPIOF, GPIO_PIN_12, GPIO_PIN_SET);
HAL_Delay(500);
HAL_GPIO_WritePin(GPIOF, GPIO_PIN_11, GPIO_PIN_RESET);
HAL_GPIO_WritePin(GPIOF, GPIO_PIN_12, GPIO_PIN_RESET);
HAL_Delay(500);
HAL_GPIO_WritePin(GPIOF, GPIO_PIN_11, GPIO_PIN_SET);
HAL_GPIO_WritePin(GPIOF, GPIO_PIN_12, GPIO_PIN_SET);
HAL_Delay(500);
HAL_GPIO_WritePin(GPIOF, GPIO_PIN_11, GPIO_PIN_RESET);
HAL_GPIO_WritePin(GPIOF, GPIO_PIN_12, GPIO_PIN_RESET);
HAL_Delay(500);
/* Second Iteration */
// Reset to OFF
HAL_GPIO_WritePin(GPIOF, GPIO_PIN_11, GPIO_PIN_RESET);
HAL_GPIO_WritePin(GPIOF, GPIO_PIN_12, GPIO_PIN_RESET);
HAL_GPIO_WritePin(GPIOF, GPIO_PIN_11, GPIO_PIN_SET);
HAL_Delay(500);
HAL_GPIO_WritePin(GPIOF, GPIO_PIN_11, GPIO_PIN_RESET);
HAL_GPIO_WritePin(GPIOF, GPIO_PIN_12, GPIO_PIN_SET);
HAL_Delay(500);
HAL_GPIO_WritePin(GPIOF, GPIO_PIN_12, GPIO_PIN_RESET);
HAL_GPIO_WritePin(GPIOF, GPIO_PIN_11, GPIO_PIN_SET);
HAL_Delay(500);
HAL_GPIO_WritePin(GPIOF, GPIO_PIN_11, GPIO_PIN_RESET);
HAL_GPIO_WritePin(GPIOF, GPIO_PIN_12, GPIO_PIN_SET);
HAL_Delay(500);
HAL_GPIO_WritePin(GPIOF, GPIO_PIN_12, GPIO_PIN_RESET);
HAL_Delay(500);
/* Iteration 3 */
for(int i = 0; i < 10; i++){
HAL_GPIO_WritePin(GPIOF, GPIO_PIN_11, GPIO_PIN_SET);
HAL_GPIO_WritePin(GPIOF, GPIO_PIN_12, GPIO_PIN_SET);
HAL_Delay(100);
HAL_GPIO_WritePin(GPIOF, GPIO_PIN_11, GPIO_PIN_RESET);
HAL_GPIO_WritePin(GPIOF, GPIO_PIN_12, GPIO_PIN_RESET);
HAL_Delay(100);
}
// Reset LEDs
HAL_GPIO_WritePin(GPIOF, GPIO_PIN_11, GPIO_PIN_RESET);
HAL_GPIO_WritePin(GPIOF, GPIO_PIN_12, GPIO_PIN_RESET);
// Cleanup Delay
HAL_Delay(500);
// Back to Iteration 1
}And after flashing...
We got the output:
As you can see, first it flashes both LED, then flashes each LED alternate and finally strobes the light before going back into the loop.
This is Great!
Part 10: Commit to GithubAssuming our windows computer already has git installed, if not yet refer to this guide
First we will create a repository for our project
Now we open a Command Prompt in our Project Directory by typing 'cmd' in the address bar.
We will then execute the following commands to commit locally:
git init
git add .
git commit -m "Initial commit: STM32F407ZGT6 Blink LED"If we git commit and we get an Author identity unknown, this means we will need to login to Github.
This year in 2026, git global user.email and user.name is no longer a working method to login to git cli. I personally use this guide by utilizing PAN (Personal Access Token) of Github to login to my account easily. You can follow that guide to be able to login to the git cli.
Now we will add our git repo origin by running the command
git remote add origin <your_git_repo_url.git>Now we will create a remote branch called main and push everything there
git branch -M main
git push -u origin mainNow check your command if it completed successfully.
The git push as complete. You can verify on your Github Repository if the files already reflected.
It should have all the files. This means that your code is now being tracked by git and we have successfully set up git in our STM32CubeIDE Project.
Part 11: ConclusionOur first Laboratory Activity was a success! We didn't just demonstrated a basic LED. We even tried creating our own Blinking Pattern!
Part 12: What have I learnedThe main thing I've learned is that how STM Boards are programmed with the provided STM32CubeMX and STM32CubeIDE Software. I got also got a glimpse of the HAL Codes and technical software stuff for the STM32 Microcontroller (specifically the STM32F407ZGT6 Chip). Also, I got to learn the 2 basic functionality of STM32 which is the GPIO Toggle function and GPIO Set Pin HIGH or LOW function. I had a lot of fun making this laboratory activity!






Comments