Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Print device by family function #205

Merged
merged 28 commits into from
Aug 1, 2021
Merged
Show file tree
Hide file tree
Changes from 13 commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
2b07232
added print function
robamu Jun 6, 2021
28cec71
added more information on function usage (cmake)
robamu Jun 6, 2021
896a490
readme fix
robamu Jun 6, 2021
a8eb114
added doc and warning if list is empty
robamu Jun 28, 2021
1bed72e
better printout
robamu Jun 28, 2021
1823926
Merge remote-tracking branch 'upstream/master' into mueller/print-by-…
robamu Jul 2, 2021
436eeab
Merge remote-tracking branch 'upstream/master' into mueller/print-by-…
robamu Jul 11, 2021
7d75f95
Update cmake/stm32/devices.cmake
robamu Jul 16, 2021
77b82c2
updated STM32 utilities to get dev list
robamu Jul 20, 2021
d3b9bf9
removed core keyword for stm32_get_devices_by_family
robamu Jul 20, 2021
14081eb
Merge remote-tracking branch 'upstream/master' into mueller/print-by-…
robamu Jul 20, 2021
0820291
including devices.cmake as well
robamu Jul 20, 2021
2b9e8e4
README update
robamu Jul 20, 2021
2f81bba
enhance stm32_print_devices_by_family
atsju Jul 24, 2021
8985ff7
Merge pull request #19 from atsju/JST/print-by-family
robamu Jul 24, 2021
1298063
some minor improvements
robamu Jul 24, 2021
6ce3f54
added pretty printer
robamu Jul 24, 2021
e7d3577
test
robamu Jul 24, 2021
5a263a6
maybe this fixes the issue?
robamu Jul 24, 2021
eb4e24c
trying the non-expanded version again
robamu Jul 24, 2021
b66eb58
test2
robamu Jul 24, 2021
5b800fe
test3
robamu Jul 24, 2021
4f3dc56
trying to get more output
robamu Jul 24, 2021
8aed69d
finally found the issue
robamu Jul 24, 2021
22358c6
setting expanded variable again
robamu Jul 24, 2021
df3f206
Update cmake/stm32/devices.cmake
robamu Jul 25, 2021
216ff8d
Update cmake/stm32/devices.cmake
robamu Jul 25, 2021
1a90d7a
Update README.md
robamu Jul 25, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 <family>])` - return into `STM_DEVICES` all
supported devices by family (or all devices if `<family>` is empty)
* `stm32_print_devices_by_family([FAMILY <family>])` - Print all supported devices by family
(or all devices if `<family>` is empty)
robamu marked this conversation as resolved.
Show resolved Hide resolved

# Additional CMake modules

stm32-cmake contains additional CMake modules for finding and configuring various libraries and RTOSes used in the embedded world.
Expand Down
6 changes: 3 additions & 3 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,7 +138,7 @@ foreach(COMP ${CMSIS_FIND_COMPONENTS})
endif()

set(DEVICES_FOUND TRUE)
foreach(DEVICE ${DEVICES})
foreach(DEVICE ${STM_DEVICES})
stm32_get_cores(DEV_CORES FAMILY ${FAMILY} DEVICE ${DEVICE})
if(CORE AND (NOT ${CORE} IN_LIST DEV_CORES))
continue()
Expand Down
66 changes: 60 additions & 6 deletions cmake/stm32/devices.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -1116,14 +1116,68 @@ 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)

if(ARGC GREATER_EQUAL 1)
if(NOT ${ARGV0} STREQUAL "STM_DEVICES")
message(WARNING "Passed list ${ARGV0} invalid. Still setting STM_DEVICES variable")
endif()
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is not what the function is doing. See https://markdewing.github.io/blog/posts/notes-on-cmake/

stm32_get_devices_by_family(retVal FAMILY L4)
message(STATUS "retVal is ${retVal}")
message(STATUS "STM_DEVICES is ${STM_DEVICES}")

outputs

[build] CMake Warning at C:/GIT/stm32-cmake/cmake/stm32/devices.cmake:1131 (message):
[build]   Passed list retVal invalid.  Still setting STM_DEVICES variable
[build] Call Stack (most recent call first):
[build]   CMakeLists.txt:8 (stm32_get_devices_by_family)
[build] 
[build] 
[build] -- retVal is L412C8;L412CB;L412K8;L412KB;L412R8;L412RB;L412T8;L412TB;L422CB;L422KB;L422RB;L422TB;L431CB;L431CC;L431KB;L431KC;L431RB;L431RC;L431VC;L432KB;L432KC;L433CB;L433CC;L433RB;L433RC;L433VC;L442KC;L443CC;L443RC;L443VC;L451CC;L451CE;L451RC;L451RE;L451VC;L451VE;L452CC;L452CE;L452RC;L452RE;L452VC;L452VE;L462CE;L462RE;L462VE;L471QE;L471QG;L471RE;L471RG;L471VE;L471VG;L471ZE;L471ZG;L475RC;L475RE;L475RG;L475VC;L475VE;L475VG;L476JE;L476JG;L476ME;L476MG;L476QE;L476QG;L476RC;L476RE;L476RG;L476VC;L476VE;L476VG;L476ZE;L476ZG;L486JG;L486QG;L486RG;L486VG;L486ZG;L496AE;L496AG;L496QE;L496QG;L496RE;L496RG;L496VE;L496VG;L496ZE;L496ZG;L4A6AG;L4A6QG;L4A6RG;L4A6VG;L4A6ZG;L4P5AE;L4P5AG;L4P5CE;L4P5CG;L4P5QE;L4P5QG;L4P5RE;L4P5RG;L4P5VE;L4P5VG;L4P5ZE;L4P5ZG;L4Q5AG;L4Q5CG;L4Q5QG;L4Q5RG;L4Q5VG;L4Q5ZG;L4R5AG;L4R5AI;L4R5QG;L4R5QI;L4R5VG;L4R5VI;L4R5ZG;L4R5ZI;L4R7AI;L4R7VI;L4R7ZI;L4R9AG;L4R9AI;L4R9VG;L4R9VI;L4R9ZG;L4R9ZI;L4S5AI;L4S5QI;L4S5VI;L4S5ZI;L4S7AI;L4S7VI;L4S7ZI;L4S9AI;L4S9VI;L4S9ZI
[build] -- STM_DEVICES is 

endif()
if(ARGC MATCHES 2)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

MATCHES is for regex. Here EQUAL may be more appropriate
https://cmake.org/cmake/help/latest/command/if.html#matches

if(NOT ARGV1 STREQUAL "FAMILY")
message(WARNING "Unknown keyword: ${ARGV1}. Matching all devices..")
endif()
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this can be handled by cmake_parse_arguments see https://cmake.org/cmake/help/latest/command/cmake_parse_arguments.html
<prefix>_KEYWORDS_MISSING_VALUES and <prefix>_UNPARSED_ARGUMENTS
I think it will be safer and avoid unexpected corner cases

endif()
# Parse arguments. Multiple families or/and one core 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})

# 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})
atsju marked this conversation as resolved.
Show resolved Hide resolved
endforeach()
else()
# No family argument, so get list of all devices
set(RESULTING_DEV_LIST ${STM32_ALL_DEVICES})
endif()
if(NOT RESULTING_DEV_LIST)
message(WARNING "Device families ${ARG_FAMILY} did not yield a device list")
endif()
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)
set(ARG_OPTIONS "")
set(ARG_SINGLE "")
set(ARG_MULTIPLE FAMILY)
cmake_parse_arguments(PARSE_ARGV 0 ARG "${ARG_OPTIONS}" "${ARG_SINGLE}" "${ARG_MULTIPLE}")
# Some basic argument checks
if(ARGC MATCHES 1)
# FAMILY is the only keyword here
if(NOT ARGV STREQUAL "FAMILY")
message(WARNING "Unknown keyword: ${ARGV}. Matching all devices..")
endif()
if(NOT ARG_FAMILY)
message(STATUS "FAMILY keyword specified without any families. Matching all devices..")
endif()
endif()
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe all checks are done in stm32_get_devices_by_family.

set(${DEVICES} ${LIST} PARENT_SCOPE)
stm32_get_devices_by_family(STM_DEVICES FAMILY ${ARG_FAMILY})
string (REPLACE ";" " " STM_DEVICES "${STM_DEVICES}")
message(STATUS "Devices for ${ARG_FAMILY} family: ${STM_DEVICES}")
endfunction()
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