2026-05-06 1:17 AM
Hi,
I changed the location of the main.c file in my disk then reimported it in the project explorer as a linked file under the same path (under core/src).
When I modify the .ioc file, save it and regerated the code, the changes of the peripheral configuration are not reflected in the linked main.c file.
I opended the project directory (on disk) to investigate and saw that a new main.c is generated and the changes are reflected there.
What is the solution that makes the generated code from the .ioc be integrated in the linked main.c and not generated a new main.c?
2026-05-06 1:28 AM - edited 2026-05-06 1:41 AM
You haven't said what versions you're using:
How to write your question to maximize your chances to find a solution
The code (re-)generation is done by CubeMX, and that knows nothing about changes you may have made to the CubeIDE folder structure.
I don't think there's any way to tell CubeMX to (re-)generate code in an alternate location.
I would strongly suggest that you leave the structure of the CubeMX-managed code alone.
You can put your own files anywhere you like, but leave the ones managed by CubeMX where it puts them!
PS:
On structuring your own code:
2026-05-06 1:34 AM - edited 2026-05-06 1:52 AM
You can't expect CubeMX to handle you moving everything. Code generators expect certain folder structures.
One workaround is to add a script that moves main.c before code generation and moves it back afterwards:
Edit. Just tested it. Works great.
pregen.bat:
move main_path\main.c Core\Src\main.c
postgen.bat:
move Core\Src\main.c main_path\main.c