stm32 ecosystem workshop
play

STM32 Ecosystem workshop T.O.M.A.S Team 2 Now it is a right time - PowerPoint PPT Presentation

STM32 Ecosystem workshop T.O.M.A.S Team 2 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 Goal of this part 4 Gain knowledge about


  1. STM32 Ecosystem workshop T.O.M.A.S Team

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

  3. Goal of this part 4  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.

  4. Low Layer Library concept and usage

  5. HAL and LL libraries coexistence 6 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.

  6. HAL and LL libraries coexistence 7 mixing HAL operation APIs with the LL • The HAL I/O operations APIs are generally given in three models: • Blocking model (Polling) • Interrupt Model (IT) • DMA model • If API of any of the HAL models gets replaced by the LL, it is not necessary to replace other models API. • For DMA and IT API models - when customized by the LL, the HAL associated callbacks cannot be used for the addressed instance anymore. • The processes customized should avoid dependencies with other processes ex: customize Transmit APIs with the LL and keep the Receive with the HAL

  7. LL drivers scope 8 • Common services (portability) • High level state machine based processes HAL Init Drivers • Init services functions Standard peripheral • Hardware basic services library • Atomic register access Unitary • Compliancy with the HAL drivers functions • Low memory footprint STM32 snippets LL Drivers

  8. LL library - introduction 9 • 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 Application • LL library is offering the following services: LL • 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. stm32yyxx_ll_ppp.c stm32yyxx_ll_ppp.h • 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) stm32yynnnxx.h stm32yyxx.h

  9. Role of some LL header files 10 • Most of ppp peripherals have their own pairs of stm32xxxx_ll_ppp.c and .h files • Some peripherals and buses are grouped within .c / .h files described below: .h file Serviced peripherals • stm32xxxx_ll_bus.h APB1, APB2, IOP, AHB registers • stm32xxxx_ll_cortex.h SYSTICK registers • Low power mode configuration (SCB register of Cortex-MCU) • MPU API • API to access to MCU info (CPUID register) • stm32xxxx_ll_system.h Some of the FLASH features (accelerator, latency, power down modes) • DBGCMU registers • SYSCFG registers (including remap and EXTI) • stm32xxxx_ll_utils.h Device electronic signature • Timing functions • PLL configuration functions

  10. Low Layer library 11 naming convention return_value LL_PPP_Operation () PPP – Type of the operation LL prefix peripheral on the peripheral, much indicating type name. more detailed like in of the library (in HAL , i.e. “ SetPinMode ” contrary to or “ EnableDMAReq ” Hardware Abstraction Layer (HAL) libraries Hint: to find proper function for the peripheral, please type LL_PPP_ and press Ctrl+Space

  11. LL drivers scope 12 unitary functions • Common services (portability) • High level state machine based processes HAL Init Drivers • Init services functions Standard peripheral • Hardware basic services library • Atomic register access Unitary • Compliancy with the HAL drivers functions • Low memory footprint STM32 snippets LL Drivers

  12. Unitary LL drivers APIs 13 Each LL peripheral driver provides the following three APIs levels: • Low level : Basic registers write and read LL_PPP_WriteReg(I2C1,CR1,0x20001000); LL_PPP_ReadReg (I2C1,CR1); • Middle level : one-shot operation APIs (atomic) with elementary LL_PPP_SetItem() and LL_PPP_Action() functions: set directly one bit field in register for a single feature LL_ADC_Enable(); LL_TIM_EnableCounter(TIM_TypeDef * TIMx); LL_TIM_SetAutoReload(TIM_TypeDef * TIMx, uint32_t AutoReload); stm32yyxx_ll_ppp.h • High level : global configuration and initialization functions that cover full standalone operations on related peripheral registers LL_RCC_PLL_ConfigDomain_SYS(LL_RCC_PLLSOURCE_HSI, LL_RCC_PLLM_DIV_1, 10, LL_RCC_PLLR_DIV_2); LL_DAC_SetTriggerSource(DAC1, LL_DAC_CHANNEL_1, LL_DAC_TRIG_EXT_TIM2_TRGO); LL_TIM_OC_SetMode(TIM2, LL_TIM_CHANNEL_CH2, LL_TIM_OCMODE_TOGGLE);

  13. Unitary LL Typical Usage 14 The LL services have to be called following the programming model of the reference manual document by calling the elementary LL drivers services Ex : System Clock Configuration Ex : Use GPIO to toggle LED continuously

  14. DMA Init Example 15 using HAL DMA Driver

  15. DMA Init Example 16 using LL DMA Driver

  16. LL drivers scope 17 init functions • Common services (portability) • High level state machine based processes HAL Init Drivers • Init services functions Standard peripheral • Hardware basic services library • Atomic register access Unitary • Compliancy with the HAL drivers functions • Low memory footprint STM32 snippets LL Drivers

  17. Init functions LL drivers APIs 18 • 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; stm32yyxx_ll_gpio.h 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) stm32yyxx_ll_gpio.c 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 }

  18. LL library - init functions 19 architecture • The init LL functions are considered as complementary services to the LL unitary ones and the HAL. HAL Init LL functionsAPIs (.c) LL unitary services (.h) • There are no init LL functions for Core, PWR and system drivers, they are provided in header file only. • Usage of init functions requires: • Definition of USE_FULL_LL_DRIVER in the user code • Inclusion all LL library .c files for each used ppp peripheral (i.e. stm32l4xx_ll_gpio.c )

  19. What have we learnt? 21  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.

  20. 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\

  21. Enjoy! /STM32 @ST_World st.com/e2e www.st.com/mcu

Recommend


More recommend