hard fault when FreeRTOS heap is in external SDRAM

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

hard fault when FreeRTOS heap is in external SDRAM

2,015 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by Alex on Thu Nov 06 03:16:37 MST 2014
Hi

I'm running a LPC1778 with a 16Mbit external SDRAM. The LPC runs at 120MHz and the SDRAM at 60MHz.
The application uses FreeRTOS and lwip.
I made a stripped down version that fits completly in the internal RAM to check if it is an SDRAM issue or a general software problem.
When I place the FreeRTOS heap in external RAM I get a hard fault while initializing lwip. It seems that a ponter is corrupted.
When I place the FreeRTOS heap in internal RAM the application runs without problems.

I already did a test with a reduced clock frequency of 32 MHz but the result is the same.

The SDRAM is tested on every startup using this test:

<code>
for(int j = 0; j < 3; ++j)
  {
    unsigned int* adr = (unsigned int*) 0xA0000000;
    for(unsigned int i = 0; i < (256 * 1024); ++i)
      *adr++ = (i << 18) | i;

    adr = (unsigned int*) 0xA0000000;
    for(unsigned int i = 0; i < (256 * 1024); ++i)
    {
      unsigned int tmp = *adr++;
      if(tmp != ((i << 18) | i))
        goto SD_RAM_ERROR;
    }
    adr = (unsigned int*) 0xA0000000;
    for(unsigned int i = 0; i < (256 * 1024); ++i)
      *adr++ = 0xA5A5A5A5;
    adr = (unsigned int*) 0xA0000000;
    for(unsigned int i = 0; i < (256 * 1024); ++i)
    {
      unsigned int tmp = *adr++;
      if(tmp != 0xA5A5A5A5)
        goto SD_RAM_ERROR;
    }
  }

  unsigned int* adr = (unsigned int*) 0xA0000000;
  for(int i = 0; i < 32; ++i)
  {
    *adr = 1 << i;
    if(*adr != 1 << i)
      goto SD_RAM_ERROR;
  }
</code>

The test runs without any problems.
The FreeRTOS heap size is 35 kB and placed at address 0xA0000000.

Is there something to consider when placing something in external SDRAM? Read/Write timing or memory alignment?

Regards,
Alex
Labels (1)
0 Kudos
Reply
4 Replies

1,552 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by Alex on Fri Nov 07 04:00:47 MST 2014
I got it.

The setting of the EMCDLYCTL register was not correct.

Now I'm using:
LPC_SC->EMCDLYCTL = 0x1410;
LPC_EMC->DynamicReadConfig = EMC_DynamicReadConfig_RD(1);

Regards,
Alex
0 Kudos
Reply

1,552 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by Alex on Thu Nov 06 06:57:57 MST 2014
The SDRAM is initialized correctly. Directly after initialising the SDRAM the test code is executed to check if it works correctly.

The MPU is not touched by the OS.

I will do some tests using a data breakpoint. Thanks for the hint.

Regards,
Alex
0 Kudos
Reply

1,552 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by MikeSimmonds on Thu Nov 06 04:49:30 MST 2014
Also, the debugger allows for a 'data' breakpoint.
Break (code) in the Reset code, place a watchpoint on the pointer's address
[the address of the variable, not where it is pointing] and see where/when is it initialised
and or changed?

Mike
0 Kudos
Reply

1,552 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by MikeSimmonds on Thu Nov 06 04:44:41 MST 2014
Silly question perhaps, but you have initialised SDRAM before initialising the RTOS and LWIP?
Does the RTOS do anything with the MPU re 'protecting' the A0000000 area?

Mike
0 Kudos
Reply