STM32CubeMX generates empty/incomplete peripheral and/or middleware output when adding a new peripheral and/or middleware
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:
- Create or open project in CubeMX.
- In Project Manager / Code Generator, set: "Generate peripheral initialization as a pair of .c/.h files per peripheral" = Disabled (default).
- Generate code.
- Add a new peripheral: USB_FS (and/or others).
- Generate code again.
- 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".
- Back to CubeMX, In Project Manager / Code Generator, set: "Generate peripheral initialization as a pair of .c/.h files per peripheral" = Enabled.
- Generate code again.
- 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.
