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.

Online stack overflow protection for Piccolo?

Hi,

I have tried to implement the online stack overflow protection (spra820) for the Piccolo 28035, but it does not work.

The STKOV_initSystemStack() routine returns with 1 (software failed to gain control of the watchpoint).

Should the online stack overflow protection described in spra820 work for the Piccolo, too? Are the C28x Analysis Block Watchpoint Registers the same for the Piccolo?

  • Hi Stephan!

    If the initialization routine returns 1 (software failed to gain control of the watchpoint) it means thet the CCS has already claimed that WP, try using the other WP (I think you can select that in appropriate .h file)

    If your code resides in FLASH you can tell the CCS NOT to put any brakepoint at the end of main (instead of you can hardocde ESTOP0 insturction at the end of main) and in C I/O code (you will not see any IO from the DSP - printf, ...) as HW breakpoints require free WP-s.

    Regards, Mitja

  • Hello Mitja,

        I have the same problem with Stephan. With your instruction, I reset the WP = 1,the initialization routine returns 0 (no error).Does that mean there is no stack overflow?

       I have to confirm whether there exists stack overflow problem in my project, and  the procedure below is what i did,

       (1)Firstly I explanted the files"stkov.h"and"stkov_systemstack.c"to my project,

       (2)Secondly allocating the stack in a section as below

      .stack: RUN = RAMM0,  /*RAMM0    : origin = 0x000000, length = 0x000400 /* on-chip RAM*/
        RUN_START(_HWI_STKBOTTOM),
        RUN_END(_HWI_STKTOP),
        PAGE = 1

    (3)then I access the routine STKOV_initSystemStack at the end of the main function.

    error = STKOV_initSystemStack((uint32)&HWI_STKBOTTOM,
                                          (uint32)&HWI_STKTOP,
                                           margin);

    Is it the correct way? Whether I still need any other actions?

     Thank you!

     Jason

  • Hi Jason!

    When the initialization retuns 0 it means, that the WP was successfully  configured. You still need to register a RTOS interrupt function (this should be done after PIE was configured):

        EALLOW;
        PieVectTable.RTOSINT = &STK_fail;
        EDIS;

    and write the RTOSINT function which will be triggered when your code will write near the end of stack (e.g.):

    void interrupt STK_fail(void)
    {
        while(1)
        {
        // her comes error handling code
            // register fault
            flags.fault = 1;
            // force all PWM extis to LOW
            EALLOW;
            EPwm1Regs.TZFRC.bit.OST = 1;
            EDIS;

            // endless loop
            while(1)
            {

                /* if in debug mode halt the DSP

                * if the CPU stops here the code wrote somewhere at the end of stack */

                asm(" ESTOP0");
            }
        }
    }

    Pleas be aware that the above code is only an example for projects which do NOT use DSP/BIOS, I don't know how the code changes if you are using DSP/BIOS.

     

    Hope this helps.

     

    Mitja

     

     

     

  • Hi Mitja,

    thanks for your hints!

    With WP 1, it worked immediately.  After disabling the breakpoints at the end of main and in C I/O code, it even works with WP 0 (my code resides in flash).

    Jason, the easiest way to test the online stack overflow protection is a recursive function that uses some stack. Call it in main() and you will get the RTOSINT just before the stack overflows.

    Regards, Stephan