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 output "Hello World" using CCSv5 and MSP430

Other Parts Discussed in Thread: MSP430F5438A

Hello,

   I asked this in the MSP430 forum a week ago but didn't get a response.

   I've done a ton of programming for the MSP430 using IAR but wanted to try out CCS. I have the full version of CCS for MSP430 and want to run a simple "Hello World" application using printf(). I don't care about code space; I'm using a big MSP430F5529. How do I do this? I looked around but didn't see anything. In IAR you just need to supply a putchar function in your code somewhere; IAR will find it and use it in stdio.h. So I did, with a simple little putchar that sends bytes out the UART and works fine in IAR.

/** Send one byte via hardware UART. Called by printf() etc. in stdio.h */
int putchar(int c)
{    
    while (!(UCA0IFG&UCTXIFG));             // USCI_A0 TX buffer ready?
    UCA0TXBUF = c;                  // TX character
    return c;
}

When I attempted to compile this same code in CCS, I got a linker error:

<Linking>
error #10056: symbol "putchar" redefined: first defined in "./hal_mcb.obj";
   redefined in "C:\ti\ccsv5\tools\compiler\msp430\lib\rts430x.lib<fputc.obj>"

So how do I do this in CCSv5? It only takes 30 seconds to do this in IAR; I assume it's that easy in CCS but I just haven't seen it yet. Of course the implementation of putchar is project dependent; for this project I do it one way but if I'm using a different UART then I'll want it implemented a different way.

Is there a simple little app note that I missed somewhere? I've seen this question asked before on the forums without much in the way of a good answer; it might be worth writing a little wiki page for it.

Thanks,

Derek

  • Hi Derek,

    from a quick look at the message it almost looks like in CCS putchar is reserved and it is defined in a compiler library.  Hence CCS doesn't like the "Redefinition".  What if you call the function myputchar?  Or pushchar?

    Cheers,
    Lisa

  • Hello,

       I can redefine putchar to be something else, but I want to use printf etc. in <stdio.h>. How do I tell stdio.h where standard output should be directed? In my case it will be output to the UART. How do I do that?

    Thanks,

    Derek

  • Hi Derek,

    unfortunately CCS sends such printf items via the JTAG interface itself only.  So this JTAG message can be capture in a console, but not by a device UART.

    Unfortunately it is just not part of CCS.  You would have to do some work to implement a few things yourself and I hope this wiki topic will help explain further. 

    http://processors.wiki.ti.com/index.php/Tips_for_using_printf#Using_printf.28.29_to_output_to_a_user-defined_device

    Does this answer the question for you?

    Best Regards,

    Lisa

  • Hello,

       I assume that you have an example of how to do this with an MSP430? It shouldn't be this complicated - it's hello world for pete's sake! It takes 30 seconds to do in IAR; if something this trivial takes this much work in CCS then it makes me wonder how hard CCS is going to be to use. No wonder your low power RF group uses IAR instead of CCS for its MSP430 development!

    I realize this sounds harsh, but look at it from a user's perspective: your compiler for your processor (430 or Stellaris) should be the easiest compiler to use. Instead you're telling me that it's one of the most difficult.

    --Derek

  • Hi Derek,

    There are of course examples for MSP to MSP UART communication and there is a hello world example easy to find in CCS which output to the CCS console.  But as I mentioned, this type of output is only handled in JTAG messages in CCS and therefore you need to follow the wiki I sent to try and work around this.

    I can understand the frustration but most use scenarios are using the devices UART for which each device group does provide many examples.  You will see this for the MSP as well.  It is simply this other type of output CCS does not support.

    Best Regards,

    LIsa

  • Hi CCS champions

    I’m doing a CCSv5 project and in one source file "hal_usb.c", there is a redifined standard library function "putchar" as shown below

    /* in hal_usb.c */

    // provide putchar used by printf

    int putchar(int c){

        halUsbSendChar(c);

        return 1;

    }

    When I attempted to compile the project but I got a link error:

    error #10056: symbol "putchar" redefined: first defined in

       Recommend initializing all unused ports to eliminate wasted current

       "./firmware/hal_usb.obj"; redefined in

       consumption on unused pins.

       "C:\ti\ccsv5\tools\compiler\msp430_4.1.0\lib\rts430x_lc_sd_eabi.lib<fputc.ob

       j>" 

    I’ve checked the --std_lib_func_redefined flag to the build option for the hal_usb.c file as below:

      

    But the result is the same:

    error #10056: symbol "putchar" redefined: first defined in

       Recommend initializing all unused ports to eliminate wasted current

       "./firmware/hal_usb.obj"; redefined in

       consumption on unused pins.

       "C:\ti\ccsv5\tools\compiler\msp430_4.1.0\lib\rts430x_lc_sd_eabi.lib<fputc.ob

       j>"

    Also I follow an E2E post and tried to resolve the error:

    http://e2e.ti.com/support/development_tools/compiler/f/343/t/121838.aspx

    In the step 4, it indicates that: The CCE v3 version will return "symbol redefined" errors when custom runtime source files are added to the project. To get around these errors, do the following: Project Properties->C/C++ Build->MSP430 Linker: Change the Command line pattern to be: ${command} ${inputs} ${flags} ${output_flag}${output} Placing ${inputs} before ${flags} puts the object files before the runtime library on the link command line, thus resolving the reference to the definition in the object file. Now rebuilding the project should no longer generate the symbol redefined errors.

    But there are another two errors appearing in the lnk_msp430f5438a.cmd:

    "../lnk_msp430f5438a.cmd", line 21: error #78-D: this declaration has no storage class or type specifier

    "../lnk_msp430f5438a.cmd", line 22: error #66: expected a ";"

     

    Since the same project for IAR can be built successfully, could you please help to indicate which step I missed or where to modify the code?

    Thanks for you kindly help!

  • For both issues above, what's going on is putchar() is redefined in user code, but then the user's code also uses other library functions that bring in the library's definition of putchar().  IAR uses a different method for users to define device drivers.  For CCS, the proper solution to creating new device drivers for CIO is discussed in this entry: http://e2e.ti.com/support/development_tools/compiler/f/343/t/194851.aspx

    More directly see this app note: spra861.pdf