stm32 ecosystem workshop
play

STM32 Ecosystem workshop T.O.M.A.S Team 2 We will continue a bit - PowerPoint PPT Presentation

STM32 Ecosystem workshop T.O.M.A.S Team 2 We will continue a bit more with software activities. Lets try to rewrite our L4_DAC_ADC application using Low Layer libraries. In this step we will create an empty STM32CubeMX template and


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

  2. 2 We will continue a bit more with software activities. • Let’s try to rewrite our L4_DAC_ADC application using Low Layer libraries. • In this step we will create an empty STM32CubeMX template and then, we will try to write complete application (except clock configuration) using only Low Layer library. Then we will compare the code size • We have two ways to complete this task: • Usage of unitary init functions requiring good knowledge of the peripherals (following reference manual configuration steps) • Usage init functions (similar method to Standard Peripherals Library) • Let’s try second option, then we can compare the code size of the projects • What would be the difference?

  3. Creating the L4_DAC_ADC project with full usage of LL library

  4. New project creation 4 • Open STM32CubeMX • Select New Project • Menu  File  New project • Select STM32L4 • STM32L4x6 • LQFP64 package • STM32L476RGTx • Do not select any peripherals (will be added manually in software)

  5. Template project generation 5 • Go to Clock Configuration Tab • Set clocks to 80MHz (based on 16MHz HSI*PLL) • Save project as LL_L4_DAC_ADC_Init • Generate the C project for SW4STM32 • Import new project into the SW4STM32 workspace used in previous exercises 80 HSI PLLCLK

  6. 6 • Generate the code with added new features • Open newly generated project in SW4STM32

  7. LL_L4_DAC_ADC_Init 7 using 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 footprint STM32 snippets LL Drivers

  8. Copy LL library files into the project 8 • From repository CubeMX  Menu  Help  Updater Settings get repository path (marked .\ below) • From .\STM32Cube_FW_L4_Vx.x.x\Drivers\STM32L4xx_HAL_Driver\src copy: stm32l4xx_ll_adc.c stm32l4xx_ll_dac.c stm32l4xx_ll_dma.c $PROJ_DIR\Drivers\STM32L4xx_HAL_Driver\Src\ stm32l4xx_ll_gpio.c stm32l4xx_ll_rcc.c stm32l4xx_ll_tim.c • From .\STM32Cube_FW_L4_Vx.x.x\Drivers\STM32L4xx_HAL_Driver\inc copy: stm32l4xx_ll_adc.h stm32l4xx_ll_bus.h stm32l4xx_ll_dac.h $PROJ_DIR\Drivers\STM32L4xx_HAL_Driver\Inc\ stm32l4xx_ll_dma.h stm32l4xx_ll_gpio.h stm32l4xx_ll_rcc.h stm32l4xx_ll_tim.h • Refresh (F5) the project source files – now, new files will become visible

  9. Project configuration 9 enable usage of init functions in Low Layer Library 1. Select project 2. Menu>Project>Properties>C/C++ Build>Settings 3. MCU GCC Compiler>Symbols Add … 4. 5. Define USE_FULL_LL_DRIVER to allow use of LL library 2 1 It will allow us to use the Init …() functions like in Standard Peripherals Library (SPL) 4 5 3

  10. Writing the code 10 LL_L4_DAC_ADC_Init project - tasks Within main.c file perform the following actions 1. Include necessary low layer header files. 2. Declare initialization structures for used peripherals and buffers for DAC and ADC. 3. Initialize peripherals one by one (mind to connect the clock to the peripheral first). 4. Start the peripheral using low layer functions. As a reference please use already copied header and source files for low layer part of the library.

  11. Replacing HAL functions with init LL 11 1 - LL_L4_DAC_ADC_Init project - includes • All used peripherals ( ppp ) need dedicated low layer header file stm32l4xx_ll_ppp.h • We have to include them in main.c file in USER CODE section. • There is a complete list of needed structures below. Please try to find and declare proper ones. /* USER CODE BEGIN Includes */ #include "stm32l4xx_ll_???.h" … … … … … … /* USER CODE END Includes */

  12. Replacing HAL functions with init LL 12 1 - LL_L4_DAC_ADC_Init project - includes • All used peripherals ( ppp ) need dedicated low layer header file stm32l4xx_ll_ppp.h • We have to include them in main.c file in USER CODE section. /* USER CODE BEGIN Includes */ #include "stm32l4xx_ll_adc.h" #include "stm32l4xx_ll_dac.h" #include "stm32l4xx_ll_dma.h" #include "stm32l4xx_ll_gpio.h" #include "stm32l4xx_ll_rcc.h" #include "stm32l4xx_ll_tim.h" #include "stm32l4xx_ll_bus.h" /* USER CODE END Includes */

  13. Replacing HAL functions with init LL 2 - LL_L4_DAC_ADC_Init project – structures declaration 13 • Each peripheral needs its own initialization structure ( PPP_InitStruct ) • Some of the peripherals (i.e. timers, ADC, …) need additional one for configuration one of the modes they should be configured in (i.e. Output Capture, Input Capture for timers etc.). • There is a complete list of needed structures below. Please try to find and declare proper ones. /* USER CODE BEGIN PV */ /* Private variables ---------------------------------------------------------*/ LL_GPIO_InitTypeDef GPIO_InitStruct; //GPIO init structure LL_TIM_InitTypeDef TIM2_InitStruct; //TIM2 init structure LL_TIM_OC_InitTypeDef TIM2_OCInitStruct; //TIM2 OC init structure LL_DAC_InitTypeDef DAC_InitStruct; //DAC init structure LL_ADC_InitTypeDef ADC_InitStruct; //ADC init structure LL_ADC_CommonInitTypeDef ADC_ComInitStruct; //ADC common init structure LL_ADC_REG_InitTypeDef ADC_RegInitStruct; //ADC regular conversion init structure LL_DMA_InitTypeDef DMA_DAC_InitStruct; //DMA init structure LL_DMA_InitTypeDef DMA_ADC_InitStruct; //DMA init structure /* USER CODE END PV */

  14. Replacing HAL functions with init LL 2 - LL_L4_DAC_ADC_Init project – structures declaration 14 • Each peripheral needs its own initialization structure ( PPP_InitStruct ) • Some of the peripherals (i.e. timers, ADC, …) need additional one for configuration one of the modes they should be configured in (i.e. Output Capture, Input Capture for timers etc.). • There is a complete list of needed structures below. Please try to find and declare proper ones. /* USER CODE BEGIN PV */ /* Private variables ---------------------------------------------------------*/ LL_GPIO_InitTypeDef GPIO_InitStruct; //GPIO init structure LL_TIM_InitTypeDef TIM2_InitStruct; //TIM2 init structure LL_TIM_OC_InitTypeDef TIM2_OCInitStruct; //TIM2 OC init structure LL_DAC_InitTypeDef DAC_InitStruct; //DAC init structure LL_ADC_InitTypeDef ADC_InitStruct; //ADC init structure LL_ADC_CommonInitTypeDef ADC_ComInitStruct; //ADC common init structure LL_ADC_REG_InitTypeDef ADC_RegInitStruct; //ADC regular conversion init structure LL_DMA_InitTypeDef DMA_DAC_InitStruct; //DMA init structure LL_DMA_InitTypeDef DMA_ADC_InitStruct; //DMA init structure /* USER CODE END PV */

  15. Replacing HAL functions with init LL 2 - LL_L4_DAC_ADC_Init project – data buffers declaration 15 • It is necessary to define the source buffer for DAC ( dacbuf[] ) and destination buffer for ADC to store the measured data ( adcbuf[] ). Size for both can be 32 . /* USER CODE BEGIN PV */ /* Private variables ---------------------------------------------------------*/ #define ADCBUFSIZE 32 #define DACBUFSIZE 32 const uint16_t dacbuf[DACBUFSIZE] = { 2047, 2447, 2831, 3185, 3498, 3750, 3939, 4056, 4095, 4056, 3939, 3750, 3495, 3185, 2831, 2447, 2047, 1647, 1263, 909, 599, 344, 155, 38, 0, 38, 155, 344, 599, 909, 1263, 1647}; uint32_t adcbuf[ADCBUFSIZE]; /* USER CODE END PV */

  16. Replacing HAL functions with init LL 2 - LL_L4_DAC_ADC_Init project – data buffers declaration 16 • It is necessary to define the source buffer for DAC ( dacbuf[] ) and destination buffer for ADC to store the measured data ( adcbuf[] ). Size for both can be 32 . /* USER CODE BEGIN PV */ /* Private variables ---------------------------------------------------------*/ #define ADCBUFSIZE 32 #define DACBUFSIZE 32 const uint16_t dacbuf[DACBUFSIZE] = { 2047, 2447, 2831, 3185, 3498, 3750, 3939, 4056, 4095, 4056, 3939, 3750, 3495, 3185, 2831, 2447, 2047, 1647, 1263, 909, 599, 344, 155, 38, 0, 38, 155, 344, 599, 909, 1263, 1647}; uint16_t adcbuf[ADCBUFSIZE]; /* USER CODE END PV */

  17. Replacing HAL functions with init LL 3 - LL_L4_DAC_ADC_Init project – GPIO configuration 17 The task is to configure 2 analog pins (PA1 – ADC1 Channel6 and PA4 – DAC output1) 1. Before PPP configuration it is necessary to connect the clock to the PPP peripheral. To do this we can use there dedicated macro: __HAL_RCC_PPP_CLK_ENABLE() 2. Initialize PPP init structure with default values using LL_PPP_StructInit() 3. Fill PPP init structure with required configuration parameters 4. Copy structure fields into PPP (GPIO in this case) registers using LL_PPP_Init() function (like in Standard Peripherals Library or in HAL library) 5. Connect GPIO analog switch to ADC input using LL_GPIO_EnablePinAnalogControl() function /* USER CODE BEGIN 2 */ /* GPIO LL configuration */ __HAL_RCC_GPIOA_CLK_ENABLE(); //enable clock to the GPIOA peripheral LL_GPIO_StructInit(&GPIO_InitStruct); //structure initialization to default values 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

Download Presentation
Download Policy: The content available on the website is offered to you 'AS IS' for your personal information and use only. It cannot be commercialized, licensed, or distributed on other websites without prior consent from the author. To download a presentation, simply click this link. If you encounter any difficulties during the download process, it's possible that the publisher has removed the file from their server.

Recommend


More recommend