Skip to main content
Visitor II
February 20, 2009
Question

code execution from RAM

  • February 20, 2009
  • 11 replies
  • 2680 views
Posted on February 20, 2009 at 12:14

code execution from RAM

    This topic has been closed for replies.

    11 replies

    olgaAuthor
    Visitor II
    May 17, 2011
    Posted on May 17, 2011 at 15:01

    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 :)

    Visitor II
    May 17, 2011
    Posted on May 17, 2011 at 15:01

    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.

    thanks

    Visitor II
    May 17, 2011
    Posted on May 17, 2011 at 15:01

    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 wrote

    olgaAuthor
    Visitor II
    May 17, 2011
    Posted on May 17, 2011 at 15:01

    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,

    Olga

    olgaAuthor
    Visitor II
    May 17, 2011
    Posted on May 17, 2011 at 15:01

    Yes, correct!

    Ciao ;)

    Visitor II
    May 17, 2011
    Posted on May 17, 2011 at 15:01

    Hi,

    I have a request. In what application would we need to Run code from RAM?

    Is it to program the EEProm?

    Regards,

    Trevor :-?

    olgaAuthor
    Visitor II
    May 17, 2011
    Posted on May 17, 2011 at 15:01

    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 ]

    Visitor II
    May 17, 2011
    Posted on May 17, 2011 at 15:01

    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 :

    olgaAuthor
    Visitor II
    May 17, 2011
    Posted on May 17, 2011 at 15:01

    Why only IAP?

    Even when you want to save on the dataEE more than 4 bytes it could help saving time.

    This because if you put in the code 2 consecutive dataEE word write the core is stalled till the first one is not completed, thus for about 6ms, while doing a block write on dataEE you have to spend only small time (about 250 usec) on RAM for buffer loading and then you can come back on program memory because of RWW (read while write) feature.

    For freeing the RAM (I mean clear the previous function), you can define an array in that area and load with 0x0 for example... otherwise you can simply define the variables that you need there.

    Let me know if it is clear enough...

    Ciao,

    Olga

    Visitor II
    May 17, 2011
    Posted on May 17, 2011 at 15:01

    Thank you Olga,

    - The HVOFF flag is set after the data loading finish (about 250 usec)?

    - When performing the word programming from RAM (only need to load 4bytes) the time to spend decrease?

    Thanks for your help

    Chinger