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.

CCS/LAUNCHXL-F28379D: 3D ARRAYS in RAM allocate, array[64][16][2]

Part Number: LAUNCHXL-F28379D

Tool/software: Code Composer Studio

Hello,
I use CCS v8
I have been trying for some time to put the 3D fields in RAM memory. But there are always problems.

Ask:
1. First store array [64] [16] [2] in FLASH first and then in RAM
     postponed?
2. I do it that way

2.1 #pragma DATA_SECTION (start_up_mode_stage_1_RAM, "expdata0")
const unsigned int start_up_mode_stage_1_RAM [64] [16] [2] = {... 0,1,2,3, ...}

It did not work for me without const. Although there are examples without const. Can constants be stored in RAM at all? Or something like that is only for FRAM?

2.2
or something like that. First the values in FRAM.
#pragma DATA_SECTION (start_up_mode_stage_1_FLASH, "expdata0")
const unsigned int start_up_mode_stage_1_FLASH [64] [16] [2] = {... 0,1,2,3, ...}

but then move it to main () from FLASH to RAM ?? Like here.

/*extern const unsigned int start_up_mode_stage_1[ 64 ] [ 16 ] [ 2 ]*/
//unsigned int ***start_up_mode_stage_1_RAM ; -> als global init
start_up_mode_stage_1_RAM = ( unsigned int *** ) malloc( 64 * sizeof( unsigned int ** ) ) ; // 64 x 2D Felder

for( i = 0; i < 64; i ++ ) {
    start_up_mode_stage_1_RAM[ i ] = ( unsigned int ** ) malloc( 16 * sizeof( unsigned int * ) ) ;
    for( j = 0; j < 16; j ++ ) {
        start_up_mode_stage_1_RAM[ i ] [ j ] = ( unsigned int * ) malloc( 2 * sizeof( unsigned int ) ) ;
    }
 }

/**/
for( val_one = 0; val_one < 64; val_one ++ ) {
    for( val_two = 0; val_two < 16; val_two ++ ) {
        for( val_tree = 0; val_tree < 2; val_tree ++ ) {
            start_up_mode_stage_1_RAM[ val_one ] [ val_two ] [ val_tree ] = ( unsigned int ) start_up_mode_stage_1_FLASH[ val_one ] [ val_two ] [ val_tree ] ;
        }
    }
}


/*Hilfsvariable auf Null setzen*/
i = 0 ;
j = 0 ;
val_one = 0 ;
val_two = 0 ;
val_tree = 0 ;

/*extern const unsigned int start_up_mode_stage_2[ 64 ] [ 64 ] 64 x 64*/
//unsigned int **start_up_mode_stage_2_RAM ; ->als global init
start_up_mode_stage_2_RAM = ( unsigned int ** ) malloc( 64 * sizeof( unsigned int * ) ) ;

for( i = 0; i < 64; i ++ ) {
    start_up_mode_stage_2_RAM[ i ] = ( unsigned int * ) malloc( 64 * sizeof( unsigned int ) ) ;
}

/**/
for( val_one = 0; val_one < 64; val_one ++ ) {
    for( val_two = 0; val_two < 64; val_two ++ ) {
        start_up_mode_stage_2_RAM[ val_one ] [ val_two ] = (unsigned int ) start_up_mode_stage_2_FLASH[ val_one ] [ val_two ] ;
    }
}

/*Hilfsvariable auf Null setzen*/
i = 0 ;
j = 0 ;
val_one = 0 ;
val_two = 0 ;
val_tree = 0 ;

I have a problem. I can either start_up_mode_stage_1_RAM, or start_up_mode_stage_2_RAM Save. But not both at the same time.

So I need a safe method as I could store multiple arrays in RAM.

Thank you in advance !

  • Alex,
    You need to use method 2.2 (store in flash and then move to RAM). I am going to move this to compiler team and someone from that team will help you on this.

    Regards,
    Vivek Singh
  • You don't need to use dynamic allocation to get access to ARM. It's a good thing that you have placed your initialization values in FRAM, because those take up a lot of space.

    So just declare the FLASH array as you have been:

    #pragma DATA_SECTION (start_up_mode_stage_1_FLASH, "expdata0")
    const unsigned int start_up_mode_stage_1_FLASH [64] [16] [2] = {... 0,1,2,3, ...}

    And a RAM array with the same dimensions:

    unsigned int start_up_mode_stage_1_RAM[64] [16] [2] ;

    Now you can initialize it with memcpy:

    memcpy(start_up_mode_stage_1_RAM, start_up_mode_stage_1_FLASH, sizeof(start_up_mode_stage_1_RAM));
  • Thank you very much! The problem is solved now ! Unfortunately, I can not only keep the data in the FLASH. The time access to the data is very critical for me now, so I should keep the data in RAM. But I can still delete some placed RAM memory arrays for some times. But I'll do that later as an optimization.
    Can you please write here briefly. How can I clear / delete the placed RAM memory so that the CPU can use again.

    free ((unsigned int *) & array [0]); ???

    -> Unfortunately free (array); Method just did not work and the memory was not released. =(

  • Use a union.
  • free only works with dynamically allocated objects (malloc, calloc, realloc).

    As Keith suggests, you want to use a union, like so:

    union {
    unsigned int start_up_mode_stage_1_RAM[64] [16] [2] ;
    unsigned int start_up_mode_stage_2_RAM[ 64 ] [ 64 ];
    } u;

    Now both of those objects occupy the same memory. Beware! Obviously, writing to one of the members invalidates the other member, so you can only use one of them at a time. Also obviously, you have to take care of loading the member when you need it.

    /* stage 1 */
    memcpy(start_up_mode_stage_1_RAM, start_up_mode_stage_1_FLASH, sizeof(start_up_mode_stage_1_RAM));
    do_stuff_with(u.start_up_mode_stage_1_RAM);

    /* stage 2 */
    memcpy(start_up_mode_stage_2_RAM, start_up_mode_stage_2_FLASH, sizeof(start_up_mode_stage_2_RAM));
    do_different_stuff_with(u.start_up_mode_stage_2_RAM);
  • Thank you very much!
    Aso now I understand what is meant and how it should be realized. The variables as pointers to static memory block are in the stack. However, since the memory block has not been set as a dynamic block, the variable remains as a local variable / pointer in the stack until the function has been executed and all local variables are deleted. Well, but with union one can still access statically defined memory block with different variables / pointers.
  • "but with union one can still access statically defined memory block with different variables / pointers."

    And types!
  • You aren't restricted to using stack memory for the union.  You could make the union a global variable, in which case your .bss section will be larger by that much, but you won't need as much stack memory.  On the other hand, if you need the space, you could indeed make the union a local variable as you've described.  It's also possible to dynamically allocate space for the union using malloc.  The choice depends on many factors, most of which depend on the nature of your application.