Skip to main content
Associate III
January 16, 2026
Question

what to include in header and source files

  • January 16, 2026
  • 2 replies
  • 358 views

I generated project with CubeIDE for Nucleo F411RE board with defaults.

Now I want to create my own function void LED_blink(int blink_num);
So, I created ledfunc.h and ledfunc.c files.
This is my ledfunc.h file:

 
#ifndef INC_LEDFUNC_H_
#define INC_LEDFUNC_H_

void LED_blink(int led_number_blink);

#endif /* INC_LEDFUNC_H_ */

and this if my ledfunc.c file:

 
void LED_blink(int led_number_blink) {
 for (int i = 0; i < led_number_blink; i++) {
 HAL_GPIO_WritePin(LD2_GPIO_Port, LD2_Pin, GPIO_PIN_SET);
 HAL_Delay(100);
 HAL_GPIO_WritePin(LD2_GPIO_Port, LD2_Pin, GPIO_PIN_RESET);
 HAL_Delay(100);
 }
}

and I want to use LED_blink(2) function in main.c
( which was generated by CubeIDE )
When I try to build code, I'm getting errors LD2_GPIO_Port undefined
Yes, those defined in main.h
Where (in which file ) I need to include #include "main.h" ?
I need proper way where to add #include


Edited to apply source code formatting - please see How to insert source code for future reference.

2 replies

Bob S
Super User
January 16, 2026

You need to include main.h in whatever file needs those pin defines, i.e. in ledfunc.c.

Andrew Neil
Super User
January 16, 2026

@Roman_E wrote:

those defined in main.h


If you want to use them in your ledfunc.c file, their definitions need to be available in your ledfunc.c file.

The definitions are in main.h so, as @Bob S said, you will need to #include main.h in your ledfunc.c file

 

This is standard C stuff - nothing special with ST or CubeMX or TouchGFX.

 

PS:

It's also good practice to #include your ledfunc.h header in your ledfunc.c source file - that way, the compiler can check that your LED_blink() function prototype in the .h file matches the implementation in the .c file.

See: 

https://community.st.com/t5/stm32cubeide-mcus/adding-new-c-source-files-to-my-project-and-navigating-through/m-p/658310/highlight/true#M25925

See also:

https://community.st.com/t5/stm32cubeide-mcus/adding-new-c-source-files-to-my-project-and-navigating-through/m-p/657455/highlight/true#M25847

A complex system that works is invariably found to have evolved from a simple system that worked.A complex system designed from scratch never works and cannot be patched up to make it work.
Roman_EAuthor
Associate III
January 16, 2026

Thanks to all for helpful replies !
Can anybody also help me with more specific place/forum to ask questions 
about coding Nucleo F411RE board pls?

Technical Moderator
January 16, 2026

Hello @Roman_E and welcome to the Community,

The STM32 MCUs Embedded software is the right place to ask your questions related to the STM32 MCUs software.

"When your question is answered, please close this topic by clicking ""Accept as Solution"".ThanksImen"