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!
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.
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.
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
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.
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.
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.
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:
MOVB XAR5, #0
MOVL XAR4, #0x010000
clear_loop:
*XAR5++, #0 MOVL @ACC, XAR4 CMPL ACC, @XAR5 SB clear_loop, HI LB _c_int00
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...
Whoa! This is a really smart way to write code in assembly. A really really nice trick.
Mitja
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