Funpack2-2上线:Infineon车规级TC275三核MCU实现多核心编程
英飞凌的开发环境的设置特别好用,直接使用相关函数,大大节省了去翻看用户手册的时间,对于新手小白而言非常友好。
标签
Funpack
MCU
TC275
xiaoxiao
更新2022-10-09
537

本期Funpack活动选用的开发板:

AURIX TM TC275 lite 套件配备了基于 32 位单芯片 AURIX TM TriCore TM的微控制器 Aurix TM TC275。它可以与一系列开发工具一起使用,包括 AURIX TM Development Studio、英飞凌免费的基于 Eclipse 的 IDE,或来自 Hightec/PLS/Infineon 的基于 Eclipse 的“FreeEntryToolchain”。

特性:

Arduino 连接器

Arduino ICSP 连接器

稳压器 5V 至 3.3V

可选 0 欧姆电阻器(1210 英制中的 R39_opt/R40_opt)

Arduino 连接器(数字)

用于 AURIX™ TM的 20 MHz 晶振和用于 OCDS 的 12 MHz 晶振

用于 WIFI/BLE 的 Mikrobus 连接器

英飞凌 CAN 收发器 TLE9251VSJ 和 CAN 连接器

FjAINMY5LVd_rBAx_27UFfzcNbrL

本期完成的任务:

任务一:

使用TC275的三个核心,轮流休眠待机,分别控制板卡上的LED灯,如core0检测按键按下,唤醒core1翻转LED1,一秒后,唤醒core2翻转LED2,系统休眠

任务设计思路:

1 当开机的时候, 使用休眠的方法, 让核心1和核心2进入休眠状态

2 使用核心0进行按键的监听, 当按键按下的时候, 启动核心1

3 核心1启动时, 关闭核心0, 并且翻转LED1, 同时启动定时器

4 定时器1秒后启动核心2

5 核心2启动后, 翻转LED2, 系统休眠

使用Aurix相应配置:

1 Pin Module 配置

2 System Module配置,不分频

3 串口设置 波特率115200,勾选Redirect STDIO to USART1,printf函数 可以使用

4 ADCC:默认配置

5 Timer1 定时器设置 时间为1000ms

主要代码:

1 gpio的初始设置

#define LED     &MODULE_P00,5   /* Port pin for the LED     */
#define BUTTON  &MODULE_P00,7   /* Port pin for the button  */

/*********************************************************************************************************************/
/*---------------------------------------------Function Implementations----------------------------------------------*/
/*********************************************************************************************************************/
/* Function to configure the port pins for the push button and the LED */
void init_GPIOs(void)
{
    # 初始化GPIO
    /* Setup the port pin connected to the LED to general output mode push-pull. This function can be used
     * to initialize any port pin by specifying the port number, pin number and port pin mode.
     */
    IfxPort_setPinMode(LED, IfxPort_Mode_outputPushPullGeneral);

    /* Setup the port pin connected to the push button to input mode. This function can be used to initialize any
     * port to input mode by just specifying the port number as illustrated.
     */
    IfxPort_setPinMode(BUTTON, IfxPort_Mode_inputPullUp);
}

/* Depending on the the state of the "BUTTON" port pin, the LED is turned on or off */
void control_LED(void)
{
    # 控制LED
    /* With the routine getPinState() the value of a particular pin can be retrieved. This
     * function can be used to retrieve any port state by just specifying the port number
     * as illustrated.
     */
    if(IfxPort_getPinState(BUTTON) == 0)
    {
        /* With the routine setPinState() the state of the port can be set to drive either
         * LOW or HIGH. This function can be used to retrieve any port state by just
         * specifying the port number as illustrated.
         */
        IfxPort_setPinState(LED, IfxPort_State_low);
    }
    else
    {
        IfxPort_setPinState(LED, IfxPort_State_high);
    }
}

2 设置核心的休眠和睡眠相关的函数

#include "SCU_Power_Down_Sleep.h"
#include "IfxGtm_Tom_Timer.h"
#include "IfxStm_Timer.h"
#include "IfxCpu.h"
#include "IfxScuWdt.h"
#include "Ifx_Types.h"

/*********************************************************************************************************************/
/*------------------------------------------------------Macros-------------------------------------------------------*/
/*********************************************************************************************************************/
#define ISR_PRIORITY_TOM    10                  /* TOM Interrupt priority                                           */
#define TOM_FREQ            25.0f               /* TOM frequency                                                    */
#define LED                 &MODULE_P00, 5      /* LED which is toggled in Interrupt Service Routine (ISR)          */

#define ISR_PRIORITY_STM    20                  /* STM Interrupt priority for interrupt ISR                         */
#define STM                 &MODULE_STM0        /* STM0 module is used in this example                              */

#define ALLOW_SLEEP_MODE    0x0                 /* Allow sleep mode for GTM                                         */
#define BLOCK_SLEEP_MODE    0x1                 /* Block sleep mode for STM                                         */
#define PMSWCR1_CPUSEL      0x1                 /* Set the CPU0 as CPU master                                       */
#define PMCSR0_REQSLP       0x2                 /* Request sleep mode                                               */

/*********************************************************************************************************************/
/*-------------------------------------------------Global variables--------------------------------------------------*/
/*********************************************************************************************************************/
IfxGtm_Tom_Timer g_gtmTimer;                    /* TOM driver handle                                                */
IfxStm_Timer g_stmTimer;                        /* STM driver handle                                                */
float32 g_stmPeriod = 2.0;                      /* Period in seconds at which power modes toggle                    */
uint8 g_sleep = 0;                              /* Variable used to monitor the current set mode (sleep/run mode)   */

/*********************************************************************************************************************/
/*--------------------------------------------Function Implementations-----------------------------------------------*/
/*********************************************************************************************************************/
/* Macro to define the Interrupt Service Routine */
IFX_INTERRUPT(tomIsr, 0, ISR_PRIORITY_TOM);
IFX_INTERRUPT(stmIsr, 0, ISR_PRIORITY_STM);

/* TOM ISR to make the LED blink */
void tomIsr(void)
{
    /* Clear the timer event */
    IfxGtm_Tom_Timer_acknowledgeTimerIrq(&g_gtmTimer);

    /* Toggle the LED */
    IfxPort_togglePin(LED);
}

/* STM ISR to switch between run mode and sleep mode every two seconds */
void stmIsr(void)
{
    /* Enabling interrupts as ISR disables it */
    IfxCpu_enableInterrupts();

    /* Clear the timer event */
    IfxStm_Timer_acknowledgeTimerIrq(&g_stmTimer);

    /* Switch between run mode and sleep mode   */
    switchMode();
}

/* This function set the device either in run mode or in sleep mode */
void switchMode(void)
    # 设置定时器,使cpu进入睡眠模式
{
    if(g_sleep == 0)
    {
        /* Next interrupt --> run mode */
        g_sleep = 1;

        /* Clear safety EndInit protection */
        IfxScuWdt_clearSafetyEndinitInline(IfxScuWdt_getSafetyWatchdogPasswordInline());
        /* Clear EndInit protection */
        IfxScuWdt_clearCpuEndinit(IfxScuWdt_getCpuWatchdogPassword());

        GTM_CLC.B.EDIS = ALLOW_SLEEP_MODE;          /* Allow GTM to go into sleep mode                              */

        STM0_CLC.B.EDIS = BLOCK_SLEEP_MODE;         /* Prohibit STM to go into sleep mode                           */

        SCU_PMSWCR1.B.CPUSEL = PMSWCR1_CPUSEL;      /* Set the CPU0 as CPU master to trigger a power down mode      */

        SCU_PMCSR0.B.REQSLP = PMCSR0_REQSLP;        /* Request System Sleep Mode CPU0                               */

        /* Set safety EndInit protection */
        IfxScuWdt_setSafetyEndinitInline(IfxScuWdt_getSafetyWatchdogPasswordInline());
        /* Set EndInit protection */
        IfxScuWdt_setCpuEndinit(IfxScuWdt_getCpuWatchdogPassword());
    }
    else
    {
        /* Next interrupt --> sleep mode */
        # 修改代码, 是睡眠之后不再被唤醒
        g_sleep = 1;
    }
}

运行情况:

1 当开机的时候, 使用休眠的方法, 让核心1和核心2进入休眠状态, 此时等待按键的按下

FmgYihLs7K8QVUQQQlGcXBqlOgB4

2 按键按下后LED1进行闪烁

3 一秒后启动核心3翻转LED2

Fo8eGllN59dtkOABAw-OeEXO_gQU

4 系统休眠

FvT9OpidbrmhBns8gMtE8839SxYg

心得体会:

1.英飞凌的开发环境的设置特别好用,直接使用相关函数,大大节省了去翻看用户手册的时间,对于新手小白而言非常友好。

2.通过这次funpack2-2活动,让我对硬件设备和相应的软件有了进一步的了解,也学会了多核心的编程, 以后有机会会多多参加这样的活动。

附件下载
makefile.zip
团队介绍
张格
评论
0 / 100
查看更多
目录
硬禾服务号
关注最新动态
0512-67862536
info@eetree.cn
江苏省苏州市苏州工业园区新平街388号腾飞创新园A2幢815室
苏州硬禾信息科技有限公司
Copyright © 2023 苏州硬禾信息科技有限公司 All Rights Reserved 苏ICP备19040198号