Skip to main content
Associate
August 20, 2026
Solved

STM32CubeMX: How to prevent unused peripheral initialization code?

  • August 20, 2026
  • 2 replies
  • 72 views

Hi everyone,

I'm working on an STM32 project using STM32CubeMX and noticed that initialization code is generated for peripherals that I don't always use.

Is there a recommended way to configure CubeMX so that only the required peripheral initialization code is generated?

Thanks!

Best answer by Mahmoud Ben Romdhane

Hello ​@Anacling 

Let me thank you for posting and welcome to the ST Community.

You can disable the generation of peripheral code under Project Manager ; Advanced Settings.

Thanks.

Mahmoud

2 replies

ST Technical Moderator
August 20, 2026

Hello ​@Anacling 

Let me thank you for posting and welcome to the ST Community.

You can disable the generation of peripheral code under Project Manager ; Advanced Settings.

Thanks.

Mahmoud

To give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.
AnaclingAuthor
Associate
August 21, 2026

Thanks for pointing me in the right direction! Found the setting in Advanced Settings. Appreciate the help!