Skip to main content
Visitor
August 11, 2026
Question

STM32CubeMX generates empty/incomplete peripheral and/or middleware output when adding a new peripheral and/or middleware

  • August 11, 2026
  • 3 replies
  • 20 views

Environment:

  • STM32CubeMX version: 6.18.1 
  • STM32CubeIDE version: 2.2.0
  • STM32 MCU: SMT32H7R3Z8J6
  • OS: Windows 11

Project configuration:

  • Code Generator option: "Generate peripheral and middleware initialization as a pair of .c/.h files per peripheral (optional)" = [Enabled / Disabled]
  • Relevant peripherals already enabled before: xSPI, USART1
  • New peripheral added that triggers the issue: USB_FS/HS, SPIx, UART/USARTx, and others. 

Description:

When I add a new peripheral or middleware in STM32CubeMX and generate code, CubeMX creates an empty folder or generates incomplete peripheral and/or middleware output.

The issue appears repeatedly with the same pattern and is not random.

 

In the first case: 

  1. Create or open project in CubeMX.
  2. In Project Manager / Code Generator, set: "Generate peripheral initialization as a pair of .c/.h files per peripheral" = Disabled (default). 
  3. Generate code. 
  4. Add a new peripheral: USB_FS (and/or others). 
  5. Generate code again.
  6. Open CubeIDE, then build. In the current situation, the compiler will give an error "missing initialization code, missing generated files, and empty or incomplete peripheral outputs".
  7. Back to CubeMX, In Project Manager / Code Generator, set: "Generate peripheral initialization as a pair of .c/.h files per peripheral" = Enabled. 
  8. Generate code again. 
  9. Error fixed. 


For the second, third, and subsequent issues:

The pattern is the same as the first issue. “Generate peripheral initialization as a pair of .c/.h files per peripheral” that was previously enabled needs to be disabled first. Then the generated code has errors. Go back to CubeMX, enable “Generate peripheral initialization as a pair of .c/.h files per peripheral” again. Generate the code again. The bug is gone.

 

Actual result:

  • The generated peripheral folder is empty, or
  • peripheral source/header files are missing, or
  • initialization code is incomplete / missing.

Examples of affected files or code:

  • Missing files such as usart.c/h or gpio.c/h
  • Missing initialization instructions in generated peripheral code
  • Incomplete generated output after adding a peripheral

Expected result:

CubeMX should generate all expected peripheral source/header files and complete initialization code after a new peripheral is added.

Observed workaround:

If I disable code generation > regenerate > re-enable > regenerate, CubeMX may generate the missing content correctly. Also, enabling or changing the per-peripheral .c/.h generation option changes the behavior.

Additional notes:

This looks like a CubeMX code-generation inconsistency rather than a one-time project corruption issue. I use external memory via xSPI as XiP. This problem happens in both boot and application contexts. 

3 replies

ST Technical Moderator
August 11, 2026

Hello ​@sltnnnrh 

Thank you for reporting in STCommunity,

Could you please add an IOC illustrating this behavior for further investigation?

BR, Souhaib

 

To give better visibility on the answered topics, please click on 'Best answer' on the reply which solved your issue or answered your question.
sltnnnrhAuthor
Visitor
August 11, 2026

Hi Souhaib,

I've attached a reproduction case that demonstrates the issue.

Reproduction Steps:

  1. Open attached .ioc
  2. Add new peripheral FDCAN1
  3. In Project Manager → Code Generator: "Generate peripheral initialization as a pair of .c/.h" is already enabled from the previous code generation
  4. Click Generate
  5. Open generated project in CubeIDE
  6. Try to Build

Expected Issue: 

  • Undefined reference to `MX_FDCAN1_Init
  • (MX_FDCAN1_Init): Unknown destination type (ARM/Thumb) in ./Application/User/Core/main.o
  • Dangerous relocation: unsupported relocation

Current Workaround:

  1. Disable "Generate peripheral initialization as a pair of .c/.h files per peripheral"
  2. Regenerate
  3. Build error
  4. Re-enable "Generate peripheral initialization as a pair of .c/.h files per peripheral"
  5. Regenerate
  6. Build succeeds

Attached: test_XiP_h7r3.ioc + build log output

Thank you,
Sultan

sltnnnrhAuthor
Visitor
August 11, 2026