Skip to main content
callsignhermit
Associate
May 17, 2026
Question

Documentation of the STM32Cube source code style ?

  • May 17, 2026
  • 2 replies
  • 312 views

Looking through the STM32Cube codebase, I’ve noticed a fairly strange but thoroughly consistent coding style. Indentation size is 2 spaces, using space for indentation; bracing style is more similar to Allman’s style rather than K&R and 1TBS. Naming style is also uniform, using CamelCase for external identifiers such as functions, structure fields, and global variables; along with a bit of Hungarian notation here and there (for example, pTxBuffPtr).

This style is mechanically consistent through STM32Cube firmwares, drivers (LL, HAL, and CMSIS), code generated by STM32CubeMX, and BSP drivers. Even example projects follow suit.

Could STM employees please share with us some documentation or guideline regarding this coding style? Looking for something similar to the Linux Kernel Coding Style and the Google C++ Style Guide. Configurations for formatter tools such as clang-format would also be appreciated.

2 replies

Technical Moderator
May 18, 2026

Hello @callsignhermit 

Unfortunately, there is no document illustrating the HAL coding style. But you can configure your own code style using the feature code style in Cube IDE .

Saket_Om_0-1779098369435.png

 

"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.Saket_Om"
callsignhermit
Associate
May 20, 2026

Can we request ST to release such document? Assuming something like it already exists among the development team who maintain the codebase, of course.

waclawek.jan
Super User
May 20, 2026

Are you planning to contribute to Cube/HAL?

JW

Andrew Neil
Super User
May 18, 2026

@callsignhermit wrote:

I’ve noticed a fairly strange ... coding style.


In what way "strange" ?

A complex system that works is invariably found to have evolved from a simple system that worked.A complex system designed from scratch never works and cannot be patched up to make it work.
callsignhermit
Associate
May 18, 2026

I apologize if I came off rude. The style looked strange to me because the K&R layout, snake case and the refrain from Hungarian style has dominated the C projects I have worked on.

Andrew Neil
Super User
May 18, 2026

No worries about rudeness.

It is a truth universally acknowledged that, in any group of N programmers, there will be at least N+1 different views on what constitutes "good style"...

A complex system that works is invariably found to have evolved from a simple system that worked.A complex system designed from scratch never works and cannot be patched up to make it work.