diff --git a/README.md b/README.md index dba3d8a8..07d922f7 100644 --- a/README.md +++ b/README.md @@ -184,11 +184,17 @@ CMSIS package will generate linker script for your device automatically (target * `stm32_get_chip_info( [FAMILY ] [TYPE ] [DEVICE ])` - classify device using name, will return device family (into `` variable), type (``) and canonical name (``, uppercase without any package codes) * `stm32_get_memory_info((CHIP )|(DEVICE TYPE ) [FLASH|RAM|CCRAM|STACK|HEAP] [SIZE ] [ORIGIN ])` - get information about device memories (into `` and ``). Linker script generator uses values from this function -* `stm32_get_devices_by_family(DEVICES [FAMILY ])` - return into `DEVICES` all supported devices by family (or all devices if `` is empty) * `stm32_print_size_of_target()` - Print the application sizes for all formats * `stm32_generate_binary_file()` - Generate the binary file for the given target * `stm32_generate_hex_file()` - 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. diff --git a/cmake/FindCMSIS.cmake b/cmake/FindCMSIS.cmake index 631d59ba..f830b063 100644 --- a/cmake/FindCMSIS.cmake +++ b/cmake/FindCMSIS.cmake @@ -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) @@ -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() @@ -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() @@ -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) diff --git a/cmake/stm32/devices.cmake b/cmake/stm32/devices.cmake index df3be71a..e21554d9 100644 --- a/cmake/stm32/devices.cmake +++ b/cmake/stm32/devices.cmake @@ -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_ 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_ + 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() diff --git a/cmake/stm32_gcc.cmake b/cmake/stm32_gcc.cmake index a8170e77..bdf5a305 100644 --- a/cmake/stm32_gcc.cmake +++ b/cmake/stm32_gcc.cmake @@ -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}) diff --git a/tests/cmsis/CMakeLists.txt b/tests/cmsis/CMakeLists.txt index 003c9072..c8b3194a 100644 --- a/tests/cmsis/CMakeLists.txt +++ b/tests/cmsis/CMakeLists.txt @@ -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) diff --git a/tests/fetch/CMakeLists.txt b/tests/fetch/CMakeLists.txt index 9ae1d4d0..b94f7a87 100644 --- a/tests/fetch/CMakeLists.txt +++ b/tests/fetch/CMakeLists.txt @@ -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) diff --git a/tests/hal/CMakeLists.txt b/tests/hal/CMakeLists.txt index c874c0ff..6875b8d8 100644 --- a/tests/hal/CMakeLists.txt +++ b/tests/hal/CMakeLists.txt @@ -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)