Docsity

Programación STM32 en C, Guías, Proyectos, Investigaciones de Electrónica Digital y Analógica

Vista previa parcial del texto

¡Descarga Programación STM32 en C y más Guías, Proyectos, Investigaciones en PDF de Electrónica Digital y Analógica solo en Docsity!

STM32 Ecosystem workshop

T.O.M.A.S Team

Now it is a right time for some theory – this time we will present basic information about a Low Layer Libraries bundled into Cube library packages

Low Layer Library concept and usage

HAL and LL libraries coexistence general points

  • The Low Layer (LL) drivers can be mixed without any constraints with all the HAL drivers not based

on objects handle concept (RCC, Cortex, common HAL, Flash and GPIO)

  • To mix the HAL with the LL, user has to be aware about some HAL concepts/constraints:
    • The LL drivers does not support the peripheral handle model
    • The LL drivers are intended to be used in an expert mode (need deep knowledge of hardware aspects).
    • The HAL drivers are just opposite to LL - they use a high abstraction level based on standalone

processes, therefore a deep knowledge of the hardware is not mandatory anymore.

  • Due to the different data structures used, LL can overwrite registers being mirrored in the HAL

handles. Therefore the LL drivers cannot be automatically used with the HAL for the same

peripheral instance: mainly can’t run concurrent process on the same IP using both APIs, however

sequential use is allowed if done carefully.

LL drivers scope 8

STM

snippets

Init functions Unitary functions LL Drivers

Standard

peripheral

library

HAL

Drivers

  • Common services (portability)
  • High level state machine based processes
  • Init services
  • Hardware basic services
  • Atomic register access
  • Compliancy with the HAL drivers
  • Low memory footprint

LL library - introduction

  • HAL library brings high-level, functionally oriented and highly portable APIs masking product/IPs complexity to the

end user

  • Low Layer (LL) library offers low-level APIs operating at registers level, w/ better optimization but less portability

and requiring deeper knowledge of the product/IPs specification

  • LL library is offering the following services:
    • Unitary functions for direct register access

(provided in stm32yyxx_ll_ppp.h files)

  • One-shot operations that can be used by HAL drivers or from application level.
  • Independent from HAL - can be used as standalone (w/o HAL drivers)
  • Full features coverage of supported IP
  • Init functions (provided in stm32yyxx_ll_ppp.c files)
  • Conceptually compatible with Standard Peripheral Library (SPL) Application stm32yyxx_ll_ppp.h LL stm32yyxx_ll_ppp.c stm32yynnnxx.h stm32yyxx.h

Low Layer library naming convention return_value LL_PPP_Operation () LL prefix indicating type of the library (in contrary to Hardware Abstraction Layer (HAL) libraries

PPP –

peripheral name. Type of the operation on the peripheral, much more detailed like in HAL , i.e. “SetPinMode” or “EnableDMAReq”

Hint: to find proper function for the peripheral, please type LL_PPP_ and press Ctrl+Space

LL drivers scope unitary functions

STM

snippets

Init functions Unitary functions LL Drivers

Standard

peripheral

library

HAL

Drivers

  • Common services (portability)
  • High level state machine based processes
  • Init services
  • Hardware basic services
  • Atomic register access
  • Compliancy with the HAL drivers
  • Low memory footprint

Unitary LL Typical Usage

Ex : System Clock Configuration

The LL services have to be called following the programming model of the reference manual document by calling the elementary LL drivers services

Ex : Use GPIO to toggle LED continuously

DMA Init Example using HAL DMA Driver

LL drivers scope init functions

STM

snippets

Init functions Unitary functions LL Drivers

Standard

peripheral

library

HAL

Drivers

  • Common services (portability)
  • High level state machine based processes
  • Init services
  • Hardware basic services
  • Atomic register access
  • Compliancy with the HAL drivers
  • Low memory footprint

stm32yyxx_ll_gpio.h stm32yyxx_ll_gpio.c

Init functions LL drivers APIs

  • The init LL functions are based on the same concept as Standard Peripherals Library:
    • Series of data structures defined in corresponding header file (stm32l4xx_ll_gpio.h)
    • Initialization functions for:
      • data structures (setting all data fields to default values) and
      • peripherals or their functional part (copying data from structure fields to physical registers of selected peripheral). All these functions are defined in related source files (i.e. stm32l4xx_ll_gpio.c) LL_GPIO_InitTypeDef GPIO_InitStruct; void GPIO_LL_configuration(void) { LL_AHB2_GRP1_EnableClock(LL_AHB2_GRP1_PERIPH_GPIOA); //enable clock to the GPIOA peripheral LL_GPIO_StructInit(&GPIO_InitStruct); GPIO_InitStruct.Pin= GPIO_PIN_1 | GPIO_PIN_4; //set pin 1 (ADC_IN6), 4 (DAC_OUT1) GPIO_InitStruct.Mode= LL_GPIO_MODE_ANALOG; //set GPIO as analog mode GPIO_InitStruct.Pull= LL_GPIO_PULL_NO; //no pull up or pull down LL_GPIO_Init(GPIOA,&GPIO_InitStruct); //initialize GPIOA, pins 1 and 4 }

What have we learnt?

Gain knowledge about complete ST software offer for STM32 microcontrollers Gain knowledge about Low Layer Library concepts: unitary and init Practice Low Layer Library concept on previously generated HAL based project Gain knowledge about differences between HAL and LL concepts.

Further reading 22

More information can be found in the following documents:

  • UM1860 - Getting started with STM32CubeL4 for STM32L4 Series, available on the web:

http://www.st.com/resource/en/user_manual/dm00157440.pdf

  • UM1884 - Description of STM32L4 HAL and Low-layer drivers, available on the web:

http://www.st.com/resource/en/user_manual/dm00173145.pdf

  • Doxygen based html manual: STM32L486xx_User_Manual.chm , available within STM32L4xx

Cube library in the path:

\STM32Cube_FW_L4_V1.5.0\Drivers\STM32L4xx_HAL_Driver\