2026-05-16 11:56 PM - last edited on 2026-05-18 3:15 AM by Andrew Neil
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.
2026-05-18 3:00 AM
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 .
2026-05-18 3:05 AM
@callsignhermit wrote:I’ve noticed a fairly strange ... coding style.
In what way "strange" ?
2026-05-18 4:05 AM
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.
2026-05-18 4:20 AM
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"...
2026-05-20 2:04 AM
Can we request ST to release such document? Assuming something like it already exists among the development team who maintain the codebase, of course.
2026-05-20 2:59 AM
Are you planning to contribute to Cube/HAL?
JW
2026-05-21 4:01 AM
Not at all, lol, I believe that’s way beyond my skill level. I’m just more comfortable when the code I’m working with is all in the same style across the project. It’s much simpler to adapt to ST’s style (and set up ClangFormat/Eclipse to do that) than to run ClangFormat on the entire codebase every time CubeMX generates a new bare-bones project.
We’re moving the ST Community to a new platform to give you a better and more reliable community experience.