MKV30F Hard Faults when Pin Interrupt enabled on some pins

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

MKV30F Hard Faults when Pin Interrupt enabled on some pins

Jump to solution
1,989 Views
krisbird
Contributor I

MKV30F128VFM10 is running code fine. Latest KSDK2 SDK.

When I try to enable pin interrupts as follows;

PORT_SetPinInterruptConfig( PORTA, 1<<4, kPORT_InterruptEitherEdge );

PORT_SetPinInterruptConfig( PORTA, 1<<18, kPORT_InterruptEitherEdge );

PORT_SetPinInterruptConfig( PORTA, 1<<19, kPORT_InterruptEitherEdge );

EnableIRQ( PORTA_IRQn );

GPIO_PinInit( GPIOA, 1<<4, &sw_config );

GPIO_PinInit( GPIOA, 1<<18, &sw_config );

GPIO_PinInit( GPIOA, 1<<19, &sw_config );

It hard faults when running the PORT_SetPinInterruptConfig on PORTA18 and PORTA19.

The command on PORTA4 doesn't hard fault. If I put the A4 command last, it won't get past A18 or A19.

Fault-

pastedImage_1.png

The pin_mux (configured in the GUI) looks sensible....

/* Port A Clock Gate Control: Clock enabled */

    CLOCK_EnableClock(kCLOCK_PortA);

    /* Port B Clock Gate Control: Clock enabled */

    CLOCK_EnableClock(kCLOCK_PortB);

    /* Port C Clock Gate Control: Clock enabled */

    CLOCK_EnableClock(kCLOCK_PortC);

    /* Port D Clock Gate Control: Clock enabled */

    CLOCK_EnableClock(kCLOCK_PortD);

    /* Port E Clock Gate Control: Clock enabled */

    CLOCK_EnableClock(kCLOCK_PortE);

    /* PORTA18 (pin 17) is configured as PTA18 */

    PORT_SetPinMux(BOARD_INITPINS_HALL2_PORT, BOARD_INITPINS_HALL2_PIN, kPORT_MuxAsGpio);

    PORTA->PCR[18] = ((PORTA->PCR[18] &

                       /* 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));

    /* PORTA19 (pin 18) is configured as PTA19 */

    PORT_SetPinMux(BOARD_INITPINS_HALL3_PORT, BOARD_INITPINS_HALL3_PIN, kPORT_MuxAsGpio);

    PORTA->PCR[19] = ((PORTA->PCR[19] &

                       /* 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));

    /* PORTA4 (pin 16) is configured as PTA4 */

    PORT_SetPinMux(BOARD_INITPINS_BUTTON_PORT, BOARD_INITPINS_BUTTON_PIN, kPORT_MuxAsGpio);

    PORTA->PCR[4] = ((PORTA->PCR[4] &

                      /* 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));

pastedImage_3.png

I have a placeholder ISR defined as-

void PORTA_IRQHandler( void ) {

uint32_t flags = GPIO_GetPinsInterruptFlags( GPIOA );

if( flags &= 1U<<4) {

GPIO_PortClearInterruptFlags( GPIOA, 1U<<4 );

}

if( flags &= 1U<<18) {

GPIO_PortClearInterruptFlags( GPIOA, 1U<<18 );

}

if( flags &= 1U<<19) {

GPIO_PortClearInterruptFlags( GPIOA, 1U<<19 );

}

}

Any ideas?

Labels (1)
1 Solution
1,700 Views
xiangjun_rong
NXP TechSupport
NXP TechSupport

Hi, Kris,

You have to enable the PORTA clock before you write the PORTA_PCRy register, pls put the line  as first line.

CLOCK_EnableClock(kCLOCK_PortA);

If it can not slove the question, you said the the line PORT_SetPinInterruptConfig( PORTA, 1<<4, kPORT_InterruptEitherEdge ); leads to the hard fault. Pls check if the address of PORTA_PCR18 or 19 are correct.

Hope it can help you

BR

xiangjun rong

View solution in original post

0 Kudos
Reply
4 Replies
1,701 Views
xiangjun_rong
NXP TechSupport
NXP TechSupport

Hi, Kris,

You have to enable the PORTA clock before you write the PORTA_PCRy register, pls put the line  as first line.

CLOCK_EnableClock(kCLOCK_PortA);

If it can not slove the question, you said the the line PORT_SetPinInterruptConfig( PORTA, 1<<4, kPORT_InterruptEitherEdge ); leads to the hard fault. Pls check if the address of PORTA_PCR18 or 19 are correct.

Hope it can help you

BR

xiangjun rong

0 Kudos
Reply
1,700 Views
krisbird
Contributor I

Thanks.

CLOCK_EnableClock Is already run by the auto generated pin_mux code

i will check if the NXP SDK is defining the correct addresses...

0 Kudos
Reply
1,700 Views
xiangjun_rong
NXP TechSupport
NXP TechSupport

Hi, Kris,

I have checked the code, I think the pin definition is incorrect. you can try to modify the code as following:

PORT_SetPinInterruptConfig( PORTA, 1<<4, kPORT_InterruptEitherEdge );

modify to

PORT_SetPinInterruptConfig( PORTA, 4, kPORT_InterruptEitherEdge );

PORT_SetPinInterruptConfig( PORTA, 1<<18, kPORT_InterruptEitherEdge );

to

PORT_SetPinInterruptConfig( PORTA, 18, kPORT_InterruptEitherEdge );

PORT_SetPinInterruptConfig( PORTA, 1<<19, kPORT_InterruptEitherEdge );

to

PORT_SetPinInterruptConfig( PORTA, 19, kPORT_InterruptEitherEdge );

This is the source code of api function of PORT_SetPinInterruptConfig()

static inline void PORT_SetPinInterruptConfig(PORT_Type *base, uint32_t pin, port_interrupt_t config)
{
    base->PCR[pin] = (base->PCR[pin] & ~PORT_PCR_IRQC_MASK) | PORT_PCR_IRQC(config);
}

Hope it can help you

BR

Xiangjun rong

1,700 Views
epicedium
Contributor II

Thank you, this is the correct solution!

0 Kudos
Reply