Search code examples
cstm32microcontrollerkeil

I initialize an array and then I see random values in it


I have the following problem when initializing an array in C. I am using an STM32 and Keil uVision IDE. The array as it is too big, it is declared in an external SDRAM memory we are using (big enough). Here is the code:

Scatter file:

SDRAM_ACQ_HARDCODED_AV 0xD0643000 0x141000{;N_DATA_ROWS_IN_N20_ALGORITHM_BUFFER
    *(.sdram_acq_hardcoded_av)
  }

C file:

#define SDRAM_ACQ_HARDCODED_AV __attribute__((section(".sdram_acq_hardcoded_av")))
SDRAM_ACQ_HARDCODED_AV const int16_t AcqRaw_StimArtifactRemoved_Buffer_By50nV_HC[14592] = {
-7154,
-7167,
-7158,
-7137,
-7122,
-7091,

.h file:

extern const int16_t AcqRaw_StimArtifactRemoved_Buffer_By50nV_HC[14592];

And when I start debugging and checking the values of this array, I see there completely random values inside the array. What is the problem here?

I have tried to see problems in the scatter file or the optimization of the code, but everything seems correct.


Solution

  • This initialization does nothing. You need to copy the data to the SDRAM after the memory controller was initialized.

    The compiler will not help you with it as the startup code is executed before your program initializes the memory controller.