Objective
St has launched three library functions to facilitate rapid customer development of the STM32 series MCU. From the earliest standard peripheral driver library, to the later Cube HAL, to the cube ll and to the direct operation register. What is the code efficiency of these kinds of libraries? This paper will be a rough analysis of this problem, and provide comparative data for your reference.
Problem analysis
We use the four common functions of gpio flipping, TIM PWM output, ADCDMA data acquisition and DMA, which are used to achieve the same function through different library functions, and finally to compare the performance of each library function. The contents of the four engineering codes are summarized as follows:
Gpio rollover: Toggles the GPIO output level, which contains the system clock initialization and GPIO rollover code. TIM PWM output: Through the TIM1 Channel 1 output frequency is 36KHz PWM, cyclic modification of its duty cycle from 25% to 50%, which contains the system clock initialization, TIM1 initialization and switching duty cycle of the code. ADC DMA Data acquisition: The ADC's analog channel 1, the acquisition of 100 ADC results, and the use of DMA transfer to the user buffer, which contains the system clock initialization, ADC initialization and the initialization of the DMA code. DMA: Use DMA1 Channel 1 to transfer 100 bytes of data from flash to on-chip SRAM. This includes the initialization of the system clock and the initialization code of the DMA.
The main comparisons are three parameters: Flash footprint, SRAM occupancy, and execution code efficiency.
The consumption of flash and SRAM can be learned by looking at the *.map file generated by the IAR.
In the *.map file, it will be like the above image, wherein the ReadOnly code memory plus readonly data memory, and is the amount of flash. The size of the ReadWrite data memory is the amount of SRAM. The flash footprint shown in the figure above is 3204=3174+30,sram occupancy is 1032. Because of the user heap (Cstack) We set the 1024, so the actual application code occupies the SRAM amount of 8=1032-1024.
The operational efficiency portion of the code is calculated by the number of kernel runs (Cycleconter) provided by the IAR. At the beginning and end of the function function, the breakpoint is set, and the difference between the number of two cores running cycles is the running period of the code here.
The test hardware selects the nucleo-f302 evaluation board.
Details of 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
The test results are as follows: [Image in Phone mode can be viewed in larger view]
Overall, code efficiency and code compatibility and portability is inversely proportional to the law is obvious. The efficiency of the Cube ll library is significantly better than that of the HAL Library, almost as much as the direct write register. The HAL library function is relatively large due to the high compatibility and portability of the code across the STM32 series. For people who have just come into contact with STM32, it's easy to get started with basic assessment and validation. The advent of LL library is a powerful addition to the HAL Library. Compared to Hal library users, ll library users need to have a more detailed understanding of the MCU and the corresponding peripherals.
At present, Stm32cubemx not only supports the generation of initialization files based on the HAL Library, but also supports the initialization files and project generation based on the LL library, and for developers who are already more familiar with the STM32 application or focus on the efficiency of the Code, the LL library will be a priority.
By the way, in the graphical interface of STM32CUBEMX, how to choose to use HAL Library or ll library to generate initialization files and corresponding projects.
In the Cubemx interface, after the selection and configuration of the various peripherals, in Project\project setting\advanced settiing The following graphical interface, you can choose the type of library to use: Hal/ll.
In addition, occasionally people ask and where ll library, in fact, LL library function is in the same directory as the HAL library function. Take STM32F4 as an example, after you download STM32CUBEF4 decompression, you can see the HAL function and ll function library file in a directory similar to the following.
。。。 \drivers\stm32f4xx_hal_driver\src