2024-12-08 11:36 AM
Hello,
I see in code generated by all Linux versions of CubeIDE that USER CODE BEGIN and USER CODE END tags in infinite loop, are not in the better place.
Code generated by Cude IDE:
/* Infinite loop */
/* USER CODE BEGIN WHILE */
while (1)
{
/* USER CODE END WHILE */
/* USER CODE BEGIN 3 */
}
/* USER CODE END 3 */
}
The USER CODE BEGIN WHILE is outside the loop, and the USER CODE BEGIN 3 is into the loop.
I think it would be better, especially for beginner programmers, something like this:
/* Infinite loop */
while (1)
{
/* USER CODE BEGIN WHILE */
/* USER CODE END WHILE */
}
/* USER CODE BEGIN 3 */
/* USER CODE END 3 */
Or is there some reason to generate the code like the above?
Greetings
Solved! Go to Solution.
2024-12-09 03:19 AM
As the others have said, this has nothing to do with Linux - it's the same on other platforms.
@xisco wrote:USER CODE BEGIN and USER CODE END tags in infinite loop, are not in the better place.
They are in a perfectly reasonable place.
@xisco wrote:is there some reason to generate the code like the above?
Yes: The current method lets the user choose whether to have a while(1) loop, or a for(;;) loop - or any other structure they prefer.
2024-12-09 12:31 AM
Hello,
It's not a limitation on Linux version, it's also implemented on other platforms: windows and MACOS. Also, there is no sense to put CODE 3 just after while(1) as it's not reachable:
/* Infinite loop */
while (1)
{
/* USER CODE BEGIN WHILE */
/* USER CODE END WHILE */
}
/* USER CODE BEGIN 3 */
/* USER CODE END 3 */
2024-12-09 12:34 AM
Hello @xisco ,
this is not only specific to CubeIDE versions on Linux it is across all platforms and the reason for that is the code generation feature of cubeMX which keeps all written code in those delimiters when regenerating the code so we wouldn't lose the while loop or the conditions that could be modified.
Regards
2024-12-09 03:19 AM
As the others have said, this has nothing to do with Linux - it's the same on other platforms.
@xisco wrote:USER CODE BEGIN and USER CODE END tags in infinite loop, are not in the better place.
They are in a perfectly reasonable place.
@xisco wrote:is there some reason to generate the code like the above?
Yes: The current method lets the user choose whether to have a while(1) loop, or a for(;;) loop - or any other structure they prefer.