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.

6678 memory problem

Hi,

I want to ask how large an array can 6678 ? I define an array which contains 20000 float data on a single core, and it seems too large because the EVM doesn't work out. An array with 20000 float data only occupies 80000 bit, that is less 10K Byte. However, there is 32K Byte L1D and 512K Byte L2 per core, so the memory should be enough. Below is my code and linker file.

code:

#include<stdio.h>
#include<stdlib.h>
void main()
{
 float a[20000];
 int i;
 for(i=0;i<10000;i++)
 {
  a[i]=i;
 }
}

Linker file:

-stack 0x10000
-heap  0x8000

MEMORY
{
  L2SRAM      : o = 0x00800000, l = 0x00080000
  MSMCSRAM       : o = 0x0c000000, l = 0x00400000
}

SECTIONS
{
  .cinit  : > L2SRAM
  .cio   : > L2SRAM
  .const  : > L2SRAM
  .data         : > L2SRAM
  .far   : > L2SRAM
  .fardata  : > L2SRAM
  .stack  : > L2SRAM
  .sysmem  : > L2SRAM
  .text         : > L2SRAM
  .neardata  : > L2SRAM
  .bss   : > L2SRAM
  
  .fasttext:  >       L2SRAM
  .switch:    >       L2SRAM
  .heap       >       L2SRAM
  .rodata     > L2SRAM
  .boot: > L2SRAM
}

  • Hi Yang,

    In your example, the array a[20000] is allocated from stack, so it will occupy 80000bytes which is larger than the size of stack. If you insist to allocate the array in stack, just extend the size of stack to fit the array. And place .stack section in larger space such as MSMCRAM or DDR3 if needed.

    Allen

  • Hi,

    When you declare a variable in a function, it will be stored in the stack. Here, you declare your array in the main function.

    Your stack's size is 0x10000, and will be in L2 memory (.stack  : > L2SRAM)

    Your array's size is 20000 floats = 20000 * 4 bytes = 0x13880

    Your array does not feet into the stack, you have a stack overflow...

    You can solve this problem in to ways :

    1 ) Increase the size of the stack :

    Linker file:

    -stack 0x10000 here, put more than 0x13880, because other things are put in the stack too.

    2 ) Declare your array as global (declare it outside functions) You should do it this way, the stack is not usualy used to save so big data.:

    float a[20000];

    void main() { ... }

    It will be in L2 ( I think it is because of  .data  : > L2SRAM )

    If you want to put it somewhere else (in MSMCSRAM for exemple), you can create a section, tell the linker where to store this section, and put your array in this section :

    SECTIONS
    {
      .cinit  : > L2SRAM
      .cio   : > L2SRAM
      .const  : > L2SRAM
      .data         : > L2SRAM
      .far   : > L2SRAM
      .fardata  : > L2SRAM
      .stack  : > L2SRAM
      .sysmem  : > L2SRAM
      .text         : > L2SRAM
      .neardata  : > L2SRAM
      .bss   : > L2SRAM
      
      .fasttext:  >       L2SRAM
      .switch:    >       L2SRAM
      .heap       >       L2SRAM
      .rodata     > L2SRAM
      .boot: > L2SRAM

    .my_new_section : > MSMCSRAM
    }


    and when declaring your variable :

    #pragma DATA_SECTION(a,".my_new_section");

    float a[20000];

    main(){...}

    Regards,

    Benoit


  • Hi Allen,

    Thank you very much! I got the idea.

    Regards,

    Yang

  • Hi Benoit,

    Thank you for your detailed answer! I got the idea.

    Regards,

    Yang