Skip to main content
chriskuku
Senior II
July 20, 2023
Solved

STM32CubeIDE cloning (copying) a project

  • July 20, 2023
  • 14 replies
  • 14478 views

A usual approach is to branch from a given project by making a copy of it and develop further on the copy, leaving the original intact.

 

How can this be achieved in the STM32CubeIDE project tree?

I tried it by copying the directory in the filsystem, to a different directory, edited every file containing the original project name to the new one. Even edited the .metadata and every occurence of the original name in the new directory tree. It lead to an existing new entry in the tree view Could be that I even did an Import by browsing to that new directory.

But the result was that I was said it not being a CDT project when I wanted to open the properties on the new project icon.

What is a safe way to do achieve this?

 

 

 

    This topic has been closed for replies.
    Best answer by chriskuku

     


    @Piranha wrote:

    CubeIDE, as every Eclipse based tool ... allows every developers to works as he prefer


    That is exactly the thing the Eclipse's workspace and overall design doesn't allow. Read this post for details. If

     

     I must say that - from my own experience - the "copy/paste in the project tree"-method worked for me and is *the* solution. I have no links in my projects. Maybe there are problems when one is using links.

    14 replies

    Harvey White
    Senior III
    July 21, 2023

    I'm not sure that CubeIDE etc is set up to gracefully do this.

    I've found that simply copying the project leaves a lot of links in that make problems for you later (like links back to previous locations).

    What I've done is a brute force approach.

    Copy the main.C program to another reference directory.

    Copy the .IOC file to another directory.

    Hopefully, you've got a standard structure for directories and the like (I do...)

    1. create a project directory.
    2. in that directory, use CUBEMX to create a new project from an existing IOC file
    3. point the initialization software at a previous version of the IOC file.
    4. let it create a new project in the new directory.  The project name should have been embedded in the IOC file and all your chip connections should be identical.
    5. generate code.
    6. your main.c program will lack any modifications you made to it.
    7. copy your older main.c program over the new main.c program, that puts all the mods to main.c back in.
    8. if your main.c had absolute paths, you need to fix them.
    9. move/paste your program addons into whatever directory you used.  I have one or two directories that are added to a project.  With luck, all the links are relative.  If not, you may need to fix them.  You won't if the project is in a subdirectory of the main "project" directory.
    10. if it's higher, you may have to fix things.
    11. as long as all the absolute paths are ok, you're fine.
    12. you may have to go into project properties and fix links and settings.

    It's not graceful, but it seems to work.  Eclipse (and CubeMX) don't seem to have a "clone project to another directory" capability.  I'd like to find one.

    Hope this helps a bit.

     

    chriskuku
    chriskukuAuthor
    Senior II
    July 21, 2023

    Thanks to you both, Harvey and Stefano,

    meanwhile I learnt that there exists the most intuitive way to clone a project in the project tree is - and that's was I was initially hoping it would work, but I was unable to detect the right protocol to do it - that you simply select the project with a right mouse click, click copy, then paste (leaving the selection as it is which is a bit confusing since no one wants to paste something into a selected item). You are the asked for the new name (default is the existing name with an incremental number attached). So easy.

     

     

    Harvey White
    Senior III
    July 23, 2023

    When you do a copy, you must make sure that the files you are editing, if you edit and use linked files, are the ones you think you want, not the ones in the older project.  Eclipse has an awkward way of linking files. 

    I have a project with included files common to all such projects.  I have to put in absolute paths or eclipse won't find the files, (nor will it tell me where it THINKS they are).  Yet in other parts of the project, the workspace paths work just fine.

     

    Stefano Oliveri
    ST Employee
    July 21, 2023

    CubeIDE, as every Eclipse based tool has a lot of flexibility that can be powerful or complex, depending on our experience and expertise with the IDE. In my opinion it is a good thing because it allows every developers to works as he prefer (with an initial cost to pay in term of time).

    In your case a simple solution is to put all source files inside the project folder, that is the folder containing these elements:

    • .settings folder
    • .cproject file
    • .project file

    Img 01Img 01

    The above SimplePrj example show this case. I generated it from the IDE using the [File > New > STM32 Project] menu command. Now, If I want to move that project I can copy and paste the project folder. To rename the project there are two options:

    1. Form the IDE, select the project with the cursor and right-click to open the context menu
      1. Select the command [Rename...] from the context menu
    2. manually edit the .cproject and .project file
      1. find and replace the original project name with the new one.

    Note

    Not always it is convenient to put all files inside the project folder, for example when you want to share some files between multiple projects (like the ST Middleware).

    Another thing that can create issue in your scenario is if your project is using linked resources or virtual folder.

    img_01.PNG

    In the above example (available in ElooMTX-SDK in the stm32-hotspot github) the files highlighted in blue are real files inside the Src folder, but the files with a little arrow icon mark, like the red highlighted, are linked resource, that means the real file can be anywhere in the file system. This can be an issue when you copy and past the project folder. 

    Last thing, be careful also at the way you specify the project settings. The recommendation is to use paths relative to the project folder like in the below image.

    img_02.PNG

    Have a good development time with STM32,

    Stefano

    Piranha
    Principal III
    July 23, 2023

    CubeIDE, as every Eclipse based tool ... allows every developers to works as he prefer


    That is exactly the thing the Eclipse's workspace and overall design doesn't allow. Read this post for details. If ST would make an IDE based on, for example, Code::Blocks, that could be a decent and worthy IDE. Now CubeIDE is just another bloated under-performing Frankenstein with PITA usability like all Eclipsoids are.

    Harvey White
    Senior III
    July 23, 2023

    I have a very large and versatile swiss army knife.  It has computer tools and just about everything else I might need, including a spatula (and no idea why, makes me wonder about the designers). 

    It is not what I'd call a rapid deploy tool.

    In that sense, it's a lot like CubeMXIDE and Eclipse itself.

    There are times that I suspect that the people who write the tools never use them, otherwise, they'd fix stuff, now....

     

    RhSilicon
    Lead
    July 23, 2023

    This is one of the reasons the Arduino community is so big, just rename a file.

    Harvey White
    Senior III
    February 17, 2024

    There is an alternate method.  My entire project is in a directory with sub-directories.  The configuration files, except for a file identifying the board, are contained there.

    I went through a period where the only way I could get the IDE/compiler to find anything was to include the absolute path.  Needless to say, changing to another computer was painful. 

    What I did find is that adding the entire subdirectory by using source location under properties worked, with limitations.

    the directory my project is in is called SUBSYSTEMS

    Therefore, pointing the source location to SUBSYSTEMS worked. 

    This required the following for any include file

    #include "SYSTEM_CPP\SYSTEM_DISPLAY.hpp"
    #include "COMMON_CPP\CPP_LINK.hpp"
    #include "GRAPHICS_CPP\string.hpp"

    Where the directory structure was SUBSYSTEMS for the project, and SYSTEM_CPP, COMMON_CPP, and GRAPHICS_CPP for subdirectories. 

    This seems to work well.

    This did not seem to be explained in the documentation.

     

    The idea is that every project has a configuration file which uses #ifdef to enable and disable subsystems, and all projects have common code under SUBSYSTEMS.  Naturally, main.c and main.h along with the standard C support files are configured by CubeMXIDE.

     

     

    PR.10
    Associate III
    February 18, 2024

    I used to work with / in include paths in some arduino project in VS code and it quickly escalated to madness due to various build system quirks, so I try to avoid it at any cost :)

    I use folder with actual source code outside of the Eclipse project folder. And the project folder is outside of workspace. So there is no hierarchy.

    There is and option to use path variables like this

    ${ProjDirPath}/../code_files/Framework

    This works for folder and files even link folder. It also works for include path so projects does not  break when i move the root folder of the entire thing.

    The format of eclipse project file is a mess so the only sane way is use gui to do that change. Once you find the macro name and where to put \ or / Adding a folder is a rare 1 time action, so I am fine with that.

    Unfortunately nothing like that works for eclipse workspace but that is generally a source of endless pain anyway. At least it seems to update correctly when the project is opened from the new location.

    It the moment I do not share the code with a linux machine but since it does accept / I assume it would work there too.

     

    Harvey White
    Senior III
    February 18, 2024

    I'm stuck with CubeMXIDE, which means eclipse. 

    The method I use works with new projects, which happens frequently at times.  The overall structure is \documents\projects\arm_projects\project 42\

    under that is SUBSYSTEMS (custom code), side by side with that is projects\<individual project name> which has the CubeMXIDE structure in it, with the IOC file, .src, .inc, etc.

    creating an individual new project (with a borrowed IOC file or not) results in another subdirectory <individual new project name> under projects.  Pointing the CubeMXIDE project "source files" at the SUBSYSTEMS directory seems to work, and is easier than trying to add paths (which for some reason includes set up in the project don't really work for me).

    This works, and should be well behaved even if I move the entire projects (top level) to another drive.

     

    Long as it works, I'm fine with it.