Skip to content

Commit

Permalink
Merge pull request #178 from Hish15/RetrieveHALVersion
Browse files Browse the repository at this point in the history
Retrieve hal version
  • Loading branch information
ObKo authored Jan 31, 2021
2 parents e1570ee + a4c310e commit 8867e9b
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 4 deletions.
8 changes: 6 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,12 @@ You can do this by passing values through command line during cmake run or by se

First thing that you need to do after toolchain configration in your `CMakeLists.txt` script is to find CMSIS package:
```
find_package(CMSIS COMPONENTS STM32F4 REQUIRED)
find_package(CMSIS [CMSIS_version] COMPONENTS STM32F4 REQUIRED)
```
You can specify STM32 family or even specific device (`STM32F407VG`) in `COMPONENTS` or omit `COMPONENTS` totally - in that case stm32-cmake will find ALL sources for ALL families and ALL chips (you'll need ALL STM32Cube packages somewhere).

[CMSIS_version] is an optional version requirement. See [find_package documentation](https://cmake.org/cmake/help/v3.13/command/find_package.html?highlight=find%20package#id4). This parameter does not make sense if multiples STM32 families are requested.

Each STM32 device can be categorized into family and device type groups, for example STM32F407VG is device from `F4` family, with type `F407xx`.

***Note**: Some devices in STM32H7 family has two different cores (Cortex-M7 and Cortex-M4).
Expand Down Expand Up @@ -87,11 +89,13 @@ Also, there is special library `STM32::NoSys` which adds `--specs=nosys.specs` t

STM32 HAL can be used similar to CMSIS.
```
find_package(HAL COMPONENTS STM32F4 REQUIRED)
find_package(HAL [HAL_version] COMPONENTS STM32F4 REQUIRED)
set(CMAKE_INCLUDE_CURRENT_DIR TRUE)
```
*`CMAKE_INCLUDE_CURRENT_DIR` here because HAL requires `stm32<family>xx_hal_conf.h` file being in include headers path.*

[HAL_version] is an optional version requirement. See [find_package documentation](https://cmake.org/cmake/help/v3.13/command/find_package.html?highlight=find%20package#id4). This parameter does not make sense if multiples STM32 families are requested.

HAL module will search all drivers supported by family and create following targets:

* `HAL::STM32::<FAMILY>` (e.g. `HAL::STM32::F4`) - common HAL source, depends on `CMSIS::STM32::<FAMILY>`
Expand Down
21 changes: 19 additions & 2 deletions cmake/FindHAL.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,25 @@ foreach(COMP ${HAL_FIND_COMPONENTS_FAMILIES})
set(STM32_CUBE_${FAMILY}_PATH /opt/STM32Cube${FAMILY} CACHE PATH "Path to STM32Cube${FAMILY}")
message(STATUS "Neither STM32_CUBE_${FAMILY}_PATH nor STM32_HAL_${FAMILY}_PATH specified using default STM32_CUBE_${FAMILY}_PATH: ${STM32_CUBE_${FAMILY}_PATH}")
endif()


#Checking HAL patch or release version
unset(VERSION_INFO)
find_file(PACKAGE_FILE NAMES package.xml PATHS ${STM32_CUBE_${FAMILY}_PATH})
if(PACKAGE_FILE)
file(READ ${PACKAGE_FILE} PACKAGE_FILE_CONTENT)
string(REGEX MATCH "PackDescription Release=\"FW.${FAMILY}.([0-9.]+)\"( Patch=\"FW.${FAMILY}.([0-9.]+)\")?" VERSION_INFO ${PACKAGE_FILE_CONTENT})
if(CMAKE_MATCH_3) # This is the "Patch" revision
set(HAL_${COMP}_VERSION ${CMAKE_MATCH_3})
set(HAL_VERSION ${CMAKE_MATCH_3})
else(CMAKE_MATCH_1) #This is the "Release" version
set(HAL_${COMP}_VERSION ${CMAKE_MATCH_1})
set(HAL_VERSION ${CMAKE_MATCH_1})
endif()
endif()
if(NOT VERSION_INFO)
message(STATUS "Could not read the HAL version from package.xml for ${COMP}")
endif()

find_path(HAL_${FAMILY}_PATH
NAMES Inc/stm32${FAMILY_L}xx_hal.h
PATHS "${STM32_HAL_${FAMILY}_PATH}" "${STM32_CUBE_${FAMILY}_PATH}/Drivers/STM32${FAMILY}xx_HAL_Driver"
Expand Down Expand Up @@ -365,4 +383,3 @@ find_package_handle_standard_args(HAL
FOUND_VAR HAL_FOUND
HANDLE_COMPONENTS
)

0 comments on commit 8867e9b

Please sign in to comment.