1:将MCAL文件复制到工程下
新建文件夹(cfg和Lib)存放生成的文件和静态代码:
将EB生成的代码复制到cfg文件夹下。
库文件路径为:
D:\NXP\AUTOSAR\S32K1XX_MCAL4_0_RTM_CD01_1_0_5\eclipse\plugins
文件添加到工程
把生成的src路径下.c文件和库中的.c文件全部添加到工程中。
将所有的路径添加到工程中:
未使用到OS,所以此处添加宏 AUTOSAR_OS_NOT_USED
3:添加SchM文件夹
创建SchM/include文件夹
将SchM_Dio.h,SchM_Mcu.h,SchM_Port.h复制到SchM/include文件夹下。
修改SchM_Dio.h,删除所有extern。
然后添加宏为空:
#define SchM_Enter_Dio_DIO_EXCLUSIVE_AREA_00()
#define SchM_Exit_Dio_DIO_EXCLUSIVE_AREA_00()
#define SchM_Enter_Dio_DIO_EXCLUSIVE_AREA_01()
#define SchM_Exit_Dio_DIO_EXCLUSIVE_AREA_01()
#define RTE_STOP_SEC_CODE
修改SchM_Mcu.h文件:
删除所有的extern,然后添加:
extern void SchM_Enter_Mcu_MCU_EXCLUSIVE_AREA_00(void);
extern void SchM_Exit_Mcu_MCU_EXCLUSIVE_AREA_00(void);
extern void SchM_Enter_Mcu_MCU_EXCLUSIVE_AREA_01(void);
extern void SchM_Exit_Mcu_MCU_EXCLUSIVE_AREA_01(void);
extern void SchM_Enter_Mcu_MCU_EXCLUSIVE_AREA_02(void);
extern void SchM_Exit_Mcu_MCU_EXCLUSIVE_AREA_02(void);
#define RTE_STOP_SEC_CODE
#include "Rte_MemMap.h"
修改SchM_Port.h文件:
删除所有的extern,然后添加:
#define SchM_Enter_Port_PORT_EXCLUSIVE_AREA_00()
#define SchM_Exit_Port_PORT_EXCLUSIVE_AREA_00()
#define SchM_Enter_Port_PORT_EXCLUSIVE_AREA_01()
#define SchM_Exit_Port_PORT_EXCLUSIVE_AREA_01()
#define SchM_Enter_Port_PORT_EXCLUSIVE_AREA_02()
#define SchM_Exit_Port_PORT_EXCLUSIVE_AREA_02()
#define SchM_Enter_Port_PORT_EXCLUSIVE_AREA_03()
#define SchM_Exit_Port_PORT_EXCLUSIVE_AREA_03()
#define SchM_Enter_Port_PORT_EXCLUSIVE_AREA_04()
#define SchM_Exit_Port_PORT_EXCLUSIVE_AREA_04()
#define SchM_Enter_Port_PORT_EXCLUSIVE_AREA_05()
#define SchM_Exit_Port_PORT_EXCLUSIVE_AREA_05()
#define SchM_Enter_Port_PORT_EXCLUSIVE_AREA_06()
#define SchM_Exit_Port_PORT_EXCLUSIVE_AREA_06()
#define SchM_Enter_Port_PORT_EXCLUSIVE_AREA_07()
#define SchM_Exit_Port_PORT_EXCLUSIVE_AREA_07()
#define SchM_Enter_Port_PORT_EXCLUSIVE_AREA_08()
#define SchM_Exit_Port_PORT_EXCLUSIVE_AREA_08()
#define RTE_STOP_SEC_CODE
添加main文件内容:
/*
* (c) Copyright 2021 NXP
*
* NXP Confidential. This software is owned or controlled by NXP and may only be used strictly
* in accordance with the applicable license terms. By expressly accepting
* such terms or by downloading, installing, activating and/or otherwise using
* the software, you are agreeing that you have read, and that you agree to
* comply with and are bound by, such license terms. If you do not agree to
* be bound by the applicable license terms, then you may not retain,
* install, activate or otherwise use the software.
*
* This file contains sample code only. It is not part of the production code deliverables.
*/
#ifdef __cplusplus
extern "C" {
#endif
/*==================================================================================================
* INCLUDE FILES
* 1) system and project includes
* 2) needed interfaces from external units
* 3) internal and external interfaces from this unit
==================================================================================================*/
#include "Mcu.h"
#include "Port.h"
#include "Dio.h"
/*==================================================================================================
* LOCAL TYPEDEFS (STRUCTURES, UNIONS, ENUMS)
==================================================================================================*/
/*==================================================================================================
* LOCAL MACROS
==================================================================================================*/
/*==================================================================================================
* LOCAL CONSTANTS
==================================================================================================*/
/*==================================================================================================
* LOCAL VARIABLES
==================================================================================================*/
/*==================================================================================================
* GLOBAL CONSTANTS
==================================================================================================*/
/*==================================================================================================
* GLOBAL VARIABLES
==================================================================================================*/
/*==================================================================================================
* LOCAL FUNCTION PROTOTYPES
==================================================================================================*/
/*==================================================================================================
* LOCAL FUNCTIONS
==================================================================================================*/
/*==================================================================================================
* GLOBAL FUNCTIONS
==================================================================================================*/
void TestDelay(uint32 delay);
void TestDelay(uint32 delay)
{
static volatile uint32 DelayTimer = 0;
while(DelayTimer<delay)
{
DelayTimer++;
}
DelayTimer=0;
}
/**
* @brief Main function of the example
* @details Initializez the used drivers and uses the Icu
* and Dio drivers to toggle a LED on a push button
*/
int main(void)
{
/* Initialize the Mcu driver */
Mcu_Init(&McuModuleConfiguration);
Mcu_InitClock(McuClockSettingConfig_0);
#if (MCU_NO_PLL == STD_OFF)
while ( MCU_PLL_LOCKED != Mcu_GetPllStatus() )
{
/* Busy wait until the System PLL is locked */
}
Mcu_DistributePllClock();
#endif
Mcu_SetMode(McuModeSettingConf_0);
/* Initialize all pins using the Port driver */
Port_Init(&PortConfigSet_0);
while (1)
{
/* Get input level of channels */
Dio_WriteChannel(DioConf_DioChannel_LED_BLUE, STD_HIGH);
Dio_WriteChannel(DioConf_DioChannel_LED_GREEN, STD_HIGH);
Dio_WriteChannel(DioConf_DioChannel_LED_YELLOW, STD_HIGH);
TestDelay(2000000);
Dio_WriteChannel(DioConf_DioChannel_LED_BLUE, STD_LOW);
Dio_WriteChannel(DioConf_DioChannel_LED_GREEN, STD_LOW);
Dio_WriteChannel(DioConf_DioChannel_LED_YELLOW, STD_LOW);
TestDelay(2000000);
}
}
#ifdef __cplusplus
}
#endif
/** @} */
修改Port_Cfg.h中的宏PORT_DEV_ERROR_DETECT为STD_OFF。
#define PORT_DEV_ERROR_DETECT (STD_OFF)
取消勾选C99 Mode及GUN externsions.
编译烧录并调试
此时编译已经没有问题了,出现一个warning是因为Keil5的license已经到期,跟代码没关系。
烧录及调试:
输出高电平:
效果:板子上的灯全部灭了(左面红色为电源指示灯)。
输出低电平:
效果:板子上的灯已经全部亮了起来(左面红色为电源指示灯).