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.

TMS320F28377S: Timer interrupt fails the first time, works every time after a reset.

Part Number: TMS320F28377S
Other Parts Discussed in Thread: C2000WARE

Hi,

I'm observing a weird behavior. My code is executed from RAM. The very first time it runs, the code ends up in an invalid location. However, afterwards it works perfectly every time. I initially thought it could be related to an initialization, but I got it to the point where I can replicate the behavior by just commenting / un-commenting one line: the interrupt enable.That is, I comment the interrupt enable, compile, run, the code behaves correctly. I un-comment it, the first time it fails, then I reset it (using CCS), and it works properly. As you can see in the code, I purposely removed all code from the interruption

So, here's the related code:

__interrupt void TimerInterrupt_vector(void) {

//void for testing
}

 
void TimerInt_Init(void) {

    /*First, disable interrupts...*/
    DINT;

    /*clear any interrupt flag*/
    __asm(" AND IER, #0"); 
    __asm(" AND IFR, #0");

    EALLOW();
    pieVectTable.TIMER1_INT = &TimerInterrupt_vector;
    EDIS();


    /*Stop timer*/
    reg_CpuTimer1.TCR.bit.TSS = 1u;

    /* Set the timer registers with the initial and reset values */
    reg_CpuTimer1.PRD.all = TIMER_PERIOD_40us;

    /*Since the period is too short, we don't need a prescaler*/
    reg_CpuTimer1.TPR.bit.TDDR = 0;
    reg_CpuTimer1.TPRH.bit.TDDRH = 0;

    /*Reset the timer (loads the period into the timer register)*/
    reg_CpuTimer1.TCR.bit.TRB = 1u;




    /*Enable interrupt*/
    reg_CpuTimer1.TCR.bit.TIE = 1u;


    /*Start timer*/
    reg_CpuTimer1.TCR.bit.TSS = 0u;

    ENABLE_T1_INT();
    EINT();
    ERTM();
}


I have verified what you might expect: that the vector is properly set, that the bits are correct, etc. I noticed, though, that the invalid address where I end up was somehow pushed into the stack (I verified this with a breakpoint in the invalid address, then checking the stack).

Am I missing one configuration bit or something that could explain this strange behavior? 

  • It seems that highlighting the line was not a good idea after all (the format didn't came up right). I hope it is till clear what the code is and which one was the highlighted line:

    reg_CpuTimer1.TCR.bit.TIE = 1u;
  • I would suggest looking at a couple of items.
    What is the initialization of the PIE look like? How does that compare to examples in C2000Ware?
    The ordering of initialization and enabling of interrupts. Perhaps there is something that is initialized after an enabling of an item which when you restart for the 2nd attempt, now things are initialized.
  • Hi Javier,

    Like Brandon mentioned try enabling PIE, and then assign Timer ISR to the PIE vector table. Let me know if you still get errors when you run first time.

    // Enable the PIE Vector Table
    PieCtrlRegs.PIECTRL.bit.ENPIE = 1;

    Regards,

    Nirav

  • Well, it was the opposite order that worked: I updated the vector and then enable PIE again



    EALLOW();
    pieVectTable.TIMER1_INT = &TimerInterrupt_vector;

    /*reenable pie*/
    reg_PieCtrl.PIECTRL.bit.ENPIE = 1;

    EDIS();



    I'm still not sure what the internal mechanism is. ENPIE was previously set as 1 (in the boot code, previous to my code), but somehow it "didn't count". Setting ENPIE again after setting the vector worked.


    Thanks a lot for your help