用CCS搭建简单的F28069M工程并控制LED闪烁,以及实现注解


tips

本文章关于项目搭建的内容来自:以TMS320F28069为例,如何使用CCS建立DSP工程文件


一 项目的搭建

1.1 说明

CCS使用9.1版本,DSP型号为TMS320F28069。使用其他芯片配置过程类似。

1.2 建立步骤

1.首先点击project->New CCS Project
2.选择器件和创建工程名
在这里插入图片描述
第3步中我选的是100v3 USB,后面无法连接到板子,所以我在项目属性那里更改为100v2 USB
在这里插入图片描述
测试一下是否可以连接:
在这里插入图片描述
如果出现了"The JTAG DR Integrity scan-test has succeeded",表示连接成功

1)选择你的目标处理器信号;
2)选择目标处理器具体的信号
3)选择下载器,如果不确定可以点击Verify确定是否连接正确
4)Porject name按照自己的喜好确定工程名称,我习惯项目名+处理器型号+版本号
按照上述设置完成以后单击finish。
3.找到要用的文件headers和common,建议安装controlSUIT。

 controlSUIT的下载地址:https://www.ti.com.cn/tool/cn/CONTROLSUITE
大概是2.4G,下载后解压,安装

在这里插入图片描述

复制到新建工程的目录
在这里插入图片描述

4.为添加的文件添加路径
在所建立的工程文件(如图标记1)处右击选择Properties.
在这里插入图片描述
在打开的设置界面中,将添加的common和header中的include文件夹按照下述步骤加入工程文件
在这里插入图片描述
上面是点击添加的按钮,然后在弹出的对话框里面直接点击Workspace…,然后选中项目中对应的comm的include和headers的include
在这里插入图片描述
5.删除common下cmd里的所有文件,否则会出现内存分配问题
6.删除common/source下的F2806x_SWPrioritizedPieVect.c和F2806x_SWPrioritizedDefaultIsr.c,否则会出现重复定义问题
7.将Header文件夹下CMD文件中的DSP2806x_Headers_nonBIOS.cmd保留,删除DSP2806x_Headers_BIOS.cmd。保证系统工作在无操作系统模式。如果使用的BIOS系统,则删除第一个。
8.接下来便可以编译通过运行了。


二 LED闪烁代码

TI的CCS里面自带了很多例子的代码,下面是官方的指导,怎么去获取这些代码,包括本项目用的LED闪烁代码。

原始链接:
https://dev.ti.com/tirex/explore/node?node=ANJXzL69ZqXoHLjas70yCQ__FUz-xrs__LATEST

2.1 Launch Code Composer Studio (CCS) and Open Resource Explorer

  1. Launch CCS with the Code Composer Studio desktop icon

  2. Specify a location for your workspace when prompted. This is where your projects will be located. Use a path that does NOT use spaces or any non-alphanumeric characters, with the exception of the underscore character

  3. Select Browse Examples in the Getting Started page

在这里插入图片描述
在这里插入图片描述

2.2 Resource Explorer: Examples

Displays all example projects available under the Resource Explorer. This includes all available content on the remote TI server, in addition to any content you may have installed locally.

  1. Select the device or board you are working with in the Select a device or board filter box in the top left corner. For this workshop, we select F28379D

  2. Select the Bitfield examples under Software -> C2000Ware -> English -> Devices -> F28379D -> Examples

  3. Click the Download and install icon. This will make a copy of the C2000Ware package that is on the Cloud onto your local machine. This is required to import any examples into your local CCS environment
    在这里插入图片描述
    A prompt will appear, asking for confirmation. After agreeing to the prompt, the C2000Ware will start downloading. Once the download and installation to the local environment is completed, C2000Ware will appear in the Resource Explorer, highlighted with green arrows, indicating that it is available locally (offline) on your machine.
    这一步我没做成功,提示:This package is not support on your OS

在这里插入图片描述
Select the timed_led_blink example under Software -> C2000Ware -> English -> Devices -> F28379D -> Examples ->Bitfield ->CPU1 and click the Import to IDE icon
在这里插入图片描述
This will import the project into your workspace. The project will appear in the Project Explorer view if the import is successful
这一步我没做成功,不能直接导入到CCS,下载失败了
在这里插入图片描述

2.3 LED闪烁的代码

因为没办法通过上面的方式下载到代码,所以我是直接打开Example_2806xLEDBlink.c,复制代码出来,然后黏贴到我的main.c文件里
在这里插入图片描述

2.4 编译,然后点击Debug

在这里插入图片描述

注意,CCS好像默认会在main入口加个断点,所以点击Debug之后,如果看到断点停在main,点击一下Resume:
在这里插入图片描述
然后,你就可以看到板子上的D9那个LED在闪烁。


3 LED闪烁的代码:通过中断定期让GPIO发生翻转

//###########################################################################
//
// FILE:   Example_2806xLEDBlink.c
//
// TITLE:  Timer based blinking LED Example
//
//!  \addtogroup f2806x_example_list
//!  <h1>Timer based blinking LED(timed_led_blink)</h1>
//!
//!  This example configures CPU Timer0 for a 500 msec period, and toggles the
//!  GPIO34 LED once per interrupt. For testing purposes, this example
//!  also increments a counter each time the timer asserts an interrupt.
//!
//!  \b Watch \b Variables \n
//!  - CpuTimer0.InterruptCount
//!
//! \b External \b Connections \n
//!  Monitor the GPIO34 LED blink on (for 500 msec) and off (for 500 msec) on
//!  the 2806x control card.
//
//###########################################################################
// $TI Release:  $
// $Release Date:  $
// $Copyright:
// Copyright (C) 2009-2022 Texas Instruments Incorporated - http://www.ti.com/
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions
// are met:
//
//   Redistributions of source code must retain the above copyright
//   notice, this list of conditions and the following disclaimer.
//
//   Redistributions in binary form must reproduce the above copyright
//   notice, this list of conditions and the following disclaimer in the
//   documentation and/or other materials provided with the
//   distribution.
//
//   Neither the name of Texas Instruments Incorporated nor the names of
//   its contributors may be used to endorse or promote products derived
//   from this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
// $
//###########################################################################

//
// Included Files
//
#include "DSP28x_Project.h"     // Device Headerfile and Examples Include File

//
// Function Prototypes statements for functions found within this file.
//
__interrupt void cpu_timer0_isr(void);

//
// Main
//
void main(void)
{
    //
    // Step 1. Initialize System Control:
    // PLL, WatchDog, enable Peripheral Clocks
    // This example function is found in the F2806x_SysCtrl.c file.
    //
    InitSysCtrl();

    //
    // Step 2. Initalize GPIO:
    // This example function is found in the F2806x_Gpio.c file and
    // illustrates how to set the GPIO to it's default state.
    //
    // InitGpio();  // Skipped for this example

    //
    // Step 3. Clear all interrupts and initialize PIE vector table:
    // Disable CPU interrupts
    //
    DINT;

    //
    // Initialize the PIE control registers to their default state.
    // The default state is all PIE interrupts disabled and flags
    // are cleared.
    // This function is found in the F2806x_PieCtrl.c file.
    //
    InitPieCtrl();

    //
    // Disable CPU interrupts and clear all CPU interrupt flags
    //
    IER = 0x0000;
    IFR = 0x0000;

    //
    // Initialize the PIE vector table with pointers to the shell Interrupt
    // Service Routines (ISR).
    // This will populate the entire table, even if the interrupt
    // is not used in this example.  This is useful for debug purposes.
    // The shell ISR routines are found in F2806x_DefaultIsr.c.
    // This function is found in F2806x_PieVect.c.
    //
    InitPieVectTable();

    //
    // Interrupts that are used in this example are re-mapped to
    // ISR functions found within this file.
    //
    EALLOW;    // This is needed to write to EALLOW protected registers
    PieVectTable.TINT0 = &cpu_timer0_isr;
    EDIS;      // This is needed to disable write to EALLOW protected registers

    //
    // Step 4. Initialize the Device Peripheral. This function can be
    //         found in F2806x_CpuTimers.c
    //
    InitCpuTimers();   // For this example, only initialize the Cpu Timers

    //
    // Configure CPU-Timer 0 to interrupt every 500 milliseconds:
    // 80MHz CPU Freq, 50 millisecond Period (in uSeconds)
    //
    ConfigCpuTimer(&CpuTimer0, 80, 500000);

    //
    // To ensure precise timing, use write-only instructions to write to the
    // entire register. Therefore, if any of the configuration bits are changed
    // in ConfigCpuTimer and InitCpuTimers (in F2806x_CpuTimers.h), the
    // below settings must also be updated.
    //

    //
    // Use write-only instruction to set TSS bit = 0
    //
    CpuTimer0Regs.TCR.all = 0x4001;

    //
    // Step 5. User specific code, enable interrupts:
    //

    //
    // Configure GPIO34 as a GPIO output pin
    //
    EALLOW;
    GpioCtrlRegs.GPBMUX1.bit.GPIO34 = 0;
    GpioCtrlRegs.GPBDIR.bit.GPIO34 = 1;
    EDIS;

    //
    // Enable CPU INT1 which is connected to CPU-Timer 0
    //
    IER |= M_INT1;

    //
    // Enable TINT0 in the PIE: Group 1 interrupt 7
    //
    PieCtrlRegs.PIEIER1.bit.INTx7 = 1;

    //
    // Enable global Interrupts and higher priority real-time debug events
    //
    EINT;   // Enable Global interrupt INTM
    ERTM;   // Enable Global realtime interrupt DBGM

    //
    // Step 6. IDLE loop. Just sit and loop forever (optional)
    //
    for(;;);
}

//
// cpu_timer0_isr -
//
__interrupt void
cpu_timer0_isr(void)
{
    CpuTimer0.InterruptCount++;

    //
    // Toggle GPIO34 once per 500 milliseconds
    //
    //我之前一直用软件的角度去看代码,以为这个是赋值的意思,但其实这个是硬件中的GPIO的翻转操作
    //,即每次=1,会让GPIO的电平发生变化,变到另外一个状态。
    //比如,原先是高电平,执行一次=1,就变成了低电平了。。。。
    GpioDataRegs.GPBTOGGLE.bit.GPIO34 = 1;

    //
    // Acknowledge this interrupt to receive more interrupts from group 1
    //
    PieCtrlRegs.PIEACK.all = PIEACK_GROUP1;
}

//
// End of File
//

代码讲解

1 关于GPIO

DSP上的GPIO有三个用途:

  1. 作为输出
  2. 作为输入
  3. 作为外设的引脚

具体用于什么用途,需要通过相关的寄存器来配置。F28069有59个GPIO引脚,需要通过对应的GPxMUXn 寄存器来配置引脚的用途

2 代码段一

这一段代码几乎是标准模板,除了设置一下cpu定时器回调函数是我们这里用到的。其他内容后面再讲

  //
    // Step 1. Initialize System Control:
    // PLL, WatchDog, enable Peripheral Clocks
    // This example function is found in the F2806x_SysCtrl.c file.
    //
    InitSysCtrl();

    //
    // Step 2. Initalize GPIO:
    // This example function is found in the F2806x_Gpio.c file and
    // illustrates how to set the GPIO to it's default state.
    //
    // InitGpio();  // Skipped for this example

    //
    // Step 3. Clear all interrupts and initialize PIE vector table:
    // Disable CPU interrupts
    //
    DINT;

    //
    // Initialize the PIE control registers to their default state.
    // The default state is all PIE interrupts disabled and flags
    // are cleared.
    // This function is found in the F2806x_PieCtrl.c file.
    //
    InitPieCtrl();

    //
    // Disable CPU interrupts and clear all CPU interrupt flags
    //
    IER = 0x0000;
    IFR = 0x0000;

    //
    // Initialize the PIE vector table with pointers to the shell Interrupt
    // Service Routines (ISR).
    // This will populate the entire table, even if the interrupt
    // is not used in this example.  This is useful for debug purposes.
    // The shell ISR routines are found in F2806x_DefaultIsr.c.
    // This function is found in F2806x_PieVect.c.
    //
    InitPieVectTable();

    //
    // Interrupts that are used in this example are re-mapped to
    // ISR functions found within this file.
    //
    EALLOW;    // This is needed to write to EALLOW protected registers
    PieVectTable.TINT0 = &cpu_timer0_isr;
    EDIS;      // This is needed to disable write to EALLOW protected registers

    //
    // Step 4. Initialize the Device Peripheral. This function can be
    //         found in F2806x_CpuTimers.c
    //
    InitCpuTimers();   // For this example, only initialize the Cpu Timers

    //
    // Configure CPU-Timer 0 to interrupt every 500 milliseconds:
    // 80MHz CPU Freq, 50 millisecond Period (in uSeconds)
    //
    ConfigCpuTimer(&CpuTimer0, 80, 500000);

    //
    // To ensure precise timing, use write-only instructions to write to the
    // entire register. Therefore, if any of the configuration bits are changed
    // in ConfigCpuTimer and InitCpuTimers (in F2806x_CpuTimers.h), the
    // below settings must also be updated.
    //

    //
    // Use write-only instruction to set TSS bit = 0
    //
    CpuTimer0Regs.TCR.all = 0x4001;

    //
    // Step 5. User specific code, enable interrupts:
    //

    //
    // Configure GPIO34 as a GPIO output pin

3 代码段2

    //
    // Configure GPIO34 as a GPIO output pin
    //
    EALLOW;
    GpioCtrlRegs.GPBMUX1.bit.GPIO34 = 0;
    GpioCtrlRegs.GPBDIR.bit.GPIO34 = 1;
    EDIS;

在这里插入图片描述
上面讲过了GPIO的引脚是需要通过寄存器来配置用于什么的。
F28069上的LED灯是连接到GPIO34的,我们查一下上面那个表,34引脚是 GpioCtrlRegs.GPBMUX1配置的。
在这里插入图片描述
配置的方法,
00=是默认功能,作为IO口使用

GpioCtrlRegs.GPBMUX1.bit.GPIO34 = 0;

IO口可以是输出,也可以是输入,我们需要作为输出,所以还要配置一下方向:

    GpioCtrlRegs.GPBDIR.bit.GPIO34 = 1;

4 代码片段3

__interrupt void
cpu_timer0_isr(void)
{
    CpuTimer0.InterruptCount++;

    //
    // Toggle GPIO34 once per 500 milliseconds
    //
    //我之前一直用软件的角度去看代码,以为这个是赋值的意思,但其实这个是硬件中的GPIO的翻转操作
    //,即每次=1,会让GPIO的电平发生变化,变到另外一个状态。
    //比如,原先是高电平,执行一次=1,就变成了低电平了。。。。
    GpioDataRegs.GPBTOGGLE.bit.GPIO34 = 1;

    //
    // Acknowledge this interrupt to receive more interrupts from group 1
    //
    PieCtrlRegs.PIEACK.all = PIEACK_GROUP1;
}

GPIO高电平时,LED亮,低电平时LED灭,我们通过翻转寄存器,让GPIO的状态不断的变到相反状态


另外一个相同的实现,直接用while循环

https://blog.csdn.net/fsvff/article/details/117996025

#include  <DSP28x_Project.h>

int main(void)
{
    InitSysCtrl();  //Step1
    EALLOW;
    //LED1端口配置
    GpioCtrlRegs.GPBMUX1.bit.GPIO34=0;//设置为通用GPIO功能
    GpioCtrlRegs.GPBDIR.bit.GPIO34=1;//设置GPIO方向为输出
    GpioCtrlRegs.GPBPUD.bit.GPIO34=0;//使能GPIO上拉电阻

    //LED2端口配置
    //LED1端口配置
    GpioCtrlRegs.GPBMUX1.bit.GPIO39=0;//设置为通用GPIO功能
    GpioCtrlRegs.GPBDIR.bit.GPIO39=1;//设置GPIO方向为输出
    GpioCtrlRegs.GPBPUD.bit.GPIO39=0;//使能GPIO上拉电阻

    EDIS;
    while(1)
    {
     GpioDataRegs.GPBTOGGLE.bit.GPIO34=1; //LED灯翻转
     DELAY_US(1000000);

    }
}


  • 1
    点赞
  • 28
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值