2019-05-24 05:14 PM
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?
2019-05-25 04:14 AM
I don't know about CubeIDE, but there is a setting in CubeMX.
Project manager/code generator/keep user code when regenerating
2019-05-26 01:42 PM
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.
2022-07-28 02:21 AM
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.
2022-07-28 10:39 AM
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.