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.

TMS320F28027F: Clear all ram contents but keep auto initialization variable

Part Number: TMS320F28027F

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...

  • Write, in assembly, bootup code to clear all the RAM before it even gets to cinit. This is probably the best way to do it with zero risk of accidentally writing over cinit stuff. In TI examples, you will see an *asm file. That is where you will add this ram clearing code. Be sure that watchdog is disabled when clearing RAM because it might take a while.
  • Sounds Good. Can you please share a reference code with me?
  • 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

  • Edward,

    Thanks for your quick response.

    It looks to me that you've just clear the .ebss SECTION which must be contiguous, as you know that there are 2 part of RAMs in this device, M0&M1 SRAM and L0 SRAM. Those of 2 rams are not contiguous, how to handle those 2 RAMs?

    In addition, if we just use regular way to clear ram, such as, clear all ram content in internal function, it will crash the stack content, and the PC won't return properly. If we could clear the ram before C code is executed as suggested by Quark(posted in above), that would be better. But there is no reference code with this solution.

    Thanks...
  • Hi Jack,

    Clearing .ebss should be enough for debug purposes.

    What for are you trying to clear stack space? To measure stack depth? You may clear all memory from CCS Memory Browser, then reload your code again, run and see how far stack grown.

    CCS boot routine is somewhere at c:\ti\ccsv8\tools\compiler\ti-cgt-c2000_18.1.2.LTS\lib\src\boot28.asm . You don't need to edit it. Instead of editing you may create your own mem clear routine, change entry point in linker settings to your routine with preceding underscope, like _MyStartup, then after zeroing is complete jump to c_int00.

    void c_int00(void);
    void MyStartup(void)
    {
    memset((void*)0x3000/*specify RAM start*/, 0, 0x1000/*RAM chunk size*/);

    // repeat memset for not contiguos RAM chunks.

    asm(" MOV SP,#0x3000"); /* either init SP for c_int00() C call, or use jump to c_int00 instruction */
    c_int00();
    }

    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.

    6242.CodeStartBranch.asm

  • Hi Edward,

    Thanks. Brilliant idea. Can you please shows how to runs MystartUp before c_int00? Below is what I'm thinking to change the assembly code, can you please help to take a look at it?

    wd_disable:
    SETC OBJMODE ;Set OBJMODE for 28x object code
    EALLOW ;Enable EALLOW protected register access
    MOVZ DP, #7029h>>6 ;Set data page for WDCR register
    MOV @7029h, #0068h ;Set WDDIS bit in WDCR to disable WD
    EDIS ;Disable EALLOW protected register access
    ;LB _c_int00 ;Branch to start of boot.asm in RTS library
    LB _MyStartup

    The reason of clearing all rams is because I'd like to build a standard platform that make sure all static/global variables are 0. But the .cmd file are different in different project due to some of ram location are used for different purpose, if the global/static variables is not cleared at initialization, that will cause a problem in my application.
  • Quark,

    Thanks for sharing the code.
  • Hi Jack,

    • Thanks. Brilliant idea. Can you please shows how to runs MystartUp before c_int00? Below is what I'm thinking to change the assembly code, can you please help to take a look at it?

    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();

    }

    • The reason of clearing all rams is because I'd like to build a standard platform that make sure all static/global variables are 0

    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

  • Edward,

    This should work, I will try with your proposal. Thanks...