没有合适的资源?快使用搜索试试~ 我知道了~
首页TMS320LF240x DSP C编程入门.pdf
TMS320LF240x DSP C编程入门.pdf
5星 · 超过95%的资源 需积分: 10 36 下载量 94 浏览量
更新于2023-03-03
评论 1
收藏 421KB PDF 举报
This application report presents basic code for initializing and operating the TMS320LF240x† DSP devices. Two functionally equivalent example programs are presented: one written in assembly language and the other in C language.
资源详情
资源评论
资源推荐
Application Report
SPRA755A - July 2002
1
Getting Started in C and Assembly Code With the
TMS320LF240x DSP
David M. Alter DSP Applications – Semiconductor Group
ABSTRACT
This application report presents basic code for initializing and operating the TMS320LF240x
†
DSP devices. Two functionally equivalent example programs are presented: one written in
assembly language and the other in C language. Detailed discussions of each program are
provided that explain numerous compiler and assembler directives, code requirements, and
hardware-related requirements. The programs are ready to run on either the TMS320LF2407
Evaluation Module (EVM) or the eZdsp LF2407 development kit. However, they are also
intended for use as a code template for any TMS320LF240x
†
(LF240x) or TMS320LF240xA
†
(LF240xA) DSP target system.
Contents
1 Introduction 2. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
2 Hardware Setup 2. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
2.1 LF2407 EVM Setup 2. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
2.2 eZdspE LF2407 Setup 3. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
3 Using the Code Composer GEL File 4. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
4 Overview of the Example Programs 4. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
5 Assembly Language Example Program 6. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
6 C Language Example Program 13. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
7 Conclusion 20. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
8 References 20. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Appendix A Assembly Language Example Program Listing 21. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Appendix B C Language Example Program Listing 30. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Appendix C Addendum to Getting Started in C and Assembly Code With the 23
TMS320LF240x DSP 30. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
List of Figures
Figure 1 Assembly Language Example Program Code Flow 7. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Figure 2 C Language Example Program Code Flow 14. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
†
Go to http://www.ti.com for a complete list of TMS320C24x devices.
eZdsp is a trademark of Spectrum Digital Incorporated.
TMS320C24x is a trademark of Texas Instruments.
All trademarks are the property of their respective owners.
SPRA755A
2 Getting Started in C and Assembly Code With the TMS320LF240x DSP
1 Introduction
A hurdle often faced by code developers working with an unfamiliar DSP is knowing how to get
started. A good example program that illustrates proper DSP initialization, interrupt handling,
and peripheral operation can be invaluable. This application report presents basic code for
initializing and operating the TMS320LF240x devices. Although the code herein is designed to
run on either the TMS320LF2407 Evaluation Module (EVM) or the eZdsp LF2407
development kit, it is also applicable, and intended for use, as a code template for any
TMS320LF240x (LF240x) or TMS320LF240xA (LF240xA) DSP target system.
This application report presents two functionally equivalent example programs: one written in
assembly language, and the other written in C programming language. A reader who possesses
an understanding of one of these two languages can compare the two programs to understand
the coding in the other language. The philosophy behind the code examples is to keep them as
simple and clear as possible. Therefore, only a few of the numerous peripherals on the LF2407
DSP are exercised. The assumption is that once the basic coding techniques for configuring a
peripheral register are illustrated, the reader can easily duplicate the code to configure any other
peripheral.
In addition to the example programs, two complete header files are provided that define the
addresses of all user-programmable registers on the LF2407 DSP: one for assembly code and
the other for C code. Finally, a Code Composer v4.1x gel file is provided (along with usage
instructions) that conveniently places all LF2407 peripheral registers into a Code Composer
menu for easy inclusion into a debugger watch window.
2 Hardware Setup
The example programs in this application note are designed to run out-of-the-box on either the
LF2407 EVM or eZdsp LF2407. If you do not have one of these boards, all of the benefits of
the example programs are still available to you. You simply may not be able to run the programs
without making modifications to them for your particular target board.
2.1 LF2407 EVM Setup
The example programs are ready to run on the LF2407 EVM board without any modification. It is
assumed that the reader already has the EVM board, an emulator (e.g., XDS510PP-plus from
Spectrum Digital Inc. or XDS510) and a debugger (e.g., Code Composer v4.10 or v4.12)
installed on a PC and ready to go. It is beyond the scope of this application report to provide
direction on tools installation. Please see the installation instructions that came with the tools for
assistance with this.
Numerous jumpers exist on the EVM board. The following are jumper setting requirements for
proper operation of the example programs:
• JP5: This jumper controls the voltage level of the VCCP pin on the DSP. Normally, leave it in
the 1–2 position. If you want to program the FLASH with the example program, set to the
2–3 position during FLASH programming. It is good practice to return it to the 1–2 position
after FLASH programming.
Code Composer is a trademark of Texas Instruments.
SPRA755A
3
Getting Started in C and Assembly Code With the TMS320LF240x DSP
• JP6: This jumper controls the voltage level of the MP/MC pin on the DSP. Normally, set to
the 1–2 position to use the external RAM in place of the internal FLASH. Set to the 2–3
position if you want to program the FLASH with the example program, and leave in the 2–3
position to run the program out of the FLASH after it is programmed.
• JP13: Set to the 1–2 position. This uses the clock oscillator on the EVM board.
• JP16: Set to the 1–2 position. This disables bootloading.
All other jumper settings are don’t cares for the example programs, since those jumpers affect
peripherals that are not used here (e.g., CAN, SPI, ADC, or SCI). Additional information on
these jumpers can be found in reference [7].
The LF2407 EVM is assumed to contain a 7.3728 MHz on-board oscillator. The example
programs configure the DSP phase-locked loop (PLL) for multiply-by-four mode, which gives a
CPU clock of 29.49 MHz (i.e., 30 MHz). The values stated in this report for the PWM carrier
frequency, GPIO toggle period, and LED bank update rate have been computed assuming a 30
MHz CPU clock. If a different oscillator value is used, these values will be different. In addition,
one must be careful not to exceed the rated clock speed of the DSP in use (30 MHz for current
LF240x devices or 40 MHz for current LF240xA devices). Some early LF2407 EVM boards used
15 MHz oscillators that exceed the 30 MHz DSP rating if multiplied by four with the PLL. All you
need to do in this situation is edit the example programs so that the PLL is configured for
multiply-by-two mode instead. This setting is selected by bits 11–9 in the SCSR1 register. These
bits are currently written as 000b. Change these to 001b to get the multiply-by-two PLL (see
discussions for program lines 114 and 572 in sections 5 and 6, respectively, of this document).
Also, some of the newest EVMs may have been fitted with a 40 MHz LF2407A DSP and use a
10 MHz oscillator. No program change is necessary here, although again timing values for the
PWM, GPIO toggle, etc., will differ from those stated in this report (i.e., they will be 33% faster).
For more information on the PLL and the SCSR1 register, see reference [2], pages 2–3 to 2–5.
2.2 eZdsp LF2407 Setup
The example programs are ready to run on the eZdsp LF2407 board (henceforth referred to as
eZdsp) without any modification. It is assumed that the reader already has the eZdsp and its
debugger software installed and ready to go. It is beyond the scope of this application report to
provide direction on tools installation. Please see the installation guide that came with the tools
for assistance with this.
Several jumpers exist on the eZdsp board. The following are jumper setting requirements for
proper operation of the example programs:
• JP3: This jumper controls the voltage level of the VCCP pin on the DSP. Normally, leave it in
the 1–2 position. If you want to program the FLASH with the example program, set to the
2–3 position during FLASH programming. It is good practice to return it to the 1–2 position
after FLASH programming.
• JP4: This jumper controls the voltage level of the MP/MC pin on the DSP. Normally, set to
the 1–2 position to use the external RAM in place of the internal FLASH. Set to the 2–3
position if you want to program the FLASH with the example program, and leave in the 2–3
position to run the program out of the FLASH after it is programmed.
All other jumper settings are don’t cares for the example programs, since those jumpers affect
the ADC peripheral and the ADC is not used by the example programs. Additional information
on these jumpers can be found in reference [8].
SPRA755A
4 Getting Started in C and Assembly Code With the TMS320LF240x DSP
The eZdsp is assumed to contain a 14.7 MHz on-board oscillator. The on-board FPGA then
implements a divide-by-two, such that a 7.35 MHz clock signal is ultimately fed into the LF2407
DSP. The example programs configure the DSP phase-locked loop (PLL) for multiply-by-four
mode, which gives a CPU clock of 29.4 MHz (i.e., 30 MHz). The values stated in this report for
the PWM carrier frequency, GPIO toggle period, and LED bank update rate have been
computed assuming a 30 MHz CPU clock. If a different oscillator value is used, these values will
be different. In addition, you must be careful not to exceed the rated clock speed of the DSP in
use (30 MHz for current LF240x devices, or 40 MHz for current LF240xA devices). For example,
if you are using a 30 MHz oscillator instead of the standard 14.7 MHz one, using the
multiply-by-four PLL mode would exceed the 30 MHz frequency rating of the LF2407 DSP. All
you need to do in this situation is edit the example programs so that the PLL is configured for
multiply-by-two mode instead. This setting is selected by bits 11–9 in the SCSR1 register, and
these bits are currently written as 000b. Change these to 001b to get the multiply-by-two PLL
(see discussions for program lines 114 and 572 in sections 5 and 6, respectively, of this
document). For more information on the PLL and the SCSR1 register, see reference [2], pages
2–3 to 2–5.
3 Using the Code Composer GEL File
The file lf2407.gel is provided with this application report download. This is a script file
containing startup instructions for TMS320C2xx Code Composer v4.1x. Specifically, it has been
tested with v4.10 and v4.12 of this debugger. When installed with Code Composer, it causes all
LF2407 DSP peripheral registers to be listed on the GEL menu inside Code Composer. When a
particular register is selected on this menu (e.g., by clicking on it with your PC mouse), that
register is added to the WATCH WINDOW inside Code Composer. This functionality is a useful
aid during code debug, and avoids having to fumble through the user’s guide to look up register
addresses. Note that the peripheral set of the LF2407 DSP is a superset of all other current
240x and 240xA devices. Therefore, this gel file is usable with any 240x or 240xA target.
To use the gel file with Code Composer, place the file in the C:\tic2xx\cc\gel directory on your PC
(assuming you used the default installation paths when you installed Code Composer). Then,
right-click on the shortcut (or Windows 95/98 Start menu item) that you use to invoke Code
Composer. Select Properties, and then click on the Short Cut menu. The Target: box on this
menu should show the following (again assuming default installation paths):
C:\tic2xx\cc\bin\cc_app.exe C:\tic2xx\cc\gel\init.gel
To use the lf2407.gel file, simply change the Target: box to read:
C:\tic2xx\cc\bin\cc_app.exe C:\tic2xx\cc\gel\lf2407.gel
4 Overview of the Example Programs
There are two functionally identical programs provided. The first is written in TMS320C2xx DSP
assembly language, while the second is written in C programming language. Each example
program has been tested on both the LF2407 EVM and the eZdsp LF2407. Code generation
was performed using the TMS320C2x/C2xx/C5x Code Generation Tools PC v7.00, with C2xx
Code Composer Software Package PC v4.12 as the debugger. The C example program was
tested with compiler optimization disabled, and also with level 3 (–o3) optimization.
SPRA755A
5
Getting Started in C and Assembly Code With the TMS320LF240x DSP
Each example program performs the following tasks on the DSP:
• Configures the two System Control and Status registers
• Disables the Watchdog Timer
• Configures the external memory interface
• Configures the shared device pins
• Configures GP Timer 1 and the compare units to provide 20KHz, 25% duty cycle symmetric
PWM on the PWM1 pin. This can be observed by connecting an oscilloscope to the
PWM1/IOPA6 signal located on the EVM and eZdsp signal headers.
• Configures GP Timer 2 to provide a 250ms interrupt
• Configures the core and event manager interrupt registers, and enables global interrupts
• In the GP Timer 2 interrupt service routine, the following is performed:
– Context save/restore using a software stack
– The quad LED bank on the EVM is sequenced (250 ms update rate). This is visible only
on the EVM, since the eZdsp does not have the quad LED bank. However, no
modifications to the program are necessary for operation on the eZdsp. The LED
update instructions produce a benign write to I/O space on the external memory interface
of the DSP when using the eZdsp.
– The IOPC0 pin is toggled, producing a 2 Hz (500ms) square wave. On the EVM, the
IOPC0 pin is connected to the red LED labeled DS1 on the board. On the eZdsp, the
IOPC0 pin is connected to the red LED labeled DS2 on the board. Users can visually see
the pin toggle by observing the LED. Alternately, an oscilloscope can be connected to the
W/R
/IOPC0 pin on the EVM and eZdsp signal headers.
In addition, the example programs illustrate the following concepts:
• How to work with multiple files
• How to work with multiple code sections
• How to write an interrupt service routine using either C or assembly language
• How to insert inline assembly code into a C language program
• How to access the I/O space using either C or assembly language
• How to access peripheral registers using either C or assembly language
• How to use include files
• Complete core interrupt vector tables for C and assembly language programs
• Example LF2407 DSP linker command files for both C and assembly language programs
Finally, note that besides running from external memory, each example program can be
programmed into the internal FLASH memory on the LF2407 DSP and run out of the FLASH on
either the LF2407 EVM or the eZdsp LF2407, without the need for any file modifications.
剩余41页未读,继续阅读
miaozhengping
- 粉丝: 0
- 资源: 3
上传资源 快速赚钱
- 我的内容管理 收起
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
会员权益专享
最新资源
- stc12c5a60s2 例程
- Android通过全局变量传递数据
- c++校园超市商品信息管理系统课程设计说明书(含源代码) (2).pdf
- 建筑供配电系统相关课件.pptx
- 企业管理规章制度及管理模式.doc
- vb打开摄像头.doc
- 云计算-可信计算中认证协议改进方案.pdf
- [详细完整版]单片机编程4.ppt
- c语言常用算法.pdf
- c++经典程序代码大全.pdf
- 单片机数字时钟资料.doc
- 11项目管理前沿1.0.pptx
- 基于ssm的“魅力”繁峙宣传网站的设计与实现论文.doc
- 智慧交通综合解决方案.pptx
- 建筑防潮设计-PowerPointPresentati.pptx
- SPC统计过程控制程序.pptx
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功
评论1