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: Linker File: Specify a section for the data from a file.

Part Number: TMS570LS3137

Tool/software:

Hello, 

In our project we use MPU regions to isolate memory regions of the task from one another. 

So far we realized this  by using the #pragma SET_DATA_SECTION in every .c file. Later at the linker stage the entire section is assigned to RAM locations. Please find a example here

/* test.c file*/

#pragma SET_DATA_SECTION("test_section")

uint8 testData;

const uint8 testConstData;



#pragma SET_DATA_SECTION()

/* END test.c file*/


/*sys_link.cmd file */

MEMORY
{
    RAM     (RW)		: origin=0x08002000 length=0x0003C000
}


SECTIONS
{
	test_section : START( StartAdrTestSection )
                        {} > RAM palign( 0x20 )
}

/*End sys_link.cmd file */

With this approach the const data and ram data goes to the same RAM memory regions. 

Could you please propose a solution where in the linker file I could extract the ram and const data from the section identifier test_section.

Alternate approach:

I tried the solution of manually doing individual file but without success, I have the following message from linker

warning: no matching section

/* sys_link.cmd file */
	testData : {
		test*(.data)
	} > RAM

I'm not very sure how to get the start address and size of the region even if the alternate approach works. Does the commands START and SIZE work with this approach? 

Thanks in advance.

  • Anudeep,

    Please expect a delayed response due to the Diwali holiday in India.

    Regards,

    Brennan

  • Hi Anudeep,

    Why don't you store them into different memory sections like below:

    /* test.c file*/
    
    #pragma SET_DATA_SECTION("test_section_data")
    uint8 testData;
    #pragma SET_DATA_SECTION()
    
    
    #pragma SET_DATA_SECTION("test_section_const")
    const uint8 testConstData;
    #pragma SET_DATA_SECTION()
    
    
    /* END test.c file*/
    
    
    /*sys_link.cmd file */
    
    MEMORY
    {
        RAM     (RW)		: origin=0x08002000 length=0x0003C000
    }
    
    
    SECTIONS
    {
    	test_section_data : START( StartAdrTestSectiondata )
                            {} > RAM palign( 0x20 )
        
        test_section_const : START( StartAdrTestSectionconst )
                            {} > RAM palign( 0x20 )
    }
    
    /*End sys_link.cmd file */

    --
    Thanks & regards,
    Jagadish.

  • Hello Jagadish,

    yes, I did use this approach for the files written by us. However, we generate third party software packages, In these generated files the const and data are not well separated so it is quite difficult to add const and ram sections every time we generate files. (manually/ via a script). 

    That's why I thought it is best to handle it at a linker file level. 

  • So, is there any other possibility to do it at file level?

  • Hi Anudeep,

    .const

                    section contains string literals, floating-point constants, and data defined with the C/C++ qualifier const. This is a read-only section.

    So in linker cmd file usually we will do like below:

    This indicates const variables to be store in the flash, so you might use this .const section name to separate the constant objects and can store it at required section.

    Try this method and let me know the result.

    --
    Thanks & regards,
    Jagadish.

  • Hi, 

    Thanks for the input. The problem is to assign the consts from a file to a specific address. Your proposed solution will assign all the consts to a location. This will be a problem because, data from individual files in our case are isolated using MPU.

    The following also doesn't work, it gives the same warning as before warning: no matching section

    	testData : {
    		test.*(.const)
    	} > FLASH0			

  • I tried the solution of manually doing individual file but without success

    I think you need to change two things:

    1) An initializer for testConstData:

    const uint8 testConstData = 0xFF;

    2) In place of the output section name you have put your variable name. I think it should look like this:

    	test_section_data : {
    		test.o(.bss)   // // testData will go here
    	} > RAM
    
    	test_section_const : {
    		test.o(.rodata)  // testConstData will go here
    	} > FLASH0

  • Hi, 

    Thanks for the hint 1. I forgot to add it in my post when I tried to replicate my actual code here. In our actual codebase the consts are initialised.

    I tried your approach already but the problem is with this approach the linker gives an error "cannot find file test.o". 

    Please find the screenshot from a test project I created.

    I see the object file test.obj, I tried using and I have following warning. 

    I think the approach is correct but I'm not sure why the const are not generated are they somehow optimised? (opt_level is Off and opt_speed is 1).

    Seems like I'm missing some obvious thing. it would be great if you can guide me. Thanks.

    Here is the test project I used

    .7127.TstMap.zip

  • I'm using a different processor and compiler so .obj is correct for you.

    I think the problem is that the compiler has substituted testv for a string literal and discarded your const variable. This is outside of the control of optimisation level.

    Try forcing the compiler to keep 'testv' variable.

    For me that would look like this:

    __attribute__((retain)) const uint16 testv = 0xFFFF;

    You need to look in your compiler manual for the required syntax for your environment. It might be called 'used' or similar.

  • That makes sense. In the test project I created a more complicated const array. Then using the .const in linker file works well. 

    However in the actual project it doesn't work.

    (I'm not allowed to share real data here, so I try to give an example). 

    In the actual project I have a similar initialized const array(of a custom type). I assign a custom section for these const values from the file as discussed above. 

        testData : {
            Test.*(.const)
        } > FLASH1          

    In the map file, I see this const array is assigned to .unpriv_flash section. representation as below:

                      0006cf28    00000c08     libTest.a : Test.c.obj (.const:Test_Dir)

    So clearly the array is identified and created as constant but I'm not sure why there is a waning from the linker as "warning: no matching section". 

  • In linker scripts order matters. Try placing your special output section definition before the regular definitions in the script file, i.e. at the start of SECTIONS. 

  • I placed at the start of the sections, doesnt seem to have any affect.