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