In ARM microcontroller development, there is a DSP function library provided by CMSIS. This library includes basic data functions, fast mathematical operations, complex operations, filters, matrices, transforms, click control, statistics, support functions, and interpolation functions, covering most algorithms used in engineering applications.
Now, I have a question: how much speed improvement can be achieved by using the DSP functions in CMSIS compared to the functions in a regular math library? Let’s compare the speed of square root operations and sine trigonometric functions. This will help in choosing different mathematical libraries for various scenarios in the future.

The test hardware platform is the STM32F103 microcontroller that I built yesterday. This is an ARM microcontroller with an M3 core, which is relatively simple and popular, so let’s check its mathematical computation speed. A port is used to output high and low levels to indicate the time required for the calculations.

To use the DSP database, you need to select CMSIS DSP in the library settings of the General options in the IAR development environment. Just include the arm math header file in your program. In the main loop of the test program, the normal sine trigonometric function is calculated, and the LED output pin is set high and low to indicate the calculation time. After a 1ms interval, the sine function from the DSP library is executed, also using the LED pin to indicate execution time. The differences in execution speeds of the two functions can be intuitively compared using an oscilloscope.

Using the oscilloscope to measure the waveform of the LED pin, we can see the two pulse signals. The first signal corresponds to the sine function from the regular math library, which takes longer, while the second signal corresponds to the sine function from the DSP library, which is noticeably shorter. This indicates that the efficiency of using the DSP math library is very high for microcontrollers with the M3 core. It should be noted that the microcontroller’s system clock is at 64MHz. To compare the execution times of the two math libraries more accurately, we expand the waveform. Using the cursor measurement function of the oscilloscope, we measure the pulse width. The normal sine function takes 41.7 microseconds, while the DSP sine function takes only 10 microseconds, indicating that the DSP algorithm library is about four times faster than the regular math function for sine calculations.

● Sine Operation Comparison: math
: 41.7us DSP
: 10us
▲ Figure 1.3.1 Comparison of Sine Function Execution Speed Between Regular Math Library and DSP Library

● Square Root Operation Comparison: math
: 12.52us DSP
: 4.9us
▲ Figure 1.3.2 Difference in Execution Speed of Square Root Algorithm Functions

▲ Figure 1.3.3 Bit-Shifting Operation
● Bit Shift Comparison: C
: 24us DSP
: 16.65us
※ Conclusion ※
This article compared the execution speeds of some functions in the CMSIS DSP math library, all of which showed improvements over the speeds of functions in the regular C language and math library. The trigonometric functions improved by about four times, while the regular bit-shifting operations improved by about one-third.

<<< STM32 Project Collection >>>
<<< Raspberry Pi Project Collection >>>
<<< ESP32 Project Collection >>>
<<< ESP8266 Project Collection >>>
<<< Arduino Project Collection >>>
<<< Darwin Project Sharing Series >>>
