2006-03-02 01:07 AM
2006-03-01 10:37 PM
Hi all,
I am using the STR710 MCU and I want to write global variables to an unused space of RAM memory. This way I can recover the variables after a watchdog reset. My problem is that I can not find answers to: 1. Is it possible to write to the RAM(starts at 0x2000 0000, 64kbyte long) from my C-program? If so, what is the C-syntact to do this? 2. When my program is executing from the flash memory(boot from flash) which part of the RAM(starts at 0x2000 0000) memory is used or unused? Or which part of the RAM can I use to store my global variables? I hope somebody knows! Regards, Jimmey2006-03-02 01:07 AM
Writing to memory in C.
THE QUICK HACK _________________________________ This is how ST library and many other applications do it. Start with the address you want to put something at 0x12345678 Make it a pointer to the type if variable you want to put there. (unsigned int *)0x12345678 Dereference it *((unsigned int *)0x12345678) Use it *((unsigned int *)0x12345678)=0x11223344; Now 0x12345678 contains 0x44 0x12345679 contains 0x33 0x1234567A contains 0x22 0x1234567B contains 0x11 If you are now thinking ''Oh of course'' then I only need to remind you to consider alignment (the address must be a multiple of 4 in this case) and to point out that the variable type could be a structure with all your preserved variables in it. If the above has filled you with awe or wonder then getting your head around pointers in C will maximise your fun. THE NICER WAYS _______________________________ Create a new area/region/section as RAM RW DATA. In Realview look for ''scatter file'' in doco. With most tools this is a linker matter. Force compiler to use this region for your variables. Check your compiler reference for area or section maybe as a pragma or as a type modifier. This option is tidier and more maintainable. Expect to spend an hour or 10 studying doco for your tools - but then you know for next time as well. WHAT IS WHERE IN MEMORY _____________________ You can get this from your linker or debugger. Search doco for MAP. But you don't want to write code where you have to check map each time and set address. Create a section/area/region and refer to it by name. One simple way to get a reserved spot is that stack normally starts at END of RAM. Check your start up code and set stacks to be a little lower and put preserved data at end of RAM. Then from high to low addresses in ram you will have END OF RAM PRESERVED DATA STACKS Unused memory GLOBAL VERIABLES START OF RAM FLASH AT ZERO _________________ I agree that FLASH at zero for simple embedded system is appropriate for STR71x. Note that this is not how ST examples etc are tailored. ST have app note on moving ram soon after boot. Hope this helps.