If you have a function that should always be run from ram, then it should be possible to have it copied to ram on startup. I haven't tried this on the msp430, but I have used it on a 68332, compiled with gcc. The idea is to specify a special section for the function, and use linker magic to get it copied to ram on startup. In the C code, have something like: void __attribute__((section("RUNFROMRAM"))) foodbar(void) { }
Then you need to make changes in the linker script, to put that section in along with the ".data" section that gets copied from flash to ram at startup, but is linked with the addresses in ram. Actually, it might well be easier just to give the function the section ".data" directly and thus not bother with the RUNFROMRAM section. It is perhaps a little inelegant to misuse the name, but it should work. Remember, when making functions that run from ram, keep them small! Disable interrupts, since these force calls to flash programs, and avoid calling library functions (so be careful with arithemetic). The big advantage of using this linker relocation is that you can use the function directly just as any other function - there is no need to go via function pointers. You can also use any sort of optomisations you want. And you can debug it fully (at least, I could on the 68332 + gdb), including single-stepping and breakpoints. If you do have to debug the manually-copied version, then you need to do it at the assembly level. mvh. David > > > > On Friday 06 December 2002 06:53, brian.sm...@tekelek.com.au wrote: > > I have a lot of data to write to the information memory and want to use the > > Block write rather than single byte write. This means I have to execute out > > of RAM while the write is happening. Any clues as to how to do this? > > You can execute a code located in RAM at any time. But first, you have to copy > this func there. To copy the function to RAM, you need to know its size and a > pointer. > > Consider the following: > -------------------------------------------------------------------------- - > type_f func_to_be_execed_from_ram(params p1, ...) > { > // func body. > // make sure there are no long branches > // or _relative_ (pc) calls (gcc does not issue them). > } > > void dummy_func() { > // must exists and be empty cause we need this function to > // determine previous' one size. > } > > void this_func_copies_another_to_ram(void *dst, void *src, size_t size) > { > // memcpy(dst,src,size) can be a good choise > } > > void *prepare_copy() > { > void *dst; > size_t size; > extern char __bss_end; // this var defined by linker. read docs for more > info. > size = (char *)&dummy_func - (char *)&func_to_be_execed_from_ram; > dst = (char *)&__bss_end + size; > this_func_copies_another_to_ram(dst, &func_to_be_execed_from_ram, size); > return dst; > } > > void (*copier)(); > > int main() > { > copier = prepare_copy(); > copier(); > return 240; > } > > > > My plan is to define a function pointer to the writing function in ROM and > > use that to copy the function to a location in RAM. The location in RAM > > will also be a function pointer so it is just a matter of executing the > > function in RAM at the pointer. My problem is, how do I know how big the > > function is to work out the copy size? Has anyone managed this? > > > > Do not pass -ffunction-sections flag to compiler. > > > Hope this helps, > ~d > > > Brian Smith > > Australia > > > > > > > > > > > > ------------------------------------------------------- > > This sf.net email is sponsored by:ThinkGeek > > Welcome to geek heaven. > > http://thinkgeek.com/sf > > _______________________________________________ > > Mspgcc-users mailing list > > Mspgcc-users@lists.sourceforge.net > > https://lists.sourceforge.net/lists/listinfo/mspgcc-users > > -- > /******************************************************************** > ("`-''-/").___..--''"`-._ (\ Dimmy the Wild UA1ACZ > `6_ 6 ) `-. ( ).`-.__.`) Enterprise Information Sys > (_Y_.)' ._ ) `._ `. ``-..-' Nevsky prospekt, 20 / 44 > _..`--'_..-_/ /--'_.' ,' Saint Petersburg, Russia > (il),-'' (li),' ((!.-' +7 (812) 3468202, 5585314 > ********************************************************************/ > > > > ------------------------------------------------------- > This sf.net email is sponsored by:ThinkGeek > Welcome to geek heaven. > http://thinkgeek.com/sf > _______________________________________________ > Mspgcc-users mailing list > Mspgcc-users@lists.sourceforge.net > https://lists.sourceforge.net/lists/listinfo/mspgcc-users > >