cancel
Showing results for 
Search instead for 
Did you mean: 

Cube and #define USE_HAL_DRIVER...

samuel23
Associate III
Posted on August 20, 2015 at 09:16

Hi,

I'm using cube with HAL driver.. and need your help to understand the right way to include headers.

I do not understand this example:

I includes ''stm32f4xx_hal_adc.h'' 

''stm32f4xx_hal_adc.h'' includes ''stm32f4xx_hal_def.h''

 ''stm32f4xx_hal_def.h'' includes ''stm32f4xx.h''

''stm32f4xx.h'' defines USE_HAL_DRIVER and includes ''stm32f4xx_hal.h''

''stm32f4xx_hal.h'' includes ''stm32f4xx_hal_conf.h''

''stm32f4xx_hal_conf.h'' includes ''stm32f4xx_hal_dma.h'' (and all the other enabled drivers)

''stm32f4xx_hal_dma.h'' uses HAL_StatusTypeDef...

BUT, HAL_StatusTypeDef is define by  ''stm32f4xx_hal_def.h''

AFTER

the inclusion of all these files...

So I get a compilation error!

Should I not define USE_HAL_DRIVER and include modules where there are needed?

Thanks!

Samuel.

4 REPLIES 4
Posted on August 20, 2015 at 11:21

Hi samuel.poiraud.005,

1- What do you mean by  ''I includes ''stm32f4xx_hal_adc.h''

 

2- ''compilation error'': please copy the error here, so I can help

3- ''Should I not define USE_HAL_DRIVER '' where are you defining it?

4-''HAL_StatusTypeDef'' is defined in ''stm32f4xx_hal_def.h'' and used in ''stm32f4xx_hal_dma.h'', so there is no problem with this.

-Shahrzad-
samuel23
Associate III
Posted on August 20, 2015 at 12:48

Thanks for your answer. I complete... (apologies about my english...)

1- My main.c begins with: 

   #include stm32f4xx_hal_adc.h

2- An example of the compilation error is:

In file included from ../lib/hal/inc/stm32f4xx_hal_conf.h:379:0,

                 from ../lib/hal/inc/stm32f4xx_hal.h:48,

                  from ../lib/hal/inc/stm32f4xx.h:213,

                 from ../lib/hal/inc/stm32f4xx_hal_def.h:48,

                 from ../lib/bsp/stm32f4_timer.h:10,

                 from ../lib/bsp/stm32f4_timer.c:7:

../lib/hal/inc/stm32f4xx_hal_pcd.h:222:1: error: unknown type name 'HAL_StatusTypeDef'

3- I define USE_HAL_DRIVER in ''stm32f4xx.h'', just here:

#if !defined  (USE_HAL_DRIVER)

/**

  * @brief Comment the line below if you will not use the peripherals drivers.

   In this case, these drivers will not be included and the application code will 

   be based on direct access to peripherals registers 

   */

  #define USE_HAL_DRIVER

#endif /* USE_HAL_DRIVER */

4- Yes, but ''HAL_StatusTypeDef'' is defined by ''stm32f4xx_hal_def.h'' AFTER the include of ''stm32f4xx_hal_dma.h''... 

''stm32f4xx_hal_dma.h'' includes ''stm32f4xx_hal_def.h'', but the 

#ifndef __STM32F4xx_HAL_DEF

makes the typedef is not visible by ''stm32f4xx_hal_dma.h''

Is it more clear?

;)

Posted on August 20, 2015 at 15:50

Hi samuel.poiraud.005,

1-You can use the project template under \STM32Cube_FW_F4_V1.7.0\Projects\...\Templates. And refer to this

http://www.st.com/st-web-ui/static/active/en/resource/technical/document/user_manual/DM00105879.pdf

, inside you will find an inclusion model for files that can help you (section 2.8).

2-Include the path of Include folder of drivers in your project options

3-You don't have to modify the ''stm32f4xx.h'', the USE_HAL_DRIVER is defined in the Prepocessor symbols (in keil: Options for target->C/C++)

4-The order of defining HAL_StatusTypeDef has no relation with including files. The include is detected in the preprocessing phase and no in the compilation phase. I invite you to read more on Preprocessor.

-Shahrzad-

samuel23
Associate III
Posted on August 20, 2015 at 17:16

Ok, thanks! It's clear.

The problem is solved. (I write it here if someone look for the same thing)

We just have to include ''stm32f4xx_hal.h'' and nothing else when using HAL files!

(With the STD_Libraries, it worked when we included each needed header.)

(It is just strange and heavy for the compiler that every file must include all the HAL, just when needed a small function somewhere...but it is easier...)

Thanks again,

Bye!