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.

  • Resolved

CCS/CCSTUDIO: Binary linked with static library does not start

Prodigy 80 points

Replies: 6

Views: 124

Part Number: CCSTUDIO

Tool/software: Code Composer Studio

I have a dummy FreeRTOS project, where I just want two LEDs to blink on the Hercules Launchpad (LAUNCHXL2-570LC43).
I created the necessary HAL and OS configuration with HALCoGen.
The two LEDs blink, if I just copy all sources etc. into a CCS910 project, click build and  flash the binary: the two LEDs start blinking as expected.
But I want to build libraries for HAL and FreeRTOS, and then link the binary based on these libraries.
I added a exported CCS workspace version 910 (libs.zip), which includes the following:
Simple: Simply build all objects and link them:
- project blinky_working: blinking project that works - just click build, flash it on the Hercules Launchpad, and the two LEDs start blinking happily.
With libraries:
- project blinky_hal: builds the hal library "blinky-hal.lib
- project blinky_os: builds the os library "blinky-os.lib", includes the search path to the HAL headers
- project blinky_not_working: just the main.c/h files and the linker command linker. References to includes and libraries as well as their search paths have been added. The project compiles and links, but after flashing the binary on the MCU, the MCU does not start. It stops somewhere even before _c_int00 as this is my the breakpoint.
What is missing in order to use libraries in a way that the binary starts?
Example project: libs.zip
  • Guru 166700 points

    Thank you for providing your project files. Please give me a day or two to reproduce and look into this issue. I will get back to you as soon as I have more information.

    ____________________________________________________________________________

    Please click This Resolved My Issue if the reply answers your question.

    Explore Code Composer Studio documentation and resources using online Resource Explorer
    Track a known bug with SDOWP. Enter the bug id in the "Find Record ID" box

  • Guru 166700 points

    In reply to AartiG:

    I compared the link map files (.map) for the working and not_working builds and found that the non_working version was missing the .intvecs section in addition to several .text sections from both the HAL and OS source files. If you compare the section allocation maps of the two .map files you will see the differences.

    In the not_working version, since you are linking the HAL and OS as libraries, the linker will bring in only those library functions that are called from the main application. That is the intent of static libraries. In your project, functions like _c_int00 (in HL_sys_startup.c) and several others are not explicitly called from main.c, hence the linker does not bring them into the final link. This results in incorrect operation of the application.

    The linker does provide an option to force a library function into the build. Please read about the --undef_sym option in the ARM Assembly Language Tools Users Guide. If you choose this path, note that you would need to add this option for every unreferenced function/symbol that you want to force to be part of the executable. For a large number of symbols, it may be more practical to add the options to a command file, then supply that command file to the linker.

    The other option of course is to add the source files directly to the project as you have done already with the working project.

    Hope this helps.

    ____________________________________________________________________________

    Please click This Resolved My Issue if the reply answers your question.

    Explore Code Composer Studio documentation and resources using online Resource Explorer
    Track a known bug with SDOWP. Enter the bug id in the "Find Record ID" box

  • In reply to AartiG:

    Thanks for looking into that issue, I will try it today with option with the linker arguments.

    Would you additionally please show me an example of a command file that adds symbols as undef_sym?

  • Guru 166700 points

    In reply to user6135372:

    user6135372
    Would you additionally please show me an example of a command file that adds symbols as undef_sym?

    Create a text file with .cmd extension that contains a list of linker options, like so:

    --undef_sym=_c_int00
    --undef_sym=setupPLL

    etc.

    You would need to add all functions/symbols that need to be brought into the link.

    Then add that .cmd file to the project so it get passed to the linker along with other command files that are already present.

    ____________________________________________________________________________

    Please click This Resolved My Issue if the reply answers your question.

    Explore Code Composer Studio documentation and resources using online Resource Explorer
    Track a known bug with SDOWP. Enter the bug id in the "Find Record ID" box

  • In reply to AartiG:

    ok, thanks for the Details on the command file.

    I had a detailed look at the map files, and the only things, that prevented the Startup seemed to be 

    • --undef_sym=__TI_static_base__
    • --undef_sym=resetEntry

    after adding these two options, main was reached, FreeRTOS started, and LEDs started blinking.

    Based on your answer I thought there must be missing more than one or two functions - can the solution really be so simple?

  • Guru 166700 points

    In reply to user6135372:

    user6135372
    can the solution really be so simple?

    It can be.

    I didn't know which functions were actually "required" for the application.  The map file of the "non working" version showed several missing functions compared to the "working" version and I wasn't sure which ones were necessary. 

    Glad you have it working.

    ____________________________________________________________________________

    Please click This Resolved My Issue if the reply answers your question.

    Explore Code Composer Studio documentation and resources using online Resource Explorer
    Track a known bug with SDOWP. Enter the bug id in the "Find Record ID" box

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.