S32DS 生成S32K144的串口代码

1 篇文章 0 订阅
1 篇文章 0 订阅

环境:

软件S32 Design Studio for ARM

仿真器 JlinkV8

目标板:S32K144 demo板

 

1 新加一个S32DS 工程

2 选择对应devices S32K144

 

3 选择SDK和Debuger工具,然后Finish

 

4  在Component Inspector界面配置串口IO,这里目标板子的串口是使用UART0,IO-PTB0、PTB1。如果没有这个界面可以点击Processor Expert-》Show Views

5 在Component Library界面选择lpuart组件加入工程

6 这个就可以生成代码了,Project-》Genrate Process Expert Code

7 生成的代码目录如下, Genrated_Code是一些配置性的代码,而SDK目录下主要是官方性的接口,需要自己编写初始化等相关代码。

 

8 这里在main中初始化了时钟,串口,IO

时钟的接口相关变量和配置结构体可以在clockMan1.h找到,其他串口和IO也可以在对应头文件中找到。

 

测试就直接在for循环中,read 然后write。一个字节收然后一个字节发。

/* ###################################################################
**     Filename    : main.c
**     Processor   : S32K14x
**     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()
*/
int main(void)
{
  /* Write your local variable definition here */
	uint8_t dat;
  /*** 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(;;) { } */
	/*Clock init */
	CLOCK_SYS_Init(g_clockManConfigsArr, CLOCK_MANAGER_CONFIG_CNT, g_clockManCallbacksArr, CLOCK_MANAGER_CALLBACK_CNT);
	CLOCK_SYS_UpdateConfiguration(0U, CLOCK_MANAGER_POLICY_AGREEMENT);

	/*Pin init */
	PINS_DRV_Init(NUM_OF_CONFIGURED_PINS, g_pin_mux_InitConfigArr);

	/*Uart init*/
	LPUART_DRV_Init(INST_LPUART0, &lpuart0_wes_State, &lpuart0_wes_InitConfig0);

  /*** 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;
    }
    LPUART_DRV_ReceiveDataPolling(INST_LPUART0, &dat, (uint32_t)sizeof(dat));
    LPUART_DRV_SendDataPolling(INST_LPUART0, &dat, (uint32_t)sizeof(dat));

  }
  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 Freescale S32K series of microcontrollers.
**
** ###################################################################
*/

 

 

 

新增中断

代码修改 新加了中断回调函数

这里有一点要注意的是

/* ###################################################################
**     Filename    : main.c
**     Processor   : S32K14x
**     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) */

void read_irq(void *driverState, uart_event_t event, void *userData)
{
	uint8_t receive;
	LPUART_Type * LPUARTx[]= LPUART_BASE_PTRS;

	if((LPUARTx[0]->STAT & LPUART_STAT_RDRF_MASK)>>LPUART_STAT_RDRF_SHIFT)
	{
		receive = LPUARTx[0]->DATA;            /* Read received data*/
		LPUART_DRV_SendDataPolling(INST_LPUART0, &receive, (uint32_t)sizeof(receive));
	}
	if(LPUARTx[0]->STAT&0x80000)
	{
		LPUARTx[0]->STAT|=0x80000;
	}
	LPUART_DRV_ReceiveData(0, &receive, 1);
}
/*!
  \brief The main function for the project.
  \details The startup initialization sequence is the following:
 * - startup asm routine
 * - main()
*/
int main(void)
{
  /* Write your local variable definition here */
	uint8_t dat;
	void *checkpar;
  /*** 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(;;) { } */
	/*Clock init */
	CLOCK_SYS_Init(g_clockManConfigsArr, CLOCK_MANAGER_CONFIG_CNT, g_clockManCallbacksArr, CLOCK_MANAGER_CALLBACK_CNT);
	CLOCK_SYS_UpdateConfiguration(0U, CLOCK_MANAGER_POLICY_AGREEMENT);

	/*Pin init */
	PINS_DRV_Init(NUM_OF_CONFIGURED_PINS, g_pin_mux_InitConfigArr);

	/*Uart init*/
	LPUART_DRV_Init(INST_LPUART0, &lpuart0_wes_State, &lpuart0_wes_InitConfig0);
	LPUART_DRV_InstallRxCallback(INST_LPUART0, (uart_callback_t)read_irq, checkpar);
	LPUART_DRV_ReceiveData(0, &dat, 1);
  /*** 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;
    }
//    LPUART_DRV_ReceiveDataPolling(INST_LPUART0, &dat, (uint32_t)sizeof(dat));
//    LPUART_DRV_SendDataPolling(INST_LPUART0, &dat, (uint32_t)sizeof(dat));

  }
  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 Freescale S32K series of microcontrollers.
**
** ###################################################################
*/

 

  • 3
    点赞
  • 35
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值