Convert to C++ project - some hints
Hey folks,
first of all: nice project and I hope that it will go on in this way
Here are some annotations and problems I had while generating a C++ project.
- I am running the plugin on 1.7.0 under Windows with Eclipse Mars as System Workbench for STM32
- I tested CubeMX generated projects and Eclipse generated projects
To convert a project to C++, check all of the points:
- if someone does not find the convert to C++ project: Window –> Show View –> Project Explorer (do NOT use the context menu New --> convert to C/C++ stuff!!!)
- after conversion, check the settings of the G++ compiler under: -> Properties -> C/C++ Build -> Settings -> MCU G++ (“you must at least check that the C++ compile build settings (in project >> Properties >> C/C++ Build >> Settings) are coherent with those from the C Compiler (mainly symbol definitions, include files and libraries)” - http://www.openstm32.org/tiki-view_forum_thread.php?comments_parentId=1231&display=print
)
- for an Eclipse generated project this did not work at all
- for a CubeMX project it seemed to work
- so I took the information from a CubeMX project and copied it to an Eclipse generated project (before doing this, close the Workbench/Eclipse) - but do this carefully otherwise your Eclipse might get troubles
(1) (2) (3)
- to get rid of the _sbrk error: “but you also must add linker flags -specs=nosys.specs -specs=nano.specs in C/C++ Build >> Settings >> MCU G++ Linker >> Miscellaneous” ( source: http://www.openstm32.org/tiki-view_forum_thread.php?comments_parentId=1231&display=print
)
- modify the linker script (for a CubeMX project I could use (but this also depends on the target): ${workspace_loc:/${ProjName}/STM32F407IGHx_FLASH.ld} ) - for details refer again: http://www.openstm32.org/tiki-view_forum_thread.php?comments_parentId=1231&display=print
- for me it still did not work. Reason: Reading the Build Console carefully, the main.cpp files still was compiled with ‘Invoking: MCU GCC Compiler’ instead of ‘Invoking: MCU G++ Compiler’. Solution: rename main.c to main.cpp in Eclipse
- Caveat at a CubeMX project: I renamed the main.c to main.cpp inside Eclipse but the path still pointed to a main.c file. So do following:
- open file explorer, open the folder /Src/ and rename main.c to main.cpp
- open the folder /SW4STM32// and open .project
- search for main.c and modify this path to: PARENT-2-PROJECT_LOC/Src/main.cpp
THEN it finally should work
For the developers of the Workbench/plugin: maybe you could fix the mentioned problems in the future.
annotations:
(1) doing this inside Eclipse might be totally crap. I did following: I diffed the .cproject files and copied the stuff line by line. If someone might have trouble because of missing new lines, one can use notepad++ together with the XML tools plugin to reformat.
(2) For the Eclipse generated project: under properties -> C/C++ Build -> Settings -> MCU G++ Builder -> All options for me it looks like in the end:
- -mcpu=cortex-m4 -mthumb -mfloat-abi=hard -mfpu=fpv4-sp-d16 -Dweak=”attributeweak” -Dpacked=”attributepacked” -DUSE_HAL_DRIVER -DSTM32F407xx -I”C:\workspace\stm3240g-eval_hal_lib” -I”C:\workspace\/inc” -I”C:\workspace\stm3240g-eval_hal_lib\CMSIS\core” -I”C:\workspace\stm3240g-eval_hal_lib\CMSIS\device” -I”C:\workspace\stm3240g-eval_hal_lib\HAL_Driver\Inc\Legacy” -I”C:\workspace\stm3240g-eval_hal_lib\HAL_Driver\Inc” -I”C:\workspace\stm3240g-eval_hal_lib\Utilities\Components\ampire480272” -I”C:\workspace\stm3240g-eval_hal_lib\Utilities\Components\ampire640480” -I”C:\workspace\stm3240g-eval_hal_lib\Utilities\Components\Common” -I”C:\workspace\stm3240g-eval_hal_lib\Utilities\Components\cs43l22” -I”C:\workspace\stm3240g-eval_hal_lib\Utilities\Components\exc7200” -I”C:\workspace\stm3240g-eval_hal_lib\Utilities\Components\ili9325” -I”C:\workspace\stm3240g-eval_hal_lib\Utilities\Components\ili9341” -I”C:\workspace\stm3240g-eval_hal_lib\Utilities\Components\l3gd20” -I”C:\workspace\stm3240g-eval_hal_lib\Utilities\Components\lis302dl” -I”C:\workspace\stm3240g-eval_hal_lib\Utilities\Components\lis3dsh” -I”C:\workspace\stm3240g-eval_hal_lib\Utilities\Components\lsm303dlhc” -I”C:\workspace\stm3240g-eval_hal_lib\Utilities\Components\mfxstm32l152” -I”C:\workspace\stm3240g-eval_hal_lib\Utilities\Components\n25q256a” -I”C:\workspace\stm3240g-eval_hal_lib\Utilities\Components\ov2640” -I”C:\workspace\stm3240g-eval_hal_lib\Utilities\Components\s5k5cag” -I”C:\workspace\stm3240g-eval_hal_lib\Utilities\Components\st7735” -I”C:\workspace\stm3240g-eval_hal_lib\Utilities\Components\stmpe1600” -I”C:\workspace\stm3240g-eval_hal_lib\Utilities\Components\stmpe811” -I”C:\workspace\stm3240g-eval_hal_lib\Utilities\Components\ts3510” -I”C:\workspace\stm3240g-eval_hal_lib\Utilities\Components\wm8994” -I”C:\workspace\stm3240g-eval_hal_lib\Utilities\Fonts” -I”C:\workspace\stm3240g-eval_hal_lib\Utilities\Log” -I”C:\workspace\stm3240g-eval_hal_lib\Utilities\STM324xG_EVAL” -O0 -g3 -Wall -fmessage-length=0 -ffunction-sections -c -fno-exceptions -fno-rtti
(3) For the CubeMX generated project: under properties -> C/C++ Build -> Settings -> MCU G++ Builder -> All options for me it looks like in the end:
- -mcpu=cortex-m4 -mthumb -mfloat-abi=hard -mfpu=fpv4-sp-d16 -Dweak=”attributeweak” -Dpacked=”attributepacked” -DUSE_HAL_DRIVER -DSTM32F407xx -I../../../Inc -I../../../Drivers/STM32F4xx_HAL_Driver/Inc -I../../../Drivers/STM32F4xx_HAL_Driver/Inc/Legacy -I../../../Middlewares/ST/STM32_USB_Device_Library/Core/Inc -I../../../Middlewares/ST/STM32_USB_Device_Library/Class/CDC/Inc -I../../../Drivers/CMSIS/Include -I../../../Drivers/CMSIS/Device/ST/STM32F4xx/Include -O0 -g3 -Wall -fmessage-length=0 -ffunction-sections -c -fno-exceptions -fno-rtti
(sorry, the bold printed stuff should be underscores. I do not find the verbatim environment :-/ )