Problems with HEAP in SDRAM

Go To Last Post
8 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hello!

As you may have read, I got my sdram running fine. Meanwhile I testet some other peripherals.
Today I tried to put the HEAP in the SDRAM.

Now I need your help! Here is what I've tried so far:

Played around with the "Placing data and the heap in external SDRAM" App-Note...

Then I copied the linker file and crt0.S file from the framework to my project. I told the linker "-nostartfiles" and "-TmyLinkerfile". This works... Behaviour is the same as before.

After that I created the void _init_startup(void) function and added "call _init_startup" to crt0.S at the position, where it is in the AppNote-version.
The problem here is: it seems as the _init_startup function is not executed. When I call _init_startup(); at the beginning von main() it runs fine.

Before this is not solved, I can't go ahead.

Any ideas? Maybe it's because I'm working with a C++ project.

Thanks a lot! Greetings
P.S. I have the UC3A0512, AVRStudio2.1, Framework 1.4

Student at the University of Applied Sciences Ulm, Germany

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Just an observation, but the framework provided with my UC3B0256 seems to be written in C, not C++

Elect reputable scientists!

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Yes you are right. But I have no problems with that as long I include the framework-headers with

extern "C"
{#include "bla.h"}

Student at the University of Applied Sciences Ulm, Germany

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Well, I just learned something today.
Thanks.

Wish I could be of more assistance.

Elect reputable scientists!

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

So here are my newest explorations:

When I put the void _init_startup(void) in a .c file, so the c-compiler instead of the c++-compliler runs through it, the function is called as it should be.
I was happy for some seconds about that....

But then I discovered, that the µC kills itself when an interrupt occurs... I have to look at an old thread here from me, I had those interrupt problems already 6 months ago.

Edit: Must be another problem, in the new Framework version the bug is fixed.

Student at the University of Applied Sciences Ulm, Germany

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

:D I just got it running. The problem must have been the EVBA-Vector... I put the evba-initialisation code inside my _init_startup function, just like it is in the "Placing data and the heap in external SDRAM" app-note.

So here is the recipe on how to get the HEAP in SDRAM with a C++-project:
- no need for a special crt0.s file if only HEAP should be transfered, so don't use "-nostartfiles"
- the "_init_startup" function must be in a .c file (look inside the mentioned app-note for things, that should be done there
- take the right linkerfile from the framework, add your SDRAM, change heap location and size (->app-note)
- go to project-propertiers->linker->misc->linker flags; add "-T../mylinkerfile.lds"

Be happy 8)

Edit: I just had a look at the syscalls.c-file from newlib, where this function is inside:

int  __attribute__((weak))
     _init_startup ()
{
  extern void _evba;
  void *handler_table;
  // Dynamically alloc the exception handlers table.
  handler_table = (void *)malloc(0x104);
  if (handler_table != (void *)0)
  {
    // Init the exception handlers table.
    init_exceptions((void *)&_evba, handler_table);
  }
  else
  {
    // The dynamic allocation failed: we might as well stay here forever.
    while (1);
  }
  return 1; // Use the same meaning as IAR: init the data segment when 1 is returned.
}

Is this function called, when I don't use my own _init_startup? And should I now also create an exception-table in my function?

Attachment(s): 

Student at the University of Applied Sciences Ulm, Germany

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

If you were to put the heap in SDRAM do you really need a custom _init_startup()? Wouldn't it be equivalent to do the initialization at the start of main()?

From the Appnote I was under the impression that you want to init SDRAM before main in order to support data and bss in SDRAM.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

At the moment I'm not sure if I really need the init_startup for the HEAP only. But everything works fine... never touch a running system.

Sorry for the late answer, I just came back from holidays in italy.

Student at the University of Applied Sciences Ulm, Germany