cancel
Showing results for 
Search instead for 
Did you mean: 

How can I use the define "__STM32H7xx_HAL_VERSION" in my main.c?

JPiet.3
Associate II

Hello,

I will supervise the version of the used HAL during the compilation process. I know, I can use the function from STM32h7xx_hal.c

HAL_VERSION = HAL_GetHalVersion(); 

to get the HAL-Version. But to use this information, I have to start the application. My aim is to avoid the usage from newer HAL-versions during the compilation to grant the traceability from of of our parts for our firmware.

The following code snipped can check it but the second line is copied in by hand. The number is the output from the HAL-definition.

#define __HAL_CURRENT_VERSION (0x010B0000UL)
#define __STM32H7xx_HAL_VERSION (0x010B0100UL)
 
#if __HAL_CURRENT_VERSION < __STM32H7xx_HAL_VERSION
    #error "Attention! STM32H7xx_HAL_VERSION newer than the current version!"
#endif

I want to get the information directly from STM32h7xx_hal.c., which is located in

%USERPROFILE%\STM32Cube\Repository\STM32Cube_FW_H7_V1.11.0

If somebody has an idea to solve this, let me know. Thanks,

Jan

3 REPLIES 3
KnarfB
Principal III

Well, if the define is only in a .c file, you can't with pure C methods. This is a limitation and the define would better be in a .h.

Depending on your toolset, you may use pre-build steps like in STM32CubeIDE:

grep -rh __STM32H7xx_HAL_VERSION_ Drivers/ > ${ProjDirPath}/Core/Inc/hal_version.h

and include the generated .h in your code.

For that,must have a grep on your path or use similar techniques (findstr on Windows,...) for your toolchain.

If you are using the sources from github, you may get the git tag or verify a specific tag/commit/clean status with similar magic.

hth

KnarfB

If you have i2c eeprom or sw upgrade code feature, you can compare the previous hal version to the new one. If hal was a lib file, this could be also one compatibility test to start or not the code. Peripheral IP rom version registers would be an intetesting thing to contemplate beyond HAL....

Pavel A.
Evangelist III

This is a known issue, already discussed here long ago.

No elegant solution was offered.