【英飞凌TC364】点亮LED灯
一、简单介绍
英飞凌单片机中,IO口被称作port。

其框架图如下所示:

有个比较有意思的特性是当port被配置成输出模式时,也能通过读Pn_IN寄存器获取port的电平状态。作为输出时,最多可以复用成7种模式。
二、开发
打开ADS,新建工程。



笔者原理图设置8个LED分别连接P2.0至P2.7。

打开pin mapper。

笔者使用的是TC364_DP 64F300W封装是LQFP144。


配置完毕点击右上角generate code。

生成的代码在这里。

aurix_pin_mappings.h
/** Generated by TASKING Pin Mapper for AURIX* - device  : TC36XPD* - package : LQFP144*//** Instructions on how to build this generated file and the Infineon's iLLD library with the TASKING  VX-toolset* for TriCore:* 1. Provide appropriate include paths to the compiler (-I option) to locate the iLLD library.* 2. Provide macro IFX_CFG_USE_COMPILER_DEFAULT_LINKER to the compiler (-D option) to prevent multiple*    definitions of symbol '_START' (in cstart.c and IfxCpu_CStart0.c).* 3. Disable compiler option 'Automatic inclusion of .sfr files' (-H option) to prevent macros to be redefined.*/#ifndef AURIX_PIN_MAPPINGS_H_
#define AURIX_PIN_MAPPINGS_H_/* Infineon's iLLD library include files */#include <Port/Io/IfxPort_Io.h>#include <_PinMap/IfxPort_PinMap.h>/* Symbolic names for GPIO ports */// p02_0
#define IFXCFG_PORT_LED0                        IfxPort_P02_0
#define IFXCFG_PORT_LED0_MODE                   IfxPort_Mode_outputPushPullGeneral
#define IFXCFG_PORT_LED0_PAD_DRIVER             IfxPort_PadDriver_cmosAutomotiveSpeed4// p02_1
#define IFXCFG_PORT_LED1                        IfxPort_P02_1
#define IFXCFG_PORT_LED1_MODE                   IfxPort_Mode_outputPushPullGeneral
#define IFXCFG_PORT_LED1_PAD_DRIVER             IfxPort_PadDriver_cmosAutomotiveSpeed4// p02_2
#define IFXCFG_PORT_LED2                        IfxPort_P02_2
#define IFXCFG_PORT_LED2_MODE                   IfxPort_Mode_outputPushPullGeneral
#define IFXCFG_PORT_LED2_PAD_DRIVER             IfxPort_PadDriver_cmosAutomotiveSpeed4// p02_3
#define IFXCFG_PORT_LED3                        IfxPort_P02_3
#define IFXCFG_PORT_LED3_MODE                   IfxPort_Mode_outputPushPullGeneral
#define IFXCFG_PORT_LED3_PAD_DRIVER             IfxPort_PadDriver_cmosAutomotiveSpeed4// p02_4
#define IFXCFG_PORT_LED4                        IfxPort_P02_4
#define IFXCFG_PORT_LED4_MODE                   IfxPort_Mode_outputPushPullGeneral
#define IFXCFG_PORT_LED4_PAD_DRIVER             IfxPort_PadDriver_cmosAutomotiveSpeed4// p02_5
#define IFXCFG_PORT_LED5                        IfxPort_P02_5
#define IFXCFG_PORT_LED5_MODE                   IfxPort_Mode_outputPushPullGeneral
#define IFXCFG_PORT_LED5_PAD_DRIVER             IfxPort_PadDriver_cmosAutomotiveSpeed4// p02_6
#define IFXCFG_PORT_LED6                        IfxPort_P02_6
#define IFXCFG_PORT_LED6_MODE                   IfxPort_Mode_outputPushPullGeneral
#define IFXCFG_PORT_LED6_PAD_DRIVER             IfxPort_PadDriver_cmosAutomotiveSpeed4// p02_7
#define IFXCFG_PORT_LED7                        IfxPort_P02_7
#define IFXCFG_PORT_LED7_MODE                   IfxPort_Mode_outputOpenDrainGeneral
#define IFXCFG_PORT_LED7_PAD_DRIVER             IfxPort_PadDriver_cmosAutomotiveSpeed4/* Generic port I/O configuration */#define IFXCFG_P02_0_IO_CONFIG                  { &IFXCFG_PORT_LED0, IFXCFG_PORT_LED0_MODE, IFXCFG_PORT_LED0_PAD_DRIVER }
#define IFXCFG_P02_1_IO_CONFIG                  { &IFXCFG_PORT_LED1, IFXCFG_PORT_LED1_MODE, IFXCFG_PORT_LED1_PAD_DRIVER }
#define IFXCFG_P02_2_IO_CONFIG                  { &IFXCFG_PORT_LED2, IFXCFG_PORT_LED2_MODE, IFXCFG_PORT_LED2_PAD_DRIVER }
#define IFXCFG_P02_3_IO_CONFIG                  { &IFXCFG_PORT_LED3, IFXCFG_PORT_LED3_MODE, IFXCFG_PORT_LED3_PAD_DRIVER }
#define IFXCFG_P02_4_IO_CONFIG                  { &IFXCFG_PORT_LED4, IFXCFG_PORT_LED4_MODE, IFXCFG_PORT_LED4_PAD_DRIVER }
#define IFXCFG_P02_5_IO_CONFIG                  { &IFXCFG_PORT_LED5, IFXCFG_PORT_LED5_MODE, IFXCFG_PORT_LED5_PAD_DRIVER }
#define IFXCFG_P02_6_IO_CONFIG                  { &IFXCFG_PORT_LED6, IFXCFG_PORT_LED6_MODE, IFXCFG_PORT_LED6_PAD_DRIVER }
#define IFXCFG_P02_7_IO_CONFIG                  { &IFXCFG_PORT_LED7, IFXCFG_PORT_LED7_MODE, IFXCFG_PORT_LED7_PAD_DRIVER }/* Initialization routines */extern void gpio_init_pins(void);#endif /* AURIX_PIN_MAPPINGS_H_ */aurix_pin_mappings.c
/** Generated by TASKING Pin Mapper for AURIX* - device  : TC36XPD* - package : LQFP144*/#include "aurix_pin_mappings.h"/* GPIO pin configuration */static const IfxPort_Io_ConfigPin gpio_pin_table[] = 
{IFXCFG_P02_0_IO_CONFIG,IFXCFG_P02_1_IO_CONFIG,IFXCFG_P02_2_IO_CONFIG,IFXCFG_P02_3_IO_CONFIG,IFXCFG_P02_4_IO_CONFIG,IFXCFG_P02_5_IO_CONFIG,IFXCFG_P02_6_IO_CONFIG,IFXCFG_P02_7_IO_CONFIG
};static const IfxPort_Io_Config gpio_io_config_table = 
{sizeof(gpio_pin_table)/sizeof(IfxPort_Io_ConfigPin),(IfxPort_Io_ConfigPin*)gpio_pin_table
};extern void gpio_init_pins(void)
{IfxPort_Io_initModule(&gpio_io_config_table);
}参考官方使用手册。

main.c
#include "Ifx_Types.h"
#include "IfxCpu.h"
#include "IfxScuWdt.h"
#include "Ifx_Cfg_Ssw.h"#include "aurix_pin_mappings.h"IFX_ALIGN(4) IfxCpu_syncEvent cpuSyncEvent = 0;
boolean state[8] = {1,1,1,1,1,1,1,1};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(&cpuSyncEvent);IfxCpu_waitEvent(&cpuSyncEvent, 1);gpio_init_pins();IfxPort_setPinLow(IFXCFG_PORT_LED0.port, IFXCFG_PORT_LED0.pinIndex);IfxPort_setPinLow(IFXCFG_PORT_LED1.port, IFXCFG_PORT_LED1.pinIndex);IfxPort_setPinLow(IFXCFG_PORT_LED2.port, IFXCFG_PORT_LED2.pinIndex);IfxPort_setPinLow(IFXCFG_PORT_LED3.port, IFXCFG_PORT_LED3.pinIndex);IfxPort_setPinLow(IFXCFG_PORT_LED4.port, IFXCFG_PORT_LED4.pinIndex);IfxPort_setPinLow(IFXCFG_PORT_LED5.port, IFXCFG_PORT_LED5.pinIndex);IfxPort_setPinLow(IFXCFG_PORT_LED6.port, IFXCFG_PORT_LED6.pinIndex);IfxPort_setPinLow(IFXCFG_PORT_LED7.port, IFXCFG_PORT_LED7.pinIndex);for (uint8 i = 0; i < 8; i++){state[i] = IfxPort_getPinState(&MODULE_P02, i);}while(1){}
}点击build后编译无误。

点击flash烧录。

板子上的8个LED灯被点亮。

打断点调试。

读取到的值均变成0,即低电平。

