Search code examples
carmembeddedlibrariescmsis

Are STM32 HAL drivers based on CMSIS?


I was wondering how HAL drivers are implemented, and more in general how CMSIS is involved in peripheral drivers for ARM based microcontrollers (specifically STM32 microcontrollers, but also Cypress PSoc).

The question is: since HAL drivers provide a high level interface to a microcontroller's peripherals, are they implemented reaching bare metal level or rather the lowest layer is implemented with CMSIS packages and HAL are developed starting from them.

Any answer is accepted as I'm trying to understand how these two types of "libraries" are linked.


Solution

  • In relation to how the HAL drivers (e.g. for STM32) interact with CMSIS, they use CMSIS-CORE as a "lower-layer" to interface to the SOC hardware, while attempting to hide compiler and tool specific details.

    CMSIS-CORE provides definitions of things like memory layout, interrupt numbers, the base addresses of peripherals, the offsets of peripheral registers from the base address, and even definitions of the bits of all of the registers.

    This is done in a layered fashion, e.g. (for an STM32F030) you might have a header file for a Cortex-M0 CPU, one for the STM32F0 range, and then finally one for the exact STM32F030 chip.

    But CMSIS-CORE doesn't provide any actual functioning code. Just definitions. There are some small inline functions defined in header files for things like enabling and disabling interrupts, or resetting the MCU. But there is no "driver" code.

    The STM32 HAL provides the driver code to actually control those peripherals, and it uses the definitions from CMSIS-CORE to do so. So to answer the question: the HAL does not access "bare metal" directly, it does use CMSIS-CORE for that.

    There is way more to CMSIS than just CMSIS-CORE, but I don't know if they're relevant to your question about the HAL.