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.

__TI_auto_init and gcc questions for tms570lc43



hi,

I am using ccs6.1 for tms570lc43, but I find some functions such as __TI_auto_init does not have source code , So where can I find help about this functions and if I use gcc compiler ,  does TI has the similar functions for gcc or does TI have any program guide for r4/r5 except arm's program guide.

thanks 

  • Hi,

    The function __TI_auto_init is part of the TI ARM compiler, the source code is part of the compilers C standard library (autoinit).
    It's purpose is to initialize the C environment such as, global variables, static variables and C++ constructors.
    However, the GCC compiler/linker should come with it's own way to initialize such things and the __TI_auto_init certainly won't work.
    We don't have a program guide for the Cortex-R4 as it's an ARM core and you already mentioned a good resource for programing it.
    We do have users guide for both, our Compiler and our Linker which do explain the concepts used by our tools, but not by the GCC tools.

    Please have a look at these resources for more related information:
    www.bravegnu.org/.../c-startup.html
    www.state-machine.com/.../Building_bare-metal_ARM_with_GNU.pdf

    Best Regards,
    Christian
  • thank you , I will try gcc to compile my code
  • Hi Christian:

    You provide a nice clear answer, however, I have been looking for source code for __TI_auto_init for weeks and I am unable to find it anywhere.

    Please provide a link to this file (or better still the file itself) so I can figure out what it is doing.

    I am stuck using Hercules RM57 with CCS version 6.

    Please let's not waste any more time on trying to solve this mystery.

    Thanks,

    Garry Anderson.

  • Garry,

    The file you are looking for is in the CCS/Compiler installation folder: ccsv6\tools\compiler\arm_15.12.3.LTS\lib\src\autoinit.c
    There is a function AUTO_INIT() and in the file autoinit.h you can fund a #define AUTO_INIT __TI_auto_init

    However, the AUTO_INIT function will call several more functions to do the actual initialization, mainly run_binit(), run_cinit() and run_pinit().
    You can find these in the header file autoinit.h defined as static inline functions.

    A description of binit, cinit and pinit can be found in the compiler manual SPNU151.

    Best Regards,
    Christian
  • Hi Christian:

    I followed your directions, and found the files that I was seeking.  Thank you for clear instructions.

    I have studied those files, and the SPNU151 document, but I cannot figure out how the auto_init code works. It is unnecessarily convoluted in my opinion.  Also, loading up many pointers to functions in an array then executing those functions (via RAM) is unreliable and appears to violate any "safety" considerations that we may be trying to achieve.

    I can live with clearing internal RAM, but specifically, I am looking for the code that clears my external SRAM device located at 0x6400 0000 address, because that is where I preserve my non-volatile data through a watchdog timeout reset exceptions.  I don't know why auto_init needs to go outside the MCU and destroy any external memory.  Sorry but this makes no sense to me because it prevents any product from preserving non-volatile data outside the MCU in static memory devices.

    I tested the linker option and found that using the Linker Option "check box" to turn off zeroization (invoking "--zero_init=off") seems to preserve both internal RAM and external SRAM content.

    But, how can I preserve my SRAM, yet keep zeroization of internal RAM? I don't think it is possible the way auto_init has been written, but you may know how to do it.  Any suggestions would be greatly appreciated.

    Thanks,

    Garry Anderson.

  • Garry Anderson said:
    But, how can I preserve my SRAM, yet keep zeroization of internal RAM?

    Consider using the compiler NOINIT or PERSISTENT pragma on your variables placed in non-volatile SRAM.

    See 5.10.18 The NOINIT and PERSISTENT Pragmas

  • Garry,

    As Gillon suggested the NOINIT pragma can be used to avoid initialization of a specific variable, an alternative is the GCC style attribute: int x __attribute__((noinit));

    The command line switch you described acts on a file level an switches off initialization of variables which aren't initialized in the source.

    There is also a third option for this you could specify a section as NOINIT in the linker command file:

    SECTIONS
    {
       sec1: load = 0x00002000, type = DSECT {f1.obj}
       sec2: load = 0x00004000, type = COPY {f2.obj}
       sec3: load = 0x00006000, type = NOLOAD {f3.obj}
       sec4: load = 0x00008000, type = NOINIT {f4.obj}
    }

    Best Regards,
    Christian

  • Hi Gillon & Christian:

    I like the idea of "pragma" or "attribute" better than modifying the linker command file because they are more accessible and obvious.

    However, I cannot figure out how to use either pragma or attribute with my structure. Because I have many non-volatiles in external SRAM, I have put them into a structure, then mapped that structure to 0x64000000, as follows:

    typedef struct {many non-volatile variables}ExtSRAM_t; // created type for the structure.

    Since the External SRAM is at fixed memory location, I need a constant pointer to the SRAM variables, so I have:

    ExtSRAM_s * const SRAM = (ExtSRAM_s *) 0x64000000; // pointer to SRAM address

    With this arrangement, I can easily access my variables using de-referencing like:

    SRAM->myVariable = 123;

    So, please let me know where to put the pragma or attribute to prevent all variables in SRAM from being initialized.

    Thanks,
    Garry Anderson.
  • Garry Anderson said:
    Since the External SRAM is at fixed memory location, I need a constant pointer to the SRAM variables, so I have:

    ExtSRAM_s * const SRAM = (ExtSRAM_s *) 0x64000000; // pointer to SRAM address

    With that method to access the SRAM variables the linker is not allocating a section for the SRAM variables, instead the compiler has been told to access a constant address. Therefore, in that case don't believe a pragma will help to prevent clearing of the external SRAM.

    Garry Anderson said:
    So, please let me know where to put the pragma or attribute to prevent all variables in SRAM from being initialized.

    The linker should only be initializing memory sections the linker has allocated. Can you post the linker command file and linker map files, so I can understand why the linker is initializing the external SRAM?

  • Christian:

    Following up on your SECTION idea, how can I create a section for external SRAM (starting at address 0x64000000 for 512 Kbytes), and how can I create my SRAM variable of type ExtSRAM_t in that section, then make it NOINIT.??

    With that arrangement, I could access my SRAM directly without pointers, e.g. SRAM.myVariable = 123;

    Thanks,
    Garry.
  • Gillon:

    I am getting the linker stuff together for you, but I will not have it ready until tomorrow.

    Garry.
  • Hi Chester:

    I have been looking for the Linker Command file and the Linker Map file. I have found a *.map file, but I don't now where to find the "linker command" file. I see some of the command line options are part of the Project Properties, but I cannot figure out which command file you would like to see. Please clarify for me. Thanks,\

    Garry
  • Hi Chester:

    I think I may have found a linker command file, so I have put it with the map file in this zip for you to download:

    Cmd-Map.zip (284.5 KB) => files.secureserver.net/0sTGERZMMVu761

    Let me know if this helps figure out why external SRAM is being cleared by __Ti_auto_init();

    Thanks,
    Garry.
  • Hi Chester:

    After several hours, I found this CMD file. Please let me know how to fix to make ExtSRAM NOINIT. Thanks:

    /*----------------------------------------------------------------------------*/
    /* Linker Settings */
    --retain="*(.intvecs)"
    -stack 0x100 /* Define main stack size */
    -heap 0x8000

    /* Define this in the linker options - Command File Processing */
    #ifndef ENABLE_BOOTLOADER
    # define ICB_APPLICATION_START (0x00000000)
    #else
    # define ICB_APPLICATION_START (0x00040100)
    #endif

    /*----------------------------------------------------------------------------*/
    /* Linker defines */
    #define RAM_SIZE 0x0006F000
    #define RAM_SYSTEM_SIZE 0x00008000
    #define RAM_CODE_SIZE 0x00000800
    #define RAM_STACK_SIZE 0x00020000
    #define ICB_VECTORS_SIZE 0x00000040
    #define ICB_AUTO_INIT_SIZE 0x00000FC0
    #define FLASH0_SIZE 0x00200000
    #define FLASH1_START 0x00200000
    #define FLASH1_SIZE 0x00200000
    #define RAM_BOOT_ADDRESS 0x08000000
    #define ICB_RAM_STK_START 0x08001000

    /* definition for program copy from Flash to RAM */
    linker_ram_code_start = (ICB_RAM_STK_START + RAM_STACK_SIZE);
    linker_ram_code_size = RAM_CODE_SIZE;
    linker_ram_code_flash_start = (ICB_APPLICATION_START + ICB_VECTORS_SIZE + ICB_AUTO_INIT_SIZE);

    /*----------------------------------------------------------------------------*/
    /* Memory Map */
    MEMORY{
    VECTORS (X) : origin=ICB_APPLICATION_START
    length=ICB_VECTORS_SIZE
    vfill = 0xffffffff

    FLASH_AUTOINIT (RX) : origin=START(VECTORS)+ICB_VECTORS_SIZE
    length=ICB_AUTO_INIT_SIZE
    vfill = 0xffffffff

    FLASH0 (RX) : origin=START(FLASH_AUTOINIT)+ICB_AUTO_INIT_SIZE
    length=(FLASH0_SIZE - ICB_AUTO_INIT_SIZE - ICB_VECTORS_SIZE - ICB_APPLICATION_START)
    vfill = 0xffffffff

    FLASH1 (RX) : origin=FLASH1_START
    length=FLASH1_SIZE
    vfill = 0xffffffff

    RAM_BOOT (RW) : origin=RAM_BOOT_ADDRESS length=ICB_RAM_STK_START-RAM_BOOT_ADDRESS
    RAM_STK (RW) : origin=ICB_RAM_STK_START length=RAM_STACK_SIZE
    RAM_CODE (RWX) : origin=START(RAM_STK)+RAM_STACK_SIZE length= RAM_CODE_SIZE
    RAM (RW) : origin=START(RAM_CODE)+RAM_CODE_SIZE length=(RAM_SIZE - RAM_SYSTEM_SIZE - RAM_CODE_SIZE - RAM_STACK_SIZE )
    LIB_SYS (RW) : origin=START(RAM_STK)+RAM_SIZE-RAM_SYSTEM_SIZE length= RAM_SYSTEM_SIZE
    EMIFCS2 (RW) : origin=0x60000000 length=0x03FFFFFF
    EMIFCS3 (RW) : origin=0x64000000 length=0x00080000
    EMIFCS4 (RX) : origin=0x68000000 length=0x00000080
    SDRAM (RW) : origin=0x80000000 length=0x007FFFFF

    }

    /*----------------------------------------------------------------------------*/
    /* Section Configuration */
    SECTIONS{
    .intvecs : {} > VECTORS
    .sl_stflash_SRAM : RUN = RAM_CODE, LOAD = FLASH0 | FLASH1
    autoinit : {} > FLASH_AUTOINIT
    .text : {} > FLASH0 | FLASH1
    .const : {} > FLASH0 | FLASH1
    .cinit : {} > FLASH0 | FLASH1
    .pinit : {} > FLASH0 | FLASH1
    .bss : {} > RAM
    .data : {} > RAM
    userstack : {} > RAM_STK
    LOG_DATA : {} > RAM
    PROFILE_DATA : {} > RAM
    .sysmem : {} > LIB_SYS
    externadc : {} > EMIFCS4
    fpga : {} > EMIFCS2
    ExtSRAM : {} > EMIFCS3

    .bootvars : {boot_variables.obj} > RAM_BOOT
    }
    /*----------------------------------------------------------------------------*/
  • Garry Anderson said:
    Let me know if this helps figure out why external SRAM is being cleared by __Ti_auto_init();

    The SE1_SysCtrl.map shows that the external SRAM is being zero-initialized due to a section named ExtSRAM which has been linked from app.obj.

    I think you need to either:

    a) Place a NOINIT pragma on the variable which is placed in the ExtSRAM section from the app.c source file.

    b) Remove the  variable which is placed in the ExtSRAM section from the app.c source file, since in one of your previous posts you mentioned that the following was being used to point the SRAM variable directly at the external SRAM:

    ExtSRAM_s * const SRAM = (ExtSRAM_s *) 0x64000000; // pointer to SRAM address

  • Help:

    Does anybody know the correct C-syntax to create a variable in a specific section of data space?

    For example, I have a section called "ExtSRAM" (defined in Linker CMD file), and I would like to know the C-syntax to create a variable called "SRAM" of type "ExtSRAM_t" in that section. Here is my pseudo code:

    section = ExtSRAM // switch to the data section
    ExtSRAM_t SRAM; // create variable SRAM of type ExtSRAM_t
    section = .text // switch back to code section.

    Sorry, but I cannot figure out how to do this with my CCS + RM57 project. The solution eludes me.

    Any help would be appreciated.

    Thanks,
    Garry.
  • Chester:

    Thanks for the clues. I found somebody else working on the project, who has since left the team, created a variable in the ExtSRAM section. I will resolve it soon.

    Garry.
  • Hi Chester:

    Here is what I found in App.c file:

    #pragma DATA_SECTION( ExtSRAMBlock, "ExtSRAM" );
    static uint16 ExtSRAMBlock[ EXTSRAM_BLOCK_SIZE ];

    I tried putting "__attribute__((noinit))" at the end of the array definition, but I got an error stating that the variable cannot be both DATA_SECTION and NOINIT.

    Any suggestions?
    Garry.
  • Hi Chester:

    How about I try the NOINIT in the Linker CMD file, like this (second last line)?

    Garry

    /*----------------------------------------------------------------------------*/
    /* Section Configuration */
    SECTIONS{
    .intvecs : {} > VECTORS
    .sl_stflash_SRAM : RUN = RAM_CODE, LOAD = FLASH0 | FLASH1
    autoinit : {} > FLASH_AUTOINIT
    .text : {} > FLASH0 | FLASH1
    .const : {} > FLASH0 | FLASH1
    .cinit : {} > FLASH0 | FLASH1
    .pinit : {} > FLASH0 | FLASH1
    .bss : {} > RAM
    .data : {} > RAM
    userstack : {} > RAM_STK
    LOG_DATA : {} > RAM
    PROFILE_DATA : {} > RAM
    .sysmem : {} > LIB_SYS
    externadc : {} > EMIFCS4
    fpga : {} > EMIFCS2
    ExtSRAM : {} > EMIFCS3, type = NOINIT

    .bootvars : {boot_variables.obj} > RAM_BOOT
    }
    /*----------------------------------------------------------------------------*/
  • Garry Anderson said:
    How about I try the NOINIT in the Linker CMD file, like this (second last line)?

    I tried that in a test program, and from inspecting the linker .map file the NOINIT in the Linker CMD file stops the linker from generating a copy table to zero-initialise the ExtSRAM memory region.

    [I didn't run the program]