环境:
软件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.
**
** ###################################################################
*/