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

Conversation

robamu
Copy link
Contributor

@robamu robamu commented Jun 8, 2021

I added a function which simply uses the existing stm32_get_devices_by_family to print out
the devices without returning them. I also updated the documentation accordingly.

Copy link
Collaborator

@atsju atsju left a comment

Choose a reason for hiding this comment

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

I just tried the code out and
stm32_print_devices_by_family(FAMILY STM32F4) returns nothing. I figured out that call must be stm32_print_devices_by_family(FAMILY F4). There should be a warning about unknown family in stm32_get_devices_by_family and maybe just some little more documentation.

Also I do not see why the function needs FAMILY as first keyword as it's in the name of the function. So maybe we could simplify the call.
If I omit FAMILY just all device get printed instead of an error that I didn't call function properly.

I think this needs a bit of rework before being merged. Maybe even stm32_get_devices_by_family must be reworked.

Maybe I'm a bit too extreme but we could completely remove file devices.cmake. This is typically something not scalable and not maintainable. And I do not see the practical use for it as we (are supposed to) support almost all STM32 devices and this list may even not fully know what we support. @Hish15 @rmspacefish what do you think of removing the file ?

edit: @rmspacefish I see you use the function in #206 but I'm still worried because of how device list is maintained.

@atsju atsju requested a review from Hish15 June 26, 2021 15:14
@robamu
Copy link
Contributor Author

robamu commented Jun 26, 2021

I will try to add the warning if the specified family is unknown. I actually found this function useful to find the right target name for my specific board quickly, because the documentation does not have a similar list. I added some more documentation in the README, so I guess you mean documentation in the code? I can add that as well. I actually like the feature that it simply prints all families with no families specified.

@robamu
Copy link
Contributor Author

robamu commented Jun 28, 2021

  • Warning is now emitted if the device family is invalid. Tested in example
  • Added documentation in CMakeLists

README.md Outdated
Comment on lines 199 to 200
* `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_devices_by_family([FAMILY <family>])` - Print all supported devices by family (or all devices if `<family>` is empty)
Copy link
Collaborator

Choose a reason for hiding this comment

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

For me this makes more sense.

Suggested change
* `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_devices_by_family([FAMILY <family>])` - Print all supported devices by family (or all devices if `<family>` is empty)
* `stm32_get_devices_by_family(DEVICES <family>)` - return into `DEVICES` all supported devices by family (or all devices if `<family>` is empty)
* `stm32_print_devices_by_family(<family>)` - Print all supported devices by family (or all devices if `<family>` is empty)

FAMILY is only needed when you have multiple possible keywords.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hmm I thought FAMILY has to be specified as a keyword. Does it work without it?

Copy link
Collaborator

Choose a reason for hiding this comment

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

No I mean you could change the implementation so that FAMILY is not used.
It brings nothing here.

Copy link
Contributor Author

@robamu robamu Jul 15, 2021

Choose a reason for hiding this comment

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

I think it is okay that way. I think this was done because https://cmake.org/cmake/help/latest/command/cmake_parse_arguments.html is used. Using it also allows easier extensibility (e.g. you still want to parse multiple families, but you also want to pass an option or something like a filter)

Copy link
Collaborator

Choose a reason for hiding this comment

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

Using it also allows easier extensibility (e.g. you still want to parse multiple families, but you also want to pass an option or something like a filter)

OK I understand the point for evolution even if I don't think this function will evolve any soon.
cmake_parse_arguments is fine. I didn't know it before but it permits to do clean things.

I think if you want to have a clean function then all misuse errors should be managed

stm32_print_devices_by_family(H7) # this shall throw error because of no FAMILY given
stm32_print_devices_by_family(FAMILY H7 L4) #this should throw error OR change FAMILY to a "multi_value_keywords"
stm32_print_devices_by_family(FAMILYH7) # this should throw error unknown keyword or something
stm32_print_devices_by_family(FAMILY) # this should throw error missing argument

Copy link
Collaborator

@Hish15 Hish15 left a comment

Choose a reason for hiding this comment

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

It does make sense to define those functions.
I find the name misleading. In fact the functions are actually stm32_print_devices_from_family or stm32_print_family_devices.
This is minor and will not block the merging of the PR, but it is my 2 cents.

cmake/stm32/devices.cmake Outdated Show resolved Hide resolved
@@ -1125,9 +1128,15 @@ function(stm32_get_devices_by_family DEVICES)
if(ARG_FAMILY)
list(FILTER LIST INCLUDE REGEX "^${ARG_FAMILY}")
endif()
if(NOT LIST)
Copy link
Collaborator

Choose a reason for hiding this comment

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

This bit is weird, where does STM32_ALL_DEVICES come from? this test checks this var, not the LIST var.
I also strongly advice against using LIST as a var name. It's not self explanatory, and it is also a cmake key word!

Copy link
Collaborator

Choose a reason for hiding this comment

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

This bit is weird, where does STM32_ALL_DEVICES come from ?

This is one of the main problems for me. It comes from here : https://github.com/ObKo/stm32-cmake/blob/master/cmake/stm32/devices.cmake
and is used only for these functions. See my very first comment in the PR where I already mentioned it and @rmspacefish seems to have an use the function.

Co-authored-by: Hish15 <pharamhector@gmail.com>
@robamu robamu changed the title Print device by family function WIP: Print device by family function Jul 16, 2021
@robamu
Copy link
Contributor Author

robamu commented Jul 16, 2021

I will introduce the safety checks mentioned by @atsju when I find some time. I'll also change the name to something better than LIST

1. More checks
2. Multiple families can now be specified
@robamu robamu changed the title WIP: Print device by family function Print device by family function Jul 20, 2021
@robamu
Copy link
Contributor Author

robamu commented Jul 20, 2021

I found out that the function to get the device list is used in FindCMSIS.cmake and in the updated FindFreeRTOS.cmake containing the new CMSIS support. Following updates:

  • Introduced the sanity checks requested by @atsju and also specified FAMILY as a multi_value_keyword now.
  • CORE is a new single value keyword in the stm32_get_devices_by_family function now because this keyword is used in FindCMSIS.cmake (though it appears not to be used) which will lead to an empty device list because the parser then assumes CORE and ${CORE} are family keywords.
  • Renamed the list which is set by the function from DEVICES to STM_DEVICES

@atsju
Copy link
Collaborator

atsju commented Jul 20, 2021

CORE is a new single value keyword in the stm32_get_devices_by_family function now because this keyword is used in FindCMSIS.cmake (though it appears not to be used) which will lead to an empty device list because the parser then assumes CORE and ${CORE} are family keywords.

Just to mention I have seen this during #235 and I removed the CORE keyword as it is not used. You could remove it now I suppose.

I will have a look at the rest later. Thank you for the update

@robamu
Copy link
Contributor Author

robamu commented Jul 20, 2021

Okay, CORE was removed

devices.cmake is now included like common.cmake as well, so both functions can be used without an extra include.

Copy link
Collaborator

@atsju atsju left a comment

Choose a reason for hiding this comment

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

I need to dig further and I'm not 100% sure of how this needs to be done. If you let me some time I will try things out and propose some changes. I don't want to abuse of your time by pointing in wrong direction and needing reverse.

Comment on lines 1130 to 1132
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 

message(WARNING "Passed list ${ARGV0} invalid. Still setting STM_DEVICES variable")
endif()
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

Comment on lines 1135 to 1137
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

cmake/stm32/devices.cmake Show resolved Hide resolved
Comment on lines 1166 to 1179
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.

@robamu robamu changed the title Print device by family function WIP: Print device by family function Jul 24, 2021
In devices.cmake
@robamu
Copy link
Contributor Author

robamu commented Jul 24, 2021

I added a pretty printer as well. The tests appear to be problematic now though..

@robamu robamu changed the title WIP: Print device by family function Print device by family function Jul 24, 2021
@robamu robamu changed the title Print device by family function WIP: Print device by family function Jul 24, 2021
@robamu
Copy link
Contributor Author

robamu commented Jul 24, 2021

I did not realize the stm32_get_devices_by_family function is used in all the tests.. But I think I will just use the way you did it and set the expanded variable.

That took longer than expected. It would be great if you could run all your checks again. I hope we will be able to merge it soon

@robamu robamu changed the title WIP: Print device by family function Print device by family function Jul 24, 2021
README.md Outdated Show resolved Hide resolved
cmake/stm32/devices.cmake Outdated Show resolved Hide resolved
cmake/stm32/devices.cmake Outdated Show resolved Hide resolved
@atsju atsju requested a review from Hish15 July 25, 2021 09:56
robamu and others added 3 commits July 25, 2021 12:25
Co-authored-by: Julien Staub <atsju2@yahoo.fr>
Co-authored-by: Julien Staub <atsju2@yahoo.fr>
Co-authored-by: Julien Staub <atsju2@yahoo.fr>
Copy link
Collaborator

@Hish15 Hish15 left a comment

Choose a reason for hiding this comment

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

I'm willing to do the PR, but lets stop adding commits to it first :D
Waiting the Go

Copy link
Collaborator

@atsju atsju left a comment

Choose a reason for hiding this comment

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

@Hish15 Go
Maybe squash merge ?

@atsju atsju requested a review from Hish15 July 26, 2021 06:06
@Hish15 Hish15 merged commit 70a5a0a into ObKo:master Aug 1, 2021
@atsju atsju mentioned this pull request Aug 1, 2021
zisi pushed a commit to zisi/stm32-cmake that referenced this pull request Aug 2, 2021
Improved stm32_get_devices_by_family to print out the devices
@robamu robamu deleted the mueller/print-by-family branch August 8, 2021 13:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants