2026-01-16 9:15 AM - last edited on 2026-01-16 9:57 AM by Andrew Neil
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.
2026-01-16 9:18 AM
You need to include main.h in whatever file needs those pin defines, i.e. in ledfunc.c.
2026-01-16 10:03 AM - edited 2026-01-20 2:05 AM
@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:
See also:
2026-01-16 12:34 PM
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?
2026-01-16 12:57 PM
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.
2026-01-17 1:58 AM - edited 2026-01-17 2:06 AM
You're welcome! If your question is now answered, please mark the solution.
As described in the link, Mark the post which answered the question - not this one!
@Roman_E wrote:Can anybody also help me with more specific place/forum to ask questions
about coding Nucleo F411RE board pls?
Here's the list of STM32 forums:
For questions specifically about ST's boards, use STM32 MCUs Boards and hardware tools
For questions about ST software, use STM32 MCUs Embedded software
etc.
gives you access to ST's new Sidekick AI assistant:
Here are some general reference & training materials on C programming - not specific to STM32:
https://blog.antronics.co.uk/2011/08/08/so-youre-thinking-of-starting-with-c/
Here are some of ST's training resources:
PS:
You can see the full list of forums by clicking on 'Product Forums' at the top of the page:
For questions/comments about the forum itself, use the Feedback forum - via the 'About' menu:
You'll find lots of tips on how to best use the forums under 'Community guidelines'