2008-09-22 09:50 PM
SRAM after Reset
2011-05-17 03:44 AM
Can the contents of SRAM be guarenteed zeros after a Reset?
(in this case, reset after an rtc alarm to exit standby). I am using gcc and would like to avoid having to set .bss to zero, which is taking about six milliseconds! Cheers, Paul.2011-05-17 03:44 AM
2011-05-17 03:44 AM
I bet you can mark the data you don't need initialized as persistent or something like that.
2011-05-17 03:44 AM
Is the BSS clearing code executed before or after the clock initialization ?
It is possible you can make it much faster by initializing the clock to high speed first (8 vs 72MHz). regards, Giovanni --- ChibiOS/RT2011-05-17 03:44 AM
Thanks for confirming st-one, and your suggestions guys.
Raising the clock speed is a good idea, but i actually want it fast to save battery power (i.e. wake up every 100ms, scan adc, go back to sleep). Lanchon, i'll look into that, I don't think there is any standard section of memory that is uninitialised, but it may be possible to specify in the .map file. A possible alternative is declaring everything volatile, which could have a serious performance impact. However I have tried commenting this code out, and the only problem I have had, is with variables that I haven't initialised properly (and i tend to be careful about that), so perhaps ensuring proper initalisation (or using volatiles to initalise) would work.2011-05-17 03:44 AM
> A possible alternative is declaring everything volatile
I can't understand, how would that help?2011-05-17 03:44 AM
>> A possible alternative is declaring everything volatile
> I can't understand, how would that help? I was thinking that if everything was volatile, the compiler would not assume anything was zero, even if it thought it had been initalised to zero. So whilst it could optimise out int x = 0 (since supposedly x was initalised 0 before main was called), it would not optimise volatile int x = 0 (since it could have changed since it's non-existant initalisation).2011-05-17 03:44 AM
n.b. I tend to keep all of my variables within structs for tidyness, and partly out of habit since I do a bit of OO. So it is quite easy to write a procedure to cast each struct to a volitale array of bytes or words and and then write that to zero when the struct is first required (altough this hasn't seemed to be necessary yet).
void MemoryToZero(void* Address, u32 ByteCount) { while (ByteCount) ((vu8*)Address)[--ByteCount] = 0; }2011-05-17 03:44 AM
Quote:
void MemoryToZero(void* Address, u32 ByteCount) { while (ByteCount) ((vu8*)Address)[--ByteCount] = 0; } Are you familiar with ''memset''? It's part of libc.http://www.iti.cs.tu-bs.de/cgi-bin/UNIXhelp/man-cgi?memset+3C
The nice thing about using standard functions in libc for things like memcpy, memset, etc., is that often the version in your C library is optimized for your processor. Like it might use SSE if you've got that, or Altivec, unroll loops, use duff's device, or be smart about the way your cache works. Not necessarily relevant for the STM32, but on processors that have a big speed difference between the core and main memory, it can be helpful. If you hand-optimize your own function, it can either use a feature that doesn't exist on a processor you want to port to, or may be very slow on the processor you want to port to.