cancel
Showing results for 
Search instead for 
Did you mean: 

From StdPeriphLib to HAL. PreProcessor AUTO definition

Ijaz  Ahmad
Associate II
Posted on February 13, 2018 at 20:13

Hi,

I have a very strange error while migrating from Standard Peripheral Libraries to HAL libraries. 

what I did was:

1. I created new Keil project for STM32F407 Discovery.

2. Added Device startup file (And CMSIS dependency)

0690X00000609glQAA.png

Now in Keil Project, when I include File STM32F4xx.h from standard peripheral library (

https://github.com/pichenettes/stmlib/blob/master/third_party/STM/CMSIS/CM3_f4xx/stm32f4xx.h

) and compile the code without defining target in Keil pre-processor (

STM32F40_41xxx), 

I get the missing target error at line 112 (

https://github.com/pichenettes/stmlib/blob/829f9db1b92d8f5a360fba203a412ad05e5aab14/third_party/STM/CMSIS/CM3_f4xx/stm32f4xx.h&sharpL112

) which is obvious.0690X00000609jJQAQ.png

But Now if I include the same file (name wise) from HAL libraries (

https://github.com/MaJerle/stm32fxxx_hal_libraries/blob/master/00-HAL_DRIVERS/CMSIS/Device/ST/STM32F4xx/Include/stm32f4xx.h

) and doesn't define target preprocessor, I don't get any error.. at line 193(

https://github.com/MaJerle/stm32fxxx_hal_libraries/blob/b295f87c649cccf0c27bcd6f8f3695666fdde571/00-HAL_DRIVERS/CMSIS/Device/ST/STM32F4xx/Include/stm32f4xx.h&sharpL193

)???  It EVEN includes the relevant header file at Line-150. i.e.

elif

defined(STM32F407xx)

     

  ♯

include

''

stm32f407xx.h

''

which means the preprocessor 

STM32F407xx

is already defined some where OR the file from HAL is defining it somewhere. I tried to dig out but couldn't find its definition in whole project or include/sub-included file..!!!!

So How is it possible that for one file (StdperiphLib) the preprocessor 

STM32F407xx

is defined and for other its not??

Kindly help.

Attachments:

GPIO-Blinky... Both the header files are inside project folder in different folders. Give path to which is needs to be included at a time.

Note: i am not using CubeMX. 

#standard-peripheral-libraries #keil-mdk5 #stm32f4-d #hal-library
8 REPLIES 8
Posted on February 13, 2018 at 20:17

How is it possible that for one file (StdperiphLib) the preprocessor 

STM32F407xx

is defined and for other its not??

Because the StdPeriph requires that you define it in the Project defines, but HAL doesn't.

IF you want to see what's actually happening, look at the Preprocessor output.

Posted on February 13, 2018 at 20:31

Thanks for the reply.

But where is the symbol visible to HAL Libraries??? From where HAL get it??

The pre-processor output I guess would not mention where STM32F407xx

 is defined rather it will only include STM32F407xx.h

file.

Posted on February 13, 2018 at 22:57

Rather than excessively complicate this, just place the correct defines in the command line and make sure the Include Paths point to the appropriate directories, and in an appropriate order, so that a current and coherent set of files are pulled in.

For STM32F4-DISCO board we typically use these defines:

USE_HAL_DRIVER,STM32F407xx,USE_STM32F4_DISCO

The CubeMX F4 trees include HAL examples, and template projects, please use and review these so you have some context about how these should be formulated.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
Posted on February 14, 2018 at 02:23

Clive One wrote:

just place the correct defines in the command line and make sure the Include Paths point to the appropriate directories, and in an appropriate order, so that a current and coherent set of files are pulled in.

Agreed. 

No point in trying to search for any coherence between old-school SPL approach, and brave-new HAL approach - likely, there isn't any.

Posted on February 14, 2018 at 05:23

 ,

 ,

Thanks Clive and Andrew. I am doing this out of curiosity. I am not trying to compare SPL with HAL. I just want to know how the library/file figures out the pre-processor directive. Its like digging deep into how things are linked in HAL libraries?? ,

like i asked in my question, How HAL library know which target is defined at point:

elif

 ,

defined(STM32F407xx)

 ,  ,  ,

 , ♯

include

 ,

'

stm32f407xx.h

'

even though we didn't mentioned anything like:

USE_HAL_DRIVER,STM32F407xx,USE_STM32F4_DISCO

it means that if i include the same file for different target, say STM32F429 how does it know that now its time in include file for F429??

Any clue Please?? ,

Posted on February 14, 2018 at 06:11

I'm not sure I'm looking to play this game.

As Andrew says, have the tool generate the Pre-processor output and review that.

I'd inspect the files using my prefered File Manager, which can grep through the files and see where specific keywords are used or defined.

My expectation if there is ♯ ifndef default option somewhere, and if it defaults to an F407 parts it is not going to later default to an F429

With the HAL the idea is that you don't have to explicitly ♯ include different peripheral files, but rather ♯ include a top level one, and the USE_HAL_DRIVER define causes an stm32f4xx_hal_conf.h to be pulled from the local project.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
Posted on February 14, 2018 at 12:38

Clive One wrote:

I'm not sure I'm looking to play this game.

Likewise.

You're the one that wants to pursue this - for your 'interest' - so you'll have to do the digging.

Again, examining PP output is a key tool here.

Look at other 'diagnostic' options for the tools; eg, listing full command-line, listing all defined sysmbols, .BAT file output, output log, etc, etc,...

Compare 'known-working' configurations ...

EDITED

typo

Posted on February 14, 2018 at 12:54

Thanks.