Hello,
I'm trying to start a new project and add some peripherals, one of them is the gpio interrupt, but i can't get it to work properly. If i import the example it works fine, but when add as a peripheral it doesn't work.
I'm working with a FRDM-K64F and want to make an interrupt with the SW3 switch of the board wich is in the PIN 6 of PORTC.
This is the generated code in
peripherals.h:
/* Alias for GPIOC peripheral */
#define GPIO_BUTTON_GPIO GPIOC
/* Alias for PORTC */
#define GPIO_BUTTON_PORT PORTC
/* GPIO_BUTTON interrupt vector ID (number). */
#define GPIO_BUTTON_IRQN PORTC_IRQn
/* GPIO_BUTTON interrupt handler identifier. */
#define IRQ_SW2 PORTC_IRQHandler
peripherals.c:
void GPIO_BUTTON_init(void) {
/* Make sure, the clock gate for port C is enabled (e. g. in pin_mux.c) */
/* Enable interrupt PORTC_IRQn request in the NVIC */
EnableIRQ(PORTC_IRQn);
}
/***********************************************************************************************************************
* Initialization functions
**********************************************************************************************************************/
void BOARD_InitPeripherals(void)
{
/* Initialize components */
PIT_1_init();
GPIO_BUTTON_init();
}
/***********************************************************************************************************************
* BOARD_InitBootPeripherals function
**********************************************************************************************************************/
void BOARD_InitBootPeripherals(void)
{
BOARD_InitPeripherals();
}
and in
pinmux.h:
#define BOARD_INITPINS_SW2_GPIO GPIOC /*!<@brief GPIO device name: GPIOC */
#define BOARD_INITPINS_SW2_PORT PORTC /*!<@brief PORT device name: PORTC */
#define BOARD_INITPINS_SW2_PIN 6U /*!<@brief PORTC pin index: 6 */
pinmux.c:
void BOARD_InitPins(void)
{
/* Port C Clock Gate Control: Clock enabled */
CLOCK_EnableClock(kCLOCK_PortC);
gpio_pin_config_t SW2_config = {
.pinDirection = kGPIO_DigitalInput,
.outputLogic = 0U
};
/* Initialize GPIO functionality on pin PTC6 (pin 78) */
GPIO_PinInit(BOARD_INITPINS_SW2_GPIO, BOARD_INITPINS_SW2_PIN, &SW2_config);
gpio_pin_config_t LED_GREEN_config = {
.pinDirection = kGPIO_DigitalOutput,
.outputLogic = 1U
};
/* PORTC6 (pin 78) is configured as PTC6 */
PORT_SetPinMux(BOARD_INITPINS_SW2_PORT, BOARD_INITPINS_SW2_PIN, kPORT_MuxAsGpio);
/* Interrupt configuration on PORTC6 (pin 78): Interrupt on falling edge */
PORT_SetPinInterruptConfig(BOARD_INITPINS_SW2_PORT, BOARD_INITPINS_SW2_PIN, kPORT_InterruptFallingEdge);
PORTC->PCR[6] = ((PORTC->PCR[6] &
/* Mask bits to zero which are setting */
(~(PORT_PCR_PS_MASK | PORT_PCR_PE_MASK | PORT_PCR_ISF_MASK)))
/* Pull Select: Internal pullup resistor is enabled on the corresponding pin, if the
* corresponding PE field is set. */
| (uint32_t)(kPORT_PullUp));
}
Then implement my IRQ handler in main.c:
void IRQ_SW2(void){
/* Clear external interrupt flag. */
GPIO_PortClearInterruptFlags(GPIOC, 1U << 6);
/* Change state of button. */
sw2_interrupt = true;
/* Add for ARM errata 838869, affects Cortex-M4, Cortex-M4F Store immediate overlapping
exception return operation might vector to incorrect interrupt */
#if defined __CORTEX_M && (__CORTEX_M == 4U)
__DSB();
#endif
}
But it never enter in this function handler.
When push the button, it always goes directly to:
And stays there forever.
My pins configuration:
What could I be missing?
Thanks and regards