Skip to main content
Visitor II
March 29, 2026
Question

The list of #include in the main.c file is lost when regerating stm32cubemx with new GPIO config.

  • March 29, 2026
  • 2 replies
  • 140 views

The list of #include in the main.c file is lost when regerating stm32cubemx with new GPIO config :

Previous :

 
/* USER CODE BEGIN Header */
/**
******************************************************************************
* @file : main.c
* @brief : Main program body
******************************************************************************
* @attention
*
* Copyright (c) 2026 STMicroelectronics.
* All rights reserved.
*
* This software is licensed under terms that can be found in the LICENSE file
* in the root directory of this software component.
* If no LICENSE file comes with this software, it is provided AS-IS.
*
******************************************************************************
*/
/* USER CODE END Header */
/* Includes ------------------------------------------------------------------*/
#include "main.h"
#include "string.h"
#include "exti.h"
#include "embedrt_debug.h"
#include <stdio.h>
#include <stdbool.h>

After regeneration with mx:

 
/* USER CODE BEGIN Header */
/**
******************************************************************************
* @file : main.c
* @brief : Main program body
******************************************************************************
* @attention
*
* Copyright (c) 2026 STMicroelectronics.
* All rights reserved.
*
* This software is licensed under terms that can be found in the LICENSE file
* in the root directory of this software component.
* If no LICENSE file comes with this software, it is provided AS-IS.
*
******************************************************************************
*/

/* USER CODE END Header */
/* Includes ------------------------------------------------------------------*/
#include "main.h"
#include "string.h"

 


Edited to apply source code formatting - please see How to insert source code for future reference.

2 replies

TDK
Super User
March 29, 2026

Any code outside of USER CODE blocks is lost. This is by design.

If you want to add includes do them in the "USER CODE Includes" block:

/* USER CODE BEGIN Includes */
#include "whatever.h"
/* USER CODE END Includes */

 

If you're having trouble with code generated directly from an IOC file, attach that IOC file here so it can be looked at.

"If you feel a post has answered your question, please click ""Accept as Solution""."
MGogr.1
Senior
March 30, 2026

All of your code should be be between

/* USER CODE BEGIN */
all your code;
/* USER CODE END */