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.

TMS570LS3137-EP: Use of linker directive #pragma CODE_SECTION increases code size

Part Number: TMS570LS3137-EP

Hi

When I use #pragma to place a specific function in user defined section, the code size increases. Being a linker directive, it is not clear why the code size increases and is there a way to avoid to place the code without increasing the code size

Example:

#pragma CODE_SECTION(SPI_TransmitData,"USER_DEF_SEC")
BOOLEAN SPI_TransmitData(SPI_CHANNEL_ENUM SPI_Channel, UINT16 TxData)

Please help.

Thanks,

Jai

  • HI Jai,

    It should not increase the code size. 

    Just did a test to show you that putting some code to other section doesn't increase the code size.

    1. Using #pragma to put test() in .USER_DEF_SEC

         section .USER_DEF_SEC is mapped to FLASH01

         Total code size: 0x080 + 0x3dd8 = 0x3e58

    2. don't use .USER_DEF_SEC for test()

        code size is 0x3e58 which is exactly same as #1

    My test code:

    /** @file HL_sys_main.c 
    *   @brief Application main file
    *   @date 11-Dec-2018
    *   @version 04.07.01
    *
    *   This file contains an empty main function,
    *   which can be used for the application.
    */
    
    /* 
    * Copyright (C) 2009-2018 Texas Instruments Incorporated - www.ti.com  
    * 
    * 
    *  Redistribution and use in source and binary forms, with or without 
    *  modification, are permitted provided that the following conditions 
    *  are met:
    *
    *    Redistributions of source code must retain the above copyright 
    *    notice, this list of conditions and the following disclaimer.
    *
    *    Redistributions in binary form must reproduce the above copyright
    *    notice, this list of conditions and the following disclaimer in the 
    *    documentation and/or other materials provided with the   
    *    distribution.
    *
    *    Neither the name of Texas Instruments Incorporated nor the names of
    *    its contributors may be used to endorse or promote products derived
    *    from this software without specific prior written permission.
    *
    *  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 
    *  "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 
    *  LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
    *  A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 
    *  OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 
    *  SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 
    *  LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
    *  DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
    *  THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 
    *  (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 
    *  OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
    *
    */
    
    
    /* USER CODE BEGIN (0) */
    /* USER CODE END */
    
    /* Include Files */
    
    #include "HL_sys_common.h"
    
    /* USER CODE BEGIN (1) */
    #include "HL_esm.h"
    #include "HL_sys_vim.h"
    /* USER CODE END */
    
    /** @fn void main(void)
    *   @brief Application main function
    *   @note This function is empty by default.
    *
    *   This function is called after startup.
    *   The user can use this function to implement the application.
    */
    
    /* USER CODE BEGIN (2) */
    #define vimram1bit      (*(volatile uint32 *)(0xFFF82008U))
    #define vimram1bitError (*(volatile uint32 *)(0xFFF82408U))
    volatile uint32 vimramread = 0U;
    
    //#pragma CODE_SECTION(test,".USER_DEF_SEC")
    //int test(void);
    
    /* USER CODE END */
    
    int main(void)
    {
    /* USER CODE BEGIN (3) */
        int a;
    
        esmInit();
        vimInit();
    
        _enable_IRQ();
    
        /*Enable ECC 1bit correction (bit 16), Enable Error Event (bit 24), enable diagnostic (bit 8), disable ECC (bit 0)*/
        vimREG->ECCCTL = (uint32)((uint32)0xAU << 0U) | (uint32)((uint32)0x5U << 16U)
                       | (uint32)((uint32)0x5U << 8U) | (uint32)((uint32)0xAU << 24U);
    
        vimram1bitError ^= 0x1U;
    
        vimREG->ECCCTL &= 0xFFFFF0F0;
        vimREG->ECCCTL |= 0x00000A0A;  //disable diag, enable ECC
    
        vimramread = vimram1bit;
    
        a = test();
    
        while(1);
    
    /* USER CODE END */
    
        return 0;
    }
    
    
    /* USER CODE BEGIN (4) */
    
    int test(void)
    {
    
        int local1 = 4;
        int local2 = local1 + 3;
        int local3 = local2 + 2;
        int local4 = local3 + 2;
        int local5 = local4 + 2;
        int local6 = local5 + 2;
        int local7 = local6 + 2;
        int local8 = local7 + 2;
    
        int nResult = 3 + proc1( local8 );
    
        return nResult;
    }
    
    int proc1( int foo )
    {
        foo++;
        int local1 = foo;
        int local2 = local1 + 3;
        int local3 = local2 + 2;
        int local4 = local3 + 2;
        {
            int foo = 3;
            int a = 2;
            int b = 4;
            int c = a + b;
            foo = c;
            c = foo;
        }
        int local5 = local4 + 2;
        int local6 = local5 + 2;
        int local7 = local6 + 2;
        int local8 = local7 + 2;
        int local9 = local8 + 2;
    
        return foo + local9;
    }
    /* USER CODE END */