Skip to main content
Senior III
September 2, 2026
Solved

MX_FATFS_Init canno't disable generated code

  • September 2, 2026
  • 6 replies
  • 55 views

i have enabled FATFS via CubeMX like below

but for some reason in the code generation settings I can’t disable

I want disable it because CubeMX generates a void function; instead, I want the MX_FATFS_Init return a status code if it is generated or not so, I want to have a uint8_t MX_FATFS_Init()

 

Best answer by mƎALLEm

Hi @nico23, and sorry for the late reply.

After checking, this is an expected behavior starting from STM32CubeMX 6.16 version. “Generate Code” option is by default greyed out with the Middleware/Packages function.

Users are able only to activate or disactivate the generation call of the code in the main.c.

There is currently no CubeMX option to independently disable the generation of the MX_FATFS_Init() implementation in fatfs.c while keeping the FATFS middleware enabled.

If you need to use your own implementation, you’ll need to avoid having two definitions of the same function, for example by using a different function name or adapting the generated code within the supported USER CODE sections.

Hope this clarifies the situation.

6 replies

mƎALLEm
ST Technical Moderator
September 2, 2026

Hello,

Try the following:

 

To give better visibility on the answered topics, please click "Best answer" on the reply which solved your issue or answered your question.
nico23Author
Senior III
September 2, 2026

Hi ​@mƎALLEm ; as my first screen suggest, I’ve already ticked the “Do Not Generate Function Call” regarding MX_FATFS_Init. (If I tick it, all the functions are not generated, which I don’t want)

mƎALLEm
ST Technical Moderator
September 2, 2026

Check “Do not Generate Function Call” then “Check MX_FATFS_Int” box in the “Do not Generate Function Call” column as I indicated previously. I’ve just tested it and it works.

You need just to check the box for MX_FATFS_Init not others. Uncheck them (others) if they are checked.

This is the generated code: 

int main(void)
{

/* USER CODE BEGIN 1 */

/* USER CODE END 1 */

/* MPU Configuration--------------------------------------------------------*/
MPU_Config();

/* MCU Configuration--------------------------------------------------------*/

/* Reset of all peripherals, Initializes the Flash interface and the Systick. */
HAL_Init();

/* USER CODE BEGIN Init */

/* USER CODE END Init */

/* Configure the system clock */
SystemClock_Config();

/* USER CODE BEGIN SysInit */

/* USER CODE END SysInit */

/* Initialize all configured peripherals */
MX_GPIO_Init();
MX_SDMMC1_SD_Init();
/* 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 */
}

The FATFs middleware still included in the project.

To give better visibility on the answered topics, please click "Best answer" on the reply which solved your issue or answered your question.