2021-10-01 05:35 AM
I have a multi target project.
My targets are STM32L152CB and STM32L152RC. I use Ubuntu 20.4 with STM32CubeMX 6.3.0.
Since STM32CubeMX does not natively support multiple targets I've decided to have two cube projects in the same folder. The generated files are the same since both targets use the same pins and peripherals and have the same core. The only difference is the processor type. Common application code will be in a seperate folder from the generated code and the project files.
The first problem I encountered was that you cannot rename the .cproject, .project and .mxproject files. They are nameless and I couldn't find an option in STM32CubeMX to add a name. Therefore they will overwrite the existing files from the other target, so you cannot have both project files in the same folder. My workaround was to place the ioc files in seperate target folders.
My second problem is that now each target folder has a copy of all the sources. I want all the sources in one place. The ioc file has several path options under ProjectManager. But changing them is of no use since the configuration is overwritten when I open it and click generate. I thought I would have more flexibility through the command line interface. However if I put in
this command I get an error:
generate code /home/user/git/myproject/projects
Error:
Exception in code generation java.lang.StringIndexOutOfBoundsException: begin 10, end 11, length 0
I tried putting the path in quotes, removing the final slash and changing the slashes. Nothing helps.
Am I stuck having two complete copies of the same project with only one parameter difference? Or is there a way to make it work natively with this tool? If not is there a workaround? One workaround I could think of is to write a script which would run cube MX and then modify the paths in the project files and move the generated folders. I do not prefer this workaround since it probably won't be cross platform and would require a lot of work.
Solved! Go to Solution.
2021-10-04 08:32 AM
Update. I was able to get it working. I created targets first (debug and release for my second target, based on those of the first target). Then I manually edited the processor references in the .cproject file. I changed STM32L152xC to STM32L152xB. I changed STM32L152RC to STM32L152CB. I changed the flash load file. I had to add one header file: stm32l152xb.h and one load file: STM32L152CBTX_FLASH.ld.
Unfortunately I cannot change the output folder path or name as this is determined by eclipse. I've read that using makefiles that would be possible, but after struggling with getting those to work I gave up.
I renamed to .ioc file to .ioc.bak so I wouldn't accidentally overwrite the files. When I need to make a change I rename it back to .ioc, make my changes, rename back to .ioc and revert unwanted changes in git such as to the .cproject file.
Other IDE's such as KEIL provided more flexibility in my opinion. But it I'm glad I got it working.
On a side note. in the past I have used STM32CubeMX in a different way. I generated different configurations for peripherals I wanted, merged the common parts and encapsulated the differences in a c++ class. Later I repeated this for different STM32 processors. But I used VSCODE with platformio then, which provided me more flexibility with targets.
2021-10-01 07:52 AM
.project & .cproject are Eclipse & Eclipse CDT proprietary files. No way to rename them.
Having one repository per .ioc file is common way of working but yes duplicates material.
Not fully sure about what you're going to achieve but a way if STM32CubeIDE to support multi targets is to be a bit fluent in build configuration setup.
To get some extra help maybe share more details about variation kind you're expecting to support if multi target ?
2021-10-01 08:10 AM
CubeMX doesn’t support this amount of flexibility. If you want the niceness of auto code generation, you have to live with the limitations.
You could generate code once and then rearrange the structure how you want.
2021-10-01 08:50 AM
I think you are right. I will use the code generation once and then manually merge them and then just archive the config files. If I need to make changes then I just need to generate again and manually merge. Shouldn't be too much work. The only issue is how to set multiple debug targets in eclipse, but I think Cartu38 OpenDev can help with that.
2021-10-01 08:57 AM
I will try to implement your solution. I will just manually merge the source codes and change the eclipse project build configurations.
I have a question. The MCU is greyed out. How can I change it? I manually changed the device defines in GCC/preprocessor and MCU G++/Preprocessor, but that didn't change the MCU.
2021-10-04 08:32 AM
Update. I was able to get it working. I created targets first (debug and release for my second target, based on those of the first target). Then I manually edited the processor references in the .cproject file. I changed STM32L152xC to STM32L152xB. I changed STM32L152RC to STM32L152CB. I changed the flash load file. I had to add one header file: stm32l152xb.h and one load file: STM32L152CBTX_FLASH.ld.
Unfortunately I cannot change the output folder path or name as this is determined by eclipse. I've read that using makefiles that would be possible, but after struggling with getting those to work I gave up.
I renamed to .ioc file to .ioc.bak so I wouldn't accidentally overwrite the files. When I need to make a change I rename it back to .ioc, make my changes, rename back to .ioc and revert unwanted changes in git such as to the .cproject file.
Other IDE's such as KEIL provided more flexibility in my opinion. But it I'm glad I got it working.
On a side note. in the past I have used STM32CubeMX in a different way. I generated different configurations for peripherals I wanted, merged the common parts and encapsulated the differences in a c++ class. Later I repeated this for different STM32 processors. But I used VSCODE with platformio then, which provided me more flexibility with targets.
2021-10-04 11:27 PM
1) If Keil such proposal is pure IDE ... STM32CubeIDE is promoting you device configuration and related code generation as addon ... it comes with obvious pros but some cons.
2) Output file name is up to you so you can set one per build configuration if you want
2021-10-04 11:35 PM
Updating target device is not possible wihout hacks ... but such are fairly obvious and safe.
Either edit .cproject file you'll see one target device reference per build configuration ... just edit it. Or remove <nature>com.st.stm32cube.ide.mcu.MCUProjectNature</nature> from .project file then build settings are enabling device target selection.
Kind reminder, doing hacks your are self responsible about .... some target device is part too of .ioc file .... but can fly depending what you're doing. High level hacking metadatas is bad practice bt may help from time to time.
2021-10-05 07:37 AM
With output folder I mean the folder with all the build artifacts. That folder always has the name of the build configuration.
Thanks for the tip of removing the line with MCUProjectNature. If I knew that beforehand I wouldn't have to manually edit the .cproject file. It works!
Now I can build and debug all build configurations (both targets in debug and release). The only issue I have right now is that I have to manually select the correct launch configuration per build configuration. I wish I could connect specific launch configurations to build configurations. Since each build configuration has its own folder with build artifacts and elf file I need multiple launch configurations to point to the different elf files. If you know a way you would make me happy.
2021-10-06 12:12 PM
About build config vs. launch not sure about your trouble.
You mayhave one launch per build artifact or one single launch on which you select prior start binary you are pointing to