UM0585
User manual
STM32F10x
DSP library
Introduction
This user manual describes the STM32F10x DSP (digital signal processing) library, which is
a suite of common digital signal processing functions:
●
●
●
PID controller
Fast Fourier transform
FIR and IIR filters
The library contains C and assembly functions. The assembly code is ported on ARM
®
,
GCC and IAR Systems™ assemblers.
June 2010
Doc ID 14988 Rev 2
1/25
www.st.com
Contents
UM0585
Contents
1
2
DSP Library description . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6
PID controller . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7
2.1
2.2
Description . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7
DSP library functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7
2.2.1
2.2.2
2.2.3
DoPID
function . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7
DoFullPID
function . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8
PID_stm32
function . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8
3
Complex 16-bit radix-4 FFT . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10
3.1
3.2
Description . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10
DSP library functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10
3.2.1
3.2.2
3.2.3
cr4_fft_64_stm32
function . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10
cr4_fft_256_stm32
function . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11
cr4_fft_1024_stm32
function . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11
3.3
FFT performance improvement . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11
4
16-bit FIR filter . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13
4.1
4.2
Description . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13
DSP library function . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13
4.2.1
fir_16by16_stm32
function . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14
5
16-bit IIR filters . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15
5.1
5.2
Description . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15
DSP library functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16
5.2.1
5.2.2
iiarma_stm32
function . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16
iir_biquad_stm32
function . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17
6
STM32F10x DSP library benchmark . . . . . . . . . . . . . . . . . . . . . . . . . . . 19
6.1
6.2
Function code footprint . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19
Function execution time . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19
6.2.1
6.2.2
6.2.3
PID controller . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19
Fast Fourier transform (FFT) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20
FIR filter . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20
Doc ID 14988 Rev 2
2/25
UM0585
6.2.4
Contents
IIR filters . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21
7
8
9
STM32F10x DSP demo description . . . . . . . . . . . . . . . . . . . . . . . . . . . . 22
Conclusion . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 23
Revision history . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24
Doc ID 14988 Rev 2
3/25
List of tables
UM0585
List of tables
Table 1.
Table 2.
Table 3.
Table 4.
Table 5.
Table 6.
Table 7.
Table 8.
Table 9.
Table 10.
Table 11.
Table 12.
Table 13.
Table 14.
Table 15.
Table 16.
Table 17.
Table 18.
Table 19.
STM32F10x DSP library functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6
DoPID
function . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7
DoFullPID
function. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8
PID_stm32
function. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8
cr4_fft_64_stm32
function . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10
cr4_fft_256_stm32
function . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11
cr4_fft_1024_stm32
function . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11
fir_16by16_stm32
function . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14
iirarma_stm32
function . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16
iir_biquad_stm32
function . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17
STM32F10x DSP library functions code footprint . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19
PID controller, error computed outside the routine . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19
PID controller, error computed within the routine . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20
Complex radix 4, 16-bit FFT, coefficients in Flash memory . . . . . . . . . . . . . . . . . . . . . . . . 20
Complex radix 4, 16-bit FFT, coefficients in RAM. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20
16-bit, 32-tap FIR filter . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20
16-bit canonic form, 4 biquad IIR filter . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21
16-bit, 4
th
-order IIR filter . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21
Document revision history . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24
4/25
Doc ID 14988 Rev 2
UM0585
List of figures
List of figures
Figure 1.
Figure 2.
Figure 3.
Figure 4.
Figure 5.
Block diagram of PID controller . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7
Block diagram of an FIR filter of length N . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13
Block diagram of the direct form I of second-order IIR filter . . . . . . . . . . . . . . . . . . . . . . . . 15
Block diagram of the canonical form of a second-order IIR filter . . . . . . . . . . . . . . . . . . . . 16
FFT of a sine wave with frequency f
1
and of a dual sine wave with
frequencies f
1
and f
2
, both sampled at a frequency F
s
. . . . . . . . . . . . . . . . . . . . . . . . . . . . 22
Doc ID 14988 Rev 2
5/25