cancel
Showing results for 
Search instead for 
Did you mean: 

Declare and initialize array in PSRAM

SA.1
Associate II

Hi,

I am running an STM32L4 on a custom board with a 64mb PSRAM attached to it.

I can write to any address on the PSRAM however I want to store a large array of sample data on the PSRAM itself.

Basically,

I want to do something like this

int a[4] = {21,3133,131,31};

I can create an empty array in PSRAM using the GCC's attribute section commands.

So,

int __attribute__((section (".myBuf1Section"))) buffer1[5] ;

This works and I can individually assign values to each index of that array , however

int __attribute__((section (".myBuf1Section"))) buffer1[5] = { 10,23,45,67,88};

this does not work.

Is there any way I can initialize an array on the PSRAM using the {} brackets as above.

My array needs to be a sample set of raw data over 50000 in count.

Is there a workaround for this?

Thank you.

-Sidd

7 REPLIES 7

Yes

You must initialize the FMC, PSRAM and PINs, nominally in SystemInit() and add code into startup.s to copy your initialized data from FLASH into PSRAM. The Linker Script (.LD) needs to corral the PSRAM load region data into FLASH.

Tips, buy me a coffee, or three.. PayPal Venmo Up vote any posts that you find helpful, it shows what's working..
SA.1
Associate II

Hi Clive,

I am a little bit confused. Do I have to save the data in FLASH first and then move it too SRAM?

Correct me if I am wrong, I added the following snippet to my linker script

/* Placing coeff buff1 at starting of SRAM address*/
.myBuf1Block 0x64000000 :
{
KEEP(*(.myBuf1Section))
} > m_data
 
/* Placing coeff buff2 at starting of SRAM address ADC1*/
.myBuf2Block 0x64030DA4 :
{
KEEP(*(.myBuf2Section))
} > m_data

0x64000000 is a memory address in the SRAM. I am assuming that doing this would directly place my array in the SRAM itself and will not create an initial copy in Flash.

I have already initialized FMC,PSRAM and the pins and can read and write data to the PSRAM.

But, for my application I need to save multiple large arrays (size>50000) having a set of sample data on the PSRAM.

Again, I might have missed the point you wanted to explain, so could you explain a bit further please?

I am pretty new to working with external memories.

Thanks.

In the same way as your internal RAM variables are initialized with data packed in FLASH, the initial content (at power up or reset) has to come from somewhere permanent.

...
  /* used by the startup to initialize data */
  _sidata = LOADADDR(.data);
 
  /* Initialized data sections goes into RAM, load LMA copy after code */
  .data :
  {
    . = ALIGN(4);
    _sdata = .;        /* create a global symbol at data start */
    *(.data)           /* .data sections */
    *(.data*)          /* .data* sections */
 
    . = ALIGN(4);
    _edata = .;        /* define a global symbol at data end */
  } >RAM AT> FLASH /* needs to end up in RAM, but is packed in FLASH for permanant storage */
...

Tips, buy me a coffee, or three.. PayPal Venmo Up vote any posts that you find helpful, it shows what's working..
S.Ma
Principal

Startup() function is called first hand to clear RAM and put default non zero RAM values from C code.

As Clive said, this Startup() function left untouch won't configure the GPIO for external memory, which will be done at later stage. It maybe easier to have the init value of the PSRAM array in FLASH (const uint8_t DefaultPSRAM[] = { xxxxxxx }; and copy it with memcpy() function after PSRAM is functional. more portable than hacking the startup() function which is quite compiler specific. Change compiler and see what happens.

SA.1
Associate II

I have 4 float arrays of 50k samples each. I have 1 mb of Flash size. Considering these arrays and the rest of the code, I don't think it will be possible.

Is the data compressible? A common trick is to unpack data into RAM.

For large arrays a QSPI Flash is more viable

Tips, buy me a coffee, or three.. PayPal Venmo Up vote any posts that you find helpful, it shows what's working..
S.Ma
Principal

uSD Card or QSPI Flash or SPI flash. Unless the data is not random and can be compressed as Clive mentionned. Manipulating floats seems overkill. Can it be Q31 or less? (16 bit integer, 16 bit fractional), or store the delta between 2 following numbers?