building STM32 with CMake

What are you developing?
ag123
Posts: 1653
Joined: Thu Dec 19, 2019 5:30 am
Answers: 24

Re: building STM32 with CMake

Post by ag123 »

massonal wrote: Thu Aug 18, 2022 1:42 pm How about https://github.com/massonal/Arduino_Cor ... wiki/Setup ? or https://github.com/massonal/Arduino_Cor ... tart-guide ? Are you suggesting these get merged? (given that the latter links to the former)
oops, I'm so blind :lol:
those are more than adequate
a little though I'm wondering if the ordering could be different if say they titles start with numbers or ordered letters. it seemed to be in alphabetical order.
that could perhaps put the quick start, setup items closer to the top in the menu.

off topic:
as I worked mostly(almost all the time) in linux. hopefully, someone working in windows could try it out and leave their notes say here.
as the system environment is certainly different. Some thoughts are about those 'unix' style shell commands quite commonly used in makefiles, which I'd hope CMake has taken care of that and is a non-issue.

I think efforts like these could be actually used in various open sourced projects at some point further down. e.g. like marlin firmware etc
https://marlinfw.org/
those projects integrate various "duino" cores and these efforts could make things considerably easier to integrate.
we are living in times where open sourced projects some of them become so widely used. e.g. marlin firmware (and derivatives) today drives many 3d printers. as like the slicers notably cura, slic3r, prusa-slicer (based on slic3r) etc.
they have created an "industry" which is literally "3d printing", the landscape would have been very different without these open sourced applications and firmware.
Last edited by ag123 on Thu Aug 18, 2022 2:58 pm, edited 1 time in total.
massonal
Posts: 12
Joined: Mon Aug 08, 2022 9:12 am

Re: building STM32 with CMake

Post by massonal »

ag123 wrote: Thu Aug 18, 2022 2:35 pm a little though I'm wondering if the ordering could be different if say they titles start with numbers or ordered letters. it seemed to be in alphabetical order.
that could perhaps put the quick start, setup items closer to the top in the menu.
That's one way to do it; the other being to define a custom side-menu, as in the stm32duino wiki. https://github.com/stm32duino/wiki/wiki
Anyway the concern is valid, especially for newcomers to find their way easily.
massonal
Posts: 12
Joined: Mon Aug 08, 2022 9:12 am

Re: building STM32 with CMake

Post by massonal »

ag123 wrote: Thu Aug 18, 2022 2:35 pm as I worked mostly(almost all the time) in linux. hopefully, someone working in windows could try it out and leave their notes say here.
as the system environment is certainly different. Some thoughts are about those 'unix' style shell commands quite commonly used in makefiles, which I'd hope CMake has taken care of that and is a non-issue.
That should indeed be a non-issue; CMake is made to be X-platform, and it worked well so far from me.
Just be careful about the paths, the path separator in Windows is "\", not "/", so it has to be escaped ("C:\\Users\\..."). Apart from that, CMake offers functions to normalize paths as illustrated in the examples I devised (https://github.com/stm32duino/CMake_workspace). Internally, it uses Unix-like paths.
ag123
Posts: 1653
Joined: Thu Dec 19, 2019 5:30 am
Answers: 24

Re: building STM32 with CMake

Post by ag123 »

just like to add, it seemed using CMake build tend to compile leaner binaries. The bin file build for the Blink example
https://github.com/stm32duino/CMake_wor ... ok/1_Blink
is 11 kbytes on a STM32F401CC black pill board. This seemed more compact than some binaries I build myself with my makefile build.

I've not tested "apple to apple" so I may be wrong. maybe someone could post some stats for that build say using arduino-cli vs cmake.
I'd guess if it is correct, CMake with the tight explicit dependencies management prevents the link stage from picking up some spurious dependencies that the linker couldn't guess if it is after all used.
ozcar
Posts: 143
Joined: Wed Apr 29, 2020 9:07 pm
Answers: 5

Re: building STM32 with CMake

Post by ozcar »

massonal wrote: Thu Aug 18, 2022 2:55 pm Just be careful about the paths, the path separator in Windows is "\", not "/", so it has to be escaped ("C:\\Users\\...").
I'm the opposite to ag123. I use Windows all the time, and Linux only under protest.

I often have trouble with things that are maybe more at home under Linux, but which supposedly will run also run under Windows. Often the problem is related to path, but not so much due to difference between \ and /.

I certainly cringe when I see the last step of the installation says to make sure that I add something or other to my path. If I do that, almost invariably either the newly installed wonder does not work, or else it breaks something else that was working before (and, if the latter I might not notice for a long time). Last time I got this was when I tried to install RPI pico development stuff. That was my first, and so far only encounter with CMake.
ag123
Posts: 1653
Joined: Thu Dec 19, 2019 5:30 am
Answers: 24

Re: building STM32 with CMake

Post by ag123 »

hi a suggested edit/add here
https://github.com/massonal/Arduino_Cor ... .cmake#L81
in the default "commented out template"

Code: Select all

build_sketch(TARGET "{{tgtname or "@binary_name_here@"}}"
  SOURCES
  {% for file in scrcfiles | sort %}
  {{file}}
  {% else %}
  ./file1.ino
  ./file2.ino
  ./file3.cpp
  ./file4.c
  ./file5.S
  {% endfor %}

  # DEPENDS
  # SD
  # Wire
}
I'd suggest to add SPI in the "commented out" section

Code: Select all

  # DEPENDS
  # SD
  # Wire
  # SPI
for the rest, those would help in case users are using a sketch using SPI but wonder why it "didn't work"
I think Wire and SPI are pretty commonly used libraries
for the rest that is shipped in the "core libraries" e.g.
CMSIS_DSP
EEPROM
IWatchdog
Keyboard
Mouse
Servo
SoftwareSerial
I'm not sure if they are as commonly used, but you could add them there nevertheless and commented out.
Just that I'd guess over time that list would grow. or place a comment in there to say that these are from the "libraries" folder, that if it isn't here look in "libraries" and one could add them here for depends.
massonal
Posts: 12
Joined: Mon Aug 08, 2022 9:12 am

Re: building STM32 with CMake

Post by massonal »

ag123 wrote: Fri Aug 19, 2022 6:26 am hi a suggested edit/add here
https://github.com/massonal/Arduino_Cor ... .cmake#L81
I'd suggest to add SPI in the "commented out" section

Code: Select all

  # DEPENDS
  # SD
  # Wire
  # SPI
for the rest, those would help in case users are using a sketch using SPI but wonder why it "didn't work"
I think Wire and SPI are pretty commonly used libraries
for the rest that is shipped in the "core libraries" e.g.
CMSIS_DSP
EEPROM
IWatchdog
Keyboard
Mouse
Servo
SoftwareSerial
I'm not sure if they are as commonly used, but you could add them there nevertheless and commented out.
Just that I'd guess over time that list would grow. or place a comment in there to say that these are from the "libraries" folder, that if it isn't here look in "libraries" and one could add them here for depends.
I was told this section of the template could use some improvements, yeah.
So I'm fine with adding SPI, but all the core libraries would be a bit much, I think. A comment block explaining the use of this keyword (syntax and semantics) would be more appropriate in my opinion.

While we're talking about the template, I also though that adding the "usual" values for the board options (Serial, USB) could be useful. They are referenced on the wiki too (or in boards.txt), but that's not so practical...

Code: Select all

include(set_board)
set_board("{{"${BOARDNAME}"}}"
  # SERIAL generic / disabled / none
  # USB none / CDCgen / CDC / HID
  # XUSB FS / HS / HSFS
  # VIRTIO disable / generic / enabled
)
massonal
Posts: 12
Joined: Mon Aug 08, 2022 9:12 am

Re: building STM32 with CMake

Post by massonal »

ozcar wrote: Fri Aug 19, 2022 6:05 am I'm the opposite to ag123. I use Windows all the time, and Linux only under protest.

I often have trouble with things that are maybe more at home under Linux, but which supposedly will run also run under Windows. Often the problem is related to path, but not so much due to difference between \ and /.

I certainly cringe when I see the last step of the installation says to make sure that I add something or other to my path. If I do that, almost invariably either the newly installed wonder does not work, or else it breaks something else that was working before (and, if the latter I might not notice for a long time). Last time I got this was when I tried to install RPI pico development stuff. That was my first, and so far only encounter with CMake.
I'm sorry you had trouble with that in the past... I can relate when you say that some things that come easy with Linux are worth much trouble with Windows. (But the converse is also true ! :P )

Anyway I did not experience any trouble with the $PATH on Windows working on this project; just tick the relevant boxes in the Python/CMake installers and you'll be fine.
Ninja is a special case: it's a standalone executable (no installer), so I just created a folder in my home directory and put ninja.exe there, then added that folder to my $PATH. This way I know exactly what gets added, and nothing breaks.

When you talk about your unfortunate experience with RPI dev tools, when was that? I know CMake has evolved much recently, and many past issue have become painless now:
ag123 wrote: Thu Aug 18, 2022 7:45 am The recent versions has features where older versions lack, e.g. that directory recursion and wildcard pattern globing, I think it is pretty important.
ag123
Posts: 1653
Joined: Thu Dec 19, 2019 5:30 am
Answers: 24

Re: building STM32 with CMake

Post by ag123 »

massonal wrote: Fri Aug 19, 2022 8:15 am I was told this section of the template could use some improvements, yeah.
So I'm fine with adding SPI, but all the core libraries would be a bit much, I think. A comment block explaining the use of this keyword (syntax and semantics) would be more appropriate in my opinion.

While we're talking about the template, I also though that adding the "usual" values for the board options (Serial, USB) could be useful. They are referenced on the wiki too (or in boards.txt), but that's not so practical...

Code: Select all

include(set_board)
set_board("{{"${BOARDNAME}"}}"
  # SERIAL generic / disabled / none
  # USB none / CDCgen / CDC / HID
  # XUSB FS / HS / HSFS
  # VIRTIO disable / generic / enabled
)
putting SPI and Wire in set_board is a good idea, as I'd guess it is mostly a "target_link_libraries" ?
I'd think SPI and Wire are "common" enough to merit "special" handling, i.e. that they are commonly used hardware interfaces as like Serial and USB.
Just that 'unfortunately' they are 'libraries', actually it is good in the sense that these things are modularized rather than always embedded as a dependency, it may contribute to binary bloat if it isn't "separated" as a library.
ag123
Posts: 1653
Joined: Thu Dec 19, 2019 5:30 am
Answers: 24

Re: building STM32 with CMake

Post by ag123 »

for windows, I'm really not a person to comment as I hardly use it, at least to built my sketches arduino etc.

However, I'm thinking if some kind of 'bundling' may help? e.g. some cmd window bundles where the paths etc are placed together.
This probably doesn't help say when one wants to integrate an IDE etc, as that'd require global paths.

This isn't just a 'windows' problem, i've got python3.10 (just) installed, and that which is shipped in my distribution 3.6, then another in some 'virtual env' 3.7. This 'dll hell' won't go away no matter which os. I think it afflicts *java* as well, some apps runs fine whatever java you use, some insist it needs to be java 8 and nothing else (many), some requires 11, some some other 'higher' versions, so much for being 'platform independent'.
and just to share I'm using python's 'virtual env' currently
https://docs.python.org/3/library/venv.html
https://realpython.com/python-virtual-e ... -a-primer/
this is done mainly for the python modules. i.e. i created a folder and run

Code: Select all

python3.10 -m venv /path/to/new/virtualenv
followed by

Code: Select all

source /path/to/new/virtualenv/bin/activate
pip install xx_module
and I install the necessary python 'modules' in the 'virtual env'. I'm not sure if it works the same in windows.
accordingly, it is possible to install cmake in this 'virtualenv' in a similar way too
e.g.
https://pypi.org/project/cmake/

Code: Select all

pip install cmake
in the 'virtual env'

this seemed to work well in current context with this cmake builds etc. It kind of 'sandboxed' the environment so that I can leave the old 3.6, 3.7 stuff alone and still working.

I think it is correct to say that the recent CMake versions has matured to address shortfalls for features that are missing in the past, e.g. recursive wildcard directory globs. It is there in some 3.x versions, but not earlier. That'd be necessary and likely used in our context.
This could help in situations where there isn't a 'CMakeList.txt' that commonly defines a cmake 'library' or module (in fact, it is recommended for individual directories). But, the reality "libraries" is in the wild aren't made up with CMakeList.txt, and wildcard pattern globing and recursion are about the means to include entire directory trees / sub-trees in the build.
Post Reply

Return to “Projects”