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.

MSP432E411Y: How to implement peripheral initialization process before main() function

Guru 12400 points
Part Number: MSP432E411Y


Hi,

Currently, we would like to allocate the memory area such as global variables to the external SRAM mounted on the custom board and implement it.

Since global variables etc. are allocated to the external SRAM, it is necessary to implement the following initialization processing such as the external bus interface before the section initialization processing is performed (before the main function).

In a project using TI-RTOS, could you tell me how to implement peripheral initialization processing such as the EPI function before the main() function? The code I'm using is below.

\simplelink_msp432e4_sdk_4_20_00_12\examples\rtos\MSP432E411Y_BGAEVM\drivers\gpiointerrupt

Thanks,

Astro

  • Hi,

      I think it is possible to add some user's supplied function before main but I don't know how to do it. Here are the documents that you can take a look. 

      https://www.ti.com/lit/pdf/spruex3 - See section 3.1

      https://www.ti.com/lit/ug/spruex4/spruex4.pdf - See XDC Boot Sequence and Control Points

      I also think you can do it after main(). 

      The first thing main will call is Board_init(). Board_init() calls Board_initHook(). You can aad your Board_initHook() function that will initialize EPI module. 

    /*
     *  ======== Board_initHook ========
     *  Perform any board-specific initialization needed at startup.  This
     *  function is declared weak to allow applications to override it if needed.
     */
    void __attribute__((weak)) Board_initHook(void)
    {
    }
    
    /*
     *  ======== Board_init ========
     *  Perform any initialization needed before using any board APIs
     */
    void Board_init(void)
    {
        /* ==== /ti/drivers/Power initialization ==== */
        Power_init();
    
        /* Grant the DMA access to all FLASH memory */
        FLASH_CTRL->PP |= FLASH_PP_DFA;
    
        /* Region start address - match FLASH start address */
        FLASH_CTRL->DMAST = 0x00000000;
    
        /*
         * Access to FLASH is granted to the DMA in 2KB regions.  The value
         * assigned to DMASZ is the amount of 2KB regions to which the DMA will
         * have access.  The value can be determined via the following:
         *     2 * (num_regions + 1) KB
         *
         * To grant full access to entire 1MB of FLASH:
         *     2 * (511 + 1) KB = 1024 KB (1 MB)
         */
        FLASH_CTRL->DMASZ = 511;
    
        Board_initHook();
    }

  • Hi,

    I want to change the memory area of variables, stack, and heap from internal SRAM to external SRAM. My understanding is that initialization of global variables etc. is done in c_int00(). If so, are you sure you want to initialize the EPI module in Board_initHook()?

    Or is it not recommended to allocate global variables in external SRAM?

    Thanks,

    Astro

  • Hi Astro,

      Yes, I agree that allocation of global variable to external SRAM is not advisable. First you need to configure the linker to place the global variables in a section that is mapped to external SRAM address. You will also need to initialize EPI before the global variable initialization takes place. Where exactly the global variable initialization takes place in _c_init00(), I do not know. I'm afraid too much hacking of the code will require. The EPI configuration (such as clocks, wait states) will also require the system clock to be defined and in stable state. This means EPI initialization needs to happen before the system clock is defined and before the global variable initialization. I just feel it will be much easier if you keep the global variables in the internal SRAM. 

  • Since global variables etc. are allocated to the external SRAM, it is necessary to implement the following initialization processing such as the external bus interface before the section initialization processing is performed (before the main function).

    RTOS/MSP432E401Y: SDRAM as Default Heap has some information on how to register a xdc.runtime.Startup function, which is called before main.

  • Hi Chester,

      Thank you! I learn something new myself on how to do this. 

  • Hi, Chester, Charles

    Is it possible to store global variables, etc. in external SRAM by initializing the external bus interface in the xdc.runtime.Startup function? Also, I would like to know where the xdc.runtime.Startup function is called in the sample project.

    Thanks,

    Astro

  • Hi,

    Do you have any update?

    Thanks,

    Astro

  • Hi Astro,

      Sorry, I do not have the knowledge in using XDC to initialize EPI or any modules prior to main() is called. I don't know if Chester or other people on the forum have tried it before. I find this webpage that may be useful. https://software-dl.ti.com/dsps/dsps_public_sw/sdo_sb/targetcontent/sysbios/6_53_02_00/exports/bios_6_53_02_00/docs/cdoc/xdc/runtime/Startup.html

    EXAMPLES
    The following code shows how to add custom startup functions to this module.
          var Startup = xdc.useModule('xdc.runtime.Startup');
          Startup.resetFxn = "&myResetFxn";
          Startup.firstFxns[Startup.firstFxns.length++] = "&myFirst";
          Startup.lastFxns[Startup.lastFxns.length++] = "&myLast";