includes inside include - header files

Asked by John Smith

I am trying to compile a project for STM32F4Discovery board and I have a problem with "invisible includes".

For example, in file stm32f4_discovery_lcd.c there are some includes:
#include "stm32f4xx.h"
#include "stm32f4_discovery.h"
#include "stm32f4_discovery_lcd.h"
#include "fonts.c"

In file stm32f4xx.h is included next file (USE_STDPERIPH_DRIVER is defined):
#ifdef USE_STDPERIPH_DRIVER
  #include "stm32f4xx_conf.h"
#endif /* USE_STDPERIPH_DRIVER */

and in file stm32f4xx_conf.h are included proper files:
...
#include "stm32f4xx_gpio.h"
...

All above doesn't work, I have unknown type name 'GPIO_InitTypeDef', 'GPIO_Pin_0' undeclared and so on.

Direct include works, i.e.
#include "stm32f4xx.h"
#include "stm32f4xx_gpio.h" <---- Added
#include "stm32f4_discovery.h"
#include "stm32f4_discovery_lcd.h"
#include "fonts.c"

Why indirect includes doesn't work?

Question information

Language:
English Edit question
Status:
Solved
For:
GNU Arm Embedded Toolchain Edit question
Assignee:
No assignee Edit question
Solved by:
Terry Guo
Solved:
Last query:
Last reply:
Revision history for this message
Terry Guo (terry.guo) said :
#1

Hi John,

Since your project isn't shared, I have to create a project which has same include behavior with yours. And everything works fine for me. Here is my screen paste:

The content of my case:
terguo01@terry-pc01:example$ cat test_discovery_lcd.c
#include "stm32f4xx.h"

GPIO_InitTypeDef GPIO_InitStructure;

void
test ()
{
  GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0 | GPIO_Pin_1 | GPIO_Pin_2 | GPIO_Pin_3 | GPIO_Pin_6 \
                                | GPIO_Pin_7 | GPIO_Pin_8 | GPIO_Pin_9 | GPIO_Pin_10 |GPIO_Pin_11 ;
}

Command to build it:
terguo01@terry-pc01:example$ arm-none-eabi-gcc -mthumb -mcpu=cortex-m4 test_discovery_lcd.c -I./stm32f4/STM32F4xx_StdPeriph_Driver/inc/device_support/ -I./stm32f4/STM32F4xx_StdPeriph_Driver/inc/core_support/ -I./stm32f4/Projects/discovery_demo/ -I./stm32f4/STM32F4xx_StdPeriph_Driver/inc/ -DUSE_STDPERIPH_DRIVER -S
terguo01@terry-pc01:example$

Command to preprocess it:
terguo01@terry-pc01:example$ arm-none-eabi-gcc -mthumb -mcpu=cortex-m4 test_discovery_lcd.c -I./stm32f4/STM32F4xx_StdPeriph_Driver/inc/device_support/ -I./stm32f4/STM32F4xx_StdPeriph_Driver/inc/core_support/ -I./stm32f4/Projects/discovery_demo/ -I./stm32f4/STM32F4xx_StdPeriph_Driver/inc/ -DUSE_STDPERIPH_DRIVER -E

Part of the file after preprocessed:

GPIO_InitTypeDef GPIO_InitStructure;

void
test ()
{
  GPIO_InitStructure.GPIO_Pin = ((uint16_t)0x0001) | ((uint16_t)0x0002) | ((uint16_t)0x0004) | ((uint16_t)0x0008) | ((uint16_t)0x0040)
                                | ((uint16_t)0x0080) | ((uint16_t)0x0100) | ((uint16_t)0x0200) | ((uint16_t)0x0400) |((uint16_t)0x0800) ;
}

Can you please double-check that there is no typo in your command line? Or if you can share your project, it will be helpful.

Revision history for this message
John Smith (john-s-22x) said :
#2

I use CooCox IDE. Project is available @ https://files.myopera.com/galaxyinc72/files/DevKit407_FSS1500NS.7z

Compiler Control String:
-mcpu=cortex-m4; -mthumb; -Wall; -ffunction-sections; -g; -O0; -DSTM32F407VG; -DSTM32F4XX; -DUSE_STDPERIPH_DRIVER; -D__ASSEMBLY__; -I.; -Icmsis_lib/include; -Iuser; -Icmsis_boot; -Icmsis_lib/source;

Revision history for this message
Best Terry Guo (terry.guo) said :
#3

I just checked the file stm32f4xx_conf.h where the stm32f4xx_gpio.h is included. I think you might omit the line:

/* Uncomment the line below to enable peripheral header file inclusion */

By default those include directives are commented out. After uncomment and add all peripherals through CoIDE Repository, I can successfully build the project. You also need to remove the line:

#include "fonts.c"

from file stm32f4_discovery_lcd.c. Otherwise you will run into link error about multiple definitions. The fonts.c is already added as one of your project file. It will be linked to your final image, no need to include it here.

Revision history for this message
John Smith (john-s-22x) said :
#4

Thanks Terry Guo, that solved my question.

Revision history for this message
John Smith (john-s-22x) said :
#5

I was having 2 stm32f4_conf.h files and I was trying to modify wrong one. Thank you.