2025-08-11 3:20 AM
I was following the tutorial (Get started with STM32Cube for VS Code: from installation to debugging - YouTube) when I managed to find a nasty footgun. STM32CubeMx will allow you to create a project whose name contains a space, and then if you set the toolchain to CMake, it generates the code fine, but if you load the project into STM32Cube for VSC and try to build, you will get all kinds of cryptic CMAKE error messages caused by the space in the project name.
Now, STM32CubeMx does have some input validation. It only prevents you from initially generating the project IF you have space in the name and you set the toolchain to CMake BEFORE you generate the code, but that's it. If you save the IOC with a space, save the project as with a space, you generate under any of the other toolchains then switch to CMake, you'll trigger this error.
I burned a few hours on this, so I thought it would be worth bringing up to save someone else the headache in the future. You might want to implement some sort of detection for projects with spaces so you can catch the error early. Given that STM32CubeMx + VSC seems to be the happy path moving forward, I'd also be updating the STM32CubeMx to at a minimum throw an error when generating CMake projects when the name contains a space, and possible enforcing no spaces in project names across all toolchains.
Anyway, in the end I figured out the error and I've got it working on both MacOS and Win11. The integration into VSC is amazing, working very smoothly!
2025-08-11 3:24 AM
Oh no - not this old chestnut again!
https://www.avrfreaks.net/s/topic/a5C3l000000UY8vEAG/t145039?comment=P-1182240
2025-08-11 4:06 AM
Ha! I know right. I spend a lot of time on the terminal so I'm normally a stickler with trying to avoid any spaces in the path. When you go "Save as" in MX, you pick the folder location, and I happened to pick the my "project folder" which is date prefixed with a space (2025-08-11 Happy project name).
Now this is a quirk of MX. In conflates the "project folder" with the "project name", which I think is derived from the "IOC name". There is some sort of underlying assumption that they are all the same. If you generate a project (without spaces), then copy it to a folder with a space, the code generator works fine (it uses the old project name), somehow it finds the project (even though the projects location + project name != project folder), and this project works fine in CubeMX + VSC. This makes sense as I've copied IOC files around into different projects with no issues previously.
Interestingly it's not the path that is the problem, it's the generated CMAKE variables based on the project name that are mangled. It's blaringly obvious what the problem is, akin to #define with spaces, instead of #define WITHOUT_SPACES. Not an error you'd ever made if you typed it, but the code generator will happily spit it out.
I'm just trying to save someone (let's face it, me in 6 months), the hassle of figuring out why their project won't build over a simple code gen error that is fairly simple to detect.