2009-02-20 03:14 AM
code execution from RAM
2011-05-17 06:01 AM
I would like to share with you the procedure for executing code in RAM.
When you have to put one or more functions in RAM, you have to put them in a separate .c file (i.e. 'RAM_routines.c') and modify the linker file using -ic Segment Control Option. For example, if you want to put the routines in RAM starting from the address 0x100, you have to use the following line: # RAM routines: +seg .text -b 0x100 -n .my_routines -ic Debug\RAM_routines.o You are now storing the code in Flash and, before calling the routines, you have to copy it to RAM using the function _fctcpy('m'); where m is first character of segment named my_routines. For further information you can refer to Cosmic 'CXSTM8_UserGuide' sections 'Using The Linker'-->'Moveable Code' Ciao :)2011-05-17 06:01 AM
Hello Diamond,
Thank you very much for this information, and I would like to ask you if there is another method to execute code from RAM without using a special functions of cosmic, so to have a portable code. thanks2011-05-17 06:01 AM
Hi,
Thank you Diamond, I want to add that in order to call this routine from RAM, for example if the Array is copied starting from 0x100 this code must be insert : #asm call $100 #endasm is it correct which I wrote2011-05-17 06:01 AM
There is another way, but it is not automatic and it is for sure less elegant... but if you want to be compiler indipendent is the only way I see.
You have anyway to put the code that you want in RAM in separate file and compile with the option: # RAM routines: +seg .text -b 0x100 -n .my_routines In this way you have your s19 containing the routine that you want to have in RAM; see below example starting from 0x100: ........... S12301009D81A600C65005A8F0C750054C721C505B721D505CC7F600C7F601C7F602C7F691 S10C01200355FF7C500A20DC8029 ........... Removing the motorola formats, i.e. in the first line S - Indicates that this is Motorola 1 - 1 means this is a data record 23 - Number of bytes to follow 0100 - Starting address you can see the bytes that have to be put in RAM. Now you have to remove from the project the file to put in RAM, but you have to define an array containing the bytes to put in RAM u8 RAM_array [] = { 0x9D, 0x81, 0xA6, 0x00, 0xC6, 0x50, 0x05, 0xA8, 0xF0, 0xC7, 0x50, 0x05, 0x4C, 0x72, 0x1C, 0x50, 0x5B, 0x72, 0x1D, 0x50, 0x5C, 0xC7, 0xF6, 0x00, 0xC7, 0xF6, 0x01, 0xC7, 0xF6, 0x02, 0xC7, 0xF6, 0x91, 0x03, 0x55, 0xFF, 0x7C, 0x50, 0x0A, 0x20, 0xDC, 0x80, 0x29 }; After in the main you have to insert a for loop that copy RAM_array in the location that you want. I hope it is clear... (?) Write me in case! Ciao, Olga2011-05-17 06:01 AM
Yes, correct!
Ciao ;)2011-05-17 06:01 AM
Hi,
I have a request. In what application would we need to Run code from RAM? Is it to program the EEProm? Regards, Trevor :-?2011-05-17 06:01 AM
Ciao Trevor,
for sure you have to jump in RAM in case of ProgramMemory block (128 bytes) and word (4 bytes) write waiting the end of programming phase but also DataEE block (128 bytes) write waiting for HVOFF flag becoming 0. I do not see any other reason at present, even because RAM execution is slower than Flash execution. Regards, Olga [ This message was edited by: diamond on 29-01-2009 13:34 ] [ This message was edited by: diamond on 29-01-2009 16:13 ]2011-05-17 06:01 AM
Hi,
The Block programming is used only for IAP, so this has to be placed in the RAM during IAP only. There is no need to have it in RAM all time. Have you an idea how to free a previously RAM allocated region for the Block programming? thanks :2011-05-17 06:01 AM