• Join
  • Sign In with my.TI Login
Texas Instruments
  • Products
  • Applications
  • Tools & Software
  • Support & Community
  • Sample & Buy
  • About TI
Sample & Purchase Cart Sample & Purchase Cart
  • Search
  • Advanced
TI E2E™ Community
  • Support Forums
  • Blogs
  • Groups
  • Videos
  • 简体中文
  • More ...
TI Home » TI E2E Community » Support Forums » Microcontrollers » C2000™ Microcontrollers » C2000 32-bit Microcontrollers Forum » Clearing RAM BEFORE main() is called
Share
C2000™ Microcontrollers
  • Forums
  • Announcements
  • E2E Wiki
Options
  • Subscribe via RSS
C2000 Resources
  • Product Folder
  • C2000 Training Portal
  • C2000 Technical Training Catalog
  • C2000 Datasheets, App Notes, User Guides
  • C2000 Hardware Design Kits
  • controlSUITE for C2000 Software Library


  • InstaSPIN Resources
  • What is InstaSPIN?
  • Videos and Support


  • InstaSPIN-FOC and InstaSPIN-MOTION Resources
  • What is InstaSPIN-FOC?
  • What is InstaSPIN-MOTION?
  • Product Folder: F28069F, F28068F, F28062F, F28068M, F28069M
  • User’s Guide
  • Technical User’s Manual
  • Tools
  • Clearing RAM BEFORE main() is called

    Clearing RAM BEFORE main() is called

    This question has suggested answer(s)
    tonyo
    Posted by tonyo
    on Jan 03 2010 15:01 PM
    Prodigy90 points

    Hi,

    I want the entire RAM on my F28335 set to 0x0000 on startup.

    Before I try to re-invent this, is there already a way to clear RAM before main() is called?

    If not, where would be a good place to put a small routine to do this?

    thanks!

    Report Abuse
    • Reply
    You have posted to a forum that requires a moderator to approve posts before they are publicly available.
    All Replies
    • Mitja Nemec
      Posted by Mitja Nemec
      on Jan 04 2010 02:49 AM
      Suggested Answer
      Genius4175 points
      Hi tonyo! As far as I know there is no solution already available. You can easily insert appropriate assembly routines within DSP2833x_CodeStartBranch.asm, if it is really necessary for you to clear RAM before entering main(). If you want to also clear external RAM, you will have to configure PLL, and XINTF and you might want to disable Watchdog as whole procedure can take some time. I would instead clear RAM after entering main(), where I would first configure PLL, XINTF and FLASH. Maybe I would clear the first few location of stack area within DSP2833x_CodeStartBranch.asm. In any case the code will be quite specific, depending on your RAM configuration. Best regards, Mitja
      Report Abuse
      • Reply
      You have posted to a forum that requires a moderator to approve posts before they are publicly available.
    • tonyo
      Posted by tonyo
      on Jan 04 2010 11:22 AM
      Prodigy90 points

      Yes, I suspected as much -

      Although there are some compilers with a #zero_ram pragma that will insert the code as part of the compile cycle.

      I'm surprised that nobody has asked about this before, as the ANSI standard for C requires this, according to TI's own document:

      Note: Initializing Variables

      In ANSI/ISO C, global and static variables that are not explicitly initialized must be set to 0

      before program execution. The C/C++ compiler does not perform any preinitialization of

      uninitialized variables. Explicitly initialize any variable that must have an initial value of 0.

      The easiest method is to have a loader clear the .bss section before the program starts

      running. Another method is to set a fill value of 0 in the link step control map for the .bss

      section.

      You cannot use these methods with code that is burned into ROM.

      Must be an embedded performance thing....

       

      thanks,

       

      tony o.

       

      Report Abuse
      • Reply
      You have posted to a forum that requires a moderator to approve posts before they are publicly available.
    • Mitja Nemec
      Posted by Mitja Nemec
      on Jan 05 2010 01:09 AM
      Genius4175 points

      Hi Tony,

       

      It simplifies matters considerably if you want to put zeros only in .bss and .ebss sections. What you can do is define symbols within linker command file with LOAD_START and LOAD_END directives. Then you can write the assembly code with these symbols that loops from start to end of the section. This solution is somewhat more portable, as it does not rely on specific Memory map and it also works regardless if you are putting your code in RAM or in FLASH.

       

      Regards, Mitja

      Report Abuse
      • Reply
      You have posted to a forum that requires a moderator to approve posts before they are publicly available.
    • tonyo
      Posted by tonyo
      on Jan 05 2010 16:51 PM
      Prodigy90 points

      I tried using memset() to zero out RAM at the beginning of main() - this seems to work but the tradeoff is that compiler-initialized variables are zeroed out too! It appears that the boot ROM would have to be modified to zero out RAM and then have it set up the variables, stack, etc. then transfer control to main(), which is probably not doable.

      Report Abuse
      • Reply
      You have posted to a forum that requires a moderator to approve posts before they are publicly available.
    • Mitja Nemec
      Posted by Mitja Nemec
      on Jan 06 2010 04:58 AM
      Genius4175 points

      You can put the code in DSP2833x_CodeStartBranch.asm, which executes after boot ROM and before initialization of C enviroment (_c_int00) which is in RTS library. You just have to learn some assembly.

      Report Abuse
      • Reply
      You have posted to a forum that requires a moderator to approve posts before they are publicly available.
    • tonyo
      Posted by tonyo
      on Jan 06 2010 12:51 PM
      Prodigy90 points

      I was hoping for some sort of call that I had not come across in the documentation, but OK.

      I added some code to main:

      register uint16_t *mem;

       

      mem = (uint16_t *)0x000000;

      while(mem < (uint16_t *)0x010000) *mem++ = 0;

      And then copied it from the disassembler into DSP2833x_CodeStartBranch.asm:

       

      MOVB XAR5, #0

      MOVL XAR4, #0x010000

      clear_loop:

       

       

      MOV

      *XAR5++, #0

      MOVL @ACC, XAR4

      CMPL ACC, @XAR5

      SB clear_loop, HI

      LB _c_int00

      ;Branch to start of boot.asm in RTS library

      And then removed the code from main() and removed all my memset() calls. Seems to work, if anybody with TI assembler experience would care to nitpick the above for correctness or efficiency, I would be happy to incorporate any changes...

      thanks,

      tony o.

      Report Abuse
      • Reply
      You have posted to a forum that requires a moderator to approve posts before they are publicly available.
    • Mitja Nemec
      Posted by Mitja Nemec
      on Jan 07 2010 03:40 AM
      Genius4175 points

      Whoa! This is a really smart way to write code in assembly. A really really nice trick.

      Mitja

      Report Abuse
      • Reply
      You have posted to a forum that requires a moderator to approve posts before they are publicly available.
    • Michael Weber1
      Posted by Michael Weber1
      on Mar 26 2013 09:28 AM
      Prodigy20 points

      Hello all,

      I also try to set the whole RAM to zero on a F28234. So I inserted the asm code by tonyo before LB _c_int00. Now I get three errors: one without a description, then [E0002] Invalid mnemonic specification  and [E0300] Symbol MOVL has already been defined.

      I'm using CCSv4. As my knowledge about assembler language is very rare the complete modified DSP2833x_CodeStartBranch.asm would be very helpful. Thank you in advance.

      Regards, Michael

      Report Abuse
      • Reply
      You have posted to a forum that requires a moderator to approve posts before they are publicly available.
    TI E2E™ Community
    • Support Forums
    • Blogs
    • Videos
    • Groups
    • Site Support & Feedback
    • Settings
    TI E2E™ Community Groups
    • TI University Program
    • Make the Switch
    • Microcontroller Projects
    • Motor Drive & Control
    Other Communities
    • Deyisupport
    • Designsomething.org
    • beagleboard.org
    • TI on Element 14
    • TI on TechXchangeSM
    Other Technical & Support Resources
    • WEBENCH® Design Center
    • Product Information Centers
    • Technical Documents
    • TI Design Network
    • TI Technical Articles
    • TI Training

    All content and materials on this site are provided "as is". TI and its respective suppliers and providers of content make no representations about the suitability of these materials for any purpose and disclaim all warranties and conditions with regard to these materials, including but not limited to all implied warranties and conditions of merchantability, fitness for a particular purpose, title and non-infringement of any third party intellectual property right. TI and its respective suppliers and providers of content make no representations about the suitability of these materials for any purpose and disclaim all warranties and conditions with respect to these materials. No license, either express or implied, by estoppel or otherwise, is granted by TI. Use of the information on this site may require a license from a third party, or a license from TI.

    Content on this site may contain or be subject to specific guidelines or limitations on use. All postings and use of the content on this site are subject to the Terms of Use of the site; third parties using this content agree to abide by any limitations or guidelines and to comply with the Terms of Use of this site. TI, its suppliers and providers of content reserve the right to make corrections, deletions, modifications, enhancements, improvements and other changes to the content and materials, its products, programs and services at any time or to move or discontinue any content, products, programs, or services without notice.

    Follow Us Texas Instruments on Facebook Texas Instruments on Twitter Texas Instruments on LinkedIn Texas Instruments on Google+
    TI Worldwide | Contact Us | my.TI Login | Site Map | Corporate Citizenship | mobile m.ti.com (Mobile Version)

    TI is a global semiconductor design and manufacturing company. Innovate with 100,000+ analog ICs and
    embedded processors, along with software, tools and the industry’s largest sales/support staff.

    © Copyright 1995-2013 Texas Instruments Incorporated. All rights reserved.
    Trademarks | Privacy Policy | Terms of Use