General HAL and LL Design Aspects ¶
The Portable APIs layer (HAL and Low-Layer drivers) provides a generic, multi-instance, and simple set of APIs to interact with the upper layer (application, libraries, and stacks). It is composed of an API set that is directly built around a generic architecture and allows built-on layers, like the middleware layer, to implement its functions without knowing in depth the underlying STM32 device. This improves library code reusability and guarantees easy portability to other devices and STM32 families.
The HAL drivers must offer a rich set of APIs to interact easily with the application upper layers. Each driver consists of a set of functions covering the full peripheral features. The development of each driver is driven by a common API, which standardizes the driver structure, the functions, and the parameter names.
Architecture principles for resource management ¶
The following principles are considered within the HAL/LL drivers:
The resource types and defines belong to the given SW layer: they are prefixed by the layer prefix, for example, HAL_ or hal_, followed by the module (e.g., HAL_FLASH or hal_flash).
Each SW layer uses its own resources and types: data structures, enums, error management, and so on.
Layer resource translation: In vertical layering (e.g., HAL on top of the LL), the upper-layer implementation includes a translation phase to accommodate lower-layer resources (the user should not need to care about it).
In case of two cohabiting layers in a user application (horizontal interaction), a translation API is provided to move from a Layer A type to the equivalent Layer B type for the required objects.