Skip to content

Commit

Permalink
Print device by family function (ObKo#205)
Browse files Browse the repository at this point in the history
Improved stm32_get_devices_by_family to print out the devices
  • Loading branch information
robamu authored and zisi committed Aug 2, 2021
1 parent b27d718 commit 5718979
Show file tree
Hide file tree
Showing 7 changed files with 108 additions and 19 deletions.
8 changes: 7 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -184,11 +184,17 @@ CMSIS package will generate linker script for your device automatically (target

* `stm32_get_chip_info(<chip> [FAMILY <family>] [TYPE <type>] [DEVICE <device>])` - classify device using name, will return device family (into `<family>` variable), type (`<type>`) and canonical name (`<device>`, uppercase without any package codes)
* `stm32_get_memory_info((CHIP <chip>)|(DEVICE <device> TYPE <type>) [FLASH|RAM|CCRAM|STACK|HEAP] [SIZE <size>] [ORIGIN <origin>])` - get information about device memories (into `<size>` and `<origin>`). Linker script generator uses values from this function
* `stm32_get_devices_by_family(DEVICES [FAMILY <family>])` - return into `DEVICES` all supported devices by family (or all devices if `<family>` is empty)
* `stm32_print_size_of_target(<target>)` - Print the application sizes for all formats
* `stm32_generate_binary_file(<target>)` - Generate the binary file for the given target
* `stm32_generate_hex_file(<target>)` - Generate the hex file for the given target

In the following functions, you can also specify mutiple families.

* `stm32_get_devices_by_family(STM_DEVICES [FAMILY families...])` - return into `STM_DEVICES` all
supported devices by family (or all devices if `FAMILY` is omitted)
* `stm32_print_devices_by_family([FAMILY families...])` - Print all supported devices by family
(or all devices if `FAMILY` is omitted)

# Additional CMake modules

stm32-cmake contains additional CMake modules for finding and configuring various libraries and RTOSes used in the embedded world.
Expand Down
12 changes: 6 additions & 6 deletions cmake/FindCMSIS.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,10 @@ foreach(COMP ${CMSIS_FIND_COMPONENTS})

if(CMAKE_MATCH_2)
set(FAMILY ${CMAKE_MATCH_1})
set(DEVICES "${CMAKE_MATCH_1}${CMAKE_MATCH_2}")
set(STM_DEVICES "${CMAKE_MATCH_1}${CMAKE_MATCH_2}")
else()
set(FAMILY ${CMAKE_MATCH_1})
stm32_get_devices_by_family(DEVICES FAMILY ${FAMILY} CORE ${CORE})
stm32_get_devices_by_family(STM_DEVICES FAMILY ${FAMILY})
endif()

if(CMAKE_MATCH_3)
Expand Down Expand Up @@ -138,8 +138,8 @@ foreach(COMP ${CMSIS_FIND_COMPONENTS})
target_sources(CMSIS::STM32::${FAMILY}${CORE_C} INTERFACE "${CMSIS_${FAMILY}${CORE_U}_SOURCE}")
endif()

set(DEVICES_FOUND TRUE)
foreach(DEVICE ${DEVICES})
set(STM_DEVICES_FOUND TRUE)
foreach(DEVICE ${STM_DEVICES})
stm32_get_cores(DEV_CORES FAMILY ${FAMILY} DEVICE ${DEVICE})
if(CORE AND (NOT ${CORE} IN_LIST DEV_CORES))
continue()
Expand All @@ -156,7 +156,7 @@ foreach(COMP ${CMSIS_FIND_COMPONENTS})
)
list(APPEND CMSIS_SOURCES "${CMSIS_${FAMILY}${CORE_U}_${TYPE}_STARTUP}")
if(NOT CMSIS_${FAMILY}${CORE_U}_${TYPE}_STARTUP)
set(DEVICES_FOUND FALSE)
set(STM_DEVICES_FOUND FALSE)
break()
endif()

Expand All @@ -171,7 +171,7 @@ foreach(COMP ${CMSIS_FIND_COMPONENTS})
cmsis_generate_default_linker_script(${FAMILY} ${DEVICE} "${CORE}")
endforeach()

if(DEVICES_FOUND)
if(STM_DEVICES_FOUND)
set(CMSIS_${COMP}_FOUND TRUE)
else()
set(CMSIS_${COMP}_FOUND FALSE)
Expand Down
94 changes: 88 additions & 6 deletions cmake/stm32/devices.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -1116,14 +1116,96 @@ set(STM32_ALL_DEVICES
WLE5JC
)

function(stm32_get_devices_by_family DEVICES)
# Store a list of devices into a given STM_DEVICES list.
# You can also specify multiple device families. Examples:
# Get list of all devices for H7 family: stm32_get_devices_by_family(STM_DEVICES FAMILY H7)
# Get list of all devices: stm32_get_devices_by_family(STM_DEVICES)
function(stm32_get_devices_by_family STM_DEVICES)
# Specify keywords for argument parsing here
set(ARG_OPTIONS "")
set(ARG_SINGLE FAMILY)
set(ARG_MULTIPLE "")
set(ARG_SINGLE "")
set(ARG_MULTIPLE FAMILY)

# Parse arguments. Multiple families can be specified and will be stored in ARG_<KeywordName>
cmake_parse_arguments(PARSE_ARGV 1 ARG "${ARG_OPTIONS}" "${ARG_SINGLE}" "${ARG_MULTIPLE}")
set(LIST ${STM32_ALL_DEVICES})
stm32_dev_parser_check()

# Build a list of families by filtering the whole list with the specified families
if(ARG_FAMILY)
list(FILTER LIST INCLUDE REGEX "^${ARG_FAMILY}")
set(RESULTING_DEV_LIST "")
foreach(FAMILY ${ARG_FAMILY})
set(STM_DEVICE_LIST ${STM32_ALL_DEVICES})
list(FILTER STM_DEVICE_LIST INCLUDE REGEX "^${FAMILY}")
list(APPEND RESULTING_DEV_LIST ${STM_DEVICE_LIST})
if(NOT STM_DEVICE_LIST)
message(WARNING "No devices found for given family ${FAMILY}")
endif()
endforeach()
else()
# No family argument, so get list of all devices
set(RESULTING_DEV_LIST ${STM32_ALL_DEVICES})
endif()
set(${DEVICES} ${LIST} PARENT_SCOPE)

set(${STM_DEVICES} ${RESULTING_DEV_LIST} PARENT_SCOPE)
endfunction()

# Print the devices for a given family. You can also specify multiple device families.
# Example usage:
# Print devices for H7 family: stm32_print_devices_by_family(FAMILY H7)
# Print all devices: stm32_print_devices_by_family()
function(stm32_print_devices_by_family)
# Specify keywords for argument parsing here
set(ARG_OPTIONS "")
set(ARG_SINGLE "")
set(ARG_MULTIPLE FAMILY)

# Parse arguments. Multiple families can be specified and will be stored in ARG_<KeywordName>
cmake_parse_arguments(PARSE_ARGV 0 ARG "${ARG_OPTIONS}" "${ARG_SINGLE}" "${ARG_MULTIPLE}")
stm32_dev_parser_check()

if(ARG_FAMILY)
# print devices one family per line
foreach(FAMILY ${ARG_FAMILY})
stm32_get_devices_by_family(STM_DEVICES FAMILY ${FAMILY})
stm32_pretty_print_dev_list(${FAMILY} "${STM_DEVICES}")
endforeach()
else()
# print all devices
stm32_get_devices_by_family(STM_DEVICES)
stm32_pretty_print_dev_list("all" "${STM_DEVICES}")
endif()

endfunction()

# The arguments checked in this macro are filled by cmake_parse_argument
macro(stm32_dev_parser_check)
# contains unexpected arguments (unknown keywords beofre ARG_MULTIPLE)
if(ARG_UNPARSED_ARGUMENTS)
message(WARNING "Unknown keyword(s) ${ARG_UNPARSED_ARGUMENTS} will be ignored")
endif()
# is populated if ARG_SINGLE or ARG_MULTIPLE is used without values
if(ARG_KEYWORDS_MISSING_VALUES)
message(FATAL_ERROR "Keyword ${ARG_KEYWORDS_MISSING_VALUES} expects values")
endif()
endmacro()

# Pretty printer to limit amount of list entries printed per line
macro(stm32_pretty_print_dev_list FAMILIES STM_DEVICES)
if(${FAMILIES} STREQUAL "all")
message(STATUS "Devices for all families")
else()
message(STATUS "Devices for ${FAMILIES} family")
endif()
set(TMP_LIST "")
foreach(STM_DEVICE ${STM_DEVICES})
list(APPEND TMP_LIST ${STM_DEVICE})
list(LENGTH TMP_LIST CURR_LEN)
if(CURR_LEN EQUAL 10)
message(STATUS "${TMP_LIST}")
set(TMP_LIST "")
endif()
endforeach()
if(TMP_LIST)
message(STATUS "${TMP_LIST}")
endif()
endmacro()
1 change: 1 addition & 0 deletions cmake/stm32_gcc.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ get_filename_component(STM32_CMAKE_DIR ${CMAKE_CURRENT_LIST_FILE} DIRECTORY)
list(APPEND CMAKE_MODULE_PATH ${STM32_CMAKE_DIR})

include(stm32/common)
include(stm32/devices)

set(CMAKE_TRY_COMPILE_TARGET_TYPE STATIC_LIBRARY)
find_program(CMAKE_C_COMPILER NAMES ${STM32_TARGET_TRIPLET}-gcc PATHS ${TOOLCHAIN_BIN_PATH})
Expand Down
4 changes: 2 additions & 2 deletions tests/cmsis/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ set(SOURCES main.c)
include(stm32/devices)

foreach(FAMILY ${TEST_FAMILIES})
stm32_get_devices_by_family(DEVICES FAMILY ${FAMILY})
stm32_get_devices_by_family(STM_DEVICES FAMILY ${FAMILY})
stm32_get_cores(CORES FAMILY ${FAMILY})
foreach(DEVICE ${DEVICES})
foreach(DEVICE ${STM_DEVICES})
stm32_get_chip_type(${FAMILY} ${DEVICE} TYPE)

if(NOT CORES)
Expand Down
4 changes: 2 additions & 2 deletions tests/fetch/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ find_package(HAL REQUIRED)
set(SOURCES main.c)

foreach(FAMILY ${TEST_FAMILIES})
stm32_get_devices_by_family(DEVICES FAMILY ${FAMILY})
list(GET DEVICES 0 DEVICE)
stm32_get_devices_by_family(STM_DEVICES FAMILY ${FAMILY})
list(GET STM_DEVICES 0 DEVICE)
stm32_get_cores(CORES FAMILY ${FAMILY} DEVICE ${DEVICE})

if(CORES)
Expand Down
4 changes: 2 additions & 2 deletions tests/hal/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ find_package(HAL REQUIRED)
set(SOURCES main.c)

foreach(FAMILY ${TEST_FAMILIES})
stm32_get_devices_by_family(DEVICES FAMILY ${FAMILY})
list(GET DEVICES 0 DEVICE)
stm32_get_devices_by_family(STM_DEVICES FAMILY ${FAMILY})
list(GET STM_DEVICES 0 DEVICE)
stm32_get_cores(CORES FAMILY ${FAMILY} DEVICE ${DEVICE})

if(CORES)
Expand Down

0 comments on commit 5718979

Please sign in to comment.