Comparison and Analysis of Three Library Function Code Efficiency Based on STM32

Foreword

ST has introduced three library functions to facilitate rapid development of STM32 series MCUs. From the earliest standard peripheral driver libraries, to the later Cube HAL , to Cube LL and direct operation registers. What is the code efficiency of these libraries? This article will provide a rough analysis of this issue and provide comparative data for your reference.

problem analysis

We use the four common functions of GPIO flip, TIM PWM output, ADCDMA data acquisition and DMA M2M to achieve the same function through different library functions, and finally compare the performance of each library function. The contents of the four engineering codes are as follows:

GPIO Flip: Switches the output level of the GPIO, which contains the code for system clock initialization and GPIO flip. TIM PWM output: Through the channel 1 of TIM1, the output frequency is 36KHz PWM, and the duty cycle is modified from 25% to 50%, including the system clock initialization, TIM1 initialization and switching duty cycle code. ADC DMA Data Acquisition: The result of 100 ADC acquisitions is acquired through analog channel 1 of the ADC and transmitted to the user buffer using DMA, which contains code for system clock initialization, ADC initialization, and DMA initialization. DMA M2M: Use channel 1 of DMA1 to transfer 100 bytes of data from Flash to the on-chip SRAM. It contains the initialization of the system clock and the initialization code of the DMA.

Mainly compare three parameters: Flash footprint , SRAM footprint and efficiency of executing code .

The amount of Flash and SRAM can be seen by looking at the *.map file generated by IAR.

In the *.map file, there will be the content of the above picture, where the readonly code memory plus the readonly data memory sum is the Flash usage. The size of Readwrite data memory is the amount of SRAM occupied. Then the flash occupancy shown in the figure above is 3204=3174+30, and the SRAM occupancy is 1032. Since the user heap (Cstack) we set 1024, the amount of SRAM occupied by the real application code is 8=1032-1024.

The operational efficiency of the code is calculated by the number of core run cycles (CYCLECONTER) provided by IAR. Set the breakpoint at the beginning and end of the function function. The difference between the number of core run cycles is the run cycle of the code here.

The test hardware used the Nucleo-F302 evaluation board.

The software environment and library functions are as follows:

• IAR V7.60

• Optimizations Level High (Size)

• STM32CubeMX V4.17

• Create Project with Copy the necessary libraryfiles

• STM32CubeF3 V1.60

• STM32F30x_DSP_StdPeriph_Lib_V1.2.3

• STM32F3xx CMSIS V2.3.0

Test results are as follows: [click picture phone mode to Zoom]

Overall, the law of code efficiency is inversely proportional to code compatibility and portability. The efficiency of the Cube LL library is significantly better than that of the HAL library, which is almost the same as the efficiency of directly writing registers. The HAL library function is relatively large in size because it takes into account the high compatibility and portability of the code between the entire STM32 series. For those new to STM32, it's very easy to get started with basic evaluation and verification, and it's quick to get started. The emergence of the LL library is a powerful complement to the HAL library . Compared with HAL library users, LL library users need to have a more detailed understanding of the MCU and the corresponding external.

At present, STM32cubeMX not only supports the generation of initialization files based on HAL library , but also supports the initialization of LL library- based initialization files and projects. For developers who are already familiar with STM32 applications or pay attention to code efficiency, LL libraries can be preferred. .

By the way, under the graphical interface of STM32CubeMx, how to choose to use HAL library or LL library to generate initialization files and corresponding projects.

Under the CubeMx interface, after selecting and configuring each peripheral, you can select the type of library to use in Project\Project Setting\Advanced Settiing as shown below: HAL/LL.

In addition, occasionally people ask and where the LL library is, in fact, the LL library function is in the same directory as the HAL library function. To STM32F4 example, after you download STM32CubeF4 decompression, similar to the following directories can be seen in the HAL function and LL library file.

. . . \Drivers\STM32F4xx_HAL_Driver\Src


FPC Membrane Switch

CIXI MEMBRANE SWITCH FACTORY , https://www.cnjunma.com

Posted on