NXP GDFLIB User Manual

GDFLIB User's Guide
ARM® Cortex® M7F
Document Number: CM7FGDFLIBUG
Rev. 4, 12/2020
GDFLIB User's Guide, Rev. 4, 12/2020
2 NXP Semiconductors
Contents
Section number Title Page
Library
1.1 Introduction.................................................................................................................................................................... 5
1.2 Library integration into project (MCUXpresso IDE) ....................................................................................................8
1.3 Library integration into project (Keil µVision) ............................................................................................................. 16
1.4 Library integration into project (IAR Embedded Workbench) ..................................................................................... 24
Algorithms in detail
2.1 GDFLIB_FilterExp.........................................................................................................................................................33
2.2 GDFLIB_FilterIIR1........................................................................................................................................................37
2.3 GDFLIB_FilterIIR2........................................................................................................................................................42
2.4 GDFLIB_FilterIIR3........................................................................................................................................................49
2.5 GDFLIB_FilterIIR4........................................................................................................................................................55
2.6 GDFLIB_FilterMA.........................................................................................................................................................62
GDFLIB User's Guide, Rev. 4, 12/2020
NXP Semiconductors 3
GDFLIB User's Guide, Rev. 4, 12/2020
4 NXP Semiconductors
Chapter 1 Library

1.1 Introduction

1.1.1 Overview

This user's guide describes the General Digital Filters Library (GDFLIB) for the family of ARM Cortex M7F core-based microcontrollers. This library contains optimized functions.
1.1.2
GDFLIB supports several data types: (un)signed integer, fractional, and accumulator, and floating point. The integer data types are useful for general-purpose computation; they are familiar to the MPU and MCU programmers. The fractional data types enable powerful numeric and digital-signal-processing algorithms to be implemented. The accumulator data type is a combination of both; that means it has the integer and fractional portions.The floating-point data types are capable of storing real numbers in wide dynamic ranges. The type is represented by binary digits and an exponent. The exponent allows scaling the numbers from extremely small to extremely big numbers. Because the exponent takes part of the type, the overall resolution of the number is reduced when compared to the fixed-point type of the same size.
The following list shows the integer types defined in the libraries:
Unsigned 16-bit integer —<0 ; 65535> with the minimum resolution of 1
Signed 16-bit integer —<-32768 ; 32767> with the minimum resolution of 1
Signed 32-bit integer —<-2147483648 ; 2147483647> with the minimum resolution

Data types

of 1
GDFLIB User's Guide, Rev. 4, 12/2020
NXP Semiconductors 5
Introduction
The following list shows the fractional types defined in the libraries:
Fixed-point 16-bit fractional —<-1 ; 1 - 2
Fixed-point 32-bit fractional —<-1 ; 1 - 2
-15
> with the minimum resolution of 2
-31
> with the minimum resolution of 2
-15
-31
The following list shows the accumulator types defined in the libraries:
Fixed-point 16-bit accumulator —<-256.0 ; 256.0 - 2-7> with the minimum resolution of 2
Fixed-point 32-bit accumulator —<-65536.0 ; 65536.0 - 2 resolution of 2
-7
-15
-15
> with the minimum
The following list shows the floating-point types defined in the libraries:
Floating point 32-bit single precision —<-3.40282 · 1038 ; 3.40282 · 1038> with the minimum resolution of 2
1.1.3

API definition

-23
GDFLIB uses the types mentioned in the previous section. To enable simple usage of the algorithms, their names use set prefixes and postfixes to distinguish the functions' versions. See the following example:
f32Result = MLIB_Mac_F32lss(f32Accum, f16Mult1, f16Mult2);
where the function is compiled from four parts:
• MLIB—this is the library prefix
• Mac—the function name—Multiply-Accumulate
• F32—the function output type
• lss—the types of the function inputs; if all the inputs have the same type as the output, the inputs are not marked
The input and output types are described in the following table:
Table 1-1. Input/output types
Type Output Input
frac16_t F16 s frac32_t F32 l acc32_t A32 a
float_t FLT f
GDFLIB User's Guide, Rev. 4, 12/2020
6 NXP Semiconductors
Chapter 1 Library

1.1.4 Supported compilers

GDFLIB for the ARM Cortex M7F core is written in C language or assembly language with C-callable interface depending on the specific function. The library is built and tested using the following compilers:
• MCUXpresso IDE
• IAR Embedded Workbench
• Keil µVision
For the MCUXpresso IDE, the library is delivered in the gdflib.a file. For the Kinetis Design Studio, the library is delivered in the gdflib.a file. For the IAR Embedded Workbench, the library is delivered in the gdflib.a file. For the Keil µVision, the library is delivered in the gdflib.lib file. The interfaces to the algorithms included in this library are combined into a single public
interface include file, gdflib.h. This is done to lower the number of files required to be included in your application.
1.1.5

Library configuration

GDFLIB for the ARM Cortex M7F core is written in C language or assembly language with C-callable interface depending on the specific function. Some functions from this library are inline type, which are compiled together with project using this library. The optimization level for inline function is usually defined by the specific compiler setting. It can cause an issue especially when high optimization level is set. Therefore the optimization level for all inline assembly written functions is defined by compiler pragmas using macros. The configuration header file RTCESL_cfg.h is located in: specific library folder\MLIB\Include. The optimization level can be changed by modifying the macro value for specific compiler. In case of any change the library functionality is not guaranteed.
Similarly as optimization level the High-speed functions execution suppport can be enable by defined symbol RAM_OPTIM_LOW (RAM_OPTIM_MEDIUM or RAM_OPTIM_HIGH) or disable by not defining any of these macrors. symbol RTCESL_MMDVSQ_OFF in project setting described in the High-speed functions execution suppport cheaper for specific compiler.
GDFLIB User's Guide, Rev. 4, 12/2020
NXP Semiconductors 7

Library integration into project (MCUXpresso IDE)

1.1.6 Special issues
1. The equations describing the algorithms are symbolic. If there is positive 1, the number is the closest number to 1 that the resolution of the used fractional type allows. If there are maximum or minimum values mentioned, check the range allowed by the type of the particular function version.
2. The library functions that round the result (the API contains Rnd) round to nearest (half up).
1.2 Library integration into project (MCUXpresso IDE)
This section provides a step-by-step guide on how to quickly and easily include GDFLIB into any MCUXpresso SDK example or demo application projects using MCUXpresso IDE. This example uses the default installation path (C:\NXP\RTCESL \CM7F_RTCESL_4.6_MCUX). If you have a different installation path, use that path instead.
1.2.1

High-speed functions execution suppport

Some RT (or other) platforms contain high-speed functions execution support by relocating all functions from the default Flash memory location to the RAM location for much faster code access. The feature is important especially for devices with a slow Flash interface. This section shows how to turn the RAM optimization feature support on and off.
1. In the MCUXpresso SDK project name node or on the left-hand side, click Properties or select Project > Properties from the menu. A project properties dialog appears.
2. Expand the C/C++ Build node and select Settings. See Figure 1-1.
3. On the right-hand side, under the MCU C Compiler node, click the Preprocessor node. See Figure 1-1.
GDFLIB User's Guide, Rev. 4, 12/2020
8 NXP Semiconductors
Chapter 1 Library
Figure 1-1. Defined symbols
4. On the right-hand side of the dialog, click the Add... icon located next to the Defined symbols (-D) title.
5. In the dialog that appears (see Figure 1-2), type the following:
RAM_RELOCATION — to turn the RAM optimization feature support on
If the define is defined, all RTCEL functions are put to the RAM.
Figure 1-2. Symbol definition
6. Click OK in the dialog.
7. Click OK in the main dialog.
The device reference manual shows how the__RAMFUNC(RAM) atribute works in connection with your device.
GDFLIB User's Guide, Rev. 4, 12/2020
NXP Semiconductors 9
Library integration into project (MCUXpresso IDE)
1.2.2 Library path variable
To make the library integration easier, create a variable that holds the information about the library path.
1. Right-click the MCUXpresso SDK project name node in the left-hand part and click Properties, or select Project > Properties from the menu. A project properties dialog appears.
2. Expand the Resource node and click Linked Resources. See Figure 1-3.
Figure 1-3. Project properties
3. Click the New… button in the right-hand side.
4. In the dialog that appears (see Figure 1-4), type this variable name into the Name box: RTCESL_LOC.
5. Select the library parent folder by clicking Folder…, or just type the following path into the Location box: C:\NXP\RTCESL\CM7F_RTCESL_4.6_MCUX. Click OK.
GDFLIB User's Guide, Rev. 4, 12/2020
10 NXP Semiconductors
Chapter 1 Library
Figure 1-4. New variable
6. Create such variable for the environment. Expand the C/C++ Build node and click Environment.
7. Click the Add… button in the right-hand side.
8. In the dialog that appears (see Figure 1-5), type this variable name into the Name box: RTCESL_LOC.
9. Type the library parent folder path into the Value box: C:\NXP\RTCESL \CM7F_RTCESL_4.6_MCUX.
10. Tick the Add to all configurations box to use this variable in all configurations. See
Figure 1-5.
11. Click OK.
12. In the previous dialog, click OK.
GDFLIB User's Guide, Rev. 4, 12/2020
NXP Semiconductors 11
Library integration into project (MCUXpresso IDE)
Figure 1-5. Environment variable
1.2.3

Library folder addition

To use the library, add it into the Project tree dialog.
1. Right-click the MCUXpresso SDK project name node in the left-hand part and click New > Folder, or select File > New > Folder from the menu. A dialog appears.
2. Click Advanced to show the advanced options.
3. To link the library source, select the Link to alternate location (Linked Folder) option.
4. Click Variables..., select the RTCESL_LOC variable in the dialog, click OK, and/or type the variable name into the box. See Figure 1-6.
5. Click Finish, and the library folder is linked in the project. See Figure 1-7.
GDFLIB User's Guide, Rev. 4, 12/2020
12 NXP Semiconductors
Chapter 1 Library
Figure 1-6. Folder link
Figure 1-7. Projects libraries paths
1.2.4

Library path setup

GDFLIB requires MLIB to be included too. These steps show how to include all dependent modules:
1. Right-click the MCUXpresso SDK project name node in the left-hand part and click Properties, or select Project > Properties from the menu. The project properties dialog appears.
2. Expand the C/C++ General node, and click Paths and Symbols.
3. In the right-hand dialog, select the Library Paths tab. See Figure 1-9.
4. Click the Add… button on the right, and a dialog appears.
GDFLIB User's Guide, Rev. 4, 12/2020
NXP Semiconductors 13
Library integration into project (MCUXpresso IDE)
5. Look for the RTCESL_LOC variable by clicking Variables…, and then finish the path in the box by adding the following (see Figure 1-8): ${RTCESL_LOC}\MLIB.
6. Click OK, and then click the Add… button.
7. Look for the RTCESL_LOC variable by clicking Variables…, and then finish the path in the box by adding the following: ${RTCESL_LOC}\GDFLIB.
8. Click OK, you will see the paths added into the list. See Figure 1-9.
Figure 1-8. Library path inclusion
Figure 1-9. Library paths
9. After adding the library paths, add the library files. Click the Libraries tab. See
Figure 1-11.
10. Click the Add… button on the right, and a dialog appears.
11. Type the following into the File text box (see Figure 1-10): :mlib.a
12. Click OK, and then click the Add… button.
13. Type the following into the File text box: :gdflib.a
14. Click OK, and you will see the libraries added in the list. See Figure 1-11.
GDFLIB User's Guide, Rev. 4, 12/2020
14 NXP Semiconductors
Chapter 1 Library
Figure 1-10. Library file inclusion
Figure 1-11. Libraries
15. In the right-hand dialog, select the Includes tab, and click GNU C in the Languages list. See Figure 1-13.
16. Click the Add… button on the right, and a dialog appears. See Figure 1-12.
17. Look for the RTCESL_LOC variable by clicking Variables…, and then finish the path in the box to be: ${RTCESL_LOC}\MLIB\Include
18. Click OK, and then click the Add… button.
19. Look for the RTCESL_LOC variable by clicking Variables…, and then finish the path in the box to be: ${RTCESL_LOC}\GDFLIB\Include
20. Click OK, and you will see the paths added in the list. See Figure 1-13. Click OK.
Figure 1-12. Library include path addition
GDFLIB User's Guide, Rev. 4, 12/2020
NXP Semiconductors 15

Library integration into project (Keil µVision)

Figure 1-13. Compiler setting
Type the #include syntax into the code where you want to call the library functions. In the left-hand dialog, open the required .c file. After the file opens, include the following lines into the #include section:
#include "mlib_FP.h" #include "gdflib_FP.h"
When you click the Build icon (hammer), the project is compiled without errors.
1.3
Library integration into project (Keil µVision)
This section provides a step-by-step guide on how to quickly and easily include GDFLIB into an empty project or any MCUXpresso SDK example or demo application projects using Keil µVision. This example uses the default installation path (C:\NXP\RTCESL \CM7F_RTCESL_4.6_KEIL). If you have a different installation path, use that path instead. If any MCUXpresso SDK project is intended to use (for example hello_world project) go to Linking the files into the project chapter otherwise read next chapter.
GDFLIB User's Guide, Rev. 4, 12/2020
16 NXP Semiconductors
Chapter 1 Library
1.3.1 NXP pack installation for new project (without MCUXpresso
SDK)
This example uses the NXP MKV58F1M0xxx22 part, and the default installation path (C:\NXP\RTCESL\CM7F_RTCESL_4.6_KEIL) is supposed. If the compiler has never been used to create any NXP MCU-based projects before, check whether the NXP MCU pack for the particular device is installed. Follow these steps:
1. Launch Keil µVision.
2. In the main menu, go to Project > Manage > Pack Installer….
3. In the left-hand dialog (under the Devices tab), expand the All Devices > Freescale (NXP) node.
4. Look for a line called "KVxx Series" and click it.
5. In the right-hand dialog (under the Packs tab), expand the Device Specific node.
6. Look for a node called "Keil::Kinetis_KVxx_DFP." If there are the Install or Update options, click the button to install/update the package. See Figure 1-14.
7. When installed, the button has the "Up to date" title. Now close the Pack Installer.
Figure 1-14. Pack Installer
1.3.2

New project (without MCUXpresso SDK)

To start working on an application, create a new project. If the project already exists and is opened, skip to the next section. Follow these steps to create a new project:
1. Launch Keil µVision.
GDFLIB User's Guide, Rev. 4, 12/2020
NXP Semiconductors 17
Library integration into project (Keil µVision)
2. In the main menu, select Project > New µVision Project…, and the Create New Project dialog appears.
3. Navigate to the folder where you want to create the project, for example C: \KeilProjects\MyProject01. Type the name of the project, for example MyProject01. Click Save. See Figure 1-15.
Figure 1-15. Create New Project dialog
4. In the next dialog, select the Software Packs in the very first box.
5. Type '' into the Search box, so that the device list is reduced to the devices.
6. Expand the node.
7. Click the MKV58F1M0xxx22 node, and then click OK. See Figure 1-16.
Figure 1-16. Select Device dialog
8. In the next dialog, expand the Device node, and tick the box next to the Startup node. See Figure 1-17.
9. Expand the CMSIS node, and tick the box next to the CORE node.
GDFLIB User's Guide, Rev. 4, 12/2020
18 NXP Semiconductors
Chapter 1 Library
Figure 1-17. Manage Run-Time Environment dialog
10. Click OK, and a new project is created. The new project is now visible in the left­hand part of Keil µVision. See Figure 1-18.
Figure 1-18. Project
11. In the main menu, go to Project > Options for Target 'Target1'…, and a dialog appears.
12. Select the Target tab.
13. Select Use Single Precision in the Floating Point Hardware option. See Figure 1-18.
GDFLIB User's Guide, Rev. 4, 12/2020
NXP Semiconductors 19
Library integration into project (Keil µVision)
Figure 1-19. FPU

1.3.3 High-speed functions execution support

Some RT (or other) platforms contain high-speed functions execution support by relocating all functions from the default Flash memory location to the RAM location for much faster code access. The feature is important especially for devices with a slow Flash interface. This section shows how to turn the RAM optimization feature support on and off.
1. In the main menu, go to Project > Options for Target 'Target1'…, and a dialog appears.
2. Select the C/C++ tab. See .
3. In the Include Preprocessor Symbols text box, type the following:
RAM_RELOCATION — to turn the RAM optimization feature support on
If the define is defined, all RTCEL functions are put to the RAM.
Figure 1-20. Preprocessor symbols
4. Click OK in the main dialog.
GDFLIB User's Guide, Rev. 4, 12/2020
20 NXP Semiconductors
Chapter 1 Library
The device reference manual shows how the__attribute__ ((section ("ram"))) atribute works in connection with your device.

1.3.4 Linking the files into the project

GDFLIB requires MLIB to be included too. The following steps show how to include all dependent modules.
To include the library files in the project, create groups and add them.
1. Right-click the Target 1 node in the left-hand part of the Project tree, and select Add Group… from the menu. A new group with the name New Group is added.
2. Click the newly created group, and press F2 to rename it to RTCESL.
3. Right-click the RTCESL node, and select Add Existing Files to Group 'RTCESL'… from the menu.
4. Navigate into the library installation folder C:\NXP\RTCESL \CM7F_RTCESL_4.6_KEIL\MLIB\Include, and select the mlib_FP.h file. If the file does not appear, set the Files of type filter to Text file. Click Add. See Figure 1-21.
Figure 1-21. Adding .h files dialog
5. Navigate to the parent folder C:\NXP\RTCESL\CM7F_RTCESL_4.6_KEIL\MLIB, and select the mlib.lib file. If the file does not appear, set the Files of type filter to Library file. Click Add. See Figure 1-22.
GDFLIB User's Guide, Rev. 4, 12/2020
NXP Semiconductors 21
Library integration into project (Keil µVision)
Figure 1-22. Adding .lib files dialog
6. Navigate into the library installation folder C:\NXP\RTCESL \CM7F_RTCESL_4.6_KEIL\GDFLIB\Include, and select the gdflib_FP.h file. If the file does not appear, set the Files of type filter to Text file. Click Add.
7. Navigate to the parent folder C:\NXP\RTCESL\CM7F_RTCESL_4.6_KEIL \GDFLIB, and select the gdflib.lib file. If the file does not appear, set the Files of type filter to Library file. Click Add.
8. Now, all necessary files are in the project tree; see Figure 1-23. Click Close.
Figure 1-23. Project workspace
1.3.5

Library path setup

The following steps show the inclusion of all dependent modules.
1. In the main menu, go to Project > Options for Target 'Target1'…, and a dialog appears.
2. Select the C/C++ tab. See Figure 1-24.
GDFLIB User's Guide, Rev. 4, 12/2020
22 NXP Semiconductors
Chapter 1 Library
3. In the Include Paths text box, type the following paths (if there are more paths, they must be separated by ';') or add them by clicking the … button next to the text box:
• "C:\NXP\RTCESL\CM7F_RTCESL_4.6_KEIL\MLIB\Include"
• "C:\NXP\RTCESL\CM7F_RTCESL_4.6_KEIL\GDFLIB\Include"
4. Click OK.
5. Click OK in the main dialog.
Figure 1-24. Library path addition
Type the #include syntax into the code. Include the library into a source file. In the new project, it is necessary to create a source file:
1. Right-click the Source Group 1 node, and Add New Item to Group 'Source Group 1'… from the menu.
2.
Select the C File (.c) option, and type a name of the file into the Name box, for example 'main.c'. See Figure 1-25.
GDFLIB User's Guide, Rev. 4, 12/2020
NXP Semiconductors 23

Library integration into project (IAR Embedded Workbench)

Figure 1-25. Adding new source file dialog
3. Click Add, and a new source file is created and opened up.
4. In the opened source file, include the following lines into the #include section, and create a main function:
#include "mlib_FP.h" #include "gdflib_FP.h"
int main(void) { while(1); }
When you click the Build (F7) icon, the project will be compiled without errors.
1.4
Library integration into project (IAR Embedded Workbench)
This section provides a step-by-step guide on how to quickly and easily include the GDFLIB into an empty project or any MCUXpresso SDK example or demo application projects using IAR Embedded Workbench. This example uses the default installation path (C:\NXP\RTCESL\CM7F_RTCESL_4.6_IAR). If you have a different installation path, use that path instead. If any MCUXpresso SDK project is intended to use (for example hello_world project) go to Linking the files into the project chapter otherwise read next chapter.
GDFLIB User's Guide, Rev. 4, 12/2020
24 NXP Semiconductors
Loading...
+ 55 hidden pages