This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

Behavior running functions from RAM

Other Parts Discussed in Thread: MSP430F5438A

Hello,

I am working on a product with a MSP430F5438A. We have build an operating counter for in the product. This counter saves the number of hours the product is on. The program writes every hour the number of operating hours in the flash. The number of hours is saved in the flash because the product can be turned off every moment. The product has also a UART communication with a baudrate of 115200 baud. 

The problem is now that the flash erase/write operations happen every moment in time and the UART communication also. During flash operations the flash is not accessible and the interrupts are disabled. So during a erase the processor doesn't do anything for 32 ms. In that time there can be about 370 bytes sent over the UART which we are missing. A solution is to execute the program from RAM while doing the flash operations and poll the UART. 

I found different posts over how to put a function in RAM and run it from there. To put the function in RAM I follow the TI's code example: "msp430x54x_flashwrite_04". But I haven't found any documentation over how the behavior of the function is. Is there somewhere documentation of a forum discussion where I can get answer to the following questions?

1. Can the function in RAM get arguments with it and returns a value with the return function?

2. Can the function in RAM use the global data of the project? 

3. Does the function always jump back, when the function is finished, to where the function is called from flash? 

Thanks in advance for the reply,

Jeroen

  • I am not aware of any restrictions on functions running from RAM, compared to running from flash, since the compiler doesn't know the difference - it is the linker which choses to place functions in RAM or flash.

    Jeroen Begeer said:
    1. Can the function in RAM get arguments with it and returns a value with the return function?

    Yes

    Jeroen Begeer said:
    2. Can the function in RAM use the global data of the project?

    Yes

    Jeroen Begeer said:
    3. Does the function always jump back, when the function is finished, to where the function is called from flash? 

    The function returns to its caller using a RET or RETA instruction. A function placed in RAM can be called from another function either in RAM or flash.

    The attached simple example for a MSP430F5438A places two functions in RAM which demonstrates:

    - Functions in RAM being called with arguments and returning a value

    - Functions in RAM accessing a global variable

    - A function in RAM (mult_and_sqrt) being called from both a function in RAM (mult_and_sqrt_2) and a function in FLASH (main)

    The example also uses a linker copy table, and the run time library copy_in, to copy the functions from FLASH to RAM - which is a simpler alternative to the msp430x54x_flashwrite_04 example.

    1462.MSP430F5438A_ram_funcs.zip

**Attention** This is a public forum