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.

How to create objects in RAM?



I have a c++ project where I would like to create some objects in RAM, and I do it like this :

struct A

{

  void foo();

  int v[10];

};

#pragma CODE_SECTION( "FuncInRam" )

void A:foo()

{}

#pragma DATA_SECTION( "Objects_Memory_Block" )

static A a;

where in my cmd file, I defined this :

Objects_Memory_Block    :  > RAM_L4, PAGE = 1

FuncInRam  : LOAD = FLASHA,
                         RUN = RAML0,
                         LOAD_START(_RamfuncsLoadStart),
                         LOAD_END(_RamfuncsLoadEnd),
                         RUN_START(_RamfuncsRunStart),
                         PAGE = 0

And I copy the functions from flash to RAM in the main().

So, is this enough to create an object in RAM_L4? Or, do I need to do something more?

Also, where are it's member variables placed? Also in RAM_L4?

  • All variables will placed in RAM only unless it is specified as const. 

    The structure is members only, means members makes the structure. So it cannot be at different places.

    If you are particular about the RAM section where the variable to be placed, can follow your method.

    Code (different functions) also can be placed in to specific sections similarly if required to.

    Cheers

    Joy

  • I modified the code a bit by adding a member function, and member variable. Is the static object A (and it's member variable v) still going into RAM section?