S32K118 MCAL GPIO interrupt

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

S32K118 MCAL GPIO interrupt

Jump to solution
3,220 Views
talha_uyar
Contributor III

Hi,

I am trying to implement interrupt functionality to one of the buttons on S32K118 EVB. I have looked at the GPIO interrupt example provided and tried to copy the functionality. The following is simply the main code. The Button_Handler is a dummy function lighting an LED. In Tresos I simply configured the RGB_RED as GPIO output and SW2 as GPIO input.

Mcu_Init(&McuModuleConfiguration);
Mcu_InitClock(McuClockSettingConfig_0);
Mcu_SetMode((Mcu_ModeType)MCU_RUN_MODE);

Port_Init(&PortConfigSet);

sys_registerIsrHandler(PORT_IRQn, (uint32)&Button_Handler);
sys_enableIsrSource(PORT_IRQn, 0x40);

while(1)

{

}

Should I also do something with the Vector_core.s file?

Thanks in advance,

M. Talha Uyar

Edit: I took a look at the GPIO interrupt example for S32K148, and I think the only difference is that in the PINS_DRV_Init() function the pins are configured to be as interrupts. I am guessing this functionality should be handled by the Port_Init() function of MCAL. Should I change the PortPin Mode in EB Tresos. If so, what should be the PortPin Mode of an interrupt pin?

0 Kudos
1 Solution
3,087 Views
namnguyenviet
NXP Employee
NXP Employee

In order to configure interrupt for PortPin in ASR, e.g., interrupt handler when a pin is toggler, you might need to use ICU module. These below steps decribes the configuration:

1. Enable ICU module and configure general parameter:

pastedImage_1.png

2. In IcuHwInterruptConfigList, add all available options, then tick to the port pin for targetting interrupt handling (for example, tick to the PORT_0_CH_3 for triggering interrupt when Pin A3 is toggled:

pastedImage_2.png

3. In ICU port tab, add the corresponding port pin to the configuration:

pastedImage_3.png

pastedImage_4.png

4. In ICU channel, configure ICU signal detection in Port Pin:

Link the IcuPortChannelRef to recent created Port pin channel. Choose ICU_MODE_SIGNAL_EDGE_DETECT in IcuMeasurementMode, and choose default start edge for expecting capture edge signal

pastedImage_5.png

Enable the Icu Signal Detect option. You can configure notification callback if desired:

pastedImage_6.png

In addition, you need to enable the interrupt source and map the interrupt handler to the NVIC. Please note that the ISR are named by default in the ICU driver, not something that you can created by your own (Please refer to the ICU IM document):

pastedImage_7.png

So it would be like:

sys_enableIsrSource(75, 0x70);
sys_registerIsrHandler(75,(uint32)&ICU_PORT_CI_A_EXT_IRQ_ISR));

Best Regards,

Nam

View solution in original post

0 Kudos
4 Replies
3,088 Views
namnguyenviet
NXP Employee
NXP Employee

In order to configure interrupt for PortPin in ASR, e.g., interrupt handler when a pin is toggler, you might need to use ICU module. These below steps decribes the configuration:

1. Enable ICU module and configure general parameter:

pastedImage_1.png

2. In IcuHwInterruptConfigList, add all available options, then tick to the port pin for targetting interrupt handling (for example, tick to the PORT_0_CH_3 for triggering interrupt when Pin A3 is toggled:

pastedImage_2.png

3. In ICU port tab, add the corresponding port pin to the configuration:

pastedImage_3.png

pastedImage_4.png

4. In ICU channel, configure ICU signal detection in Port Pin:

Link the IcuPortChannelRef to recent created Port pin channel. Choose ICU_MODE_SIGNAL_EDGE_DETECT in IcuMeasurementMode, and choose default start edge for expecting capture edge signal

pastedImage_5.png

Enable the Icu Signal Detect option. You can configure notification callback if desired:

pastedImage_6.png

In addition, you need to enable the interrupt source and map the interrupt handler to the NVIC. Please note that the ISR are named by default in the ICU driver, not something that you can created by your own (Please refer to the ICU IM document):

pastedImage_7.png

So it would be like:

sys_enableIsrSource(75, 0x70);
sys_registerIsrHandler(75,(uint32)&ICU_PORT_CI_A_EXT_IRQ_ISR));

Best Regards,

Nam

0 Kudos
3,087 Views
talha_uyar
Contributor III

I think for S32K118, ICU_PORT_CI_A_EXT_IRQ_ISR does not work since the Macro defined in Icu_Cfg.h is "ICU_IRQ_SINGLE_INTERRUPT" which enables ISR(ICU_EXT_IRQ_SINGLE_INTERRUPT). I guess this enables a single interrupt for all ports at the hardware interrupt vector 9, is this correct? I am not sure because I did not find this in the Integration Manual but through the "Icu_Port_Ci_Irq.c" file.

Although there are Macros for ISR(ICU_PORT_CI_D_EXT_IRQ_ISR) etc. they are not enabled since ICU_PORT_3_ISR_USED etc. macro is not defined in the Icu_Cfg.h for this Tresos configuration. Can you tell me for which configurations are these macros defined?

0 Kudos
3,087 Views
namnguyenviet
NXP Employee
NXP Employee

Hello talha.uyar@karel.com.tr

I think for S32K118, ICU_PORT_CI_A_EXT_IRQ_ISR does not work since the Macro defined in Icu_Cfg.h is "ICU_IRQ_SINGLE_INTERRUPT" which enables ISR(ICU_EXT_IRQ_SINGLE_INTERRUPT). I guess this enables a single interrupt for all ports at the hardware interrupt vector 9, is this correct? I am not sure because I did not find this in the Integration Manual but through the "Icu_Port_Ci_Irq.c" file.

You're right. I didn't notice that you're asking about s32k118. For this platform, all of ports' interrupts have a single NVIC ID:

NIVC_ID.JPG

Although there are Macros for ISR(ICU_PORT_CI_D_EXT_IRQ_ISR) etc. they are not enabled since ICU_PORT_3_ISR_USED etc. macro is not defined in the Icu_Cfg.h for this Tresos configuration. Can you tell me for which configurations are these macros defined?

In this case, you need to map this ISR: ICU_EXT_IRQ_SINGLE_INTERRUPT to the NVIC ID, so it would be something like:

sys_enableIsrSource(9, 0x70);
sys_registerIsrHandler(9,(uint32)&ICU_EXT_IRQ_SINGLE_INTERRUPT);

Also, please make sure the option for Port Interrupt is enabled in IcuHwInterruptConfigList:

ICU_PORT_S32k118.JPG

Nam

0 Kudos
3,087 Views
talha_uyar
Contributor III

Thanks a lot for the reply

0 Kudos