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"...