This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

C-func call in ISR seems to cause stack corruption

Target: ST uPSD3454 running at 36.8864 Mhz

What seems simple is causing extreme confusion.

Enhanced template code from Keil:

;  Define instructions executed on a hardware timer interrupt.
HW_TIMER_CODE   MACRO
        EXTRN   CODE (TIMER_Update)
        USING   2       ; Registerbank 2 for following code
        LCALL   TIMER_Update ; C-func
        RETI
        ENDM


C-func:

void TIMER_Update( void )
{   unsigned char data i;

    for( i=0; i<NUM_TIMERS; i++ )
    {   timers[i]--;
        if( timers[i] == 0 )
        {   timers[i] = reload[i];
            if( events[i] < 255 )
                events[i]++;
        }
    }
}


HW_TIMER_CODE is ISR and occurring ever 10ms.
TIMER_update is attempt to implement software timers for additional systems functionality.

After about the 3rd HW_TIMER_CODE execution (between 30 and 50ms) system resets.

No stack corruption is detected in trace.

What silly thing am I overlooking?

Parents
  • Check to make sure that your TIMER_Update( ) function is operating properly with the USING 2 register bank.

    You might need to also add USING 2 to the TIMER_Update( ) function, or omit the register bank part in the ISR vector routine.

    There might be other problems, but that's the first one I noticed as being a potential problem.

    Oh, the other problem... I hate macros. All of them.

    --Cpt. Vince Foster
    2nd Cannon Place
    Fort Marcy Park, VA

Reply
  • Check to make sure that your TIMER_Update( ) function is operating properly with the USING 2 register bank.

    You might need to also add USING 2 to the TIMER_Update( ) function, or omit the register bank part in the ISR vector routine.

    There might be other problems, but that's the first one I noticed as being a potential problem.

    Oh, the other problem... I hate macros. All of them.

    --Cpt. Vince Foster
    2nd Cannon Place
    Fort Marcy Park, VA

Children