Cmcsis DSP Ccs
Cmcsis DSP Ccs
Cmcsis DSP Ccs
Using the CMSIS DSP Library in Code Composer Studio for Tiva C Series ARM MCUs
Jordan Wills ABSTRACT This application report describes the process required to build the ARM CMSIS DSP library in Code Composer Studio v5. This document also describes how to use Code Composer Studio v5 to build, run, and verify the 11 ARM DSP example projects that are included in the CMSIS package. Project collateral and source code discussed in this application report can be downloaded from the following URL: http://www.ti.com/lit/zip/spmc017.
NOTE: This document applies to both the Tiva C Series and the Stellaris Cortex-M4 MCUs. Many screen captures reflect the Stellaris version of the device.
1 2 3 4 5 6
Contents Introduction .................................................................................................................. 1 CMSIS DSP Library ......................................................................................................... 1 Building the DSP Library in Code Composer Studio v5 ............................................................... 2 ARM Example Projects ................................................................................................... 14 Conclusion .................................................................................................................. 28 References ................................................................................................................. 29
Introduction
Many microcontroller-based applications can benefit from the use of an efficient digital signal processing (DSP) library. To that end, ARM has developed a set of functions called the CMSIS DSP library that is compatible with all Cortex M3 and M4 processors and that is specifically designed to use ARM assembly instructions to quickly and easily handle various complex DSP functions. Currently, ARM supplies example projects for use in their Keil uVision IDE that are meant to show how to build their CMSIS DSP libraries and run them on an M3 or M4. This application report details the steps that are necessary to build these DSP libraries inside Code Composer Studio version 5 and run these example applications on a Tiva C Series TM4C123G Launchpad.
Code Composer Studio, Tiva are trademarks of Texas Instruments. Stellaris is a registered trademark of Texas Instruments. Cortex is a trademark of ARM Limited . ARM is a registered trademark of ARM Limited. All other trademarks are the property of their respective owners. SPMA041C January 2012 Revised January 2014 Submit Documentation Feedback Using the CMSIS DSP Library in Code Composer Studio for Tiva C Series ARM MCUs 1
www.ti.com
If ARM releases a future update to CMSIS, you might need to download and install a patch to the DSP library in order to provide support for new functionality and to fix any bugs that ARM discovers in the CMSIS source code. After you download the patch files from the ARM web site, follow these instructions to install: 1. Unzip the patch file. 2. Navigate to the patch directory and copy any files found in that directory to the corresponding location of the CMSIS DSP library. 3. Overwrite existing files when prompted. For example, if the patch directory contains a file named arm_common_tables.c in the CMSIS/DSP_Lib/Source/CommonTables directory, copy this file into the same directory (CMSIS/DSP_Lib/Source/CommonTables) of your original CMSIS installation, overwriting the arm_common_tables.c that already exists in the original installation directory. After the CMSIS source code has been downloaded, you must download and run the SW01291 installer from Texas Instruments. This installer is located on the Texas Instruments website at http://www.ti.com/lit/zip/spmc017. The installer contains a set of support files that are needed for building and running the CMSIS DSP library in Code Composer Studio. After you download the installer, run the installer and select a location in which to extract the files.
3.1
2. Create an assembly file to take the place of the file arm_bitreversal2.S, which is found in CMSIS/DSP_Lib/Sources/TransformFunctions. Unfortunately, the Texas Instruments ARM assembler uses a vastly different syntax when handling macro statements than other assemblers, so it is not possible to have a single assembly file which can be properly parsed by the TI assembler and the other assemblers supported by CMSIS. It is highly recommended that you simply copy the arm_bitreversal2.asm file that accompanies this application report into the TransformFunctions directory. If you do wish to instead modify the assembly file to work with the TI assembler, you must: (a) Replace all #if statements to use the .if syntax defined in the ARM Assembly Language Tools Users Guide (SPNU118) (b) Replace the CODESECT definition to be .text (c) Replace the THUMB definition to be .thumb (d) Replace the EXPORT definition to be .global (e) Replace the PROC definition to be : .asmfun (f) Replace the LABEL definition to be : (g) Replace the ENDP definition to be .endasmfunc
2 Using the CMSIS DSP Library in Code Composer Studio for Tiva C Series ARM MCUs SPMA041C January 2012 Revised January 2014 Submit Documentation Feedback
www.ti.com
(h) Replace the and the END definition to be an empty #define. 3. Add the header file cmsis_ccs.h that accompanies this application report into the CMSIS/Include directory. This file is used by the DSP library to inform the build system of the syntax necessary to call various compiler intrinsics using the TI ARM C/C++ Compiler. If you wish to use pre-modified versions of the above files, the SW01291 installer creates an Include directory and a TransformFunctions directory, which contains a pre-modified version of arm_math.h, a copy of cmsis_ccs.h, and the arm_bitreversal2.asm assembly file that will build with the most recent version of CMSIS as of this document being created, version 3 patch 1. To use these files: 1. Rename the arm_math.h that was created in the CMSIS installation process to arm_math.h.backup 2. Copy arm_math.h and cmsis_ccs.h from this application report into the CMSIS/Include directory 3. Copy arm_bitreversal2.asm from this application report into CMSIS/DSP_Lib/Sources/TransformFunctions.
3.2
Using the CMSIS DSP Library in Code Composer Studio for Tiva C Series ARM MCUs
www.ti.com
3.3
Using the CMSIS DSP Library in Code Composer Studio for Tiva C Series ARM MCUs
www.ti.com
13. Verify that the drop-down menu of environment variables is set to PROJECT_LOC (see Figure 2). If there are no variables listed in the drop-down menu, select Edit Variables and add a variable to represent the location of the dsplib project file.
Figure 2. Importing the DSP_Lib Source Code 14. Click Finish to link the DSP_Lib source code into the project.
Using the CMSIS DSP Library in Code Composer Studio for Tiva C Series ARM MCUs
www.ti.com
Figure 3. The Project Explorer Window After the DSP_Lib Code has Been Imported
3.4
Figure 4. The Processor Settings for a Cortex-M4 Processor With Hardware FPU Support
Using the CMSIS DSP Library in Code Composer Studio for Tiva C Series ARM MCUs
www.ti.com
4. Click the Optimization level (--opt_level, -O) drop-down menu in the Optimization panel and select 2 (see Figure 5).
Figure 5. The Proper Optimization Settings for Compiling the DSP_Lib Source Code 5. Expand the Advanced Options section of the ARM Compiler pane, and select Assembler Options. 6. Click the Use unified assembly language (--ual) checkbox to select that option (see Figure 6).
Using the CMSIS DSP Library in Code Composer Studio for Tiva C Series ARM MCUs
www.ti.com
7. Click the Emit diagnostic identifier numbers (--display_error_number, -pden) checkbox in the Diagnostic Options panel to deselect.
Using the CMSIS DSP Library in Code Composer Studio for Tiva C Series ARM MCUs
www.ti.com
8. Click the Enable support for GCC extensions (--gcc) checkbox in the Include Options panel to select (see Figure 8).
Figure 8. Setting the ARM Compiler to Support GCC Extensions, Pragma Statements, and Macros
Using the CMSIS DSP Library in Code Composer Studio for Tiva C Series ARM MCUs
www.ti.com
9. Add the DSP library CMSIS-<version>/CMSIS/Include directory to the compilers include path in the Include Options panel. This is done by pressing the Add button by the Add dir to #include search path (--include_path, -I) (see Figure 9), then either typing in the path to the CMSIS Include directory or clicking File System and navigating to the Include directory and navigating to the Include directory (CMSIS-<version>/CMSIS/Include).
Figure 9. Adding the CMSIS Top Level Include Directory to the Compiler's #include Search Path
10
Using the CMSIS DSP Library in Code Composer Studio for Tiva C Series ARM MCUs
www.ti.com
10. Expand the Advanced Options menu again and select the Predefined Symbols panel. Create a symbol to tell the DSP library to use either the Cortex-M3 or Cortex-M4 based math functions. Click the Add... button in the Pre-define NAME (--define, -D) area. In the Enter Value dialog box, type ARM_MATH_CM4 (or ARM_MATH_CM3 if building for a Cortex M3) into the Pre-define NAME (-define, -D) field and click OK (see Figure 10). Click the Add button again type __FPU_PRESENT=1 (or __FPU_PRESENT=0 if building for a Cortex M3, which has no hardware FPU support) into the Pre-define NAME (--define, -D) field and click OK.
Figure 10. Adding Project Level #defines for the Processor Characteristics
Using the CMSIS DSP Library in Code Composer Studio for Tiva C Series ARM MCUs
11
www.ti.com
11. Select the on option from the Place each function in a separate subsection (--gen_func_subsections, ms) drop-down menu in the Runtime Model Options panel (see Figure 11).
Figure 11. The Proper Runtime Model Options for Compiling the DSP_Lib Source Code
12
Using the CMSIS DSP Library in Code Composer Studio for Tiva C Series ARM MCUs
www.ti.com
12. Uncheck the Emit diagnostic identifier numbers (--display_error_number, -pden) checkbox in the Diagnostic Options (see Figure 12).
Figure 12. The Proper Diagnostic Options for Compiling the DSP_Lib Source Code
3.5
Using the CMSIS DSP Library in Code Composer Studio for Tiva C Series ARM MCUs
13
www.ti.com
4.1
Figure 13. The New CCS Project Window With Options Set to Build the arm_dotproduct_example Project
14
Using the CMSIS DSP Library in Code Composer Studio for Tiva C Series ARM MCUs
www.ti.com
Figure 14. The Project Explorer After the arm_class_marks_example Project has Been Created
4.2
Figure 15. Adding the Primary Source File for the arm_class_marks_example to the Project
Using the CMSIS DSP Library in Code Composer Studio for Tiva C Series ARM MCUs
15
www.ti.com
3. Select the Link to files radio button, check the Create link locations relative to: checkbox, and select PROJECT_LOC from the drop-down menu when the File Operation dialog box appears (see Figure 16). Press OK to add the source file(s) to the project.
Figure 16. Selecting the Proper Options to Link the Source Files Into the Project 4. It is also necessary to link the math_helper.c file into the project workspace, which can be done by following the same steps listed above for linking in example_f32.c (see Figure 17). This file contains a set of helper functions that many of the example projects reference and can be found at CMSIS<version>/CMSIS/DSP_Lib/Examples/Common/Source/math_helper.c.
Figure 17. Adding the Source Code for the Math Helper Functions to the Project 5. Some projects also contain a file named arm_<example>_data.c. If the example you are building contains such a file, add it in the same way you added the files in the previous steps.
16
Using the CMSIS DSP Library in Code Composer Studio for Tiva C Series ARM MCUs
www.ti.com
6. The last file that is needed for all of the example projects is the microcontroller startup code file for Code Composer Studio v5. This file, startup_ccs.c, is among the files extracted by the SW01291 installer mentioned in Section 2, available at http://www.ti.com/lit/zip/spmc017. Either copy that file into the same directory in which the project was created or link the file in using the steps listed above.
4.3
Figure 18. The Processor Options Used for Building the Example on a Cortex-M4 Process With hardware FPU Support
Using the CMSIS DSP Library in Code Composer Studio for Tiva C Series ARM MCUs
17
www.ti.com
4. Click the Optimization level (--opt_level, -O) drop-down menu and select 2 in the Optimization panel (see Figure 19).
Figure 19. The Proper Optimization Settings for Compiling the Example Projects 5. Expand the Advanced Options section of the ARM Compiler pane, and select Assembler Options. 6. Click the Use unified assembly language (--ual) checkbox to select that option (see Figure 20).
Figure 20. The Proper Assembler Options Needed for Compiling the Example Projects
18
Using the CMSIS DSP Library in Code Composer Studio for Tiva C Series ARM MCUs
www.ti.com
7. Expand the Advanced Options menu again and select the Predefined Symbols panel. Create a symbol to tell the DSP library to use either the Cortex-M3 or Cortex-M4 based math functions. Click the Add... button in the Pre-define NAME (--define, -D) area. In the Enter Value dialog box, type ARM_MATH_CM4 (or ARM_MATH_CM3 for the Stellaris Cortex-M3 parts) into the Pre-define NAME (--define, -D) field and click OK (see Figure 21). Click the Add button again type __FPU_PRESENT=1 (or __FPU_PRESENT=0 for the Stellaris Cortex-M3 parts, which contain no hardware FPU support) into the Pre-define NAME (--define, -D) field and click OK.
Figure 21. Adding the Pre-Processor Statements Necessary for Building an Example Project on a CortexM4 Part With Hardware FPU Support
Using the CMSIS DSP Library in Code Composer Studio for Tiva C Series ARM MCUs
19
www.ti.com
8. Look for the Add <dir> to #include search path (--include_path, -I) field in the Include Options section (see Figure 22). 9. Click the Add button, then the File System button and browse to the Include directory located in the CMSIS/DSP_LIB/Examples/Common directory, then click OK.
Figure 22. Using the File System Option to Add the Common Example Project's Include Directory to the Compiler's #include Search Path
20
Using the CMSIS DSP Library in Code Composer Studio for Tiva C Series ARM MCUs
www.ti.com
10. Click the Add button again, then the File System button and browse to the Include directory located in the CMSIS directory, then click OK (see Figure 23).
Figure 23. Using the File System Option to Add the Base CMSIS Include Directory to the Compiler's #include Search Path
Figure 24. Compiler's #include Search Path Modified to Contain Both the Base CMSIS Include Directory and the Example Projects' Common Include Directory
Using the CMSIS DSP Library in Code Composer Studio for Tiva C Series ARM MCUs
21
www.ti.com
11. Click the Enable support for GCC extensions (--gcc) checkbox in the Language Options panel to select (see Figure 25).
Figure 25. The Compiler Language Options Set Up to Provide Support for GCC Extensions
22
Using the CMSIS DSP Library in Code Composer Studio for Tiva C Series ARM MCUs
www.ti.com
12. Select the on option from the Place each function in a separate subsection (--gen_func_subsections, ms) drop-down menu (see Figure 26), in the Runtime Model Options panel.
Figure 26. The Runtime Model Options Set Up for Compiling the Example Projects 13. Open the File Search Path panel in the ARM Linker section. 14. Create an entry for the precompiled CMSIS DSP binary (.lib) that will be used in the Include library file or command file as input (--library, -l) area (see Figure 27). For this example, the library file created in section three will be used, so click on the Add button, then the File system button and navigate to the location of the .lib you want to use. If you built the precompiled binary from scratch as detailed in section 3 without changing the default project location, the .lib will be found at C:\Users\<user_name>\CCS workspaces\<your workspace>\dsplib-cm4f\Debug\dsplib-cm4f.lib. When you have found the binary, click Open, then OK.
Using the CMSIS DSP Library in Code Composer Studio for Tiva C Series ARM MCUs
23
www.ti.com
Figure 27. The Linker's File Search Path Modified to Include the dsplib Binary Compiled in Section 3
24
Using the CMSIS DSP Library in Code Composer Studio for Tiva C Series ARM MCUs
www.ti.com
4.4
Figure 28. The Debug Context Being Displayed After the arm_class_marks_example Project has Been Set Up for Debugging
Using the CMSIS DSP Library in Code Composer Studio for Tiva C Series ARM MCUs
25
www.ti.com
2. It takes a moment for Code Composer Studio to connect to the MCU and download the code. Once the connection has been established and the flash programmed with the compiled project code, the MCU will run until it reaches the projects main() function (see Figure 29). Press the Resume button (or F8) to cause the program to start executing.
Figure 29. The arm_class_marks_example Project, After it has Been Loaded Into Flash and the Startup Code has run to the main() Function 3. After a few seconds have passed, the program will run to completion (see Figure 30). Press the suspend button, which will halt the processor and show you what line of code is being executed.
Figure 30. The arm_dotproduct_example Project Having Run to Successful Completion 4. For every function other than the class marks example, the program will have halted in one of two while loops. If the program did not successfully execute, it will be caught in a while loop surrounded by an if statement with a test condition of (status != ARM_MATH_SUCCESS). If the program did successfully execute, it is caught in a while loop found immediately after the previously mentioned if statement. For the class marks example, there is no built in method by which the microcontrollers execution state can be verified.
26 Using the CMSIS DSP Library in Code Composer Studio for Tiva C Series ARM MCUs SPMA041C January 2012 Revised January 2014 Submit Documentation Feedback
www.ti.com
4.5
Using the CMSIS DSP Library in Code Composer Studio for Tiva C Series ARM MCUs
27
Conclusion
www.ti.com
Figure 31. Using the Debugger to Examine the Results of the linear_interp_example Project 8. If you manually examine the values stored at each element, you will see that for the most part, the sin values calculated using both cubic and linear interpolation are closer to the reference values than those calculated using only cubic interpolation. In the example above, this is especially noticeable on element 7 of the output arrays.
Conclusion
Using the information provided in this document, combined with the resources available from ARMs CMSIS website, it is possible to easily and quickly implement various complex DSP algorithms. While it is possible to code a number of these functions independently, the result would likely lead to a much greater development time and produce less efficient code. It is highly recommended that anytime a Texas Instruments Tiva or Stellaris microcontroller is being used for an application that requires complex DSP functionality, the procedure listed here should be followed to ensure accurate, reliable, efficient code.
28
Using the CMSIS DSP Library in Code Composer Studio for Tiva C Series ARM MCUs
www.ti.com
References
References
The following related documents and software are available on the Tiva C Series web site at: http://www.ti.com/product/tm4c123gh6pm Tiva C Series TM4C123GH6PM Microcontroller Data Sheet (SPMS376) Tiva C Series TM4C123GH6PM Errata (SPMZ846) Tiva TM4C123GH6PGE Microcontroller Data Sheet (SPMS375) The source code for the CMSIS DSP Library and example code can be downloaded from ARMs CMSIS website: cmsis.arm.com. A quickstart guide for using Texas Instruments Code Composer Studio v5 can be found on the TI processor wiki at: http://processors.wiki.ti.com/index.php/Category:Code_Composer_Studio_v5.
Using the CMSIS DSP Library in Code Composer Studio for Tiva C Series ARM MCUs
29
IMPORTANT NOTICE
Texas Instruments Incorporated and its subsidiaries (TI) reserve the right to make corrections, enhancements, improvements and other changes to its semiconductor products and services per JESD46, latest issue, and to discontinue any product or service per JESD48, latest issue. Buyers should obtain the latest relevant information before placing orders and should verify that such information is current and complete. All semiconductor products (also referred to herein as components) are sold subject to TIs terms and conditions of sale supplied at the time of order acknowledgment. TI warrants performance of its components to the specifications applicable at the time of sale, in accordance with the warranty in TIs terms and conditions of sale of semiconductor products. Testing and other quality control techniques are used to the extent TI deems necessary to support this warranty. Except where mandated by applicable law, testing of all parameters of each component is not necessarily performed. TI assumes no liability for applications assistance or the design of Buyers products. Buyers are responsible for their products and applications using TI components. To minimize the risks associated with Buyers products and applications, Buyers should provide adequate design and operating safeguards. TI does not warrant or represent that any license, either express or implied, is granted under any patent right, copyright, mask work right, or other intellectual property right relating to any combination, machine, or process in which TI components or services are used. Information published by TI regarding third-party products or services does not constitute a license to use such products or services or a warranty or endorsement thereof. Use of such information may require a license from a third party under the patents or other intellectual property of the third party, or a license from TI under the patents or other intellectual property of TI. Reproduction of significant portions of TI information in TI data books or data sheets is permissible only if reproduction is without alteration and is accompanied by all associated warranties, conditions, limitations, and notices. TI is not responsible or liable for such altered documentation. Information of third parties may be subject to additional restrictions. Resale of TI components or services with statements different from or beyond the parameters stated by TI for that component or service voids all express and any implied warranties for the associated TI component or service and is an unfair and deceptive business practice. TI is not responsible or liable for any such statements. Buyer acknowledges and agrees that it is solely responsible for compliance with all legal, regulatory and safety-related requirements concerning its products, and any use of TI components in its applications, notwithstanding any applications-related information or support that may be provided by TI. Buyer represents and agrees that it has all the necessary expertise to create and implement safeguards which anticipate dangerous consequences of failures, monitor failures and their consequences, lessen the likelihood of failures that might cause harm and take appropriate remedial actions. Buyer will fully indemnify TI and its representatives against any damages arising out of the use of any TI components in safety-critical applications. In some cases, TI components may be promoted specifically to facilitate safety-related applications. With such components, TIs goal is to help enable customers to design and create their own end-product solutions that meet applicable functional safety standards and requirements. Nonetheless, such components are subject to these terms. No TI components are authorized for use in FDA Class III (or similar life-critical medical equipment) unless authorized officers of the parties have executed a special agreement specifically governing such use. Only those TI components which TI has specifically designated as military grade or enhanced plastic are designed and intended for use in military/aerospace applications or environments. Buyer acknowledges and agrees that any military or aerospace use of TI components which have not been so designated is solely at the Buyer's risk, and that Buyer is solely responsible for compliance with all legal and regulatory requirements in connection with such use. TI has specifically designated certain components as meeting ISO/TS16949 requirements, mainly for automotive use. In any case of use of non-designated products, TI will not be responsible for any failure to meet ISO/TS16949. Products Audio Amplifiers Data Converters DLP Products DSP Clocks and Timers Interface Logic Power Mgmt Microcontrollers RFID OMAP Applications Processors Wireless Connectivity www.ti.com/audio amplifier.ti.com dataconverter.ti.com www.dlp.com dsp.ti.com www.ti.com/clocks interface.ti.com logic.ti.com power.ti.com microcontroller.ti.com www.ti-rfid.com www.ti.com/omap TI E2E Community e2e.ti.com www.ti.com/wirelessconnectivity Mailing Address: Texas Instruments, Post Office Box 655303, Dallas, Texas 75265 Copyright 2014, Texas Instruments Incorporated Applications Automotive and Transportation Communications and Telecom Computers and Peripherals Consumer Electronics Energy and Lighting Industrial Medical Security Space, Avionics and Defense Video and Imaging www.ti.com/automotive www.ti.com/communications www.ti.com/computers www.ti.com/consumer-apps www.ti.com/energy www.ti.com/industrial www.ti.com/medical www.ti.com/security www.ti.com/space-avionics-defense www.ti.com/video