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.

RTOS/MSP432E401Y: SDRAM as Default Heap

Part Number: MSP432E401Y


Tool/software: TI-RTOS

Hi,

I have a tirtos project that I would like to, at least, have malloc() pull from external SDRAM. Being able to assign specific task stacks to SDRAM would also be useful. Can someone show me how this is done?  On a previous project with a different RTOS there was a call to set the default memory pool.  This did not require any linker modifications. Simply pass in the address and size.

Thanks,

-Mike

  • Hi Mike,

    TI-RTOS creates a "system" heap by default. Again by default, it is a HeapMem instance (variable size first fit heap). It also creates the malloc (and free, etc.) function that sits on top of the system heap.

    The easiest thing to do would be to create the SDRAM memory segment in the linker (I just grabbed an open memory range) and then direct the .priheap section to that segment. 

    MEMORY
    {
        FLASH (RX)  : origin = 0x00000000, length = 0x00100000
        SRAM (RWX)  : origin = 0x20000000, length = 0x00040000
        SDRAM (RWX) : origin = 0x10000000, length = 0x00040000
    }
    
    ...
    
    /* Heap buffer used by HeapMem */
        .priheap   : {
            __primary_heap_start__ = .;
            . += HEAPSIZE;
            __primary_heap_end__ = .;
        } > SDRAM align 8

    Of course you can adjust the HEAPSIZE in the linker file also. When I built an application with the above linker file, I see this in the mapfile

    .priheap   0    10000000    00020000     UNINITIALIZED
                      10000000    00020000     --HOLE--

    HeapMem uses __primary_heap_start__ and __primary_heap_end__ to know the location of the heap (and initialize it accordingly during startup before main()). Here is the code in the .cfg to do this.

    var HeapMem = xdc.useModule('ti.sysbios.heaps.HeapMem');
    HeapMem.primaryHeapBaseAddr = "&__primary_heap_start__";
    HeapMem.primaryHeapEndAddr = "&__primary_heap_end__";
    
    var heapMemParams = new HeapMem.Params();
    heapMemParams.usePrimaryHeap = true;
    Program.global.heap0 = HeapMem.create(heapMemParams);
    
    Memory.defaultHeapInstance = Program.global.heap0;

    Todd

  • Sorry, I missed the task stack part....

    In the linker file, create a subsection (e.g. .bss:myStacks) that is in SDRAM

        .data   :   > SRAM
        .bss:myStacks : > SDRAM
        .bss    :   > SRAM

    Then in the .cfg, if you want all the statically created tasks to be placed there, add the following

    Task.defaultStackSection = ".bss:myStacks";

    Note: you can individually control each task stack placement also if you want finer granularity via the stackSection parameter. In the app I built, only the idle task was statically created. Here is the mapfile

    .bss:myStacks 
    *          0    10020000    00000200     UNINITIALIZED
                      10020000    00000200     mutex_pem4f.oem4f (.bss:myStacks)

    For runtime created (or constructed) tasks, if you supply the stack in the params structure, you can place it via #pragma or via the linker file. If you don't supply a stack, the create will allocate it for you. By default, it will use the System heap. You can supply a Heap_Handle in the stackHeap parameter in the create though if you want it from a different heap. Also in the .cfg, you can specify the default heap to use for allocating stacks (via the Task.defaultStackHeap setting).

    Todd

  • Hi Todd,

    I need to initialize the EPI early in the startup.  In a non-tirtos project creating a _system_pre_init() function works. The tirtos project seems to have it's own generated _system_pre_init() so the one I have never gets called.

    Regards,

    -Mike

  • I Have the SDRAM initialization figured out, .cfg file needed:

    var Startup = xdc.useModule('xdc.runtime.Startup');
    Startup.resetFxn = "&epi_init"; //my epi startup function

**Attention** This is a public forum