This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

Allocating Variables to External SDRAM/.far section

Other Parts Discussed in Thread: SYSBIOS

I'm using CCS v5.2 on the Stellaris LM3S9D96 with SYS/BIOS 6.33.  Internal SRAM is at a premium, so I need to put less-accessed variables and buffers in an external SDRAM.  It is the same SDRAM used on the DK-LM3S9D96 development kit, connected to the EPI.

Anyway, I have already declared a ".far" memory section and pointed it to the SDRAM address region in my CMD file.  I've detailed my CMD file in this thread.  As also mentioned in the linked thread, I added the Startup module to SYS/BIOS and am using the ResetFxn to call an initialization function for the external SDRAM, so it is ready before variable initialization.

The NDK/Global module defaults to putting its buffers in the .far section, and my .map file shows that it is indeed allocating.  Since the program appears to run without any problems, including Ethernet functionality, it seems the communication to SDRAM is working.

Now, I need to allocate some variables and buffers of my own to SDRAM.  It seems like I need to use the Memory_alloc function from the Memory module, but it has an argument for heap.  If I don't specify anything, it will default to the standard heap which is in internal SRAM. 

I guess I need to create a separate heap in SDRAM, but how do I do this?

  • Andrew,
    I am assuming that you are planning to create a heap statically, in your CFG script. If that's the case, you can take a look at the SYS/BIOS Memory example. The relevant part of that example is in the CFG script, where a heap is created:

    var heapBufParams = new HeapBuf.Params;
    heapBufParams.blockSize = 32;
    heapBufParams.numBlocks = 2;
    heapBufParams.align = 8;
    heapBufParams.sectionName =".sdramHeap";
    Program.global.task0Heap = HeapBuf.create(heapBufParams);

    The line in read is not in the example, because the example leaves the heap to be allocated together with other data sections, but that's not what you want, so you have to specify 'sectionName'. Now, you need to allocate ".sdramHeap" to SDRAM. You already have a CMD file, where you can do that allocation, but just for reference there is an alternative mechanism, if you want to allocate the section inside your CFG script. You can do that using Program.sectMap.

    Program.sectMap[".sdramHeap"] = new Program.SectionSpec();
    Program.sectMap[".sdramHeap"].loadSegment = "SDRAM";

    This example works for HeapBuf manager, but most of other heap managers have the parameter sectionName, and you would basically do the same thing except that some of other parameters could be different. Then, in your C source, you need to include a header file where your heap is declared:
    #include <xdc/cfg/global.h>

    Then, you need to upcast the heap handle because the function Memory_alloc expects an IHeap handle, which is an interface that all heaps inherit
    IHeap_Handle heap = HeapBuf_Handle_upCast(task0Heap);

    Then, you can call Memory_alloc:
    Memory_alloc(heap, ....);

    I am not sure if you are using CCS, so I'll just point to the example sources in the SYS/BIOS installation. If you are a CCS user, let me know and I'll help you with creating the example in CCS. So, the sources are in <SYS/BIOS install dir>\packages\ti\sysbios\examples\generic\memory.