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.

TMS320F280049: RAM initialization and Stack

Part Number: TMS320F280049

Hi Champs,

I try to use _system_pre_init() to clear RAM, in this function I can use function memset() to set the RAM contents to 0, but I should avoid the address range of stack, otherwise the function return address will be cleared and system will fail to work(return to address 0x0000), please refer to below C code.

int _system_pre_init(void)

{

   /* clear M0 RAM */

   memset((void *)0x00000000, 0x0000, 0x400);

 

   /* clear M1 RAM, avoid stack region(0x0400 - 0x04FF) */

   memset((void *)0x00000500, 0x0000, 0x300);

 

   /* clear CPU-to-CLA MSGRAM */

   memset((void *)0x00001500, 0x0000, 0x80);

 

   /* clear LS0 - LS7 RAM */

   memset((void *)0x00008000, 0x0000, (0x0800 * 8));

 

   /* clear GS0 - GS3 RAM */

   memset((void *)0x0000C000, 0x0000, (0x2000 * 2));

   memset((void *)0x00010000, 0x0000, (0x2000 * 2));

 

   return 1;

}

 

But I find that if we use Dedicated RAM Init Register to clear RAM contents, then system still works well even the stack contents are cleared to 0. I have no idea how this could happen, what's the difference between these two RAM clear methods?

int _system_pre_init(void)

{

   EALLOW;

   *(int *)0x5F412 =0x0003;     // RAM INIT FOR M0/M1 Memory

   *(int *)0x5F432 =0x00FF;     // RAM INIT FOR LS0..LS7 Memory

   *(int *)0x5F452 =0x000F;     // RAM INIT FOR GS0..GS3 Memory

   EDIS;

   while(!((*(int *)0x5F414 == 0x0003) && (*(int *)0x5F434 == 0x00FF) && (*(int *)0x5F454 == 0x000F) ));

 

   return 1;

}

Please advise your comments, thanks for help.

Regards,

-Luke

  • Hi Luke,

    Have you checked that RAMINIT did happened correctly for all the RAMs after the code execution (by looking at RAM content in CCS memory watch window) and you see all the values 0x0 in stack which was non-zero before RAMINIT ?

    Regards,

    Vivek Singh

  • Vivek,

    Yes, I set break point in function _system_pre_init() and monitor stack(address 0x400) in memory browser window. I am sure that the contents of stack are not all zero(because call _system_pre_init()) before I clean RAM, and all the stack RAM contents are zero after initialization.

    I did those two experiments, method 1(memset) fails to return and software fails to work if I don't avoid stack region, method 2 is able to return and system works well. I use method 2 and LaunchPad with led_ex1_blinky example, the example code works well and the LED is flickering I run it standalone without CCS.

    It doesn't make sense and I don't know the reason yet, please advise your idea if any, thanks.

    -Luke

  • Luke,

    This look strange but since there is only one function call and no argument passed when you are using the RAMINIT feature, there may not be any valid info on stack hence even after RAMINIT, there is no issue in return. In other case you have function inside function (have function memset() with in _system_pre_init()) hence if you clear the stack there, it will not work.

    You can try another function call in passing case and see if that fails.

    Regards,

    Vivek Singh 

  • Vivek,

    I have further check and understand what is happening. When I use memset() to clean RAM, system will push RPC data(previous PC+2 before calling _system_pre_init) into stack before entering memset(), if I clean stack data in memset() function, then RPC will get wrong data when returning from memset() and pop data from stack.

    This problem is solved, thanks for your help.

    -Luke