Open File → New → C Project
Give a project name ‘nucleo64_F072RB_template’. Use Empty Project profile.
Click Next and leave the configurations as proposed:
Click Finish.
You should get the following project structure. All you have is an empty file structure with only few include definitions. These includes are for the GCC compiler libraries, and are part of any GCC related project:
Using Right-Click → New → Folder from the Project Explorer, prepare 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.
In order to get up-to-date CMSIS driver and startup files, a good option is to download the latest release of STM32 Cube libraries for the targeted device. It comes as a pretty big package including HAL libraries, but do not worry, we will only pick-up few files from this archive.
You can get the STM32F0 Cube library from ST website :
Unzip the archive somewhere on your file system. The content should be as below:
In another window, open your project folder located in your workspace folder:
Then copy/paste the following files, from the Cube library, into your project folders:
File(s) | Source folder | Destination folder |
*.h | \Drivers\CMSIS\Include\ | \cmsis\core\ |
stm32f0xx.h, stm32f072xb.h system_stm32f0xx.h | \Drivers\CMSIS\Device\ST\STM32F0xx\Include | \cmsis\device\inc |
startup_stm32f072xb.s | \Drivers\CMSIS\Device\ST\STM32F0xx\ Source\Templates\gcc |
\cmsis\device\src |
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.
Back into Eclipse, right-click on the project name in the Project Explorer and select Refresh (or press F5). Your project structure now should be:
Some explainations about files we've just added to the project:
*(int *)0x48000014 ^= 0x00000020U;
now becomes:
GPIOA->ODR ^= GPIO_ODR_5;
which is exactly same code, as there are just a #define behind GPIOA, ODR, GPIO_ODR_5 labels. Still, it makes code writing and reading way more comfortable. When hovering the mouse over a #defined symbol, you get a bubble info that provides the definition:
These headers also include data types based on <stdint.h> that we will use instead of standard C types for integer numbers:
C types | Embedded types |
char | int8_t |
unsigned char | uint8_t |
short | int16_t |
unsigned short | uint16_t |
int | int32_t |
unsigned int | uint32_t |
Right-click on the /app/src folder in the Project Explorer and choose New → Source File and add main.c to that folder
Right-click on the /app/inc folder in the Project Explorer and choose New → Header File and add main.h to that folder
Open main.c in the editor. Let us write something simple, just to have something to watch in the debugger:
/*
* main.c
*
* Created on: 5 août 2017
* Author: Laurent
*/
#include "stm32f0xx.h"
int main()
{
uint8_t i = 0;
while(1)
{
i++;
}
}
Save main.c. We can leave main.h empty for the moment.
Double-click stm32f0xx_it.c to open editor. Then scroll down until you find the SysTick_Handler() function. Comment (or delete) the call to HAL_IncTick() function as we are not going to use the HAL library.
/**
* @brief This function handles SysTick Handler.
* @param None
* @retval None
*/
void SysTick_Handler(void)
{
// HAL_IncTick();
}
Open project Properties (right-click→Properties) and select the C/C++ Build→Settings category or simply click the build configuration button.
Atollic will first prompt you for target (device) setting:
Click OK. Then select the MCU you want as project target:
Click Apply.
Let TrueSTUDIO generate a new linker script based on the MCU you've just set:
Clicking OK in the popup window
Even better, if you plan to share your project using Git, you may use workspace and project name global variables to avoid using your own paths, making the import into another workspace directly working:
You must provide the compiler with all the paths you've used to store header (.h) files. Having them into the project file structure is not enough.
Go into C Compiler → Directories
Use the Add button of the Include paths frame to add the following folders by browsing into the workspace:
Most library source files (.h, .c) include conditional-build sections (using the #ifdef compiler directive). These sections are included in or excluded from the build depending on the definition (or not) of specific symbols. In particular, you need to tell the generic header stm32f0xx.h wich particular device you are using in order to include the right code sections.
Go into C Compiler → Symbols
Hit the rebuild button or right-click the project name and select Build Project. The project should build successfully without any warning or error! If you have error, then carefully review the above settings...
Note that two new items have appeared in the Project Explorer:
Open the Debug Configuration window .
Select Embedded C/C++ Application and then click the New button
Review the Main tab to make sure that the right .elf file is set:
In the Debugger tab, set the probe to whatever you have (ST-Link or J-Link). Most likely, if you're working with a fresh Nucleo board, you need to set the probe to ST-Link, with SWD interface.
When you are done reviewing these settings, just Apply.
You can then click the Debug button, or close the window and click . If it doesn’t work, make sure you have a connected Nucleo at the end of the USB cable !
Once in the debugger environment, you can control program execution via usual toolbar commands (,
,
,
,
, ...), add variables or expressions to watch, etc.
Set a breakpoint on the i++ line, and then press resume several times watching the i variable:
Then terminate the debug session and switch back to C/C++ perspective.
In this tutorial, you have created a new project to work with the STM32F072 target under Atollic TrueSTUDIO®. You now have a clear view of files you need to include in order to have a clean startup code, register definitions, and access to Cortex-M specific functions.