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.

Code size increases with usage of MSP430 Library

Other Parts Discussed in Thread: MSP430WARE, MSP430F5529, MSP430F5308

hi,

This is regarding MSP430 Driver Library's code size.
The User guide mentions:
"The drivers are not necessarily as efficient as they could be
(from a code size and/or execution speed point of view)"

I tested with a simple test example from MSP430Ware library(wdt_a_ex1_intervalSMCLK)
and the general sample code(MSP430F55xx_WDT_01.c).

Below are code sizes after the compiling/downloading the code to MSP430F5529.

General sample code:
-------------------------
MSP430F55xx_WDT_01.c with Output format :Legacy COFF
Code Size - Text: 74 bytes Data: 4 bytes.

MSP430F55xx_WDT_01.c with Output format :EABI(ELF)
Code Size - Text: 174 bytes Data: 4 bytes.
------------------------

Sample code which uses Library:
----------------------------
MSP430Ware(wdt_a_ex1_intervalSMCLK) with Output format :Legacy COFF
Code Size - Text: 1738 bytes Data: 202 bytes.

MSP430Ware(wdt_a_ex1_intervalSMCLK) with Output format :EABI(ELF)
Code Size - Text: 598 bytes Data: 4 bytes.
----------------------------

1.As the code size increases with usage of MSP430 Library,
can we assume that the Driver Library is not recommended for smaller devices
like MSP430F5308?

2.And shown above with the output format EABI(ELF) the code size reduces
in case of Driver Library sample code but increases in case of normal code,
please let me know which Output format is recommended?

Best regards,
Paddu.

  • EABI has a different startup code than COFF. One of the differences is a loop that clears uninitialized data space, which won't happen on COFF. Sure this loop doesn't take 100 bytes, so there are probably other differences too.

    As for the second case, well, it is possible that in EABI format, the linker is a bit smarter and excludes code form the build that is is the same compilation unit as otehr code bu tnot used at all. Usually, whole compilation units are included, whether all of their content is used or not.

    To be sure, the generated output must be analyzed further. Since I don't use CSS, that's beyond my capabilities.

  • paddu1 said:

    please let me know which Output format is recommended?

    Well, generally said, it depends on your requirements. Starting with version 4.0.0 TI's MSP430 compiler supports the new EABI in addition to the current COFFABI. As JMO already noted it has a different startup code. I would recommend you to read the file named readme.txt included to the compiler. Here are some important excerpts:

    2.1) Features
    -------------

    MSP430 EABI is an ABI for the MSP430 architecture based on the ELF object file format.  The major features are:

     - ELF object format
     - DWARF3 debug format
     - Improved "GPP parity"

    The advantage of EABI is that it provides a modern, well-documented ABI that is well-supported.  Many newer C++ language features, such as template instantiation and "extern inline," can be implemented more effectively.

    Future development of TI's MSP430 compiler will be primarily implemented within EABI.  We encourage users to consider switching to EABI at their earliest convenience.

    [...]

    2.3) 64-bit "double"
    --------------------

    In EABI mode, the C standard type "double" is 64 bits.  In COFF ABI mode, the "double" type remains 32 bits.

    Because the C standard requires the compiler to treat unsuffixed floating-point constants as type "double," the compiler is required use double-precision arithmetic for expressions involving such constants. Programs which use such constants may run a little slower in EABI.  This performance can be reclaimed by changing the constants to have the suffix "f".

    2.4) Table-Driven Exception Handling
    ------------------------------------

    MSP430 compiler version 4.0.0 supports table-driven exception handling for ELF executables.  Table-driven exception handling is more time-efficient than setjmp/longjmp support when exceptions are not thrown.

    The user interface is almost entirely the same as the COFFABI support; use the option --exceptions and link with an RTS which has exception handling enabled. For EABI only, if you have any 'extern "C"' functions which need to throw exceptions, you must use the option "--extern_c_can_throw".

    The underlying implementation is very different.  No support will be provided for migrating assembly files generated using the COFF scheme to the EABI environment; such files should be recompiled from the original C++ files.

    [...]

     2.6) Migration from COFF to ELF
    -------------------------------

    To take advantage of MSP430 EABI, users must explicitly request it using the "--abi=eabi" command-line option.  Object files generated with this option will not be compatible with object files generated for COFFABI.  However, most C source files will not require modification, and most assembly source files will require only trivial modification.

    The major differences between EABI and COFFABI are:

     - Different name mangling
     - C++ names are mangled using IA64 name mangling scheme
     - Different C auto-initialization

    However, there are many more details.  Review the MSP430 EABI Migration document for these migration details.

    Users need to take specific steps to migrate their projects to EABI:

     - COFF objects and libraries are not compatible with EABI objects; programs and libraries must be recompiled from source. There is no COFF to ELF conversion utility.

    Please refer to the MSP430 EABI Migration document for details.

    Since it can be expected that future major releases of TI's MSP430 compiler support the EABI format only, I followed those recommendations of TI. I already use the new EABI format in all my current projects. Of course, as long as you don't use those new features provided by the EABI format, then you can use the COFF format also.

    Jens-Michael Gross said:
    As for the second case, well, it is possible that in EABI format, the linker is a bit smarter and excludes code form the build that is is the same compilation unit as otehr code bu tnot used at all. Usually, whole compilation units are included, whether all of their content is used or not.

    paddu1 said:
    And shown above with the output format EABI(ELF) the code size reduces in case of Driver Library sample code [...]

    Indeed, the conditional linking paradigm is different under COFF compared to ELF. In COFF, you must mark a section to make it eligible for removal during conditional linking. In ELF, all sections are considered eligible for removal through conditional linking. Under COFF, a section that has been marked for conditional linking is removed from the program only, if it is never referenced by any other section in the program. Under ELF, a section that is never referenced by any other section in the program is removed from the program automatically, unless it is marked to retain. See slau132 - "MSP430 Optimizing C/C++ Compiler v4.1 User's Guide" - for more details about both ABIs.

  • Hi,

    I'm back on this subject as I'm currently compiling a quite big project on MSP430 with cl430 (numerous source file) and a resulting flash size of more than 100 Kb.

    I'm currently experimenting cl430 v4.3 (from ccsv6) in EABI mode with opt-level 4 as I hope to reduce my flash size occupation... But I never get a flash size occupation smaller than the one i get with cl430 v3.3 (ccsv4).

    Any idea, suggestion ?

  • For a given source code and run-time library,, there is a limit of how much the optimizer of a given compiler/linker can do. To "optimize" beyond that, you need to optimize your source code, use a more suitable run-time library, consider a more suitable compiler/linker, or even consider a totally different approach.  

  • Thanks for your first answer.

    I do agree.

    But, as a pass has already been done on the code to save flash size, very succesfully.

    I was now wondering if using a recent version of cl430 compiler (particularly using EABI) could help me saving a bit more space. Then this would be an argument more to justify the need of upgrading CCS version in my place.

    By the way, I use opt_level=3 on cl430 v3.3 (ccsv4), which (according to documentation) was maybe not able to make a program level optimization if sources were compiled separatly. So I decided to try opt-level 4 with cl430 v4.3 (ccs v6) that "is said" (slau123i) to make correctly the "link-level" optimzation on separatly compiled source files.

    Any opinion about these expectations ?

**Attention** This is a public forum