FRDM-K64F Interrupt Handling - How to perform?

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

FRDM-K64F Interrupt Handling - How to perform?

2,670 Views
dgrullon
Contributor I

====================================

The Situation

====================================

I'm trying to figure out how to control interrupts. I've looked at the GPIO driver SDK example called 'gpio_input_interrupt' (as this is the closest to what I'm trying to do). I see that in the initialization they perform these functions:

    /* Init input switch GPIO. */
    PORT_SetPinInterruptConfig(BOARD_SW_PORT, BOARD_SW_GPIO_PIN, kPORT_InterruptFallingEdge);
    EnableIRQ(BOARD_SW_IRQ);
    GPIO_PinInit(BOARD_SW_GPIO, BOARD_SW_GPIO_PIN, &sw_config);

And that this function is what handles the interrupt:

void BOARD_SW_IRQ_HANDLER(void);

====================================

The Questions

====================================

  1. Is there a step by step tutorial on how to handle interrupts?
  2. How does the MCU know to go to BOARD_SW_IRQ_HANDLER() when the button is pressed?
  3. The EnableIRQ() function is not included in the API Reference manual that came with my SDK, does anyone know where I can get information on this?
  4. What if I wanted to have multiple interrupts for different GPIO pins but they are all on the same port - can they each have their own function?

Thank you very much!

Labels (1)
0 Kudos
2 Replies

1,267 Views
kerryzhou
NXP TechSupport
NXP TechSupport

Hi dgrullon,

    Answer your several questions:

1 Is there a step by step tutorial on how to handle interrupts?Answer

= You can refer to the K64 SDK source code directly, that code already very clear.

2 How does the MCU know to go to BOARD_SW_IRQ_HANDLER() when the button is pressed?

= Please check these code:

#define BOARD_SW_IRQ_HANDLER BOARD_SW3_IRQ_HANDLER

#define BOARD_SW3_IRQ_HANDLER PORTA_IRQHandler

So, BOARD_SW_IRQ_HANDLER is PORTA_IRQHandler, you can find PORTA_IRQHandler in the .s file:

pastedImage_1.png

3 The EnableIRQ() function is not included in the API Reference manual that came with my SDK, does anyone know where I can get information on this?

=EnableIRQ function is defined like this:

static inline void EnableIRQ(IRQn_Type interrupt)
{
if (NotAvail_IRQn == interrupt)
{
return;
}

#if defined(FSL_FEATURE_SOC_INTMUX_COUNT) && (FSL_FEATURE_SOC_INTMUX_COUNT > 0)
if (interrupt < FSL_FEATURE_INTMUX_IRQ_START_INDEX)
#endif
{
#if defined(__GIC_PRIO_BITS)
GIC_EnableIRQ(interrupt);
#else
NVIC_EnableIRQ(interrupt);
#endif
}
}

Actually, it is enable the IRQ in the core cm4 register.

4 What if I wanted to have multiple interrupts for different GPIO pins but they are all on the same port - can they each have their own function?

= Then same port just share one interrupt, If you enable different GPIO pins on the same port, then you need to judge it in the interrupt handler by yourself.

Wish it helps you!


Have a great day,
Kerry

-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------

0 Kudos

1,267 Views
mjbcswitzerland
Specialist V

Hi

Take a look as this video explaining GPIO interrupts: https://youtu.be/CubinvMuTwU
It shows a KL27 but it is essentially identical for most devices.
There is a GPIO pin interrupt/DMA driver included in the Open Source uTasker project on Gut Hub which allows you to assign an interrupt handler to every individual pin of the K64 (the handling of this is also shown in the video). You can analyse and test it in the uTasker K64 simulator.

Regards

Mark

Kinetis: http://www.utasker.com/kinetis.html
FRDM-K64F: http://www.utasker.com/kinetis/FRDM-K64F.html

0 Kudos