2024-08-26 08:35 PM - last edited on 2024-08-30 02:30 AM by SofLit
Hi. I am using NUCLE-F439ZI board
STM32CubeIDE Version: 1.16.0
Build: 21983_20240628_1741 (UTC)
Lately I am experiencing problem, when I make changes in .IOC file and save and generate code
it is messing my main.c file. It is copying big portion of main.c lines and adding them again in main.c file.
It is impossible to continue working. Is this a setting problem or a bug in the software?
Please help.
Thank you.
Rasem
Solved! Go to Solution.
2024-09-02 07:14 PM
This really shouldn't be this difficult.
> I am attaching good main.c which builds without errors.
The main.c file you have attached contains many "/* USER CODE" texts within USER CODE blocks.
It also includes several duplicate definitions, including two of main() where the first one is unfinished. It definitely does not compile.
Perhaps edit your file so "USER CODE" is not used anywhere within the user code sections.
When I edit your file to correct the above errors, it compiles. If I edit the IOC and regenerate code, it does not duplicate sections.
2024-08-27 05:44 AM
Are you modifying the USER CODE lines? What lines is it copying/adding? Your code should only be put within a USER CODE block.
Include your main.c file here.
2024-08-27 06:58 AM
Hello,
Are you putting your custom code between:
/* USER CODE BEGIN XXX */
<Your custom code>
/* USER CODE END XXX */
2024-08-27 09:12 AM
HI SofLit,
Thanks for the reply.
Yes, all codes are between the user specified locations. The problem happens when I copy and paste some code from
another project, and then I make changes in .IOC file, Save and generate code.
Now, I am trying now to Build the project every time I paste a new code, and before I make changes in .IOC and before
Generating code. It seems to be working without problem.
This is my assumption of the problem, I hope it will solve future problems.
Rasem
2024-08-27 09:18 AM
Could you please describe the exact operation you are doing?
Could you please share the exact code you are copying/pasting in the generated code and where? Is the code you are copying contains /* USER CODE BEGIN XXX */ and /* USER CODE END XXX */ ?
2024-08-27 03:03 PM
2024-08-27 03:17 PM
But you didn't answer these questions:
Could you please describe the exact operation you did?
Could you please share the exact code you are copying/pasting in the generated code and where?
We need to know which code was generated and which user code you paste and were?
For that, we need from you to:
1- Provide the original main.c generated code
2- Provide the user code and where you paste it? at which lines
3- Attach the .ioc file to reproduce the behavior.
Thank you.
2024-09-02 05:37 PM
Thank you for al the help. When I make changes in main.c file, build and download always work.
Sometime when I make changes in .ioc file save and generate code, it will copy many portions of the main.c
again and corrupt the file. I tried to remove the extra lines, but sometime I don't succeed.
I am guessing, when I make changes in main.c without saving it and building it, rather make another change in .ioc
file where the problem starts. I am attaching my main.c and .ioc file without any changes.
Thanks,
Rasem
2024-09-02 05:53 PM
Don't add the text "/* USER CODE" within your USER CODE sections.
2024-09-02 06:10 PM
Thank you TDK.
Very good advice. I removed and never use it again.
However the problem did not go away. I was able to recover my good code by Edit -> Undo button.
I am attaching good main.c which builds without errors. and also .ioc file in which I made one change
PG10=GPIO-Output. If I generate code now the main.c will rewrite many sections again.
Thanks,
Rasem