Skip to main content
Ijaz Ahmad
Associate II
February 13, 2018
Question

From StdPeriphLib to HAL. PreProcessor AUTO definition

  • February 13, 2018
  • 2 replies
  • 2467 views
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
This topic has been closed for replies.

2 replies

Andrew Neil
Super User
February 13, 2018
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.

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.
Ijaz Ahmad
Associate II
February 13, 2018
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.

Tesla DeLorean
Guru
February 13, 2018
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 VenmoUp vote any posts that you find helpful, it shows what's working..
Andrew Neil
Super User
February 14, 2018
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.

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.