cancel
Showing results for 
Search instead for 
Did you mean: 

STM32CubeIDE generates a main.c with confusing comments?

landydoc
Associate

It is not realy a bug as the code works fine even if any comment is placed at a wrong line but comments should make life easier.

Steps done to generate a main.c with STM32CubeIDE 1.7.0:

  • New STM32 project
  • selected a NUCLEO-F44rRE board and chose default initialization
  • on Clock Config tab for Code Generator set "Gen. peripheral init as a pair of c/h files..."

Generated code of main.c at line 90ff:

 /* USER CODE BEGIN 2 */
 
 /* USER CODE END 2 */
 
 /* Infinite loop */
 /* USER CODE BEGIN WHILE */
 while (1)
 {
   /* USER CODE END WHILE */
 
   /* USER CODE BEGIN 3 */
 }
 /* USER CODE END 3 */

What I think it should look like:

 /* USER CODE BEGIN 2 */
 
 /* USER CODE END 2 */
 
 /* Infinite loop */
 while (1)
 {
   /* USER CODE BEGIN WHILE */
 
   /* USER CODE END WHILE */
 }
 
 /* USER CODE BEGIN 3 */
 
 /* USER CODE END 3 */

1 ACCEPTED SOLUTION

Accepted Solutions
KnarfB
Principal III

That's not a bug, that's a feature. CubeMX will place sometimes generated code in the middle of the while loop, e.g. code for periodic background activities. The two user comment blocks leave you a choice placing your code before or after that generated code.

hth

KnarfB

View solution in original post

1 REPLY 1
KnarfB
Principal III

That's not a bug, that's a feature. CubeMX will place sometimes generated code in the middle of the while loop, e.g. code for periodic background activities. The two user comment blocks leave you a choice placing your code before or after that generated code.

hth

KnarfB