GPIO Interrupt Newbie Question

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

GPIO Interrupt Newbie Question

3,406 Views
mspenard603
Contributor IV

Hi Gents,

 New to interrupts on the iMXRT. How does one register a GPIO interrupt handler (say as you use to do with registerHandlerGPIO(x,y, my_handler) )? 
There are the double-weak functions...  So is the proper way to register a handler now by doing: ?
    #define my_handler GPIO5_Combined_0_15_IRQHandler

But, how do I register an interrupt handler that is variable?

Also, I assume that even though I EnableIRQ( GPIO5_Combined_0_15_IRQn) it doesn't trigger on an edge of any of those 0-15 pins, but only those specified by GPIO_Pinit(). Is this correct?

Thank you

Labels (1)
11 Replies

2,952 Views
EdSutter
Senior Contributor II

Very late reply, but since this appears unanswered, and I stumbled on it, here's my 2 cents...

The applications come with the default vector table pre-established with "weak" handlers.

Refer to the file startup_MIMXRT1062.S in the case of the '1062.

That means there is a default handler in place without doing anything.

That handler will typically just put the board in a endless loop.

To override that handler you simply write another function with the same name (for example GPIO5_Combined_0_15_IRQHandler()) that that will replace the "weak" handler.

The linker will automatically use it instead of the default "weak" handler, so it is inserted directly

into the vector table.

If you're still reading this, I hope this helps.

0 Kudos

2,952 Views
victorjimenez
NXP TechSupport
NXP TechSupport

Hello Mike,


Within the SDK for the RT1060-EVK there's an example named igpio_input_ interrupt. I highly recommend you to take a look at this code and use it as a base for your project.


Have a great day,
TIC

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

- We are following threads for 7 weeks after the last post, later replies are ignored
Please open a new thread and refer to the closed one, if you have a related question at a later point in time.
-------------------------------------------------------------------------------

0 Kudos

2,952 Views
mspenard603
Contributor IV

Yes, I've been looking at that example project. Which is why I have the questions above. The example nor the SDK do little to explain how you register an interrupt handler being passed as a variable. So could you be so kind as to explain?

2,952 Views
victorjimenez
NXP TechSupport
NXP TechSupport

Hello Mike,

The first thing you do in the example after the hardware initialization is enabling the interrupt that corresponds to the SW8 of the EVK:

EnableIRQ(EXAMPLE_SW_IRQ);

 After, you initialize and configure the pin that will trigger the interrupt:

GPIO_PinInit(EXAMPLE_SW_GPIO, EXAMPLE_SW_GPIO_PIN, &sw_config);

The data for the configuration of the pin is inside the structure sw_config. Here you define that the pin will be an input and the interrupt will be generated when a rising edge occurs. 

    gpio_pin_config_t sw_config = {
        kGPIO_DigitalInput,
        0,
        kGPIO_IntRisingEdge,
    };

After, you enable the interrupt of the pin:

GPIO_PortEnableInterrupts(EXAMPLE_SW_GPIO, 1U << EXAMPLE_SW_GPIO_PIN);

The handler is declared with the help of the definitions at the beginning of the file gpio_input_interrupt.c:

#define EXAMPLE_SW_GPIO BOARD_USER_BUTTON_GPIO
#define EXAMPLE_SW_GPIO_PIN BOARD_USER_BUTTON_GPIO_PIN
#define EXAMPLE_SW_IRQ BOARD_USER_BUTTON_IRQ
#define EXAMPLE_GPIO_IRQHandler BOARD_USER_BUTTON_IRQ_HANDLER
#define EXAMPLE_SW_NAME BOARD_USER_BUTTON_NAME

With the 4 define, you are setting the handler's name of the interrupt thanks to the macro BOARD_USER_BUTTON_IRQ_HANDLER 

Regards,

Victor

0 Kudos

2,952 Views
mspenard603
Contributor IV

Yes, I understood all that. But that is not the question I had. Which is:

   [...] the proper way to register a handler now [...]
       #define my_handler GPIO5_Combined_0_15_IRQHandler

   But, ****how do I register an interrupt handler that is variable?******

For instance, I have this function which passes a variable "plflsr" that contains the ISR handler function to register:

    void nm_bsp_register_isr(tpfNmBspIsr pfIsr) {

       // What is needed here??   something like LPC had with registerHandlerGPIO(x,y, plflsr) .....????

      }

How does one register an ISR handler that is being passed as a variable?

0 Kudos

2,952 Views
victorjimenez
NXP TechSupport
NXP TechSupport

Hello Mike,

Could you please clarify where did you see the function registerHandlerGPIO in the LPC?

Regards,

Victor

0 Kudos

2,952 Views
mspenard603
Contributor IV

My mistake, that call must be something besides LPC or a 3rd party call. But I still have the question, How does one register an ISR handler that is being passed as a variable?

0 Kudos

2,952 Views
victorjimenez
NXP TechSupport
NXP TechSupport

Hello Mike,


Unfortunately, I'm not aware of the implementation you are referring to. But, if I understood correctly what you are trying to do, your function will receive only the interrupt handler, so inside you need to call the following function to activate the interrupt: EnableIRQ(the_variable_you_passed_through_the_function).

Regards,

Victor

0 Kudos

2,952 Views
mspenard603
Contributor IV

No no, the passed variable isn't a IRQ number. It's the name of a callback function. And EnableIRQ() is looking for an IRQ number. So that does not answer the question: How does one register an ISR handler that is being passed as a variable?

0 Kudos

2,952 Views
victorjimenez
NXP TechSupport
NXP TechSupport

Hello Mike,


Unfortunately, as mentioned before, I'm not aware of any implementation like this for the GPIO driver on the i.MXRT. However, the example lpuart_interrupt_transfer provided within the SDK uses this approach, you can use it as a base to make your implementation on the GPIO driver.

Your question is related to C programming instead of the functionality of the i.MXRT.

Best Regards,

Victor

0 Kudos

1,273 Views
PedroBecerra
Contributor III

I have the same problem.

When you configure anything to use an interrupt with the tool in mcuxpresso, the tool will create and configure almost everithing but the irq_handler.

So you can create a new project. activate an uart, or a pin or a timer and activat the irq on that peripheral.

Generate the code.

Compile it.

And try to execute. You will get a runtime error. The callback that is called inside the irqhandler IS NOT CREATED.

In the next example  s_flexcommIrqHandler is empty.

Example:

void FLEXCOMM1_DriverIRQHandler(void)
{
 uint32_t instance;

/* Look up instance number */
   instance = FLEXCOMM_GetInstance(FLEXCOMM1);
   assert(s_flexcommIrqHandler[instance] != NULL);
   s_flexcommIrqHandler[instance]((uint32_t *)s_flexcommBaseAddrs[instance], s_flexcommHandle[instance]);
SDK_ISR_EXIT_BARRIER;
}

 

So the question is: How to register my irqhandler to get s_flexcommIrqHandler filled wiht my irqhandler?

 

0 Kudos