cancel
Showing results for 
Search instead for 
Did you mean: 

STM32CubeIDE erases code that exists between USER CODE blocks.

Hello,

I noticed that sometimes, STM32CubeIDE erases code that exists between USER CODE blocks. This definitely wasn't an issue with STM32Cube but have found this happening at least twice. Has this issue been reported?

4 REPLIES 4
turboscrew
Senior III

I don't know about CubeIDE, but there is a setting in CubeMX.

Project manager/code generator/keep user code when regenerating

That setting was left unchanged. I did receive an error during a project creation from STM32CubeIDE's built-in CubeMX about an invalid/out-of-date "firmware" but I did not snapshot it. I'll keep this post updated if I see it again.

After the generation wiped out my existing code, it wouldn't compile normally, even with no custom user code. I ended up deleting the project entirely and regenerating a project with CubeMX stand-alone application and not STM32CubeIDE. Everything seems to be working with CubeMX + TrueStudio for now.

I may switch back to CubeIDE but for now, I'm going to stick with what I know works.

MHoss.3
Associate

I have the same problem! Every time after code generation with STM32CubeIDE and switching back to code perspective, the same code is deleted. In my case, the code being deleted is  MX_GPIO_Init();

and the code withnin " /* USER CODE BEGIN WHILE */".

Any useful tips on that?

Thanks in advance.

Bob S
Principal

What version of CubeIDE and/or CubeMX are you using?

The MX_***_Init() functions (MX_GPIO_Init, etc.) do not usually make allowances for "user" code. So I would expect any code you put there to disappear.

Is the "USER CODE BEGIN WHILE" in main()? Yeah, that shouldn't happen, at least not on "newer" versions. That would be at least CubeMX 6.3 and newer, and IDE version 1.7 or newer. CubeMX 5.x had issues, and I don't recall where in the 6.x sequence they got cleaned up.

For me, the real answer is to never trust code generators. I always have code checked into version control (git, in my case) before I allow CubeMX or CubeIDE to (re)generate its part of the code. To do otherwise is just asking for trouble.