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.

EK-TM4C129EXL: Default Handler being triggered for no reason

Part Number: EK-TM4C129EXL

Hi team,

My customer need assistance.

I am running my code and when I enter into my while loop, I pause it and get sent into the IntDefaultHandler function.  I cannot find any issues with my code.  I have the same functions used (with slight modifications) in a different project and it works just fine.  I am attaching the 2 C files that I am having problems with, both are similar and the image from the Debugger.

6283.main.c
#include <stdint.h>
#include <stdbool.h>

#define GPIO_PORTN ((volatile uint32_t *)0x40064000)
#define GPIO_PORTJ ((volatile uint32_t *)0x40060000)
#define GPIO_PORTK ((volatile uint32_t *)0x40061000)
#define GPIO_PORTF ((volatile uint32_t *)0x4005D000)
#define SYSCTL ((volatile uint32_t *)0x400FE000)
#define SysTick ((volatile uint32_t *)0xE000E000)

#define SYSCTL_MOSCCTL_PWRDN (1 << 3)
#define SYSCTL_MOSCCTL_NOXTAL (1 << 2)
#define SYSCTL_MOSCCTL_OSCRNG (1 << 4)

#define SYSCTL_RIS_MOSCPUPRIS (1 << 8)

#define SYSCTL_MISC_MOSCPUMIS (1 << 8)

#define SYSCTL_RSCLKCFG_OSCSRC_MOSC (3 << 20)
#define SYSCTL_RSCLKCFG_PLLSRC_MOSC (3 << 24)
#define SYSCTL_RSCLKCFG_NEWFREQ (1 << 30)
#define SYSCTL_RSCLKCFG_PSYSDIV_M (0x3ff >> 0)
#define SYSCTL_RSCLKCFG_PSYSDIV_3 3
#define SYSCTL_RSCLKCFG_USEPLL (1 << 28)
#define SYSCTL_RSCLKCFG_MEMTIMU (1 << 31)

#define SYSCTL_PLLFREQ0_MINT_S 0
#define SYSCTL_PLLFREQ0_MFRAC_S 10
#define SYSCTL_PLLFREQ0_PLLPWR (1 << 23)

#define SYSCTL_MEMTIM0_EBCHT_M (0b1111 << 22)
#define SYSCTL_MEMTIM0_EWS_M (0b1111 << 16)
#define SYSCTL_MEMTIM0_EBCE (1 << 21)
#define SYSCTL_MEMTIM0_FBCHT_3_5 (6 << 6)
#define SYSCTL_MEMTIM0_EWS_6 (6 << 16)
#define SYSCTL_MEMTIM0_FBCHT_M (0b1111 << 6)
#define SYSCTL_MEMTIM0_FWS_M (0b1111 >> 0)
#define SYSCTL_MEMTIM0_FBCE (1 << 5)
#define SYSCTL_MEMTIM0_FWS_6 (6 >> 0)

#define GPIO_PIN_0  (1 >> 0)
#define GPIO_PIN_1  (1 << 1)
#define GPIO_PIN_2  (1 << 2)
#define GPIO_PIN_3  (1 << 3)
#define GPIO_PIN_4  (1 << 4)
#define GPIO_PIN_5  (1 << 5)
#define GPIO_PIN_6  (1 << 6)
#define GPIO_PIN_7  (1 << 7)

#define LED1_PN1 GPIO_PIN_1
#define LED2_PN0 GPIO_PIN_0
#define LED3_PF4 GPIO_PIN_4
#define LED4_PF0 GPIO_PIN_0

#define SYSCTL_RCGCGPIO_PORTF (1 << 5)
#define SYSCTL_RCGCGPIO_PORTJ (1 << 8)
#define SYSCTL_RCGCGPIO_PORTK (1 << 9)
#define SYSCTL_RCGCGPIO_PORTN (1 << 12)

#define PUSH1_PJ0 GPIO_PIN_0
#define PUSH2_PJ1 GPIO_PIN_1

#define OUT_PK0 GPIO_PIN_0
#define OUT_PK1 GPIO_PIN_1
#define OUT_PK2 GPIO_PIN_2
#define OUT_PK3 GPIO_PIN_3

#define out (OUT_PK0 | OUT_PK1 | OUT_PK2 | OUT_PK3)

#define IN_PK4 GPIO_PIN_4
#define IN_PK5 GPIO_PIN_5
#define IN_PK6 GPIO_PIN_6
#define IN_PK7 GPIO_PIN_7

#define in (IN_PK4 | IN_PK5 | IN_PK6 | IN_PK7)

#define C 4778
#define D 4257
#define E 3792
#define G 3189

unsigned char index = 0;

const unsigned char sin[48] = {
   0,0,1,1,1,2,2,3,4,5,6,7,8,9,10,11,12,13,13,14,14,14,15,15,
   15,15,14,14,14,13,13,12,11,10,9,8,7,6,5,4,3,2,2,1,1,1,0,0
};

enum {
  SYSCTL_RCGCGPIO = (0x608 >> 2),
  GPIO_DEN  =   (0x51c >> 2),
  GPIO_DIR  =   (0x400 >> 2),
  GPIO_PUR  =   (0x510 >> 2),
  SYSCTL_MOSCCTL = (0x07C >> 2),
  SYSCTL_RIS = (0x050 >> 2),
  SYSCTL_MISC = (0x058 >> 2),
  SYSCTL_RSCLKCFG = (0x0B0 >> 2),
  SYSCTL_PLLFREQ0 = (0x160 >> 2),
  SYSCTL_PLLFREQ1 = (0x164 >> 2),
  SYSCTL_MEMTIM0 = (0x0C0 >> 2),
  SYSCTL_PLLSTAT = (0x168 >> 2),
  STCTRL    =   (0x010 >> 2),
  STRELOAD  =   (0x014 >> 2),
  STCURRENT =   (0x018 >> 2),
  PRI3 = (0xD20 >> 0)
};

void pll(void){
    uint32_t tmp;

    SYSCTL[SYSCTL_MOSCCTL] &= ~(SYSCTL_MOSCCTL_NOXTAL | SYSCTL_MOSCCTL_PWRDN);
    if (!(SYSCTL[SYSCTL_MOSCCTL] & SYSCTL_MOSCCTL_OSCRNG)){
        SYSCTL[SYSCTL_MOSCCTL] |= SYSCTL_MOSCCTL_OSCRNG;
        while (!(SYSCTL[SYSCTL_RIS] & SYSCTL_RIS_MOSCPUPRIS));
    }
    SYSCTL[SYSCTL_MISC] = SYSCTL_MISC_MOSCPUMIS;
    SYSCTL[SYSCTL_RSCLKCFG] |= SYSCTL_RSCLKCFG_OSCSRC_MOSC | SYSCTL_RSCLKCFG_PLLSRC_MOSC;
    SYSCTL[SYSCTL_PLLFREQ0] = (96 << SYSCTL_PLLFREQ0_MINT_S) | (0 << SYSCTL_PLLFREQ0_MFRAC_S);
    SYSCTL[SYSCTL_PLLFREQ1] = 4;

    tmp = SYSCTL[SYSCTL_MEMTIM0];
    tmp &= ~(SYSCTL_MEMTIM0_EBCHT_M | SYSCTL_MEMTIM0_EWS_M | SYSCTL_MEMTIM0_EBCE);
    tmp |= SYSCTL_MEMTIM0_FBCHT_3_5 | SYSCTL_MEMTIM0_EWS_6;
    tmp &= ~(SYSCTL_MEMTIM0_FBCHT_M | SYSCTL_MEMTIM0_FWS_M | SYSCTL_MEMTIM0_FBCE);
    tmp |= SYSCTL_MEMTIM0_FBCHT_3_5| SYSCTL_MEMTIM0_FWS_6;
    SYSCTL[SYSCTL_MEMTIM0] = tmp;

    SYSCTL[SYSCTL_PLLFREQ0] |= SYSCTL_PLLFREQ0_PLLPWR;
    SYSCTL[SYSCTL_RSCLKCFG] |= SYSCTL_RSCLKCFG_NEWFREQ;
    while (!SYSCTL[SYSCTL_PLLSTAT]);

    tmp = SYSCTL[SYSCTL_RSCLKCFG];
    tmp = (tmp & ~SYSCTL_RSCLKCFG_PSYSDIV_M) | SYSCTL_RSCLKCFG_PSYSDIV_3;
    tmp |= SYSCTL_RSCLKCFG_USEPLL | SYSCTL_RSCLKCFG_MEMTIMU;
    SYSCTL[SYSCTL_RSCLKCFG] = tmp;
}

unsigned long piano(void){
    unsigned long freq;

    if (!GPIO_PORTK[IN_PK4]){
        freq = C;
        GPIO_PORTN[LED1_PN1] ^= LED1_PN1;
    }
    else if(!GPIO_PORTK[IN_PK5]){
        freq = D;
        GPIO_PORTN[LED2_PN0] ^= LED2_PN0;
    }
    else if(!GPIO_PORTK[IN_PK6]){
        freq = E;
        GPIO_PORTF[LED3_PF4] ^= LED3_PF4;
    }
    else if(!GPIO_PORTK[IN_PK7]){
        freq = G;
        GPIO_PORTF[LED4_PF0] ^= LED4_PF0;
    }
    else
        freq = 0;

    return freq - 1;
}

void DAC(unsigned long data){
    if (GPIO_PORTK[in] != in)
        GPIO_PORTK[out] = 0;
    else
        GPIO_PORTK[out] = data;
}

void tone(unsigned long period){
    SysTick[STRELOAD] = period;
}

void sysHand(void){
    index = (index + 1) & 0x30;
    DAC(sin[index]);
}

void main()
{
    pll();

    SysTick[STCTRL] = 0;
    SysTick[STCURRENT] = 0;
    SysTick[PRI3] = (0x2 << 28);
    SysTick[STCTRL] = 0x7;
    SysTick[STRELOAD] = 1000000;

    SYSCTL[SYSCTL_RCGCGPIO] |= SYSCTL_RCGCGPIO_PORTN;
    SYSCTL[SYSCTL_RCGCGPIO] |= SYSCTL_RCGCGPIO_PORTF;
    SYSCTL[SYSCTL_RCGCGPIO] |= SYSCTL_RCGCGPIO_PORTJ;
    SYSCTL[SYSCTL_RCGCGPIO] |= SYSCTL_RCGCGPIO_PORTK;
    SYSCTL[SYSCTL_RCGCGPIO] |= SYSCTL_RCGCGPIO_PORTN;
    SYSCTL[SYSCTL_RCGCGPIO] |= SYSCTL_RCGCGPIO_PORTF;
    SYSCTL[SYSCTL_RCGCGPIO] |= SYSCTL_RCGCGPIO_PORTJ;
    SYSCTL[SYSCTL_RCGCGPIO] |= SYSCTL_RCGCGPIO_PORTK;

    GPIO_PORTN[GPIO_DIR] |= LED1_PN1;
    GPIO_PORTN[GPIO_DEN] |= LED1_PN1;
    GPIO_PORTN[GPIO_DIR] |= LED2_PN0;
    GPIO_PORTN[GPIO_DEN] |= LED2_PN0;
    GPIO_PORTF[GPIO_DIR] |= LED3_PF4;
    GPIO_PORTF[GPIO_DEN] |= LED3_PF4;
    GPIO_PORTF[GPIO_DIR] |= LED4_PF0;
    GPIO_PORTF[GPIO_DEN] |= LED4_PF0;

    GPIO_PORTJ[GPIO_PUR] |= PUSH1_PJ0 | PUSH2_PJ1;
    GPIO_PORTJ[GPIO_DEN] |= PUSH1_PJ0 | PUSH2_PJ1;

    GPIO_PORTK[GPIO_DIR] &= ~in;
    GPIO_PORTK[GPIO_DEN] |= in;

    GPIO_PORTK[GPIO_DIR] |= out;
    GPIO_PORTK[GPIO_DEN] |= out;

    while(true){
        GPIO_PORTN[LED1_PN1] ^= LED1_PN1;
    }
}

main (1).c
#include <stdint.h>
#include <stdbool.h>

#define GPIO_PORTA ((volatile uint32_t *)0x40058000)
#define SYSCTL ((volatile uint32_t *)0x400fe000)
#define SysTick ((volatile uint32_t *)0xE000E000)

#define GPIO_PIN_3  (1 << 3)
#define GPIO_PIN_4  (1 << 4)
#define GPIO_PIN_5  (1 << 5)

#define SYSCTL_RCGCGPIO_PORTA (1 >> 0)

#define left GPIO_PIN_5
#define right GPIO_PIN_4
#define button GPIO_PIN_3

#define SYSCTL_MOSCCTL_PWRDN (1 << 3)
#define SYSCTL_MOSCCTL_NOXTAL (1 << 2)
#define SYSCTL_MOSCCTL_OSCRNG (1 << 4)

#define SYSCTL_RIS_MOSCPUPRIS (1 << 8)

#define SYSCTL_MISC_MOSCPUMIS (1 << 8)

#define SYSCTL_RSCLKCFG_OSCSRC_MOSC (3 << 20)
#define SYSCTL_RSCLKCFG_PLLSRC_MOSC (3 << 24)
#define SYSCTL_RSCLKCFG_NEWFREQ (1 << 30)
#define SYSCTL_RSCLKCFG_PSYSDIV_M (0x3ff >> 0)
#define SYSCTL_RSCLKCFG_PSYSDIV_3 3
#define SYSCTL_RSCLKCFG_USEPLL (1 << 28)
#define SYSCTL_RSCLKCFG_MEMTIMU (1 << 31)

#define SYSCTL_PLLFREQ0_MINT_S 0
#define SYSCTL_PLLFREQ0_MFRAC_S 10
#define SYSCTL_PLLFREQ0_PLLPWR (1 << 23)

#define SYSCTL_MEMTIM0_EBCHT_M (0b1111 << 22)
#define SYSCTL_MEMTIM0_EWS_M (0b1111 << 16)
#define SYSCTL_MEMTIM0_EBCE (1 << 21)
#define SYSCTL_MEMTIM0_FBCHT_3_5 (6 << 6)
#define SYSCTL_MEMTIM0_EWS_6 (6 << 16)
#define SYSCTL_MEMTIM0_FBCHT_M (0b1111 << 6)
#define SYSCTL_MEMTIM0_FWS_M (0b1111 >> 0)
#define SYSCTL_MEMTIM0_FBCE (1 << 5)
#define SYSCTL_MEMTIM0_FWS_6 (6 >> 0)

#define TOGGLE_OFF 0
#define TOGGLE_ON 1

enum {
  SYSCTL_RCGCGPIO = (0x608 >> 2),
  GPIO_DEN  =   (0x51c >> 2),
  GPIO_DIR  =   (0x400 >> 2),
  SYSCTL_MOSCCTL = (0x07C >> 2),
  SYSCTL_RIS = (0x050 >> 2),
  SYSCTL_MISC = (0x058 >> 2),
  SYSCTL_RSCLKCFG = (0x0B0 >> 2),
  SYSCTL_PLLFREQ0 = (0x160 >> 2),
  SYSCTL_PLLFREQ1 = (0x164 >> 2),
  SYSCTL_MEMTIM0 = (0x0C0 >> 2),
  SYSCTL_PLLSTAT = (0x168 >> 2),
  STCTRL    =   (0x010 >> 2),
  STRELOAD  =   (0x014 >> 2),
  STCURRENT =   (0x018 >> 2),
  PRI3 = (0xD20 >> 0)
};

void pll(void){
    uint32_t tmp;

    SYSCTL[SYSCTL_MOSCCTL] &= ~(SYSCTL_MOSCCTL_NOXTAL | SYSCTL_MOSCCTL_PWRDN);
    if (!(SYSCTL[SYSCTL_MOSCCTL] & SYSCTL_MOSCCTL_OSCRNG)){
        SYSCTL[SYSCTL_MOSCCTL] |= SYSCTL_MOSCCTL_OSCRNG;
        while (!(SYSCTL[SYSCTL_RIS] & SYSCTL_RIS_MOSCPUPRIS));
    }
    SYSCTL[SYSCTL_MISC] = SYSCTL_MISC_MOSCPUMIS;
    SYSCTL[SYSCTL_RSCLKCFG] |= SYSCTL_RSCLKCFG_OSCSRC_MOSC | SYSCTL_RSCLKCFG_PLLSRC_MOSC;
    SYSCTL[SYSCTL_PLLFREQ0] = (96 << SYSCTL_PLLFREQ0_MINT_S) | (0 << SYSCTL_PLLFREQ0_MFRAC_S);
    SYSCTL[SYSCTL_PLLFREQ1] = 4;

    tmp = SYSCTL[SYSCTL_MEMTIM0];
    tmp &= ~(SYSCTL_MEMTIM0_EBCHT_M | SYSCTL_MEMTIM0_EWS_M | SYSCTL_MEMTIM0_EBCE);
    tmp |= SYSCTL_MEMTIM0_FBCHT_3_5 | SYSCTL_MEMTIM0_EWS_6;
    tmp &= ~(SYSCTL_MEMTIM0_FBCHT_M | SYSCTL_MEMTIM0_FWS_M | SYSCTL_MEMTIM0_FBCE);
    tmp |= SYSCTL_MEMTIM0_FBCHT_3_5| SYSCTL_MEMTIM0_FWS_6;
    SYSCTL[SYSCTL_MEMTIM0] = tmp;

    SYSCTL[SYSCTL_PLLFREQ0] |= SYSCTL_PLLFREQ0_PLLPWR;
    SYSCTL[SYSCTL_RSCLKCFG] |= SYSCTL_RSCLKCFG_NEWFREQ;
    while (!SYSCTL[SYSCTL_PLLSTAT]);

    tmp = SYSCTL[SYSCTL_RSCLKCFG];
    tmp = (tmp & ~SYSCTL_RSCLKCFG_PSYSDIV_M) | SYSCTL_RSCLKCFG_PSYSDIV_3;
    tmp |= SYSCTL_RSCLKCFG_USEPLL | SYSCTL_RSCLKCFG_MEMTIMU;
    SYSCTL[SYSCTL_RSCLKCFG] = tmp;
}

struct state{
    unsigned int out;
    unsigned int next[2];
}; typedef const struct state fsm;

fsm sound[2] = {
                {0, {TOGGLE_OFF, TOGGLE_ON}},
                {1, {TOGGLE_ON, TOGGLE_OFF}}
};

unsigned int input = 0;
unsigned int output = 0;
unsigned int curr = TOGGLE_OFF;

void sys_hand(void){
    if (output == 1){
        GPIO_PORTA[left] ^= left;
        GPIO_PORTA[right] ^= right;
    } else if((output == 0) && (GPIO_PORTA[button] == 0x00)){
        GPIO_PORTA[left] = 0;
        GPIO_PORTA[right] = 0;
    } else{
        GPIO_PORTA[left] = 0;
        GPIO_PORTA[right] = 0;
    }
}

void delay(unsigned int param){
    unsigned int i, j;

    for(j = 0; j < param; j++){
        for(i = 0; i < 15; i++){

        }
    }
}

void edgeDetect(char param){
    if (param == 'r'){
        output = sound[curr].out;
        if (GPIO_PORTA[button] == 0){
            delay(1);
            if (!GPIO_PORTA[button])
                input = TOGGLE_ON;
        } else
            input = TOGGLE_OFF;
        curr = sound[curr].next[input];
    }
    else if (param == 'f'){
        output = sound[curr].out;
        if (!GPIO_PORTA[button]){
            delay(1);
            if (GPIO_PORTA[button] == 0)
                input = TOGGLE_ON;
        } else
            input = TOGGLE_OFF;
        curr = sound[curr].next[input];
    }
}

void main(void)
{
    SYSCTL[SYSCTL_RCGCGPIO] |= SYSCTL_RCGCGPIO_PORTA;
    SYSCTL[SYSCTL_RCGCGPIO] |= SYSCTL_RCGCGPIO_PORTA;

    GPIO_PORTA[GPIO_DEN] |= button;
    GPIO_PORTA[GPIO_DIR] &= ~button;
    GPIO_PORTA[GPIO_DIR] |= left;
    GPIO_PORTA[GPIO_DEN] |= left;
    GPIO_PORTA[GPIO_DIR] |= right;
    GPIO_PORTA[GPIO_DEN] |= right;

    SysTick[STCTRL] = 0;
    SysTick[STRELOAD] = 136363;
    SysTick[STCURRENT] = 0;
    SysTick[PRI3] = (0x2 << 28);
    SysTick[STCTRL] = 0x7;

    pll();

    while(true){
        edgeDetect('r');
        sys_hand();
    }
}

Could you help look into it? Thank you for your help.

  • Hi,

      First, please refer to FAQ #4 in https://e2e.ti.com/support/microcontrollers/arm-based-microcontrollers-group/arm-based-microcontrollers/f/arm-based-microcontrollers-forum/695568/faq-faqs-for-tm4c-arm-cortex-m4f-microcontrollers. We do not support DRM style of coding. We encourage people to use TivaWare API for software development. 

      With that said, if you are getting  IntDefaultHandler, this means the interrupt vector for the peripheral that is being used is not assigned. The default handler is used. 

      See below default startup file in TivaWare. You need to check your own startup file. The vector table has all the vectors assigned to IntDefaultHandler. If you have interrupt generated on GPIO Port F, then it will jump to IntDefaultHandler which is a default handler simply looping in a while loop. You will need to plug in your own ISR vector associated with the peripheral that you want to generate interrupt. 

    //*****************************************************************************
    //
    // This is the code that gets called when the processor receives an unexpected
    // interrupt.  This simply enters an infinite loop, preserving the system state
    // for examination by a debugger.
    //
    //*****************************************************************************
    static void
    IntDefaultHandler(void)
    {
        //
        // Go into an infinite loop.
        //
        while(1)
        {
        }
    }

  • Hello,

         This is the original question asker.

         I understand that you do not want people to use the DRM style, but I (and this is only my personal opinion) cannot stand using others code.  I want the feeling of I did this, I made this.  Also, I would need to find all the right functions and libraries, so to me, it would be easier to use the DRM style coding.  That is what I am trained in.

         That out of the way, if I am understanding you right, the starter file needs to be modified in order to use interrupts?  For one file, I am using Port A and SysTick, for another, Port K and SysTick.  Those ports/functions in my starter file use the default handler.  I need to create my own Interrupt Service Routine in order for that default not to be called.  Am I right with this?

    Thank you,

    Drew

  •  That out of the way, if I am understanding you right, the starter file needs to be modified in order to use interrupts?  For one file, I am using Port A and SysTick, for another, Port K and SysTick.  Those ports/functions in my starter file use the default handler.  I need to create my own Interrupt Service Routine in order for that default not to be called.  Am I right with this?

    Yes, you need to create your own ISR in order for that default handler not to be used. 

  • Hello,

         Alright.  Thank you very much.  I will try it out and let you know if it works.

    Drew

  • Hello,

         Haha, yes.  That was the problem.  Thank you so much.  Now all I need is to fix it so that the interrupt only gets triggered upon my button press.

    Drew