cancel
Showing results for 
Search instead for 
Did you mean: 

STM32F4 - Possible bug in compiler/linker/me? using large arrays in external ram

tecnico23
Associate II
Posted on October 06, 2015 at 13:46

I recently run into a problem while using the following:

Crossworks v2.3.5.201401120385 with a STM32F407ZG Cortex-M4

It goes like this:

I installed an external SRAM (AS6C4016A-45ZIN, 512KB) on the FSMC bus and configured it correctly. I know it's correctly configured because I can read and write successfully to any 8 or 16 bit register with custom functions I made. Since it's a static ram and I have a battery I even cut the power and read it in another day, everything is fine.

The problem comes with definitions like this:

int someVariable[someLength] __attribute__ ((section(''.SOME_SECTION'')));

If ''someLength'' is a small number (like 10 or 20) it's ok, it works. But if I increase the array size to, say, 1000, I get random reads and writes that are all over the place but somehow consistent, what makes me believe it is reading and writing to some register, just not the correct one. Is the compiler assuming the array length correctly? Are there any known bugs with this implementation?

Also, I just tried creating a 64 bit integer array and it does not work! I cannot correctly write to it as every single index always returns 0, no matter the size of the array, no matter how many times it is written with different values.

For reference, I declared the external RAM in the memorymap file like this:

<
MemorySegment
start
=
''0x64000000''
name
=
''RAM_EXTERNA''
size
=
''0x80000''
access
=
''Read/Write''
/>

Declared the corresponding section in the flash_placement.xml:

<
MemorySegment
name
=
''RAM_EXTERNA''
>

 <
ProgramSection
alignment
=
''2''
load
=
''Yes''
name
=
''.SRAM_SENSORES''
/>

</
MemorySegment
>

And declared an array like this:

static int16_t sensores_ultimaLeitura[500] __attribute__ ((section(''.SRAM_SENSORES'')));

3 REPLIES 3
jpeacock
Associate III
Posted on October 06, 2015 at 13:58

From your description you may have a problem with the address line connections on your SRAM.  If a small array can be written and read correctly but a large array cannot then you are hitting an address boundary that fails.  This will likely be on a power of 2 address boundary, so build a large array of 16 bit unsigned ints, write a test pattern to every location, and then read it back.  Look for the address where it fails, and see if this repeats further on.

Being able to read and write a few locations does not guarantee the full range works on an external memory.  You need to run memory tests for shorted address or data pins.  For DRAMs you also need to look for pattern sensitivity but this is less of a problem with SRAM.

The FSMC works fine on an F4 with SRAMs so it's highly unlikely you found a compiler bug.  More likely it's a problem with your PCB.

  Jack Peacock

qwer.asdf
Senior
Posted on October 06, 2015 at 14:03

Tell your linker to generate a map file, then you can check whether your variable are being placed where you had intended them to be.

tecnico23
Associate II
Posted on October 06, 2015 at 15:29

peacock.jack.003, you are absolutely correct.

I run the memory test you suggested and an error came up on the 12 to 13 bit boundary.

Checked the PCB and there it was, the 13rd address pin floating with no solder.

Everything seems to be working now. Many thanks ;)