Dear Champs,
TI's example project are just to have feature for auto initialization variable, but no feature to clear RAM contents. Can you please recommend a way of clearing all ram content but keep auto initialization variable value?
Thanks...
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.
Dear Champs,
TI's example project are just to have feature for auto initialization variable, but no feature to clear RAM contents. Can you please recommend a way of clearing all ram content but keep auto initialization variable value?
Thanks...
Hi Jack,
standard C startup routine should clear all static storage variables (SSV) and initialize those which have initializer. As I understand it, since RAM with ECC on these MCUs is unusable without initial initialization (see DxINIT, LSxINIT etc registers), boot ROM clears (initializes) all RAM, so that C compiler kind of doesn't have to clear SSV. This is true but only for normal power on boot. While debugging, RAM clear routine in boot ROM isn't called and SSV are not cleared. Linkers RAM initialization model doesn't help, since often it's necessary to restart program without reloading.
In TI C compiler for C2000, you may define _system_pre_init() routine, which is called prior to initialization of variables with initializer. You may add there code to somehow clear .ebss section.
1. You may for example dedicate some memories like GS0 for .ebss, then use GS0INIT register to initialize GS0.
2. You may also use memset() to initialize .ebss.
in cmd file:
.ebss : > RAMGS23, PAGE = 1, RUN_START(_EbssStart), RUN_SIZE(_EbssSize), table(ebsstable)
To use linker ??_START and ??_END addresses, .ebss has to be contiguous. This is why I concatenated GS2 and GS3 memories.
in code
#if defined(_DEBUG)
#include <string.h>
int _system_pre_init(void)
{
extern int EbssSize, EbssStart;
memset(&EbssStart, 0, (size_t)&EbssSize);
return 1;
}
#endif
Edward
Attached is code I modified very long time ago for the 28335.
See function "stack_fill" at around line 143. You may want to modify __STACK_END and __STACK_SIZE symbols to fit your application.
This function is called on line 98. Notice that c_init00 is called afterwards at line 109.
Hi Jack,
I think I already explained how. By default C2000 Linker -> Advanced Options -> Symbol Management -> Specify program entry point ... = _c_int00. In C you need to remove leading underscore:
void c_int00(void);
So replace _c_int00 in linker settings with _MystartUp, then create function void MystartUp(void) in C, which would call c_int00() at exit. Since it's C, you could call DisableDog() from MystartUp(), no need for asm at all. Sorry, I had to insert stack initialization above memset(), though, since ROM initializes and uses stack, I think stack init is not necessary at all.
void c_int00(void);
void MyStartup(void)
{
asm(" MOV SP,#0x3000"); /* specify stack bottom address */
DisableDog();
memset((void*)0x3000/*specify RAM start*/, 0, 0x1000/*RAM chunk size*/);
// repeat memset for not contiguos RAM chunks.
c_int00();
}
If reason is standard zeroing, then it's enough to clear just .ebss . Any other C compiler for different architecture would clear just ebss or bss.
Edward