In the previous tutorial, we have introduced CubeIDE® environment. The project was built using the graphical configuration tool, which heavily relies on HAL libraries. Let us now see how to get a very basic template project, without HAL libraries.
Within CubeIDE®, close any open project and then go to File → New → STM32 Project
Follow the same steps as in previous tutorial until you reach that dialog window:
Provide a name to your project ('blink_nolib', for instance) and select Empty as targeted project type. Then click Finish.
You'll get the following starting project structure:
Let us create our own project file organization structure. For that, you can use the New → Source folder or New → Folder
buttons, either using right-clicking in the Project Explorer, or from the main toolbar:
Using these tools, construct the following folder structure in order to organize the project files:
![]() |
|
Note that this folder structure is only a suggestion. If you know what you are doing, you can organize files the way you want and even put everything below root folder, although not recommended…
As your project grows, the number of source files can become really big. You need a clean file structure that you know and understand well to navigate comfortably between sources. The sooner you get familiar with your choice of folder structure, the better. Even for small projects.
When done building the folder hierarchy, you'll need to redefine the included paths. From the Project Explorer, right-click on the project name ('blink_nolib') and then select Properties.
Select the C/C++ Build category. Then, in the Tool Settings tab, select the MCU GCC Compiler→Include paths section.
Delete () any existing path, then add (
) paths to the header folders (use Workspace button to select folder and avoid mistakes entering paths):
Click Apply and Close when done.
The default project already features a Linkerscript (.ld) file and a Startup (.s) file. In order to complete the template project, we need to collect few additional CMSIS files from the Cube Library provided by ST.
For that, you'll need a copy of the whole software package associated to our device family (STM32 F0 here). There are few options to get this archive:
Open that folder using Windows® file explorer to make sure that the library is there:
Note that FW package for STM32F0 version is 1.11.1 at time of writing. You may have a different one.
Then copy/paste (using Windows® file explorer) the following files, from library folders, into your project folders:
File(s) | Library folder | Project folder |
*.h | \Drivers\CMSIS\Include\ | \cmsis\core\ |
stm32f0xx.h, stm32f072xb.h system_stm32f0xx.h | \Drivers\CMSIS\Device\ST\STM32F0xx\Include | \cmsis\device\inc |
system_stm32f0xx.c | \Projects\STM32F072RB-Nucleo\Templates\Src | \cmsis\device\src |
stm32f0xx_it.h | \Projects\STM32F072RB-Nucleo\Templates\Inc | \app\inc |
stm32f0xx_it.c | \Projects\STM32F072RB-Nucleo\Templates\Src | \app\src |
If you are working with a device other than STM32F0RB, just adapt the previous table to your needs… All ST Cube Libraries share the same file structure.
You should end-up with a project structure similar to this one (press F5 to refresh) :
We need to perform some housecleaning before first build.
- delete or comment the #include "main.h" line. We don't have any main.h file yet.
/* Includes */
// #include "main.h"
#include "stm32f0xx_it.h"
- delete or comment the reference to HAL_IncTick() in the SystTick_Handler() function. We don't want to use HAL library.
void SysTick_Handler(void)
{
// HAL_IncTick();
}
Then you can hit the build button. There should be no error or warning:
Well done! Time to get the LED blinking. Edit the main.c file as follows:
#include "stm32f0xx.h"
int main(void)
{
uint32_t i;
// Start GPIOA clock
RCC->AHBENR |= RCC_AHBENR_GPIOAEN;
// Setup PA5 as output
GPIOA->MODER |= 0x01 <<GPIO_MODER_MODER5_Pos;
// Loop forever
while(1)
{
// Toggle LED
GPIOA->ODR ^= GPIO_ODR_5;
// Wait using a counting delay
for(i=0; i<100000; i++);
}
}
Build the project again. Then configure and run the debug
session as explained in the previous tutorial. You should get the (famous) blinking LED working!