2026-03-29 6:07 AM - last edited on 2026-03-30 9:11 AM by Andrew Neil
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.
2026-03-29 6:48 AM
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.
2026-03-29 11:39 PM
All of your code should be be between
/* USER CODE BEGIN */
all your code;
/* USER CODE END */