# S32K3学习笔记—S32K3之Gpt、Dio、Platform
1.前言
本文是在S32K324上在两个核上分别注册一个定时器中断,在每个定时器中断里面翻转一个IO。用这个简单功能来记录Port、Dio、Platform、Gpt、Ecuc等模块的配置,这些模块都很基础,就简单记录了
2.原理
2.1 Port模块主要是分配 每个Pin的属性,主要是输出输入、默认高低低电平、功能复用等
2.2 Dio模块主要是配置Id (0 - 15)
2.3 platform模块主要是对中断的使能,注册回调,监控等功能。
2.4 Gpt模块主要是配置定时器,选择不同的定时器种类等
3.EB配置
3.1 ECUC模块
1.定义两个核ID
1.定义两个分区
3.2 BaseNXP模块
1.使能多核支持
2.前面文章提到SystemTick给到OS使用,所以此处失能
3.选择AutosarOs类型
此处配置OS的计数参考
3.3 OS模块
1. AUTOSAR操作系统必须能够支持一组操作系统对象(任务、中断、警报、挂钩等),这些对象构成一个有凝聚力的功能单元。此对象集合称为操作系统应用程序
1.分别在OsApplication_0、OsApplication_1中选择Ecuc的分区参考和core参考
3.4 Port模块
1.这些特殊的Pin是用于PE debug和一个MCU复位引脚,保持默认配置就行
1.对于没用到的Pin做一个输入IO 且 默认拉低
2.这些General都是失能一些API,失能某些功能,具体按需求勾选
3.多核支持失能,两个核都需要分配PORT
1.将Port驱动映射到两个Ecuc分区
1.可以按照Portx来分这些所有的port,为了好修该,我们可以将所有的Port都分配出来
1.对于上拉、下拉、模式可变等根据实际需求来配置
2. 用于指定端口配置寄存器:SIUL I/O引脚多路复用信号配置寄存器(MSCR编号)
3.确定是输出方向还是输入方向
4.模式选择,如GPIO、ADC、CAN_TX等
5.默认输出电平状态
1.将PTA2划分到ECUC_0分区
类似的,我们将PTB18注册到核1上
至此,Port模块就配置完成了。在实际项目中,我们需要配置很多个Port,在配置的时候注意区分一下主核还是从核。可以将所有的IO都加到PortContainer 里面,对于后续改版会比方便,没用的到Pin默认输入模式,低电平。
3.5 Dio模块
1.使能API和一些同意功能,按需求开启
2.使能多核支持
1.PortA(0 - 15) – DioPor_A_L 、 PortA(16 - 31) – DioPor_A_H。其他的PortB等都依次增加16,直至最后一个PortPin Mscr ,其Id范围必须在0 - 15
1.例如PTA2 其PortPin Mscr 为2,所以放在DioPor_A_L,其ID为2
1.资源分配到核0
类似的,我们在核1注册另外一个Dio
1. PTB18的PortPin Mscr 为50 , 所以其Id = 50 - (16 * 3) = 2
1.资源分配到核1
至此,Dio模块也是配置完成,和Port相似,我们可以将所有的分组都加上,方便后期修改
3.6 Platform模块
1. 分区参考,应用Ecuc中的两个分区,可以将不同中断绑定到不同的核
1.使能多核支持,其他的API和通用功能按需求使能
1.我们在此注册两个中断向量表
1.将向量表分别定义到两个分区
1.先使能中断,在注册中断回调函数,函数名字不是随便的,可以去对应的模块的XX_Ip.h中找
类似的,我们可以在另一个核注册PIT1
3.4 Gpt模块
1.此处的时间参考点是MCU那边配置的,供外部模块使用,MCU详细配置可参考:S32K3学习笔记—S32K3之MCU模块-CSDN博客
1.使能多核配置,其他配置项按照需求使能
1.可以看出能支持定时器配置的有pit、stm、rtc、emios,此处只用到Pit定时器,其他的几种也是可以选择的
2.新增两个Pit通道,每路Pit有5个通道,此处用Pit0、Pit1的通道0
1.硬件配置这需要使能中断和通道是否需要使用
1.配置两个通道,并且分配到不同的核
1.选择通道
2.选择连续触发的方式
3.选择时钟参考
4.注册回调函数,此函数需要在工程里面手动注册
1.将此GPT分配给核0
类似的,可以注册两外一个Gpt通道到核1
至此,EB里面对MCAL的配置就基本完成,后续需要将代码集成到工程里面调试
4.代码调试
分别在main_c0 和 main_c1注册两个回调函数
/**
* @brief Gpt notification called by the configured channel periodically
* @details Used to blink a led
*/
void Gpt0_Notification(void)
{
Dio_FlipChannel(DioConf_DioChannel_PTA2);
}
/**
* @brief Main function of the example
* @details Initializes the used drivers and uses the Gpt
* and Dio drivers to toggle a LED periodically
*/
int main_c0(void)
{
/* Init clock */
#if (STD_ON == MCU_PRECOMPILE_SUPPORT)
Mcu_Init(NULL_PTR);
#else
Mcu_Init(&Mcu_Config_VS_0);
#endif
#if (STD_ON == MCU_INIT_CLOCK)
/* Initialize the clock tree and apply PLL as system clock */
Mcu_InitClock(McuClockSettingConfig_0);
#if (STD_OFF == MCU_NO_PLL)
while ( MCU_PLL_LOCKED != Mcu_GetPllStatus() )
{
/* Busy wait until the System PLL is locked */
}
Mcu_DistributePllClock();
#endif
Mcu_SetMode(McuModeSettingConf_0);
#else
#error "The Mcu Init Clock API should be enabled from the Mcu driver"
#endif
/* Initialize all pins using the Port driver */
#if (STD_ON == PORT_PRECOMPILE_SUPPORT)
Port_Init(NULL_PTR);
#else
Port_Init(&Port_Config_VS_0);
#endif
/* Initialize Platform driver */
Platform_Init(NULL_PTR);
/* Initialize the high level configuration structure of Gpt driver */
#if (STD_ON == GPT_PRECOMPILE_SUPPORT)
Gpt_Init(NULL_PTR);
#else
Gpt_Init(&Gpt_Config_VS_0);
#endif
/* Start the Gpt timer */
Gpt_StartTimer(GptConf_GptChannelConfiguration_GptChannelConfiguration_0, 20000000U);
/* Enable the Gpt notification to get the event for toggling the LED periodically */
Gpt_EnableNotification(GptConf_GptChannelConfiguration_GptChannelConfiguration_0);
for(;;)
{
/* do nothing */
}
return (0U);
}
/**
* @brief Gpt notification called by the configured channel periodically
* @details Used to blink a led
*/
void Gpt1_Notification(void)
{
Dio_FlipChannel(DioConf_DioChannel_PTB18);
}
/**
* @brief Main function of the example
* @details Initializes the used drivers and uses the Gpt
* and Dio drivers to toggle a LED periodically
*/
int main_c1(void)
{
/* Initialize all pins using the Port driver */
#if (STD_ON == PORT_PRECOMPILE_SUPPORT)
Port_Init(NULL_PTR);
#else
Port_Init(&Port_Config_VS_0);
#endif
/* Initialize Platform driver */
Platform_Init(NULL_PTR);
/* Initialize the high level configuration structure of Gpt driver */
#if (STD_ON == GPT_PRECOMPILE_SUPPORT)
Gpt_Init(NULL_PTR);
#else
Gpt_Init(&Gpt_Config_VS_0);
#endif
/* Start the Gpt timer */
Gpt_StartTimer(GptConf_GptChannelConfiguration_GptChannelConfiguration_1, 20000000U);
/* Enable the Gpt notification to get the event for toggling the LED periodically */
Gpt_EnableNotification(GptConf_GptChannelConfiguration_GptChannelConfiguration_1);
for(;;)
{
/* do nothing */
}
return (0U);
}