文章目錄
- 目標
- 建立工程
- ProcessorExpert配置
- 代碼拖動和補全
- 除錯設定
- 工程原始碼
目標
通過定時器每1s翻轉一次 LED_GREEN(引腳PTE22) 的亮滅狀態.
建立工程
步驟:
- File -> New -> S32DS Application Project
- Processors 選擇 S32K148, Project Name 填你自己的工程名
- Select SDK: SDKs 選擇 S32K148_SDK 3.0.0, Finish
ProcessorExpert配置
雙擊工程名, 點擊Components視窗Components目錄下的 pin_mux:PinSetting, 設定綠色LED引腳PTE22為輸出:

匯入lpit組件:

雙擊Components視窗Components目錄下的 lpit1:lpit:

此處周期單元選擇了us, 周期1000000us, 也就是1s, 使能中斷.
到此配置完畢, 點擊生成代碼:

代碼拖動和補全
打開 main.c, 函式可以從Components中的組件展開直接用滑鼠拖入, 然后補全代碼即可:
/* 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) */
#define LED0_PIN_INDEX 22U
#define LED_GPIO_PORT PTE
#define LPIT_CHANNEL 0UL
#define LPIT_Channel_IRQn LPIT0_Ch0_IRQn
void LPIT_Callback(void) {
LPIT_DRV_ClearInterruptFlagTimerChannels(INST_LPIT1, (1 << LPIT_CHANNEL));
PINS_DRV_TogglePins(LED_GPIO_PORT, (1 << LED0_PIN_INDEX));
}
/*!
\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 */
/*** 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_SYS_Init(g_clockManConfigsArr, CLOCK_MANAGER_CONFIG_CNT, g_clockManCallbacksArr, CLOCK_MANAGER_CALLBACK_CNT);
CLOCK_SYS_UpdateConfiguration(0U, CLOCK_MANAGER_POLICY_AGREEMENT);
PINS_DRV_Init(NUM_OF_CONFIGURED_PINS, g_pin_mux_InitConfigArr);
PINS_DRV_SetPinsDirection(LED_GPIO_PORT, (1 << LED0_PIN_INDEX));
PINS_DRV_WritePin(LED_GPIO_PORT, LED0_PIN_INDEX, 1);
LPIT_DRV_Init(INST_LPIT1, &lpit1_InitConfig);
LPIT_DRV_InitChannel(INST_LPIT1, LPIT_CHANNEL, &lpit1_ChnConfig0);
INT_SYS_InstallHandler(LPIT_Channel_IRQn, &LPIT_Callback, (isr_t *)0);
LPIT_DRV_StartTimerChannels(INST_LPIT1, (1 << LPIT_CHANNEL));
/*** 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 */
時鐘:
CLOCK_SYS_Init(g_clockManConfigsArr, CLOCK_MANAGER_CONFIG_CNT, g_clockManCallbacksArr, CLOCK_MANAGER_CALLBACK_CNT);
CLOCK_SYS_UpdateConfiguration(0U, CLOCK_MANAGER_POLICY_AGREEMENT);
IO:
#define LED0_PIN_INDEX 22U
#define LED_GPIO_PORT PTE
PINS_DRV_Init(NUM_OF_CONFIGURED_PINS, g_pin_mux_InitConfigArr);
PINS_DRV_SetPinsDirection(LED_GPIO_PORT, (1 << LED0_PIN_INDEX));
PINS_DRV_WritePin(LED_GPIO_PORT, LED0_PIN_INDEX, 1); //點亮LED
定時器:
#define LPIT_CHANNEL 0UL
#define LPIT_Channel_IRQn LPIT0_Ch0_IRQn
void LPIT_Callback(void) {
LPIT_DRV_ClearInterruptFlagTimerChannels(INST_LPIT1, (1 << LPIT_CHANNEL));
PINS_DRV_TogglePins(LED_GPIO_PORT, (1 << LED0_PIN_INDEX));
}
LPIT_DRV_Init(INST_LPIT1, &lpit1_InitConfig);
LPIT_DRV_InitChannel(INST_LPIT1, LPIT_CHANNEL, &lpit1_ChnConfig0);
INT_SYS_InstallHandler(LPIT_Channel_IRQn, &LPIT_Callback, (isr_t *)0); //回呼函式
LPIT_DRV_StartTimerChannels(INST_LPIT1, (1 << LPIT_CHANNEL));
除錯設定
參考前篇, 此處略.
工程原始碼
https://download.csdn.net/download/weifengdq/11813519
轉載請註明出處,本文鏈接:https://www.uj5u.com/qita/181286.html
標籤:其他
上一篇:PHP面試題
下一篇:Istio組件日志設定
