Skip to main content
landydoc
Visitor II
November 9, 2021
Solved

STM32CubeIDE generates a main.c with confusing comments?

  • November 9, 2021
  • 1 reply
  • 1002 views

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 */

This topic has been closed for replies.
Best answer by KnarfB

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

1 reply

KnarfB
KnarfBBest answer
Super User
November 9, 2021

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