Browse Source

Print device by family function (#205)

Improved stm32_get_devices_by_family to print out the devices
Robin Mueller 4 years ago
parent
commit
70a5a0a07f

+ 7 - 1
README.md

@@ -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_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_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_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_binary_file(<target>)` - Generate the binary file for the given target
 * `stm32_generate_hex_file(<target>)` - Generate the hex 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
 # Additional CMake modules
 
 
 stm32-cmake contains additional CMake modules for finding and configuring various libraries and RTOSes used in the embedded world.
 stm32-cmake contains additional CMake modules for finding and configuring various libraries and RTOSes used in the embedded world.

+ 6 - 6
cmake/FindCMSIS.cmake

@@ -53,10 +53,10 @@ foreach(COMP ${CMSIS_FIND_COMPONENTS})
     
     
     if(CMAKE_MATCH_2)
     if(CMAKE_MATCH_2)
         set(FAMILY ${CMAKE_MATCH_1})
         set(FAMILY ${CMAKE_MATCH_1})
-        set(DEVICES "${CMAKE_MATCH_1}${CMAKE_MATCH_2}")
+        set(STM_DEVICES "${CMAKE_MATCH_1}${CMAKE_MATCH_2}")
     else()
     else()
         set(FAMILY ${CMAKE_MATCH_1})
         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()
     endif()
     
     
     if(CMAKE_MATCH_3)
     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}")
         target_sources(CMSIS::STM32::${FAMILY}${CORE_C} INTERFACE "${CMSIS_${FAMILY}${CORE_U}_SOURCE}")
     endif()
     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})
         stm32_get_cores(DEV_CORES FAMILY ${FAMILY} DEVICE ${DEVICE})
         if(CORE AND (NOT ${CORE} IN_LIST DEV_CORES))
         if(CORE AND (NOT ${CORE} IN_LIST DEV_CORES))
             continue()
             continue()
@@ -156,7 +156,7 @@ foreach(COMP ${CMSIS_FIND_COMPONENTS})
         )
         )
         list(APPEND CMSIS_SOURCES "${CMSIS_${FAMILY}${CORE_U}_${TYPE}_STARTUP}")
         list(APPEND CMSIS_SOURCES "${CMSIS_${FAMILY}${CORE_U}_${TYPE}_STARTUP}")
         if(NOT CMSIS_${FAMILY}${CORE_U}_${TYPE}_STARTUP)
         if(NOT CMSIS_${FAMILY}${CORE_U}_${TYPE}_STARTUP)
-            set(DEVICES_FOUND FALSE)
+            set(STM_DEVICES_FOUND FALSE)
             break()
             break()
         endif()
         endif()
         
         
@@ -171,7 +171,7 @@ foreach(COMP ${CMSIS_FIND_COMPONENTS})
         cmsis_generate_default_linker_script(${FAMILY} ${DEVICE} "${CORE}")
         cmsis_generate_default_linker_script(${FAMILY} ${DEVICE} "${CORE}")
     endforeach()
     endforeach()
 
 
-    if(DEVICES_FOUND)
+    if(STM_DEVICES_FOUND)
        set(CMSIS_${COMP}_FOUND TRUE)
        set(CMSIS_${COMP}_FOUND TRUE)
     else()
     else()
        set(CMSIS_${COMP}_FOUND FALSE)
        set(CMSIS_${COMP}_FOUND FALSE)

+ 88 - 6
cmake/stm32/devices.cmake

@@ -1116,14 +1116,96 @@ set(STM32_ALL_DEVICES
     WLE5JC
     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_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}")
     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)
     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()
     endif()
-    set(${DEVICES} ${LIST} PARENT_SCOPE)
+    
+    set(${STM_DEVICES} ${RESULTING_DEV_LIST} PARENT_SCOPE)
 endfunction()
 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 - 0
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})
 list(APPEND CMAKE_MODULE_PATH ${STM32_CMAKE_DIR})
 
 
 include(stm32/common)
 include(stm32/common)
+include(stm32/devices)
 
 
 set(CMAKE_TRY_COMPILE_TARGET_TYPE STATIC_LIBRARY)
 set(CMAKE_TRY_COMPILE_TARGET_TYPE STATIC_LIBRARY)
 find_program(CMAKE_C_COMPILER NAMES ${STM32_TARGET_TRIPLET}-gcc PATHS ${TOOLCHAIN_BIN_PATH})
 find_program(CMAKE_C_COMPILER NAMES ${STM32_TARGET_TRIPLET}-gcc PATHS ${TOOLCHAIN_BIN_PATH})

+ 2 - 2
tests/cmsis/CMakeLists.txt

@@ -18,9 +18,9 @@ set(SOURCES main.c)
 include(stm32/devices)
 include(stm32/devices)
 
 
 foreach(FAMILY ${TEST_FAMILIES})
 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})
     stm32_get_cores(CORES FAMILY ${FAMILY})
-    foreach(DEVICE ${DEVICES})
+    foreach(DEVICE ${STM_DEVICES})
         stm32_get_chip_type(${FAMILY} ${DEVICE} TYPE)
         stm32_get_chip_type(${FAMILY} ${DEVICE} TYPE)
         
         
         if(NOT CORES)
         if(NOT CORES)

+ 2 - 2
tests/fetch/CMakeLists.txt

@@ -17,8 +17,8 @@ find_package(HAL REQUIRED)
 set(SOURCES main.c)
 set(SOURCES main.c)
 
 
 foreach(FAMILY ${TEST_FAMILIES})
 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})
     stm32_get_cores(CORES FAMILY ${FAMILY} DEVICE ${DEVICE})
     
     
     if(CORES)
     if(CORES)

+ 2 - 2
tests/hal/CMakeLists.txt

@@ -19,8 +19,8 @@ find_package(HAL REQUIRED)
 set(SOURCES main.c)
 set(SOURCES main.c)
 
 
 foreach(FAMILY ${TEST_FAMILIES})
 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})
     stm32_get_cores(CORES FAMILY ${FAMILY} DEVICE ${DEVICE})
     
     
     if(CORES)
     if(CORES)