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.

How to link an unused function in C with CCSv6 and cl430 compiler

Other Parts Discussed in Thread: MSP430F5438A

Hello all!

I am working a project in CCS_V6, with cl430 as compiler and MSP430F5438A

I'm looking for an instruction which enable to me to link an unused function. In fact, I need to use the code of my function without calling it.

I've ever tried something like that by calling directly my function:

#ifndef => it's not good for the precompilation

#pragma FUNC_EXT_CALLED(my_function) => I thought it would be useful, but it doesn't work as well

Create an impossible condition in which I call my function => not good according to me

So, does anyone would have an idea or would have ever done something like that ? 

Regards,

Bertrand

  • Use #pragma RETAIN(function_name).  Please read about it in the MSP430 compiler manual.

    Thanks and regards,

    -George

  • Please notice that RETAIN won't work if you put the function in a library. For library functions, you have to use an undocumented directive "--undef_sym" in your linker command file. For example,
    --undef_sym=_my_function
  • Thanks George,

    My function is never called from main() or other function.
    However, I use #pragma CODE_SECTION(function, ".name") in order to define an address where I would like to store it.

    By using #pragma RETAIN(), I don't have the wished result. My section doesn't appear in my .map file and there is nothing at the .name address

    Regards,
  • Bertrand.V said:
    My section doesn't appear in my .map file and there is nothing at the .name address

    I am unable to reproduce that result.  Is your code organized as a CCS project?  I'd appreciate if you would submit the project.

    Thanks and regards,

    -George

  • By using #pragma RETAIN(), I don't have the wished result. Moreover, I have "unrecognized #pragma" => I use cl430 v3.3.3 so it's may be "hasbeen"

    My aim will be to have an empty function which has to be called by another one, and run from RAM
  • If the empty function X is called by another function Y, then Y will refer to X and X should be included in the link. Are you sure Y is being included in the link?

    Also, make sure you refer to X by name in Y, not by address.

  • This works for me.

    #pragma SET_CODE_SECTION(".BSL")        // specify code section
    #pragma RETAIN(cBSL_main)               // The retain pragma, notice function name in parenthesis
    void cBSL_main(void) {                  // The function I need to retain.
        // ..... My code here
    }
    #pragma SET_CODE_SECTION()
    

  • For instance, #pragma RETAIN doesn't work, I have a warning saying "unrecognized #pragma#

    CPU : MSP430F5438A; CCS : 6.1.2; Compiler : cl430 V3.3.3
  • Can you post your pragma RETAIN code snipped, just cut and paste it.

  • #pragma CODE_SECTION(tsim_reflash_test, ".ramcode1") // .ramcode is defined into .cmd file
    #pragma RETAIN(tsim_reflash_test)
    void tsim_reflash_test()
    { ... }
  • Your code is correct, can you post the compiler and linker command and the output, it should be in your terminal.
  • Comiler : cl430 -DACTUATOR_TEST=1 -DMANAGE_CALIBRATION=1 -DBASE_APP_NAME=ips-sp -DWTC_VERSION_MAJOR=3 -DWTC_VERSION_MINOR=3 -DWTC_VERSION_REVISION=2 -DWTC_VERSION_BUILD=0 -DWTC_APPLICATION_TYPE=8 -DRPL_LEAF -DLORAMAC_VERSION -DLORAMAC_SEMTECH -DLORAMAC_R3 -DLORAMAC_REVISION=3 -DUSE_BAND_868 -DWITH_CHECK_POINT=1 -DWATCHDOG_TYPE=2 -DWITH_UIP6=1 -DUIP_CONF_ROUTER=1 -DRPL_CONF_GROUNDED=1 -DUIP_CONF_IPV6_RPL=0 -DNO_DEFAULT_REPORT_PARAMS=1 -DWITH_BATCH_REPORT=1 -DTRAFFIC_SIM=1 -DPHY_SIZE_MAX=230 -DLORAWAN_UNCONFIRMED_PORT=6 -DLORAWAN_MULTICAST=1 -DWITH_RSSI_TOOL=1 -DWTC_APP_NAME=\"ips-sp-btntest.cal.leaf.EU.chkpt.wdt2-br-TrafficSim\" -DCONTIKI=1 -DCONTIKI_TARGET_WTC_296_SP=1 -DUIP_CONF_IPV6=1 -DSP_NB_MEAS_CHAN=1 -DPLATFORM_SELECT=296 -DPLATFORM_VERSION=3 -DPHY_SELECT_CONF=6 -DMOD_RF_CONF=1 -DANTENNA_TYPE=0 -DTEST_PER=0 -DWITH_UIP6=1 -DRF154BB=6 -DWPC154BB -DREVCONF=4 -D__MSP430F5438A__ -Dcompile=1 --gcc --silicon_version=mspx --large_memory_model --symdebug:dwarf --opt_level=3 --opt_for_speed=5 --optimize_with_debug -I C:/Program\ Files\ \(x86\)/Texas\ Instruments/ccsv4/tools/compiler/msp430/include -I C:/Program\ Files\ \(x86\)/Texas\ Instruments/ccsv4/msp430/include --diag_warning=225 --sat_reassoc=off --fp_reassoc=off --plain_char=unsigned --printf_support=minimal --preproc_with_compile --preproc_dependency=obj_wtc-296-sp/uart1-putchar.d -I. -Iwtc-296-sp -I../../core/net/wtc-periodic/ -I../../core/net/wtc-loramac/ -I../../apps/wtc-traffic-simulator/lib -I../../apps/wtc-traffic-simulator/ips-traffic-simulator -I../../apps/wtc-loramac/mac/ -I../../apps/wtc-loramac/radio/sx1272/ -I../../apps/wtc-loramac/system/crypto/ -I../../apps/wtc-loramac/boards -I../../apps/wtc-loramac/radio -I../../apps/wtc-loramac -I../../platform/wtc-generic -I../../platform/wtc-generic/dev -I../../platform/wtc-generic/Types_nke -I../../cpu/msp430/radio/semtech_sx1272/ -I../../platform/wtc-296-sp/. -I../../platform/wtc-296-sp/dev -I../../platform/wtc-296-sp/apps -I../../platform/wtc-296-sp/net -I../../cpu/msp430/radio/semtech_sx1272 -I../../cpu/msp430/plc/wpc154bb -I../../cpu/msp430/. -I../../cpu/msp430/dev -I../../core/dev -I../../core/lib -I../../core/net -I../../core/net/mac -I../../core/net/rime -I../../core/net/wtc-mle -I../../core/net/wtc-beacon -I../../core/net/wtc-bootstrap -I../../core/net/wtc-datarequest -I../../core/net/wtc-loramac -I../../core/net/rpl -I../../core/net/txdiag -I../../core/sys -I../../core/cfs -I../../core/ctk -I../../core/lib/ctk -I../../core/loader -I../../core/lib/tfp_printf -I../../core/. -I../../apps/wtc-zcd -I../../apps/wtc-ips-std-mngts -I../../apps/wtc-m25pxx -I../../apps/wtc-fota-checksum -I../../apps/wtc-traffic-simulator -I../../apps/wtc-ips-std-mngts -I../../apps/wtc-loramac -I../../apps/wtc-check-point -I../../apps/wtc-rom-tools -I../../apps/wtc-rssi-tool -I../../apps/wtc-batch-report -I../../transmitter/wpc154 -c ../../cpu/msp430/dev/uart1-putchar.c --output_fileobj_wtc-296-sp/uart1-putchar.o

    Linker command :
    cl430 --run_linker --map_file=contiki-wtc-296-sp.map --stack_size=0x0200 --heap_size=0x0205 --use_hw_mpy=F5 --warn_sections -I C:/Program\ Files\ \(x86\)/Texas\ Instruments/ccsv4/msp430/include -I C:/Program\ Files\ \(x86\)/Texas\ Instruments/ccsv4/tools/compiler/msp430/include -I C:/Program\ Files\ \(x86\)/Texas\ Instruments/ccsv4/tools/compiler/msp430/lib --reread_libs --rom_model obj_wtc-296-sp/pre_init.o obj_wtc-296-sp/boot.o --output_file=ips-sp.wtc-296-sp ips-sp.co contiki-wtc-296-sp.a --library=C:/Program\ Files\ \(x86\)/Texas\ Instruments/ccsv4/tools/compiler/msp430/lib/rts430xl.lib ../../cpu/msp430/lnk_msp430f5438a.cmd obj_wtc-296-sp/ips-sp-ade-management.o

    About the output, I don't understand what you want ..

    Regards,
  • The only thing I see that can make a difference is the --gcc option.  You may want to use the GCC approach:

    void tsim_reflash_test(void) __attribute__((section(".ramcode1"), used));

    This should be in your forward declaration in your header file.  Per TI C/C++ compiler user guide, this should work.

  • Bertrand.V said:
    I'm looking for an instruction which enable to me to link an unused function. In fact, I need to use the code of my function without calling it.

    Use the RETAIN pragma.  Something like this ...

    #pragma RETAIN(name_of_function_here)

    This pragma is documented in the MSP430 compiler manual.

    Thanks and regards,

    -George

  • I've ever tried to implement it, but it doesn't work with my compiler. I'm going to try with UNION attribute, hoping that it would be useful and compatible with my issue

    Regards,

    Bertrand
  • Bertrand.V said:
    I've ever tried to implement it, but it doesn't work with my compiler.

    I presume you use the TI MSP430 compiler, and not gcc.  Please show what you tried to implement.  What do you see that makes you say it doesn't work?

    Thanks and regards,

    -George

  • George Mock said:
    Use the RETAIN pragma.  Something like this ...
    #pragma RETAIN(name_of_function_here)

    Bertrand's previous posts said that the TI MSP430 compiler version in use is V3.3.3

    I found MSP430 Optimizing C/C++ Compiler v 3.3 User's Guide SLAU132E, and a V3.3 compiler doesn't support the RETAIN pragma.
    Not sure how to get the equivalent of the RETAIN pragma in a v3.3 compiler.
  • Yes I use another compiler as gcc, it's cl430 compiler

    My purpose :

    I use 2 functions. Each function is located in Flash memory with a section assigned.

    On the one hand, "reflash()" contains all data what I need, its size is ~4KB
    On the other hand, I use an empty function which will be executed from RAM "virtual_function()" after
    having copied inside my function the code of "reflash()" function. It sounds like "copy_in()" function using .UNION directive.

    Only one function should be called during execution of my code, "virtual_function()".
    So, I would like to find a solution for keeping up my "reflash()" function though during the compilation,
    using optimized code option, it disappears and isn't linked.

    Then, during "virtual_function()" execution from RAM, I would like to understand why it starts correctly at the right address
    and at any time it jumps in Flash. (Probably a problem with range of my variable .def, .ref and .global)

    I hope that I have been able to throw some light on my matter!

    Regards,

    Bertrand

  • Sorry for the delay.

    I somehow overlooked that you are using a very old compiler.  Version 3.3.3 was released in 2010, 6 years ago.  It would be much easier to support you if you upgraded to recent tools.  I hope that is a practical alternative.

    If you are using version 3.3.3, then you are building with the old COFF ABI.  That being the case, I think adding --disable_clink to your linker options will fix your problem.  I cannot test whether I am right on this.  But I am confident enough to tell you to give it a try.

    Thanks and regards,

    -George