【S32K3 RTD LLD篇1】 LPUART helloword so easy


开启外设篇的学习了,首先来一个lpuart的helloworld,体验下S32K3在S32DS的CT工具配置外设下有多丝滑多好用。关于LPUART的理论,无需多讲,感兴趣的可以去S32Kxx Reference manual中看看,IP的功能比较简单易懂,文档写的也足够详细。这里在配置LPUART的过程中,主要几部分:引脚配置,时钟配置,中断配置,Siul2_Port配置,lpuart配置。

一,配置步骤

首先打开之前装好的S32DS工具,注意RTD一定要装,本文基于S32DS3.5.0和RTD4.0.0. 板子基于NXP 官方的S32K3XXEVB-Q172.
新建一个工程:File->New->S32DS Application Project, debugger选择PE Micro的,因为EVB板载使用的是PE的debugger。一定主要要选择基于RTD,这样会新建好之后,会添加好RTD的驱动。
新建好之后,双击工程中的.mex,打开CFG工具。

1. 1 Pins配置

打开S32K344EVB-Q172的原理图,可以看到板载的串口对应的脚是芯片的PTA15,PTA16:

在这里插入图片描述

图 1

在Pins工具中,添加两个引脚如下:
在这里插入图片描述

图 2

原理图使用的引脚是PTA15,PTA16,这里的需要注意的就是在选择PTA16作为发送引脚的时候,会让选择方向,输入,输出,或者双向,这里需要选择输出,因为这里使用的是单纯输出,并不像单线模式那样可以输入也可以输出。
配置好后,可以生成下代码。

1.2 Clocks

这里在CT工具中,有一些调整,配置LPUART6的时钟源为24MHZ,

在这里插入图片描述

图 3

在这里插入图片描述

图 4

AIPS_SLOW_CLK从FIRC走,然后经过2分频,HSE_CLK 分频改成1,否则报错。
这里,关于UART的时钟就改好了,时钟系统还是很简单的。生成下代码。

1.3 Peripherals

外设配置,这里在新建的基础上添加Int_Ctrl_Ip,Lpuart_Uart,Siul2_Port这三个块:
IntCtrl_Ip: 配置中断控制器
Siul2_Port: 配置使用到的引脚port
Lpuart_Uart: 配置lpuart外设

1.3.1 IntCtrl_Ip

添加lpuart6的中断名称,并且使能中断,修改Handler的名称为:LPUART_UART_IP_6_IRQHandler
在这里插入图片描述

图5

1.3.2 Siul2_Port

在PortConfigSet中添加两个引脚port:
在这里插入图片描述

图 6

PortPin Mscr号分别为15和16,这个号可以在S32K3xxx RM配套的IOMUX.xlsx中查到:
在这里插入图片描述

图 7

1.3.3 Lpuart_Uart

这里配置的选项如下:
在这里插入图片描述

图 8

这个是配置uart超时间隔,us单位,用于同步传输的超时时间设置。
在这里插入图片描述

图 9

这里配置uart的接口号,波特率,选中中断方式,其他都保持默认。
配置好后,生成代码。
到目前为止,所有的CT工具代码已经配置完成,下面就是在main中做底层调用了,可以根据自己应用的情况去做对应的调用。

二,main代码

本文实现发送一个helloword的字样,然后能够接受数据到接受buffer中。
Main代码如下:

/*==================================================================================================
* Project : RTD AUTOSAR 4.7
* Platform : CORTEXM
* Peripheral : S32K3XX
* Dependencies : none
*
* Autosar Version : 4.7.0
* Autosar Revision : ASR_REL_4_7_REV_0000
* Autosar Conf.Variant :
* SW Version : 4.0.0
* Build Version : S32K3_RTD_4_0_0_D2311_ASR_REL_4_7_REV_0000_20231128
*
* Copyright 2020 - 2023 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.
==================================================================================================*/

/**
*   @file main.c
*
*   @addtogroup main_module main module documentation
*   @{
*/

/* Including necessary configuration files. */
#include "Mcal.h"
#include "Lpuart_Uart_Ip.h"
#include "Lpuart_Uart_Ip_Irq.h"
#include "Clock_Ip.h"
#include "IntCtrl_Ip.h"
#include "Siul2_Port_Ip.h"
#include "string.h"

#define UART_LPUART6_INTERNAL_CHANNEL 6
#define WELCOME_MSG "Helloworld for automotive with S32K344!\r\n"
volatile int exit_code = 0;
uint8 RX_Buffer[50];
/* User includes */

/*!
  \brief The main function for the project.
  \details The startup initialization sequence is the following:
 * - startup asm routine
 * - main()
*/
int main(void)
{
    /* Write your code here */

	Clock_Ip_Init(&Clock_Ip_aClockConfig[0]);

	Siul2_Port_Ip_Init(NUM_OF_CONFIGURED_PINS_PortContainer_0_BOARD_InitPeripherals,g_pin_mux_InitConfigArr_PortContainer_0_BOARD_InitPeripherals);

	IntCtrl_Ip_Init(&IntCtrlConfig_0);

	Lpuart_Uart_Ip_Init(UART_LPUART6_INTERNAL_CHANNEL, &Lpuart_Uart_Ip_xHwConfigPB_6);

	Lpuart_Uart_Ip_AsyncSend(UART_LPUART6_INTERNAL_CHANNEL,(const uint8 *)WELCOME_MSG, strlen(WELCOME_MSG));


	Lpuart_Uart_Ip_AsyncReceive(UART_LPUART6_INTERNAL_CHANNEL,RX_Buffer,20);

	for(;;)
    {


    }
    return exit_code;
}

/** @} */

Main代码写好后,编译工程,并且下载代码到目标S32K344EVB-Q172中。

三,测试结果

打开一个串口助手,选择串口号为板子做模拟出来的串口号。然后代码运行起来,打印结果如下:
在这里插入图片描述

图10

Helloword so easy的完成了。

  • 9
    点赞
  • 18
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值