This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

Starterware/PROCESSOR-SDK-AM335X: am335x problem with interrupt in input pin

Part Number: PROCESSOR-SDK-AM335X

Tool/software: Starterware

Hey everyone,

i am trying to create an interrupt when pressing a switch connected to an input pin of my beaglebone white.
When this event occurs, i have created an isr which i want to turn off (an already on) led and turn on an other (currently off) led...
i don't know what is not working properly so i am giving you my code (actually a piece of it, which is responsible for enabling the pin, interrupt controller and the isr) in hope that someone can help..

IntMasterIRQEnable();
IntAINTCInit();
GPIO1ModuleClkConfig();
GpioModuleEnable(SOC_GPIO_1_REGS);
GPIODirModeSet(SOC_GPIO_1_REGS, GPIO_INTER_INP, GPIO_DIR_INPUT);
IntRegister(SYS_INT_GPIOINT1A, isr_buttonLed);
IntPrioritySet(SYS_INT_GPIOINT1A, 0, AINTC_HOSTINT_ROUTE_IRQ);
IntSystemEnable(SYS_INT_GPIOINT1A);
GPIOIntTypeSet(SOC_GPIO_1_REGS,GPIO_INTER_INP,GPIO_INT_TYPE_LEVEL_HIGH);
HWREG(SOC_GPIO_1_REGS + 0x34) = 0x10;
HWREG(SOC_GPIO_1_REGS + 0x38) = 0x10;
HWREG(SOC_GPIO_1_REGS + 0x44) = 0x10;
//
//------isr function
//
static void isr_buttonLed(void)
{
  /*    Clear interrupt      */
  HWREG(SOC_GPIO_1_REGS + 0x2C) = 0x10;
  HWREG(SOC_GPIO_1_REGS + 0x30) = 0x10;
  //turn off led that is already on
  GPIOPinWrite(SOC_GPIO_1_REGS, GPIO_LED_ON, GPIO_PIN_LOW);
  //turn on an other led
  GPIOPinWrite(SOC_GPIO_1_REGS, GPIO_LED_2, GPIO_PIN_HIGH);
  //again enable IRQ
  HWREG(SOC_GPIO_1_REGS + 0x34) = 0x10;//GPIO_IRQSTATUS_SET_0
  HWREG(SOC_GPIO_1_REGS + 0x38) = 0x10;//GPIO_IRQSTATUS_SET_1
  HWREG(SOC_GPIO_1_REGS + 0x44) = 0x10;//GPIO_IRQWAKEN_0
}

Do i have to enable something more? Are the above correct?
Also i am not pretty sure that i have understood how to choose the correct interrupt request line..any help is more than welcome...

Thanks in advance!

  • in case that matters, i should also say that i am using starterware 2.00.01.01, code composer studio version: 6.1.0.00104 and i am building the project using compiler version GNU v4.8.4 (Linaro)
  • Sorry for being so annoying but i really need to find out what is going on...

    Firstly, i tested that the input pin is actually working and "understands" a logic level difference when the switch is pushed or not..for that reason i used the GPIOPinRead function inside a loop and it seems that the pin works just fine..(although the high level was indicated by an int value of 65536, rather than an 1 as i would expect but i guess that's not a mistake).

    Thus, i come to believe that the problem could be one of the following:

    • the interrupt controller is not properly working (but why?how can i be sure and what else should i try?)
    • the gpio module(and probably any other peripheral), when it comes to interrupts need some extra setting-or-initialization (for that i used GPIOPinIntEnable, but again it didn't work out. Maybe there are more things to do?)
    • is there any chance that the problem is created by the linker file or the startup file used from code composer studio? maybe the interrupt vector is not properly initialized or the interrupt vector table is at the wrong location?
      As far as the linker file relationship with the problem, i base that assumption on an other thread (last post) https://e2e.ti.com/support/embedded/starterware/f/790/t/491415 which is a different problem but somehow it seems to me, possible to be relevant (or i am truly desperate).

    Relatively to the last bullet...in order to successfully build the project, except for the necessary header and source files and the startup_ARMCA8.S and AM335x.lds files(which are automatically created) do i need to include anything else?
    Like, the exceptionhandler.S located in AM335X_StarterWare_02_00_01_01/system_config/armv7a/am335x/gcc/           or files cp15.S,init.S located in
    AM335X_StarterWare_02_00_01_01/system_config/armv7a/gcc/ ?
    (in case i inlude the init.S the build can not be successful since this error pop ups:               "selected processor does not support ARM mode `fmxr FPEXC,r0')
    Based on the link given above, maybe AM335x.lds should be replaced with an other file?

    I remind that i use the GNU v4.8.4 (Linaro) compiler provided by code composer studio (version 6.1)

    Thanks again in advance 

  • well, some update..

    inserting the GPIOPinIntEnable function seems to SOLVE the problem, since the push of the switch actually triggers an interrupt and the leds are off and on respectivelly.
    Of course the way my isr handles things, leaves the leds in such a way that a second press of the switch doesn't have obvious results (since the led that should turn on is already on and the other is already off).
    For that reason, i changed my isr and i let the led blink...there is where a new problem occurs....

    it seems like every single push of the switch triggers an interrupt and the isr takes place TWICE, meaning that the led blinks 4times instead of 2. i provide the piece of code in case anyone can help..

    IntRegister(SYS_INT_GPIOINT1A, isr_buttonLed);
    IntPrioritySet(SYS_INT_GPIOINT1A, 0, AINTC_HOSTINT_ROUTE_IRQ);
    IntSystemEnable(SYS_INT_GPIOINT1A);
    GPIOIntTypeSet(SOC_GPIO_1_REGS,GPIO_INTER_INP,GPIO_INT_TYPE_LEVEL_HIGH);
    GPIOPinIntEnable(SOC_GPIO_1_REGS,GPIO_INT_LINE_1,GPIO_INTER_INP);
    HWREG(SOC_GPIO_1_REGS + 0x34) = 0x10;
    HWREG(SOC_GPIO_1_REGS + 0x44) = 0x10;
    while(1);
    //
    //----------isr
    //
    static void isr_buttonLed(void)
    {
      GPIOPinIntClear(SOC_GPIO_1_REGS, GPIO_INT_LINE_1, GPIO_INTER_INP);
      int counter = 0;
      for(counter=0;counter<2;counter++)
      {
        GPIOPinWrite(SOC_GPIO_2_REGS, GPIO_LEDAKI_ON, GPIO_PIN_LOW);
        GPIOPinWrite(SOC_GPIO_1_REGS, GPIO_LED_BACK_UP, GPIO_PIN_HIGH);
        Delay(0xAFFFF);
        GPIOPinWrite(SOC_GPIO_2_REGS, GPIO_LEDAKI_ON, GPIO_PIN_HIGH);
        GPIOPinWrite(SOC_GPIO_1_REGS, GPIO_LED_BACK_UP, GPIO_PIN_LOW);
        Delay(0xAFFFF);
      }
    }