cancel
Showing results for 
Search instead for 
Did you mean: 

Code Generation would clear my code in `main.c`!

Fei
Associate

Hi,

When I updating the pin assignment information and doing code generation, I find my code, for example, USER CODE part is clear. Why? Is any setup wrong here?

 

 

 

while (1)

{

/* USER CODE END WHILE */

 

/* USER CODE BEGIN 3 */

}

/* U

 

STM32CubeIDE

Version: 1.16.0

Build: 21983_20240628_1741 (UTC)

 MacOS: 14.2.1

6 REPLIES 6
STTwo-32
ST Employee

Hello @Fei and welcome to the ST Community .

Could you please attach you .ioc file and a screenshot of the issue if possible.

Best Regards.

STTwo-32 

To give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.

LCE
Principal

My advice:

As soon as you start coding, create another CubeMX dummy project to copy new stuff from there.

Then you are safe from Cube overwriting stuff - and from unwanted HAL/LL library updates.

Andrew Neil
Evangelist III

Please see the posting tips for how to properly post source code:

https://community.st.com/t5/community-guidelines/how-to-write-your-question-to-maximize-your-chances-to-find-a/ta-p/575228

 

Where are you putting your user code?

while (1)
{
/* USER CODE END WHILE */
                              /*
                              <<< Any code here is OUTSIDE the 'User' block,
                              <<< so WILL get overwritten by code generation
                              */
/* USER CODE BEGIN 3 */
}
/* U

 

int main(void)
{
    /* USER CODE BEGIN WHILE */
    // user code
    /* USER CODE END WHILE */

    // NOT user code. Will be deleted!

    /* USER CODE BEGIN 3 */
    // more user code
    /* USER CODE END 3 */
}
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.

@Fei if you prefer video, see this for correct placement of user code:

https://youtu.be/hyZS2p1tW-g?t=573