2022-03-09 01:45 PM
Requirement: I need to create a basic C++ project (into which I'll insert files from an embedded C++ project built for another platform, then begin port testing.) The specifics are using a STM32F051R8 with "LL" low level support, but I don't think my problem is specific to the device. The C++ project is necessary for this task, and when I tried just changing main.c to main.cpp in my prior attempt(s), the project would not build (could not find main() to link from the .s startup file, even though main() was clearly present.)
What I tried before: I tried using STM32CubeMX to generate a trivial (light one LED using LL code generation setting), and that works, until I change the name of main.c to main.cpp, then when I try to build, main() can't be found (bl main in the .s file doesn't find main() in main.cpp)
What I'm trying now: I am now trying to use STM32CubeIDE as the starting point (File > New > STM32 Project); I specify the requested project name and set as C++, executable, STM32Cube project type (in "Setup STM32 project" dialog box), then click Finish.) After a time in "perform project creation", I see the new project folder (and some of it's folders/files) in STM32CubeIDE project explorer, and (now familiar) STM32CubeMX appears, allowing me to make hardware configuration selections, which I complete.
Where I'm stuck: After configuring the device hardware settings in the STM32CubeMX session, I don't see a way to finish the STM32CubeMX session, and no src/ directory is created in STM32CubeIDE's project explorer entry for the new project.
Questions:
Thanks for any advice or any requests for clarifying information!
Dave
2022-03-09 02:17 PM
Found the problem - I had overlooked the "convert to C++" (and corresponding "convert to C" options in the project properties.
I believe problem solved at this point.
2022-03-09 02:17 PM
There should be a "generate code" button or menu option.
I don't think CubeMX can generate a C++ project directly, but you can certainly convert it to C++ after creation. Things may have changed recently.
Edit:
And it appears you can create C++ projects directly now, but it still names the main file "main.c". You can rename it to main.cpp and it will work. I just checked this.
17:22:28 **** Incremental Build of configuration Debug for project test_f105_something ****
make -j12 all
arm-none-eabi-g++ "../Core/Src/main.cpp" -mcpu=cortex-m0 -std=gnu++14 -g3 -DDEBUG -DUSE_HAL_DRIVER -DSTM32F051x8 -c -I../Core/Inc -I../Drivers/STM32F0xx_HAL_Driver/Inc -I../Drivers/STM32F0xx_HAL_Driver/Inc/Legacy -I../Drivers/CMSIS/Device/ST/STM32F0xx/Include -I../Drivers/CMSIS/Include -O0 -ffunction-sections -fdata-sections -fno-exceptions -fno-rtti -fno-use-cxa-atexit -Wall -fstack-usage -MMD -MP -MF"Core/Src/main.d" -MT"Core/Src/main.o" --specs=nano.specs -mfloat-abi=soft -mthumb -o "Core/Src/main.o"
arm-none-eabi-gcc "../Core/Src/stm32f0xx_hal_msp.c" -mcpu=cortex-m0 -std=gnu11 -g3 -DDEBUG -DUSE_HAL_DRIVER -DSTM32F051x8 -c -I../Core/Inc -I../Drivers/STM32F0xx_HAL_Driver/Inc -I../Drivers/STM32F0xx_HAL_Driver/Inc/Legacy -I../Drivers/CMSIS/Device/ST/STM32F0xx/Include -I../Drivers/CMSIS/Include -O0 -ffunction-sections -fdata-sections -Wall -fstack-usage -MMD -MP -MF"Core/Src/stm32f0xx_hal_msp.d" -MT"Core/Src/stm32f0xx_hal_msp.o" --specs=nano.specs -mfloat-abi=soft -mthumb -o "Core/Src/stm32f0xx_hal_msp.o"
arm-none-eabi-gcc "../Core/Src/stm32f0xx_it.c" -mcpu=cortex-m0 -std=gnu11 -g3 -DDEBUG -DUSE_HAL_DRIVER -DSTM32F051x8 -c -I../Core/Inc -I../Drivers/STM32F0xx_HAL_Driver/Inc -I../Drivers/STM32F0xx_HAL_Driver/Inc/Legacy -I../Drivers/CMSIS/Device/ST/STM32F0xx/Include -I../Drivers/CMSIS/Include -O0 -ffunction-sections -fdata-sections -Wall -fstack-usage -MMD -MP -MF"Core/Src/stm32f0xx_it.d" -MT"Core/Src/stm32f0xx_it.o" --specs=nano.specs -mfloat-abi=soft -mthumb -o "Core/Src/stm32f0xx_it.o"
arm-none-eabi-gcc "../Core/Src/syscalls.c" -mcpu=cortex-m0 -std=gnu11 -g3 -DDEBUG -DUSE_HAL_DRIVER -DSTM32F051x8 -c -I../Core/Inc -I../Drivers/STM32F0xx_HAL_Driver/Inc -I../Drivers/STM32F0xx_HAL_Driver/Inc/Legacy -I../Drivers/CMSIS/Device/ST/STM32F0xx/Include -I../Drivers/CMSIS/Include -O0 -ffunction-sections -fdata-sections -Wall -fstack-usage -MMD -MP -MF"Core/Src/syscalls.d" -MT"Core/Src/syscalls.o" --specs=nano.specs -mfloat-abi=soft -mthumb -o "Core/Src/syscalls.o"
arm-none-eabi-gcc "../Core/Src/sysmem.c" -mcpu=cortex-m0 -std=gnu11 -g3 -DDEBUG -DUSE_HAL_DRIVER -DSTM32F051x8 -c -I../Core/Inc -I../Drivers/STM32F0xx_HAL_Driver/Inc -I../Drivers/STM32F0xx_HAL_Driver/Inc/Legacy -I../Drivers/CMSIS/Device/ST/STM32F0xx/Include -I../Drivers/CMSIS/Include -O0 -ffunction-sections -fdata-sections -Wall -fstack-usage -MMD -MP -MF"Core/Src/sysmem.d" -MT"Core/Src/sysmem.o" --specs=nano.specs -mfloat-abi=soft -mthumb -o "Core/Src/sysmem.o"
arm-none-eabi-gcc "../Core/Src/system_stm32f0xx.c" -mcpu=cortex-m0 -std=gnu11 -g3 -DDEBUG -DUSE_HAL_DRIVER -DSTM32F051x8 -c -I../Core/Inc -I../Drivers/STM32F0xx_HAL_Driver/Inc -I../Drivers/STM32F0xx_HAL_Driver/Inc/Legacy -I../Drivers/CMSIS/Device/ST/STM32F0xx/Include -I../Drivers/CMSIS/Include -O0 -ffunction-sections -fdata-sections -Wall -fstack-usage -MMD -MP -MF"Core/Src/system_stm32f0xx.d" -MT"Core/Src/system_stm32f0xx.o" --specs=nano.specs -mfloat-abi=soft -mthumb -o "Core/Src/system_stm32f0xx.o"
arm-none-eabi-g++ -o "test_f105_something.elf" @"objects.list" -mcpu=cortex-m0 -T"C:\Users\tdkostk\STM32CubeIDE\workspace_1.1.0\test_f105_something\STM32F051R8TX_FLASH.ld" --specs=nosys.specs -Wl,-Map="test_f105_something.map" -Wl,--gc-sections -static --specs=nano.specs -mfloat-abi=soft -mthumb -Wl,--start-group -lc -lm -lstdc++ -lsupc++ -Wl,--end-group
Finished building target: test_f105_something.elf
arm-none-eabi-size test_f105_something.elf
arm-none-eabi-objdump -h -S test_f105_something.elf > "test_f105_something.list"
arm-none-eabi-objcopy -O binary test_f105_something.elf "test_f105_something.bin"
text data bss dec hex filename
3844 20 1572 5436 153c test_f105_something.elf
Finished building: default.size.stdout
Finished building: test_f105_something.list
Finished building: test_f105_something.bin
2022-03-09 02:33 PM
Thanks, TDK - I did find the "Generate code" in STMCube32IDE, but wasn't sure if that was the right way to proceed as STM32CubeMX still seemed to be waiting for user input. I'm accustomed to seeing "GENERATE CODE" on the upper right of STM32CubeMX (when I run it directly, to create a new project for subsequent use in STM32CubeIDE), but that ("GENERATE CODE") button isn't rendered when STM32CubeMX is running as a child of STM32CubeIDE in the path I followed in the first post.
I also just realized I'm using one older version STMCube32MX (6.4.0 vs 6.5.0) at STMCube32IDE (1.8.0 vs 1.9.0). Before I go any further, I'll get the updates done.