内容提要
1.1 S32K1xx的PORT模块配置寄存器介绍
1.2 S32K1xx的GPIO模块配置与状态寄存器介绍
1.3 S32K1xx系列MCU的GPIO IRQ中断
2.1 PinSettings组件属性配置详解
2.2 PinSettings组件API函数详解
2.3 PinSettings组件使用Tips
3.1 S32K144-EVB的用户按键输入硬件设计及其PinSettings组件GPIO中断配置
3.2 S32K144-EVB的RGB LED硬件设计及其PinSettings组件GPIO输入配置
3.3 GPIO IRQ中断控制RGB LED亮灭功能代码实现
Tips:S32K1xx系列MCU复位后大多数引脚的默认配置为disable状态,也就是三态(tristate),若该引脚有ADC输入通道的复用,则为ADC模拟信号输入,否则,该引脚既不做GPIO也不复用任何外设功能;
PCR寄存器定义如下:
.long PORT_IRQHandler /* Port A, B, C, D and E pin detect interrupt */
.long PORTA_IRQHandler /* Port A pin detect interrupt*/
.long PORTB_IRQHandler /* Port B pin detect interrupt*/
.long PORTC_IRQHandler /* Port C pin detect interrupt*/
.long PORTD_IRQHandler /* Port D pin detect interrupt*/
.long PORTE_IRQHandler /* Port E pin detect interrupt*/
.align 1
.thumb_func
.weak DefaultISR
.type DefaultISR, %function
DefaultISR:
b DefaultISR
.size DefaultISR, . - DefaultISR
/* Macro to define default handlers. Default handler
* will be weak symbol and just dead loops. They can be
* overwritten by other handlers */
.macro def_irq_handler handler_name
.weak \handler_name
.set \handler_name, DefaultISR
.endm
/* Exception Handlers */
。。。。。。。。。。 def_irq_handler LPTMR0_IRQHandler
def_irq_handler PORTA_IRQHandler
def_irq_handler PORTB_IRQHandler
def_irq_handler PORTC_IRQHandler
def_irq_handler PORTD_IRQHandler
def_irq_handler PORTE_IRQHandler
void PORTA_IRQHandler(void)
{
uint32_t Port_IntFlag = 0;
/* read the PORT interrupt flags*/
Port_IntFlag = PINS_DRV_GetPortIntFlag(PORTA);
if(Port_IntFlag & (1<<3))
{
/*
*the PTA3 PIN IRQ interrupt happaned,
*add corresponding user handle code here
*/
/* clean the PTA3 interrupt flag bit */
PINS_DRV_ClearPinIntFlagCmd(PORTA,3);
}
}
void User_Button_IRQ_ISR(void)
{
uint32_t Port_IntFlag = 0;
/* read the PORT interrupt flags*/
Port_IntFlag = PINS_DRV_GetPortIntFlag(PORTA);
if(Port_IntFlag & (1<<3))
{
/*
*the PTA3 PIN IRQ interrupt happaned,
*add corresponding user handle code here
*/
/* clean the PTA3 interrupt flag bit */
PINS_DRV_ClearPinIntFlagCmd(PORTA,3);
}
}
/*
* install PORTA IRQ interrupt ISR
*/
INT_SYS_InstallHandler(PORTA_IRQn, User_Button_IRQ_ISR, NULL);
/*
* enable PORTC IRQ interrupt
*/
INT_SYS_EnableIRQ(PORTA_IRQn);
/*!
* @brief Enables digital filter for digital pin muxing
*
* This function enables digital filter feature for digital pin muxing
*
* @param[in] base Port base pointer (PORTA, PORTB, PORTC, etc.)
* @param[in] pin Port pin number
*/
void PINS_DRV_EnableDigitalFilter(PORT_Type * const base,
uint32_t pin);
/*!
* @brief Disables digital filter for digital pin muxing
*
* This function disables digital filter feature for digital pin muxing
*
* @param[in] base Port base pointer (PORTA, PORTB, PORTC, etc.)
* @param[in] pin Port pin number
*/
void PINS_DRV_DisableDigitalFilter(PORT_Type * const base,
uint32_t pin);
/*!
* @brief Configures digital filter for port with given configuration
*
* This function configures digital filter for port with given configuration
*
* Note: Updating the filter configuration must be done only after all filters are disabled.
*
* @param[in] base Port base pointer (PORTA, PORTB, PORTC, etc.)
* @param[in] config the digital filter configuration struct
*/
void PINS_DRV_ConfigDigitalFilter(PORT_Type * const base,
const port_digital_filter_config_t * const config);
/*!
* @brief Write a pin of a port with a given value
*
* This function writes the given pin from a port, with the given value
* ('0' represents LOW, '1' represents HIGH).
*
* @param[in] base GPIO base pointer (PTA, PTB, PTC, etc.)
* @param[in] pin Pin number to be written
* @param[in] value Pin value to be written
* - 0: corresponding pin is set to LOW
* - 1: corresponding pin is set to HIGH
*/
void PINS_DRV_WritePin(GPIO_Type * const base,
pins_channel_type_t pin,
pins_level_type_t value);
/*!
* @brief Write all pins of a port
*
* This function writes all pins configured as output with the values given in
* the parameter pins. '0' represents LOW, '1' represents HIGH.
*
* @param[in] base GPIO base pointer (PTA, PTB, PTC, etc.)
* @param[in] pins Pin mask to be written
* - 0: corresponding pin is set to LOW
* - 1: corresponding pin is set to HIGH
*/
void PINS_DRV_WritePins(GPIO_Type * const base,
pins_channel_type_t pins);
/*!
* @brief Get the current output from a port
*
* This function returns the current output that is written to a port. Only pins
* that are configured as output will have meaningful values.
*
* @param[in] base GPIO base pointer (PTA, PTB, PTC, etc.)
* @return GPIO outputs. Each bit represents one pin (LSB is pin 0, MSB is pin
* 31). For each bit:
* - 0: corresponding pin is set to LOW
* - 1: corresponding pin is set to HIGH
*/
pins_channel_type_t PINS_DRV_GetPinsOutput(const GPIO_Type * const base);
/*!
* @brief Write pins with 'Set' value
*
* This function configures output pins listed in parameter pins (bits that are
* '1') to have a value of 'set' (HIGH). Pins corresponding to '0' will be
* unaffected.
*
* @param[in] base GPIO base pointer (PTA, PTB, PTC, etc.)
* @param[in] pins Pin mask of bits to be set. Each bit represents one pin (LSB is
* pin 0, MSB is pin 31). For each bit:
* - 0: corresponding pin is unaffected
* - 1: corresponding pin is set to HIGH
*/
void PINS_DRV_SetPins(GPIO_Type * const base,
pins_channel_type_t pins);
/*!
* @brief Write pins to 'Clear' value
*
* This function configures output pins listed in parameter pins (bits that are
* '1') to have a 'cleared' value (LOW). Pins corresponding to '0' will be
* unaffected.
*
* @param[in] base GPIO base pointer (PTA, PTB, PTC, etc.)
* @param[in] pins Pin mask of bits to be cleared. Each bit represents one pin (LSB
* is pin 0, MSB is pin 31). For each bit:
* - 0: corresponding pin is unaffected
* - 1: corresponding pin is cleared(set to LOW)
*/
void PINS_DRV_ClearPins(GPIO_Type * const base,
pins_channel_type_t pins);
/*!
* @brief Toggle pins value
*
* This function toggles output pins listed in parameter pins (bits that are
* '1'). Pins corresponding to '0' will be unaffected.
*
* @param[in] base GPIO base pointer (PTA, PTB, PTC, etc.)
* @param[in] pins Pin mask of bits to be toggled. Each bit represents one pin (LSB
* is pin 0, MSB is pin 31). For each bit:
* - 0: corresponding pin is unaffected
* - 1: corresponding pin is toggled
*/
void PINS_DRV_TogglePins(GPIO_Type * const base,
pins_channel_type_t pins);
/*!
* @brief Read input pins
*
* This function returns the current input values from a port. Only pins
* configured as input will have meaningful values.
*
* @param[in] base GPIO base pointer (PTA, PTB, PTC, etc.)
* @return GPIO inputs. Each bit represents one pin (LSB is pin 0, MSB is pin
* 31). For each bit:
* - 0: corresponding pin is read as LOW
* - 1: corresponding pin is read as HIGH
*/
pins_channel_type_t PINS_DRV_ReadPins(const GPIO_Type * const base);
/*!
* @brief Clears the individual pin-interrupt status flag.
*
* This function clears the individual pin-interrupt status flag.
*
* @param[in] base Port base pointer (PORTA, PORTB, PORTC, etc.)
* @param[in] pin Port pin number
*/
void PINS_DRV_ClearPinIntFlagCmd(PORT_Type * const base,
uint32_t pin);
/*!
* @brief Reads the entire port interrupt status flag
*
* This function reads the entire port interrupt status flag.
*
* @param[in] base Port base pointer (PORTA, PORTB, PORTC, etc.)
* @return All 32 pin interrupt status flags
*/
uint32_t PINS_DRV_GetPortIntFlag(const PORT_Type * const base);
/*!
* @brief Clears the entire port interrupt status flag.
*
* This function clears the entire port interrupt status flag.
*
* @param[in] base Port base pointer (PORTA, PORTB, PORTC, etc.)
*/
void PINS_DRV_ClearPortIntFlagCmd(PORT_Type * const base);
/*!
* @brief Quickly configures multiple pins with the same pin configuration.
*
* This function quickly configures multiple pins within the one port for the same peripheral
* function with the same pin configuration. Supports up to 16 pins with the lower or upper
* half of pin registers at the same port.
*
* Note: The set global interrupt control function (PINS_DRV_SetGlobalIntControl) cannot be
* configured if you ever used this function at the same port
*
* @param[in] base Port base pointer (PORTA, PORTB, PORTC, etc.)
* @param[in] pins Pin mask where each bit represents one pin. For each bit:
* - 0: pins corresponding to bits with value of '1' is updated with the value input
* - 1: pins corresponding to bits with value of '0' is not updated with the value input
* @param[in] value the config value will be updated for the pins are set to '1'
* @param[in] halfPort the lower or upper half of pin registers at the same port
*/
void PINS_DRV_SetGlobalPinControl(PORT_Type * const base,
uint16_t pins,
uint16_t value,
port_global_control_pins_t halfPort);
/*!
* @brief Quickly configures multiple pins with the same interrupt configuration.
*
* This function quickly configures multiple pins within the one port for the same peripheral
* function with the same interrupt configuration. Supports up to 16 pins with the lower or
* upper half of pin registers at the same port.
*
* Note: The set global pin control function (PINS_DRV_SetGlobalPinControl) cannot be
* configured if you ever used this function at the same port
*
* @param[in] base Port base pointer (PORTA, PORTB, PORTC, etc.)
* @param[in] pins Pin mask where each bit represents one pin. For each bit:
* - 0: pins corresponding to bits with value of '1' is updated with the value input
* - 1: pins corresponding to bits with value of '0' is not updated with the value input
* @param[in] value the config value will be updated for the pins are set to '1'
* @param[in] halfPort the lower or upper half of pin registers at the same port
*/
void PINS_DRV_SetGlobalIntControl(PORT_Type * const base,
uint16_t pins,
uint16_t value,
port_global_control_pins_t halfPort);
若是PORT_Type ,则合法的参数为: PORTA/PORTB/PORTC/PORTD/PORTE;
/* PORT - Peripheral instance base addresses */
/** Peripheral PORTA base address */
#define PORTA_BASE (0x40049000u)
/** Peripheral PORTA base pointer */
#define PORTA ((PORT_Type *)PORTA_BASE)
/** Peripheral PORTB base address */
#define PORTB_BASE (0x4004A000u)
/** Peripheral PORTB base pointer */
#define PORTB ((PORT_Type *)PORTB_BASE)
/** Peripheral PORTC base address */
#define PORTC_BASE (0x4004B000u)
/** Peripheral PORTC base pointer */
#define PORTC ((PORT_Type *)PORTC_BASE)
/** Peripheral PORTD base address */
#define PORTD_BASE (0x4004C000u)
/** Peripheral PORTD base pointer */
#define PORTD ((PORT_Type *)PORTD_BASE)
/** Peripheral PORTE base address */
#define PORTE_BASE (0x4004D000u)
/** Peripheral PORTE base pointer */
#define PORTE ((PORT_Type *)PORTE_BASE)
/** Array initializer of PORT peripheral base addresses */
#define PORT_BASE_ADDRS { PORTA_BASE, PORTB_BASE, PORTC_BASE, PORTD_BASE, PORTE_BASE }
/** Array initializer of PORT peripheral base pointers */
#define PORT_BASE_PTRS { PORTA, PORTB, PORTC, PORTD, PORTE }
/* GPIO - Peripheral instance base addresses */
/** Peripheral PTA base address */
#define PTA_BASE (0x400FF000u)
/** Peripheral PTA base pointer */
#define PTA ((GPIO_Type *)PTA_BASE)
/** Peripheral PTB base address */
#define PTB_BASE (0x400FF040u)
/** Peripheral PTB base pointer */
#define PTB ((GPIO_Type *)PTB_BASE)
/** Peripheral PTC base address */
#define PTC_BASE (0x400FF080u)
/** Peripheral PTC base pointer */
#define PTC ((GPIO_Type *)PTC_BASE)
/** Peripheral PTD base address */
#define PTD_BASE (0x400FF0C0u)
/** Peripheral PTD base pointer */
#define PTD ((GPIO_Type *)PTD_BASE)
/** Peripheral PTE base address */
#define PTE_BASE (0x400FF100u)
/** Peripheral PTE base pointer */
#define PTE ((GPIO_Type *)PTE_BASE)
/** Array initializer of GPIO peripheral base addresses */
#define GPIO_BASE_ADDRS { PTA_BASE, PTB_BASE, PTC_BASE, PTD_BASE, PTE_BASE }
/** Array initializer of GPIO peripheral base pointers */
#define GPIO_BASE_PTRS { PTA, PTB, PTC, PTD, PTE }
void PINS_DRV_WritePin(GPIO_Type * const base,
pins_channel_type_t pin,
pins_level_type_t value);
void PINS_DRV_WritePins(GPIO_Type * const base,
pins_channel_type_t pins);
PINS_DRV_WritePin(PTA, 3, 1);/*output high on PTA3*/
PINS_DRV_WritePins(PTA, 1<<3 );/*output high on PTA3*/
PINS_DRV_WritePin(PTA, 3, 0);/*output low on PTA3*/
PINS_DRV_WritePins(PTA, 0<<3 );/*output low on PTA3*/
void PINS_DRV_SetPins(GPIO_Type * const base,
pins_channel_type_t pins);
void PINS_DRV_ClearPins(GPIO_Type * const base,
pins_channel_type_t pins);
void PINS_DRV_TogglePins(GPIO_Type * const base,
pins_channel_type_t pins);
按键 | S32K144 GPIO端口 |
SW2 | PTC12 |
SW3 | PTC13 |
RGB LED | S32K144 GPIO端口 |
RED | PTD15 |
GREEN | PTD16 |
BLUE | PTD0 |
#define BUTTON_PORT PORTC /*PORT_Type*/
#define SW2_PIN 12
#define SW3_PIN 13
#define LED_GPIO PTD /*GPIO_Type*/
#define BLUE_PIN 0
#define RED_PIN 15
#define GREEN_PIN 16
/************************************************************
* the PORTC IRQ interrupt ISR
* toggle RGB LED according to different user button press
*
* SW2-->toggle blue LED
* SW3-->toggle red LED
*
* use API--PINS_DRV_ClearPinIntFlagCmd() to clear GPIO pin
* interrupt flag independently to avoid interrupt missing
***********************************************************/
void User_Button_IRQ_ISR(void)
{
uint32_t Port_IntFlag = 0;
/* read the PORT interrupt flags*/
Port_IntFlag = PINS_DRV_GetPortIntFlag(BUTTON_PORT);
if(Port_IntFlag&(1<<SW2_PIN)) /*if SW2 pressed*/
{
/*toggle blue LED*/
PINS_DRV_TogglePins(LED_GPIO, 1<<BLUE_PIN);
/*clear pin interrupt flag*/
PINS_DRV_ClearPinIntFlagCmd(BUTTON_PORT,SW2_PIN);
}
if(Port_IntFlag&(1<<SW3_PIN)) /*if SW3 pressed*/
{
/*toggle red LED*/
PINS_DRV_TogglePins(LED_GPIO, 1<<RED_PIN);
/*clear pin interrupt flag*/
PINS_DRV_ClearPinIntFlagCmd(BUTTON_PORT,SW3_PIN);
}
}
/*
* install PORTC IRQ interrupt ISR
*/
INT_SYS_InstallHandler(PORTC_IRQn, User_Button_IRQ_ISR, NULL);
/*
* enable PORTC IRQ interrupt
*/
INT_SYS_EnableIRQ(PORTC_IRQn);
联系客服