TC397 AUTOSAR EB MCAL DIO 配置与ADS测试
本文介绍了基于TC397XP芯片的MCAL DIO模块配置与测试方法,通过EB tresos工具实现LED周期性翻转控制。硬件连接使用P21_0引脚控制LED(低电平点亮),软件环境包括AURIX开发套件和AutoSAR CP 4.2.2规范。详细说明了ADS工程创建、EB配置流程(包括McalLib、Mcu、Port、Dio模块设置),以及应用层代码实现,重点展示了Dio_FlipChannel
文章目录
前言
整理库存发现, 约摸3年前的文章了, TC397 的 EB Mcal 配置与测试, 有DIO STM UART CAN FlsLoader CRC, 本篇是 MCAL DIO, 照本文描述可复现工程, 故不再提供源码,嵌入式_机器人_自动驾驶交流QQ群: 1040239879
MCAL DIO
本篇目的在于配置和单独测试 Mcal 的 Dio. 最终效果是每500ms翻转一次LED的状态.
硬件连接
- MCU: TC397XP, 外部晶振20MHz
- LED0: P21_0, 低电平点亮
软件环境
- Mcal: 对应 Autosar CP 4.2.2
- 配置软件: EB tresos 23.0.0
- IDE: AURIX™ Development Studio V1.9.4(仅用于学习交流, 以下简称ads)
ADS新建工程




删掉图中框选

从MCAL的安装文件夹里面拷贝过来

点灯用到的 Mcal/Tricore 模块有:
- McalLib
- Mcu
- Port
- Dio
用到哪个拷贝哪个就可以
EB新建工程


记得勾选下图中的 Automatically add ...



EB配置
ResourceM 这里用默认值即可, 暂不配置
Irq 这里用默认值即可, 暂不配置
McalLib

Mcu

Mcu模块主要是配置时钟等, 建议对照用户手册 TC3xx User Manual part1 V2.0.pdf 中的 Figure 90 Clocking System example with external 20MHz crystal / clock input 或 Figure 91 Clocking System example with external 25MHz crystal / clock input 来配置时钟, 如有不同, 可适当更改EB中的时钟配置. 本小节采用默认值, 暂不配置时钟部分, 默认值如下:
- 外部晶振 20MHz
- 主频 300MHz
- STM时钟 100MHz

Port

P21_0 推挽输出, 默认高电平(熄灭LED)

Dio
记得勾选翻转Flip的API

起个名字叫 LED0, 实际对应 DioConf_DioChannel_LED0

生成配置代码
先检查, 再生成配置代码, 默认在EB工程的 output/generated 文件夹里面

App代码
Mcu初始化代码
主要是配置时钟
#include "Mcu.h"
void app_mcu_init(void) {
Mcu_Init(&Mcu_Config);
if (E_OK == Mcu_InitClock(0)) {
while (MCU_PLL_LOCKED != Mcu_GetPllStatus());
#if (MCU_DISTRIBUTE_PLL_CLOCK_API == STD_ON)
Mcu_DistributePllClock ();
#endif
}
}
Port初始化代码
主要是配置端口输入输出, 上下拉, 推挽浮空, 默认电平等
#include "Port.h"
void app_port_init(void) {
Port_Init(&Port_Config);
}
delay函数
STM定时器默认是64bit, 100MHz向上计数, 可以据此写一个简单的秒延时函数
#include "IfxStm_reg.h"
void delay(volatile float seconds)
{
volatile unsigned int stm_count_begin = STM0_TIM0.U;
volatile unsigned int stm_count;
stm_count = (unsigned int)(Ifx_Ssw_getStmFrequency() * seconds);
while ((unsigned int)(STM0_TIM0.U - stm_count_begin) < stm_count) {}
}
Dio应用代码
此处无需Dio的初始化函数, 直接写应用代码即可
#include "Dio.h"
void app_dio(void) {
Dio_WriteChannel(DioConf_DioChannel_LED0, STD_HIGH);
delay(0.5);
Dio_WriteChannel(DioConf_DioChannel_LED0, STD_LOW);
delay(0.5);
}
也可以直接用Flip函数(EB Dio配置勾选了这个API)
#include "Dio.h"
void app_dio(void) {
delay(0.5);
Dio_FlipChannel(DioConf_DioChannel_LED0);
}
core0_main代码
void core0_main (void)
{
volatile unsigned short LoopFlag = 1U;
unsigned short cpuWdtPassword;
unsigned short safetyWdtPassword;
ENABLE();
/*
* !!WATCHDOG0 AND SAFETY WATCHDOG ARE DISABLED HERE!!
* Enable the watchdog in the demo if it is required and also service the watchdog periodically
* */
cpuWdtPassword = Ifx_Ssw_getCpuWatchdogPassword(&MODULE_SCU.WDTCPU[0]);
safetyWdtPassword = Ifx_Ssw_getSafetyWatchdogPassword();
Ifx_Ssw_disableCpuWatchdog(&MODULE_SCU.WDTCPU[0], cpuWdtPassword);
Ifx_Ssw_disableSafetyWatchdog(safetyWdtPassword);
app_mcu_init();
app_port_init();
while (LoopFlag == 1U)
{
app_dio();
}
}
编译下载
ADS编译
回到 ads 里面, 选中工程, F5刷新(ads会自动包含路径), 全部编译, 应该能编译通过

Memtool下载
本来ads里面应该是可以直接一键编译下载运行的, 但是我这里配置可能哪里有问题, 暂时用 Memtool下载:
Connect -> Open File -> Select All -> Add Sel -> Program -> Disconnect- 下完程序后记得给MCU复位或者断电重启, 然后就可以看到板子上LED在闪烁了

附录 最小工程文件列表
PS D:\ws\gitlab\ads_mcal\ads_mcal_dio_blinky_led> wsl tree
.
├── AppSw
│ └── Tricore
│ ├── Cfg_Ssw
│ │ └── TC39B
│ │ ├── Ifx_Cfg.h
│ │ ├── Ifx_Cfg_Ssw.c
│ │ ├── Ifx_Cfg_Ssw.h
│ │ └── Ifx_Cfg_SswBmhd.c
│ └── Main
│ ├── Cpu0_Main.c
│ ├── Cpu1_Main.c
│ ├── Cpu2_Main.c
│ ├── Cpu3_Main.c
│ ├── Cpu4_Main.c
│ └── Cpu5_Main.c
├── BaseSw
│ └── Infra
│ ├── Integration
│ │ ├── Adc_MemMap.h
│ │ ├── Bfx_MemMap.h
│ │ ├── CanTrcv_17_V9251_MemMap.h
│ │ ├── CanTrcv_17_W9255_MemMap.h
│ │ ├── Can_17_McmCan_MemMap.h
│ │ ├── Compiler_Cfg.h
│ │ ├── Crc_MemMap.h
│ │ ├── Dio_MemMap.h
│ │ ├── Dma_MemMap.h
│ │ ├── Dsadc_MemMap.h
│ │ ├── Fee_MemMap.h
│ │ ├── FlsLdr_ExclArea.c
│ │ ├── FlsLdr_ExclArea.h
│ │ ├── FlsLoader_MemMap.h
│ │ ├── Fls_17_Dmu_MemMap.h
│ │ ├── Gpt_MemMap.h
│ │ ├── Hssl_MemMap.h
│ │ ├── I2c_MemMap.h
│ │ ├── IFX_Os.c
│ │ ├── IFX_Os.h
│ │ ├── Icu_17_TimerIp_MemMap.h
│ │ ├── Iom_MemMap.h
│ │ ├── Irq_MemMap.h
│ │ ├── Lin_17_AscLin_MemMap.h
│ │ ├── McalLib_MemMap.h
│ │ ├── McalLib_OsStub.h
│ │ ├── Mcu_MemMap.h
│ │ ├── Ocu_MemMap.h
│ │ ├── Port_MemMap.h
│ │ ├── Pwm_17_GtmCcu6_MemMap.h
│ │ ├── SchM_Adc.c
│ │ ├── SchM_Adc.h
│ │ ├── SchM_CanTrcv_17_W9255.c
│ │ ├── SchM_CanTrcv_17_W9255.h
│ │ ├── SchM_Can_17_McmCan.c
│ │ ├── SchM_Can_17_McmCan.h
│ │ ├── SchM_Crc.c
│ │ ├── SchM_Crc.h
│ │ ├── SchM_Dma.c
│ │ ├── SchM_Dma.h
│ │ ├── SchM_Dsadc.c
│ │ ├── SchM_Dsadc.h
│ │ ├── SchM_Fee.h
│ │ ├── SchM_Fls_17_Dmu.h
│ │ ├── SchM_Gpt.c
│ │ ├── SchM_Gpt.h
│ │ ├── SchM_Hssl.c
│ │ ├── SchM_Hssl.h
│ │ ├── SchM_Icu_17_TimerIp.c
│ │ ├── SchM_Icu_17_TimerIp.h
│ │ ├── SchM_McalLib.c
│ │ ├── SchM_McalLib.h
│ │ ├── SchM_Mcu.c
│ │ ├── SchM_Mcu.h
│ │ ├── SchM_Ocu.c
│ │ ├── SchM_Ocu.h
│ │ ├── SchM_Pwm_17_GtmCcu6.c
│ │ ├── SchM_Pwm_17_GtmCcu6.h
│ │ ├── SchM_Smu.c
│ │ ├── SchM_Smu.h
│ │ ├── SchM_Spi.c
│ │ ├── SchM_Spi.h
│ │ ├── SchM_Uart.h
│ │ ├── SchM_Wdg_17_Scu.c
│ │ ├── SchM_Wdg_17_Scu.h
│ │ ├── Sent_MemMap.h
│ │ ├── Smu_MemMap.h
│ │ ├── Spi_MemMap.h
│ │ ├── Stm_MemMap.h
│ │ ├── Uart_MemMap.h
│ │ └── Wdg_17_Scu_MemMap.h
│ ├── Irq
│ │ └── ssc
│ │ ├── inc
│ │ │ └── Irq.h
│ │ └── src
│ │ └── Irq.c
│ └── Ssw
│ └── TC39B
│ └── Tricore
│ ├── Ifx_Ssw.h
│ ├── Ifx_Ssw_Compilers.h
│ ├── Ifx_Ssw_CompilersDcc.h
│ ├── Ifx_Ssw_CompilersGhs.h
│ ├── Ifx_Ssw_CompilersGnuc.h
│ ├── Ifx_Ssw_CompilersTasking.h
│ ├── Ifx_Ssw_Infra.c
│ ├── Ifx_Ssw_Infra.h
│ ├── Ifx_Ssw_LegacySwCfg.h
│ ├── Ifx_Ssw_Tc0.c
│ ├── Ifx_Ssw_Tc1.c
│ ├── Ifx_Ssw_Tc2.c
│ ├── Ifx_Ssw_Tc3.c
│ ├── Ifx_Ssw_Tc4.c
│ └── Ifx_Ssw_Tc5.c
├── Lcf_Tasking_Tricore_Tc.lsl
└── Mclsar
├── Src
│ ├── Infra_Prod
│ │ ├── Platform
│ │ │ ├── AS422
│ │ │ │ ├── Can_GeneralTypes.arxml
│ │ │ │ ├── Eth_GeneralTypes.arxml
│ │ │ │ ├── Eth_GeneralTypes.h
│ │ │ │ ├── Fr_GeneralTypes.arxml
│ │ │ │ └── Lin_GeneralTypes.arxml
│ │ │ ├── Can_GeneralTypes.h
│ │ │ ├── Compiler.h
│ │ │ ├── Fr_GeneralTypes.h
│ │ │ ├── Lin_GeneralTypes.h
│ │ │ ├── PlatformTypes.arxml
│ │ │ ├── Platform_Types.h
│ │ │ ├── StdTypes.arxml
│ │ │ └── Std_Types.h
│ │ └── Sfr
│ │ └── TC39xB
│ │ └── _Reg
│ │ ├── IfxAgbt_bf.h
│ │ ├── IfxAgbt_reg.h
│ │ ├── IfxAgbt_regdef.h
│ │ ├── IfxAsclin_bf.h
│ │ ├── IfxAsclin_reg.h
│ │ ├── IfxAsclin_regdef.h
│ │ ├── IfxCan_bf.h
│ │ ├── IfxCan_reg.h
│ │ ├── IfxCan_regdef.h
│ │ ├── IfxCbs_bf.h
│ │ ├── IfxCbs_reg.h
│ │ ├── IfxCbs_regdef.h
│ │ ├── IfxCcu6_bf.h
│ │ ├── IfxCcu6_reg.h
│ │ ├── IfxCcu6_regdef.h
│ │ ├── IfxConverter_bf.h
│ │ ├── IfxConverter_reg.h
│ │ ├── IfxConverter_regdef.h
│ │ ├── IfxCpu_bf.h
│ │ ├── IfxCpu_reg.h
│ │ ├── IfxCpu_regdef.h
│ │ ├── IfxDam_bf.h
│ │ ├── IfxDam_reg.h
│ │ ├── IfxDam_regdef.h
│ │ ├── IfxDma_bf.h
│ │ ├── IfxDma_reg.h
│ │ ├── IfxDma_regdef.h
│ │ ├── IfxDmu_bf.h
│ │ ├── IfxDmu_reg.h
│ │ ├── IfxDmu_regdef.h
│ │ ├── IfxDom_bf.h
│ │ ├── IfxDom_reg.h
│ │ ├── IfxDom_regdef.h
│ │ ├── IfxEbcu_bf.h
│ │ ├── IfxEbcu_reg.h
│ │ ├── IfxEbcu_regdef.h
│ │ ├── IfxEbu_bf.h
│ │ ├── IfxEbu_reg.h
│ │ ├── IfxEbu_regdef.h
│ │ ├── IfxEdsadc_bf.h
│ │ ├── IfxEdsadc_reg.h
│ │ ├── IfxEdsadc_regdef.h
│ │ ├── IfxEmem_bf.h
│ │ ├── IfxEmem_mpu_bf.h
│ │ ├── IfxEmem_mpu_reg.h
│ │ ├── IfxEmem_mpu_regdef.h
│ │ ├── IfxEmem_reg.h
│ │ ├── IfxEmem_regdef.h
│ │ ├── IfxEray_bf.h
│ │ ├── IfxEray_reg.h
│ │ ├── IfxEray_regdef.h
│ │ ├── IfxEvadc_bf.h
│ │ ├── IfxEvadc_reg.h
│ │ ├── IfxEvadc_regdef.h
│ │ ├── IfxFce_bf.h
│ │ ├── IfxFce_reg.h
│ │ ├── IfxFce_regdef.h
│ │ ├── IfxFsi_bf.h
│ │ ├── IfxFsi_reg.h
│ │ ├── IfxFsi_regdef.h
│ │ ├── IfxGeth_bf.h
│ │ ├── IfxGeth_reg.h
│ │ ├── IfxGeth_regdef.h
│ │ ├── IfxGpt12_bf.h
│ │ ├── IfxGpt12_reg.h
│ │ ├── IfxGpt12_regdef.h
│ │ ├── IfxGtm_bf.h
│ │ ├── IfxGtm_reg.h
│ │ ├── IfxGtm_regdef.h
│ │ ├── IfxHsct_bf.h
│ │ ├── IfxHsct_reg.h
│ │ ├── IfxHsct_regdef.h
│ │ ├── IfxHspdm_bf.h
│ │ ├── IfxHspdm_reg.h
│ │ ├── IfxHspdm_regdef.h
│ │ ├── IfxHssl_bf.h
│ │ ├── IfxHssl_reg.h
│ │ ├── IfxHssl_regdef.h
│ │ ├── IfxI2c_bf.h
│ │ ├── IfxI2c_reg.h
│ │ ├── IfxI2c_regdef.h
│ │ ├── IfxInt_bf.h
│ │ ├── IfxInt_reg.h
│ │ ├── IfxInt_regdef.h
│ │ ├── IfxIom_bf.h
│ │ ├── IfxIom_reg.h
│ │ ├── IfxIom_regdef.h
│ │ ├── IfxLmu_bf.h
│ │ ├── IfxLmu_reg.h
│ │ ├── IfxLmu_regdef.h
│ │ ├── IfxMcds_bf.h
│ │ ├── IfxMcds_reg.h
│ │ ├── IfxMcds_regdef.h
│ │ ├── IfxMsc_bf.h
│ │ ├── IfxMsc_reg.h
│ │ ├── IfxMsc_regdef.h
│ │ ├── IfxMtu_bf.h
│ │ ├── IfxMtu_reg.h
│ │ ├── IfxMtu_regdef.h
│ │ ├── IfxPfi_bf.h
│ │ ├── IfxPfi_reg.h
│ │ ├── IfxPfi_regdef.h
│ │ ├── IfxPms_bf.h
│ │ ├── IfxPms_reg.h
│ │ ├── IfxPms_regdef.h
│ │ ├── IfxPmu_bf.h
│ │ ├── IfxPmu_reg.h
│ │ ├── IfxPmu_regdef.h
│ │ ├── IfxPort_bf.h
│ │ ├── IfxPort_reg.h
│ │ ├── IfxPort_regdef.h
│ │ ├── IfxPsi5_bf.h
│ │ ├── IfxPsi5_reg.h
│ │ ├── IfxPsi5_regdef.h
│ │ ├── IfxPsi5s_bf.h
│ │ ├── IfxPsi5s_reg.h
│ │ ├── IfxPsi5s_regdef.h
│ │ ├── IfxQspi_bf.h
│ │ ├── IfxQspi_reg.h
│ │ ├── IfxQspi_regdef.h
│ │ ├── IfxRif_bf.h
│ │ ├── IfxRif_reg.h
│ │ ├── IfxRif_regdef.h
│ │ ├── IfxSbcu_bf.h
│ │ ├── IfxSbcu_reg.h
│ │ ├── IfxSbcu_regdef.h
│ │ ├── IfxScu_bf.h
│ │ ├── IfxScu_reg.h
│ │ ├── IfxScu_regdef.h
│ │ ├── IfxSdmmc_bf.h
│ │ ├── IfxSdmmc_reg.h
│ │ ├── IfxSdmmc_regdef.h
│ │ ├── IfxSent_bf.h
│ │ ├── IfxSent_reg.h
│ │ ├── IfxSent_regdef.h
│ │ ├── IfxSmu_bf.h
│ │ ├── IfxSmu_reg.h
│ │ ├── IfxSmu_regdef.h
│ │ ├── IfxSpu_bf.h
│ │ ├── IfxSpu_reg.h
│ │ ├── IfxSpu_regdef.h
│ │ ├── IfxSpulckstp_bf.h
│ │ ├── IfxSpulckstp_reg.h
│ │ ├── IfxSpulckstp_regdef.h
│ │ ├── IfxSrc_bf.h
│ │ ├── IfxSrc_reg.h
│ │ ├── IfxSrc_regdef.h
│ │ ├── IfxStm_bf.h
│ │ ├── IfxStm_reg.h
│ │ ├── IfxStm_regdef.h
│ │ ├── Ifx_TypesReg.h
│ │ └── Ifx_reg.h
│ └── Mcal
│ └── Tricore
│ ├── Dio
│ │ └── ssc
│ │ ├── inc
│ │ │ └── Dio.h
│ │ └── src
│ │ └── Dio.c
│ ├── McalLib
│ │ └── ssc
│ │ ├── inc
│ │ │ ├── AS422
│ │ │ │ └── Mcal_Version.h
│ │ │ ├── McalLib.h
│ │ │ └── Mcal_Compiler.h
│ │ └── src
│ │ └── McalLib.c
│ ├── Mcu
│ │ └── ssc
│ │ ├── inc
│ │ │ ├── Mcu.h
│ │ │ ├── Mcu_17_TimerIp.h
│ │ │ └── Mcu_17_TimerIp_Local.h
│ │ └── src
│ │ ├── Mcu.c
│ │ └── Mcu_17_TimerIp.c
│ └── Port
│ └── ssc
│ ├── inc
│ │ └── Port.h
│ └── src
│ └── Port.c
└── eb_blinky_led
├── config
│ ├── Dio.xdm
│ ├── Irq.xdm
│ ├── McalLib.xdm
│ ├── Mcu.xdm
│ ├── Port.xdm
│ ├── ResourceM.xdm
│ └── SystemModel2.tdb
└── output
└── generated
├── Dio_Bswmd.arxml
├── Irq_Bswmd.arxml
├── McalLib_Bswmd.arxml
├── Mcu_Bswmd.arxml
├── Port_Bswmd.arxml
├── inc
│ ├── Dio_Cfg.h
│ ├── Irq_Cfg.h
│ ├── McalLib_Cfg.h
│ ├── Mcu_17_TimerIp_Cfg.h
│ ├── Mcu_Cfg.h
│ ├── Mcu_PBcfg.h
│ ├── Port_Cfg.h
│ └── Port_PBcfg.h
└── src
├── Dio_Lcfg.c
├── Mcu_17_TimerIp_Cfg.c
├── Mcu_PBcfg.c
└── Port_PBcfg.c
48 directories, 301 files
更多推荐



所有评论(0)