【MPC5744P】S32DS中Processor Expert自动生成代码工具使用教程(四) GPIO配置之点亮LED

一、新建项目

新建一个S32SD项目,名称为led_test,芯片选择MPC5744P,SDK选择最新版本,注意不要选择FreeMaster,当前版本自动配置有些问题,我们后面手动配置。若是以后有更新,大家可以添加FreeMaster自动配置试试。

【MPC5744P】S32DS中Processor Expert自动生成代码工具使用教程(四) GPIO配置之点亮LED_第1张图片

【MPC5744P】S32DS中Processor Expert自动生成代码工具使用教程(四) GPIO配置之点亮LED_第2张图片【MPC5744P】S32DS中Processor Expert自动生成代码工具使用教程(四) GPIO配置之点亮LED_第3张图片

 

二、Processor Expert配置

新建项目完毕,我们会在项目最底下看到ProcessorExpert.pe文件,在菜单栏显示Processor Expert,可以看到配置项,系统自动将核心配置已经添加进去了。

注意,若是Componets为空,一般是没有选中项目。

 

【MPC5744P】S32DS中Processor Expert自动生成代码工具使用教程(四) GPIO配置之点亮LED_第4张图片

【MPC5744P】S32DS中Processor Expert自动生成代码工具使用教程(四) GPIO配置之点亮LED_第5张图片

由于刚刚接触Processor Expert,为了避免出现错误,我们使用默认的时钟即可。选择pin_mux:PinSettings我们来设置GPIO,来点亮led。假设我们LED为PC11,低电平亮。

1、选择pin_mux:PinSettings,然后选中Component Inspector - pin_mux界面

2、在Routing界面选中Pins,设置PC11引脚功能为GPIO,输出

3、在Functional Properties界面将PC11的初始值为High。

设置完毕后保存,再在Project中选择Generate Processor Expert Code,此时,所有驱动代码生成完毕。

【MPC5744P】S32DS中Processor Expert自动生成代码工具使用教程(四) GPIO配置之点亮LED_第6张图片

【MPC5744P】S32DS中Processor Expert自动生成代码工具使用教程(四) GPIO配置之点亮LED_第7张图片

 

若是还想进行高级设置,例如开漏,上下拉等等,在pin_mux的Functional Properties界面选中Pins选项,就可以设置。

 

【MPC5744P】S32DS中Processor Expert自动生成代码工具使用教程(四) GPIO配置之点亮LED_第8张图片

 

设置完毕,就可以生成代码了(生成完代码仍需要手动调用)。

【MPC5744P】S32DS中Processor Expert自动生成代码工具使用教程(四) GPIO配置之点亮LED_第9张图片

 

三、使用自动生成的代码

自动生成了代码不意味着就可以直接编译下载了,生成的只是驱动代码而已,还需要我们去引用。

Processor Expert的自动生成代码思路为:将所有外设的配置变成数组,生成时变化的只是数组,我们可以查看Generated_Code文件夹里面的.c/.h文件,全是配置文件数组。而需要传入这些数据的函数都存于SDK中。

例如我们要初始化时钟。调用clock_MPC57xx.h和cloclMan1.h中的函数和参数即可。设置pin脚也是这样。

【MPC5744P】S32DS中Processor Expert自动生成代码工具使用教程(四) GPIO配置之点亮LED_第10张图片

我们初始化时钟和引脚,然后延时亮灭led。注意这里led的函数中操作pin和pins是不同的,pin直接写引脚号即可,pins是操作多个引脚,采用的是位控,例如PC11:

pin操作:PINS_DRV_WritePin(PTC, 11,1);  //PC11电平拉高

pins操作:PINS_DRV_TogglePins(PTC, (1 << 11)); //PC11电平翻转

 

main.c代码示例:

注意不同版本SDK函数会略有区别,例如‘SDK1.9.0中就没有CLOCK_SYS_UpdateConfiguration(0U, CLOCK_MANAGER_POLICY_AGREEMENT);了

/*
 * Copyright (c) 2013 - 2015, Freescale Semiconductor, Inc.
 * Copyright 2016-2017 NXP
 * All rights reserved.
 *
 * THIS SOFTWARE IS PROVIDED BY NXP "AS IS" AND ANY EXPRESSED OR
 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
 * IN NO EVENT SHALL NXP OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
 * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
 * THE POSSIBILITY OF SUCH DAMAGE.
 */
/* ###################################################################
**     Filename    : main.c
**     Processor   : MPC574xP
**     Abstract    :
**         Main module.
**         This module contains user's application code.
**     Settings    :
**     Contents    :
**         No public methods
**
** ###################################################################*/
/*!
** @file main.c
** @version 01.00
** @brief
**         Main module.
**         This module contains user's application code.
*/
/*!
**  @addtogroup main_module main module documentation
**  @{
*/
/* MODULE main */


/* Including necessary module. Cpu.h contains other modules needed for compiling.*/
#include "Cpu.h"

  volatile int exit_code = 0;
/* User includes (#include below this line is not maintained by Processor Expert) */

/*!
  \brief The main function for the project.
  \details The startup initialization sequence is the following:
 * - startup asm routine
 * - main()
*/

uint32_t count=0;
int main(void)
{
  /* Write your local variable definition here */

  /*** Processor Expert internal initialization. DON'T REMOVE THIS CODE!!! ***/
  #ifdef PEX_RTOS_INIT
    PEX_RTOS_INIT();                   /* Initialization of the selected RTOS. Macro is defined by the RTOS component. */
  #endif
  /*** End of Processor Expert internal initialization.                    ***/

  /* Write your code here */
  /* For example: for(;;) { } */
    /* Initialize clock gate*/
	CLOCK_SYS_Init(g_clockManConfigsArr,   CLOCK_MANAGER_CONFIG_CNT,
				   g_clockManCallbacksArr, CLOCK_MANAGER_CALLBACK_CNT);
	CLOCK_SYS_UpdateConfiguration(0U, CLOCK_MANAGER_POLICY_AGREEMENT);
	/* Initialize and configure pins */
	PINS_DRV_Init(NUM_OF_CONFIGURED_PINS, g_pin_mux_InitConfigArr);

    for(;;)
    {
    	count++;
    	if(count>800000)
    	{
    		count=0;
    		PINS_DRV_TogglePins(PTC, (1 << 11));
    		//PINS_DRV_WritePin(PTC, 11);
    	}
    }

  /*** Don't write any code pass this line, or it will be deleted during code generation. ***/
  /*** RTOS startup code. Macro PEX_RTOS_START is defined by the RTOS component. DON'T MODIFY THIS CODE!!! ***/
  #ifdef PEX_RTOS_START
    PEX_RTOS_START();                  /* Startup of the selected RTOS. Macro is defined by the RTOS component. */
  #endif
  /*** End of RTOS startup code.  ***/
  /*** Processor Expert end of main routine. DON'T MODIFY THIS CODE!!! ***/
  for(;;) {
    if(exit_code != 0) {
      break;
    }
  }
  return exit_code;
  /*** Processor Expert end of main routine. DON'T WRITE CODE BELOW!!! ***/
} /*** End of main routine. DO NOT MODIFY THIS TEXT!!! ***/

/* END main */
/*!
** @}
*/
/*
** ###################################################################
**
**     This file was created by Processor Expert 10.1 [05.21]
**     for the NXP C55 series of microcontrollers.
**
** ###################################################################
*/

【MPC5744P】S32DS中Processor Expert自动生成代码工具使用教程(四) GPIO配置之点亮LED_第11张图片

 

七、编译下载

注意下载时,选择的要是编译的同一个Interface,Debug就选Debug,而Debug_RAM则要选Debug_RAM。

注意选择你的调试器。

下载完毕,即可看到led在闪烁了。

【MPC5744P】S32DS中Processor Expert自动生成代码工具使用教程(四) GPIO配置之点亮LED_第12张图片

你可能感兴趣的:(MCU,NXP,MPC574X开发)