cancel
Showing results for 
Search instead for 
Did you mean: 

How to Deeply Understand STM32 HAL Without Relying on CubeMX?

Zaeem-Ahmed
Associate

Hi, my name is Zaeem Ahmed.

I'm currently digging into the STM32F1 HAL and trying to understand it at a deeper level. I'm intentionally not using STM32CubeMX — not because I have anything against it (it’s a great tool) — but because I want to read the HAL documentation and implement configurations manually to better understand what’s really happening under the hood.

What I'm looking for:

I would really appreciate any good resources, expert tips, or learning strategies that help connect:

  • HAL APIsHardware-level understanding from the reference manual

The challenge I'm facing:

Often, when reading HAL documentation, I encounter vague or overly simplified explanations. For example:

  • HAL_TIM_Base_Init vs. HAL_TIM_Base_MspInit — the documentation just says one initializes the timer and the other the MSP, which is obvious from the names but not why they're separated or how they work together under the hood.

Another example:

  • When initializing timers, there are different functions for different modes (e.g., HAL_TIM_OnePulse_Init, HAL_TIM_PWM_Init, etc.).
    But modes like PWM, Input Capture, Output Compare seem to be channel-specific, not timer-wide.
    So why is the timer itself initialized in a specific mode?

This leads to questions like:

  • What happens if I initialize a timer in one mode (say PWM), and configure its channel for another (like Input Capture)?

  • How is HAL actually helping if I have to dig into its source every time to validate my approach?

I understand how the timer works at the register level from the reference manual, but when I move to HAL, it feels like a black box. I'd really like to bridge that gap.

  • How can one truly learn HAL (not just use it as a wrapper)?

  • Are there any guides/resources that map HAL APIs to actual peripheral behavior?

  • What’s the best way to approach HAL if you want full control and hardware understanding, but still benefit from its abstraction?

I’d really appreciate any learning resources, explanations, or just your own journey if you’ve been through this.

Thanks in advance!

— Zaeem Ahmed

3 REPLIES 3
TDK
Super User

Timers are one of the things that HAL doesn't do that well, purely due to the sheer number of configurations possible. Consider using register-only code instead if it's something that can't be selected in CubeMX.

Best way to learn is to look at the code and see what it's doing, IMO.

If you feel a post has answered your question, please click "Accept as Solution".
Saket_Om
ST Employee

Hello @Zaeem-Ahmed 

To learn what the HAL function do exactly you should follow these steps

  • Step 1: Read the reference manual for the peripheral (e.g., TIMx).
  • Step 2: Look at the HAL function (e.g., HAL_TIM_PWM_Init).
  • Step 3: Dive into the HAL function and see which registers are set.
  • Step 4: Compare with the reference manual to see what’s being configured.
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
Andrew Neil
Super User

@Zaeem-Ahmed wrote:

I want to read the HAL documentation


That would be a good starting point - have you done that?

eg, for F1, it's UM1850 Description of STM32F1 HAL and low-layer drivers.

See also the 'Documentation' tab on the Cube-F1 package Product Page:

https://www.st.com/en/embedded-software/stm32cubef1.html#documentation

 

You could also look at the code that CubeMX generates - it's all just HAL calls...

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.