Help on ATSAML10 EIC IRQ issue

Go To Last Post
4 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hello All,

 

Firing up this little part for a project, could really need some help to figure out the issue.

 

Currently using ATSAML10E14A, sans Atmel framework.

 

The goal is to sense an external trigger every few ms on pin 14 (PA11 / PMUX_A).

 

Pin setup omitted, test pin output initialized to low.  here is the EIC setup code:

 

MCLK is working and running on 32MHz from DFLL

GCLK2 is working and running 32MHz from DFLL, checked by routing out divided output.

 

void config_eic(void)
{
    MCLK->APBAMASK.reg |= MCLK_APBAMASK_EIC;

    GCLK->PCHCTRL[EIC_GCLK_ID].reg = GCLK_PCHCTRL_GEN_GCLK2 | GCLK_PCHCTRL_CHEN;
    while (0 == (GCLK->PCHCTRL[EIC_GCLK_ID].reg & GCLK_PCHCTRL_CHEN)) {}

 

    EIC->CTRLA.bit.SWRST = 1;
    while(EIC->SYNCBUSY.bit.SWRST) {}

 

    EIC->CONFIG[0].reg = EIC_CONFIG_SENSE2_RISE ;

    EIC->INTENSET.reg = EIC_INTENSET_EXTINT(1<<2);

    EIC->INTFLAG.reg = EIC_INTFLAG_EXTINT(1<<2);

 

    while(EIC->SYNCBUSY.bit.ENABLE) {}
    EIC->CTRLA.bit.ENABLE = 1;
    while(EIC->SYNCBUSY.bit.ENABLE) {}

 

    // NVIC_EnableIRQ(EIC_2_IRQn);
}

 

Here is the handler for EIC2

test pin is toggled via a working macro

 

void EIC_2_Handler(void)
{
    EIC->INTFLAG.reg = EIC_INTFLAG_EXTINT(1<<2);
    GPIO_TEST_TOGGLE();
}

 

But this handler does not seem to get called and handled, with nothing else but a empty while(1) loop or __WFI() in main after configurations.

 

So if I commented out the NVIC_EnableIRQ(EIC_2_IRQn) at the end of the first code segment, and run a manual check in the while(1) loop as follow:

 

    while(1)
    {
        if(EIC->INTFLAG.reg)
        {
            for(uint32_t i=0; i<EIC->INTFLAG.reg; i++)
            {
                GPIO_TEST_SET();
                GPIO_TEST_CLEAR();
            }

            EIC->INTFLAG.reg = EIC_INTFLAG_EXTINT(0xff);
        }
        else
        {
            GPIO_TEST_CLEAR();
        }
    }

 

This gives 4 pulses out (0b0000_0100) on test pin per trigger inline with expectation. Also checked using EIC5 via another pin, same behaviour, working without the IRQ enable and handler.

 

The peripheral seems to be working, though the program have trouble dealing with NVIC_EnableIRQ(EIC_2_IRQn) and/or EIC_2_Handler().

 

I do not have a full blown debugger/IDE setup, just text editor, gcc/make, swd binary loader and scope (prefer this way). Working with several these chips, dev setup is working on everything else more complicated.

 

Thanks anyone for helping to debug and figure this issue out.  Ideas please.

 

Best.

 

This topic has a solution.

ototo

Last Edited: Fri. Mar 13, 2020 - 03:14 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

It's EIC_Handler (there is only one EIC handler)

Edit: A quick look in the datasheet (I should have done before answering), this looks different on the SAML10, multiple handlers in fact.

/Lars

Last Edited: Fri. Mar 13, 2020 - 08:07 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I think you are missing the connection of the pin to the ext int.  I have attached some test code I wrote a while ago.  Its for the SAML22, but the SAML10 has almost identical registers.

 

The code just turns on the LED on the eval board when you press the button.  You seem to be missing the l.ines starting with Port[2]...

 

int main (void)
{
    SystemInit();                                                       /* Initialize the SAM system */
    __disable_irq();

    GCLK->PCHCTRL[3].reg = GCLK_PCHCTRL_CHEN | GCLK_PCHCTRL_GEN(0);     /* Connect GenClk0 to IEC (4MHz CPU clock) */
    while ((GCLK->PCHCTRL[3].reg & GCLK_PCHCTRL_CHEN) == 0);            /* Wait for Sync */

    EIC->CTRLA.reg = EIC_CTRLA_SWRST;                                   /* reset the External Interrupt Controller */
    while(EIC->SYNCBUSY.reg & EIC_SYNCBUSY_SWRST);                      /* wait for reset to complete */
    EIC->CONFIG[1].reg |= EIC_CONFIG_SENSE1_BOTH;                       /* trigger on either edge */ 
    EIC->INTENSET.reg = USER_BUTTON_EXT_MASK;
    EIC->INTFLAG.reg  = USER_BUTTON_EXT_MASK;
    EIC->CTRLA.reg = EIC_CTRLA_ENABLE;                                  /* enable EIC */ 
    while(EIC->SYNCBUSY.reg & EIC_SYNCBUSY_ENABLE);                     /* wait for enable to complete */

    PORT->Group[2].PINCFG[USER_BUTTON_PORT_PIN].reg = PORT_PINCFG_PMUXEN | PORT_PINCFG_PULLEN | PORT_PINCFG_INEN;  /* alternate function for PC01 */
    PORT->Group[2].PMUX[USER_BUTTON_PORT_PIN/2].reg |= PORT_PMUX_PMUXO(0);                                         /* PC01 = EIC/EXTINT[9] */

    PORT->Group[2].OUTSET.reg = (1 << USER_BUTTON_PORT_PIN);            /* Make user button a pull-up */
    PORT->Group[2].DIRSET.reg = LED_BITMASK;                            /* make Port C pin 27 output */
    PORT->Group[2].OUTSET.reg = LED_BITMASK;                            /* turn off LED */ 
    
    NVIC_EnableIRQ(EIC_IRQn);
    __enable_irq();

    while(1)
    {
    } 

/* in the interrupt handler, the yellow LED0 blinks twice */
void EIC_Handler( void)

    if (EIC->INTFLAG.reg & USER_BUTTON_EXT_MASK)
    { 
        PORT->Group[2].OUTCLR.reg = LED_BITMASK;    /* turn on LED */
        EIC->INTFLAG.reg = USER_BUTTON_EXT_MASK;    /* clear interrupt flag */
    }

}
 

John Malaugh

This reply has been marked as the solution. 
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Thanks Lajon and Malaugh.  Really appreciate!

 

The issue is resolved, observing response per expectations. We narrowed in on the interrupt serving and handling yesterday, so the area of the issue, in the startup script (custom), the handler vector is named differently (that's it, but take some time to track down), surprising it's been working for other interrupt calls this way.  Will dig this further to clean things up.

 

 

I do not have a process to manage this kinda of minimalistic somewhat custom dev environment yet, but will collect some thoughts for future discussion and inputs in another post, wishing some part of the environment is managed, controlled, reused and/or upgraded across project. 

 

Thanks again!

 

ototo

Last Edited: Fri. Mar 13, 2020 - 03:12 PM