cancel
Showing results for 
Search instead for 
Did you mean: 

Problem with main.c as a linked file

melek_g
Visitor

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?

 

2 REPLIES 2
Andrew Neil
Super User

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:

https://community.st.com/t5/stm32cubemx-mcus/how-to-organize-the-folder-structure-in-cubemx-generated-code/m-p/873747/highlight/true#M34912

 

A complex system that works is invariably found to have evolved from a simple system that worked.
A complex system designed from scratch never works and cannot be patched up to make it work.

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:

unsigned_char_array_0-1778056325032.png

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

 

Kudo posts if you have the same problem and kudo replies if the solution works.
Click "Accept as Solution" if a reply solved your problem. If no solution was posted please answer with your own.