AURIX TC397 环境搭建 延时 GPIO

AURIX™ Development Studio

AURIX™ Development Studio, 一个综合开发环境,包括Eclipse IDE、C-编译器、多核调试器、英飞凌低级驱动程序(iLLD),没有时间和代码大小的限制,能够编辑、编译和调试应用程序代码。

注册完后, 下载链接会发到邮箱. 我下载的是 AURIX-studio-setup_1.2.2_20201012-1308版本, 大小382MB. 默认安装目录C:\Infineon\AURIX-Studio-1.2.2, 就不改了.

主要安装 AURIX™Development StudioDAS64, 勾选同意协议, 下一步就可以了.

导入工程

AURIX™ Development Studio可以导入最新的示例工程, 可能是 Github Infineon
/AURIX_code_examples
这里面的:

  • 打开 AURIX Development Studio

  • File -> Import...

  • 选择Infineon -> AURIX Development Studio Project, 然后点 Next: 在这里插入图片描述

  • 选择一个TC397的Blink工程(也可以选择多个工程)), 点Finish, 如果点不动, 可能默认workspace下有同名文件夹: 66

新建工程

上面是导入示例工程的方法, 也可以自己新建工程:

  • File -> New -> New AURIX Project: 55

  • 输入工程名 TC397_Blink_LED, Next: 44

  • 选择器件和板子或者Custom Board: 33

  • 有时候编辑的时候发现编辑器页面变灰, 说明当前文件所在工程不是Actice的, 工程右键, 选择Set Active Project即可: 22

打开Cpu0_Main.c, 默认代码如下:

#include "Ifx_Types.h"
#include "IfxCpu.h"
#include "IfxScuWdt.h"

IFX_ALIGN(4) IfxCpu_syncEvent g_cpuSyncEvent = 0;

void core0_main(void)
{
    IfxCpu_enableInterrupts();
    
    /* !!WATCHDOG0 AND SAFETY WATCHDOG ARE DISABLED HERE!!
     * Enable the watchdogs and service them periodically if it is required
     */
    IfxScuWdt_disableCpuWatchdog(IfxScuWdt_getCpuWatchdogPassword());
    IfxScuWdt_disableSafetyWatchdog(IfxScuWdt_getSafetyWatchdogPassword());
    
    /* Wait for CPU sync event */
    IfxCpu_emitEvent(&g_cpuSyncEvent);
    IfxCpu_waitEvent(&g_cpuSyncEvent, 1);
    
    while(1)
    {
    }
}

KIT_A2G_TC397_5V_TFT 板子上有4颗LED, 分别为:

ReferencePINON
D107P13.00
D108P13.10
D109P13.20
D110P13.30

原理图:

11

现在加入一些延时还有点灯的功能:

#include "Ifx_Types.h"
#include "IfxCpu.h"
#include "IfxScuWdt.h"
#include "Bsp.h"    //initTime();

IFX_ALIGN(4) IfxCpu_syncEvent g_cpuSyncEvent = 0;

void core0_main(void)
{
    IfxCpu_enableInterrupts();
    
    /* !!WATCHDOG0 AND SAFETY WATCHDOG ARE DISABLED HERE!!
     * Enable the watchdogs and service them periodically if it is required
     */
    IfxScuWdt_disableCpuWatchdog(IfxScuWdt_getCpuWatchdogPassword());
    IfxScuWdt_disableSafetyWatchdog(IfxScuWdt_getSafetyWatchdogPassword());
    
    /* Wait for CPU sync event */
    IfxCpu_emitEvent(&g_cpuSyncEvent);
    IfxCpu_waitEvent(&g_cpuSyncEvent, 1);
    
    initTime(); /* Calculate iLLDs time constants   */
    IfxPort_setPinModeOutput(&MODULE_P13,0, IfxPort_OutputMode_pushPull, IfxPort_OutputIdx_general);
    IfxPort_setPinHigh(&MODULE_P13,0);   //Switch OFF the LED (low-level active)

    while(1)
    {
        IfxPort_togglePin(&MODULE_P13,0);       /* Toggle the state of the LED*/
        waitTime(5 * TimeConst_100ms);          /* Wait 500 milliseconds*/
    }
}

Build Active Project:

在这里插入图片描述

结果如下:

在这里插入图片描述

用Micro-USB线连接板子和电脑, 设备管理器中确认驱动没有问题:

在这里插入图片描述

可以调试, 也可以RUN, 这里以后者为例, AURIX™ Development Studio中工程右键 Run As -> Run Configuration:

在这里插入图片描述

发现啥也没有, 右键TASKING C/C++ Debugger -> New Configuration:

在这里插入图片描述

然后就出现工程同名的配置:

在这里插入图片描述

可以保持默认, 然后 Run, Console中提示Loading 'D:\CodeVarietyShop\AURIX-v1.2.2-workspace\TC397_Blink_LED\Debug\TC397_Blink_LED.elf'..., 已经下到单片机里面了, 程序还没有运行, 按下复位键S101 PORST, 发现D107蓝色LED以500ms交替亮灭.

修改下代码:

    initTime(); /* Calculate iLLDs time constants   */
    IfxPort_setPinModeOutput(&MODULE_P13,0, IfxPort_OutputMode_pushPull, IfxPort_OutputIdx_general);
    IfxPort_setPinModeOutput(&MODULE_P13,1, IfxPort_OutputMode_pushPull, IfxPort_OutputIdx_general);
    IfxPort_setPinModeOutput(&MODULE_P13,2, IfxPort_OutputMode_pushPull, IfxPort_OutputIdx_general);
    IfxPort_setPinModeOutput(&MODULE_P13,3, IfxPort_OutputMode_pushPull, IfxPort_OutputIdx_general);
    IfxPort_setPinHigh(&MODULE_P13,0);   //Switch OFF the LED (low-level active)
    IfxPort_setPinHigh(&MODULE_P13,1);   //Switch OFF the LED (low-level active)
    IfxPort_setPinHigh(&MODULE_P13,2);   //Switch OFF the LED (low-level active)
    IfxPort_setPinHigh(&MODULE_P13,3);   //Switch OFF the LED (low-level active)

    while(1)
    {
        IfxPort_togglePin(&MODULE_P13,0);       /* Toggle the state of the LED*/
        IfxPort_togglePin(&MODULE_P13,1);
        IfxPort_togglePin(&MODULE_P13,2);
        IfxPort_togglePin(&MODULE_P13,3);
        waitTime(5 * TimeConst_100ms);          /* Wait 500 milliseconds*/
    }

点击锤子形状的 Build Active Project, 编译完后提示:

在这里插入图片描述

Yes, 自动下载, 提示 Re-loading 'D:\CodeVarietyShop\AURIX-v1.2.2-workspace\TC397_Blink_LED\Debug\TC397_Blink_LED.elf'..., 按下复位按键, 可以看到4个灯同时500ms交替亮灭.

延时

  • 头文件包含 #include "Bsp.h"
  • 初始化 initTime(); /* Calculate iLLDs time constants */
  • 延时 waitTime(5 * TimeConst_100ms); /* Wait 500 milliseconds*/

还可以使用的常量有:

#define TimeConst_0s    ((Ifx_TickTime)0)                           /**< \brief time constant equal to 1s */
#define TimeConst_10ns  (TimeConst[TIMER_INDEX_10NS])               /**< \brief time constant equal to 10ns */
#define TimeConst_100ns (TimeConst[TIMER_INDEX_100NS])              /**< \brief time constant equal to 100ns */
#define TimeConst_1us   (TimeConst[TIMER_INDEX_1US])                /**< \brief time constant equal to 1us */
#define TimeConst_10us  (TimeConst[TIMER_INDEX_10US])               /**< \brief time constant equal to 10us */
#define TimeConst_100us (TimeConst[TIMER_INDEX_100US])              /**< \brief time constant equal to 100us */
#define TimeConst_1ms   (TimeConst[TIMER_INDEX_1MS])                /**< \brief time constant equal to 1ms */
#define TimeConst_10ms  (TimeConst[TIMER_INDEX_10MS])               /**< \brief time constant equal to 10ms */
#define TimeConst_100ms (TimeConst[TIMER_INDEX_100MS])              /**< \brief time constant equal to 100ms */
#define TimeConst_1s    (TimeConst[TIMER_INDEX_1S])                 /**< \brief time constant equal to 1s */
#define TimeConst_10s   (TimeConst[TIMER_INDEX_10S])                /**< \brief time constant equal to 10s */
#define TimeConst_100s  (TimeConst[TIMER_INDEX_100S])               /**< \brief time constant equal to 100s */

GPIO设置推挽输出

  • 设置推挽输出 IfxPort_setPinModeOutput(&MODULE_P13,0, IfxPort_OutputMode_pushPull, IfxPort_OutputIdx_general);

GPIO输出

  • 输出高电平 IfxPort_setPinHigh(&MODULE_P13,0);
  • 输出低电平 IfxPort_setPinLow(&MODULE_P13,0);
  • 翻转 IfxPort_togglePin(&MODULE_P13,0);

GPIO电平读取

不论引脚被配置为输入还是输出, 电平都是可以读取的.

  • 函数原型: uint32 IfxPort_getGroupState(Ifx_P *port, uint8 pinIndex, uint16 mask)

  • 读取P13.2电平: IfxPort_getGroupState(&MODULE_P13,2,1)

  • 读取P33[7:0]电平: uint16 value = IfxPort_getGroupState(&MODULE_P33, 0, 0xff);

		if(IfxPort_getGroupState(&MODULE_P13,2,1) == 1) {
            IfxPort_setPinLow(&MODULE_P13,3);
        } else {
            IfxPort_setPinHigh(&MODULE_P13,3);
        }

Ports

另一种初始化方法

#include "IfxPort_PinMap.h"
#include "IfxPort_Io.h"

    const IfxPort_Io_ConfigPin configPin[] = {
        {&IfxPort_P13_0, IfxPort_Mode_outputPushPullGeneral, IfxPort_PadDriver_cmosAutomotiveSpeed1},
        {&IfxPort_P13_1, IfxPort_Mode_outputPushPullGeneral, IfxPort_PadDriver_cmosAutomotiveSpeed1},
        {&IfxPort_P13_2, IfxPort_Mode_outputPushPullGeneral, IfxPort_PadDriver_cmosAutomotiveSpeed1},
        {&IfxPort_P13_3, IfxPort_Mode_outputPushPullGeneral, IfxPort_PadDriver_cmosAutomotiveSpeed1}
    };

    const IfxPort_Io_Config conf = {
            sizeof(configPin)/sizeof(IfxPort_Io_ConfigPin),
            (IfxPort_Io_ConfigPin *)configPin
    };

    IfxPort_Io_initModule(&conf);

完整代码

注意P13.2翻转电平后延时了10ns才读取, 如果直接读, 读出的状态是错误的. 当然, 调换一下Toggle的顺序为P13.2, P13.1, P13.0, 然后再读取P13.2电平也可以.

#include "Ifx_Types.h"
#include "IfxCpu.h"
#include "IfxScuWdt.h"
#include "Bsp.h"    //initTime();

IFX_ALIGN(4) IfxCpu_syncEvent g_cpuSyncEvent = 0;

void core0_main(void)
{
    IfxCpu_enableInterrupts();
    
    /* !!WATCHDOG0 AND SAFETY WATCHDOG ARE DISABLED HERE!!
     * Enable the watchdogs and service them periodically if it is required
     */
    IfxScuWdt_disableCpuWatchdog(IfxScuWdt_getCpuWatchdogPassword());
    IfxScuWdt_disableSafetyWatchdog(IfxScuWdt_getSafetyWatchdogPassword());
    
    /* Wait for CPU sync event */
    IfxCpu_emitEvent(&g_cpuSyncEvent);
    IfxCpu_waitEvent(&g_cpuSyncEvent, 1);
    
//    IfxPort_setPinModeOutput(&MODULE_P13,0, IfxPort_OutputMode_pushPull, IfxPort_OutputIdx_general);
//    IfxPort_setPinModeOutput(&MODULE_P13,1, IfxPort_OutputMode_pushPull, IfxPort_OutputIdx_general);
//    IfxPort_setPinModeOutput(&MODULE_P13,2, IfxPort_OutputMode_pushPull, IfxPort_OutputIdx_general);
//    IfxPort_setPinModeOutput(&MODULE_P13,3, IfxPort_OutputMode_pushPull, IfxPort_OutputIdx_general);

    const IfxPort_Io_ConfigPin configPin[] = {
        {&IfxPort_P13_0, IfxPort_Mode_outputPushPullGeneral, IfxPort_PadDriver_cmosAutomotiveSpeed1},
        {&IfxPort_P13_1, IfxPort_Mode_outputPushPullGeneral, IfxPort_PadDriver_cmosAutomotiveSpeed1},
        {&IfxPort_P13_2, IfxPort_Mode_outputPushPullGeneral, IfxPort_PadDriver_cmosAutomotiveSpeed1},
        {&IfxPort_P13_3, IfxPort_Mode_outputPushPullGeneral, IfxPort_PadDriver_cmosAutomotiveSpeed1}
    };

    const IfxPort_Io_Config conf = {
            sizeof(configPin)/sizeof(IfxPort_Io_ConfigPin),
            (IfxPort_Io_ConfigPin *)configPin
    };

    IfxPort_Io_initModule(&conf);
    
    IfxPort_setPinHigh(&MODULE_P13,0);   //Switch OFF the LED (low-level active)
    IfxPort_setPinHigh(&MODULE_P13,1);   //Switch OFF the LED (low-level active)
    IfxPort_setPinHigh(&MODULE_P13,2);   //Switch OFF the LED (low-level active)
    IfxPort_setPinHigh(&MODULE_P13,3);   //Switch OFF the LED (low-level active)

    while(1)
    {
        IfxPort_togglePin(&MODULE_P13,0);       /* Toggle the state of the LED*/
        IfxPort_togglePin(&MODULE_P13,1);
        IfxPort_togglePin(&MODULE_P13,2);
        //IfxPort_togglePin(&MODULE_P13,3);
        waitTime(1 * TimeConst_10ns);   //wait for P13.3 State
        if(IfxPort_getGroupState(&MODULE_P13,2,1) == 1) {
            IfxPort_setPinLow(&MODULE_P13,3);
        } else {
            IfxPort_setPinHigh(&MODULE_P13,3);
        }
        waitTime(4 * TimeConst_100ms);          /* Wait 500 milliseconds*/
    }
}

完整工程

先Project -> Clean 再压缩的, 由于iLLD是Full Set, 不算小:

TC397_Blink_LED

打开AURIX Development Studio, File -> Open Project From File System, 然后点击 Directory… 按钮, 进入工程文件夹, 点Finish即可打开工程.

参考

代码提示与补全

默认 .或者->提示, 其实按 alt+/ 可以提前提示的.

微信公众号

欢迎扫描关注我的微信公众号, 及时获取最新文章:
在这里插入图片描述

  • 8
    点赞
  • 57
    收藏
    觉得还不错? 一键收藏
  • 5
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值