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.

CCS: msp430g2553 Launchpad and printf

Other Parts Discussed in Thread: MSP430G2553, CCSTUDIO, MSP430F4793

Tool/software: Code Composer Studio

Dear Sir:

      I am trying to get a printf program to compile on my msp430g2553 Launchpad using CCS 5.    This program is not the standard printf C program but a reduced memory size program.  

      One can find a discussion about running this program on a msp430 CPU at this link:

forum.43oh.com/.../

      I have attached a copy of the program below:

tiny_printf.c
#include "msp430g2553.h"
// #include "msp430.h"
#include "stdarg.h" //

void putc(unsigned);
void puts(char *);

static const unsigned long dv[] = {
//  4294967296      // 32 bit unsigned max
    1000000000,     // +0
     100000000,     // +1
      10000000,     // +2
       1000000,     // +3
        100000,     // +4
//       65535      // 16 bit unsigned max
         10000,     // +5
          1000,     // +6
           100,     // +7
            10,     // +8
             1,     // +9
};

static void xtoa(unsigned long x, const unsigned long *dp)
{
    char c;
    unsigned long d;
    if(x) {
        while(x < *dp) ++dp;
        do {
            d = *dp++;
            c = '0';
            while(x >= d) ++c, x -= d;
            putc(c);
        } while(!(d & 1));
    } else
        putc('0');
}

static void puth(unsigned n)
{
    static const char hex[16] = {

'0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F'};
    putc(hex[n & 15]);
}

void printf(char *format, ...)
{
    char c;
    int i;
    long n;

    va_list a;
    va_start(a, format);
    while(c = *format++) {
        if(c == '%') {
            switch(c = *format++) {
                case 's':                       // String
                    puts(va_arg(a, char*));
                    break;
                case 'c':                       // Char
                    putc(va_arg(a, char));
                    break;
                case 'i':                       // 16 bit Integer
                case 'u':                       // 16 bit Unsigned
                    i = va_arg(a, int);
                    if(c == 'i' && i < 0) i = -i, putc('-');
                    xtoa((unsigned)i, dv + 5);
                    break;
                case 'l':                       // 32 bit Long
                case 'n':                       // 32 bit uNsigned loNg
                    n = va_arg(a, long);
                    if(c == 'l' &&  n < 0) n = -n, putc('-');
                    xtoa((unsigned long)n, dv);
                    break;
                case 'x':                       // 16 bit heXadecimal
                    i = va_arg(a, int);
                    puth(i >> 12);
                    puth(i >> 8);
                    puth(i >> 4);
                    puth(i);
                    break;
                case 0: return;
                default: goto bad_fmt;
            }
        } else
bad_fmt:    putc(c);
    }
    va_end(a);
}

      I have attached a snapshot of the error message that I received from the compiler.   Please take notice that I have inserted larger size stack and heap sizes but to no avail.   The copy below is a typical error message.

     

      As part of the solution to this problem I am attaching a snapshot of the MSP430g datasheets.   I would like to be able to interpret the datasheet information in the snapshot correctly.   In the picture below you will see 2 values of RAM.   Can you please tell me how to interpret those 2 values, in terms of the maximum values that can be inserted into the heap and stack size using the msp430g2553 processor.

  • As you can see from my first post, I was having problems trying to get this post to format correctly. I hope that the information in this post is interpreted correctly.

    It is my belief that someone got this program to compile correctly and run on the msp430g2553 Launchpad. Hopefully, a TI engineer will be able to get this program to run (not just compile) and explain to the user how to get this program to run in CCS 5 with a test program and an explanation of the required steps to build this program.
  • Michael Choi said:
    In the picture below you will see 2 values of RAM.   Can you please tell me how to interpret those 2 values, in terms of the maximum values that can be inserted into the heap and stack size using the msp430g2553 processor.

    The reason the block diagram shows 2 values for the RAM size is that the datasheet SLAS735J covers a number of different devices, with varying amounts of memory.

    If you look at the later Table 8 that shows the actual memory size of each device, which shows that the MSP430G2553 has 512 bytes of RAM:

    Based upon the errors messages you have shown, the linker is using the correct RAM size of 512 (0x200) bytes.

    The error messages show that the allocation of the .stack segment of size 0x1f4 (500) bytes failed, meaning there is insufficient space for the program.

    Michael Choi said:
    Please take notice that I have inserted larger size stack and heap sizes but to no avail.

    Increasing the stack and heap sizes requires more memory, increasing the probability that the program won't fit.

    Does your program need the heap? The code of the Tiny printf() you referenced doesn't use the heap itself, but what do your putc() and puts() functions do?

    See Finding out static stack usage for a utility to determine the stack requirements for a program, which is useful for devices with small amount of RAM to find the smallest stack size to allow the program to run.

  • Dear Chester;

    Thank you for your replies.

    When you wrote:

    "Based upon the errors messages you have shown, the linker is using the correct RAM size of 512 (0x200) bytes.

    The error messages show that the allocation of the .stack segment of size 0x1f4 (500) bytes failed, meaning there is insufficient space for the program."

     
    I tried different RAM value sizes - 512 bytes was tried already.

    I originally wrote:

    "Please take notice that I have inserted larger size stack and heap sizes but to no avail."

    I posted the "snapshot" of the error message to show the reader the "typical" error message.

    I would like to thank you for the literature that you pointed me to. I will read it. I read a post written by a TI engineer and he felt that the "stack" value calculation was not a trivial task.

    I copied and pasted the program so that any TI engineer could just copy the code and then try to run it on CCS 5. It is my belief that this program was already experimented with by a TI engineer in the past (it appears all over the internet). When the MSP430g2553 was in its development stages, it is my belief that someone tried using it. "Printf" is so useful - fundamental for a beginner programmer developer - someone had to have tried it.

    With regard to your question:

    "what do your putc() and puts() functions do?"

    Go to these links:

    www.tutorialspoint.com/.../c_function_putc.htm

    www.tutorialspoint.com/.../c_function_puts.htm

    I started this post because I believe "experience" knows best.

    You surfed onto an excellent topic because the MSP430G dual in line package is so excellent to work with. I just hope that some TI engineer can find me a solution. I got printf to work on other launchpads but the dual in line package cannot be beat. TI should market another dual in line package processor Launchpad with more memory and a blank development board to go along with it. I would definitely buy it at the right price. TI needs to market another dual in line package processor for developers.

  • Michael Choi said:
    With regard to your question:

    "what do your putc() and puts() functions do?"

    Go to these links:

    www.tutorialspoint.com/.../c_function_putc.htm

    www.tutorialspoint.com/.../c_function_puts.htm

    What I meant was have you implemented your own "tiny" putc() and puts() functions, or did you use the functions in the standard run time library?

    If you use the standard run time library functions that will increase the memory requirements.

    Also, do you want the output from the tiny printf to appear in the CCS CIO console, or to be written to another device such as UART on the MSP430G2553?

  • Thank you for your fast reply.

    All I did at this stage, was try to get the program to compile.  The program was cut and pasted - there were no other modifications - with exception of a different #include file (msp430g2553.h or msp430.h).

    If there is a setting that needs to be made in CCS 5 to utilize the standard run time library please let me know.

    I already visited this TI wiki page and changed some settings but the compile still failed.  See the link below:

    http://processors.wiki.ti.com/index.php/Printf_support_for_MSP430_CCSTUDIO_compiler

    I have surfed onto a lot of other pages and tried what was recommended.   At this point, I am seeking to answer the question, is it possible to compile the program that I had originally posted on the MSP430G2553?
     
    To answer your question about how I would like to see the tiny printf output, I would like the tiny printf library call to appear in the CCS CIO console.

    Did you cut and paste (or download) the program and manage to compile the program already? 

  • Michael Choi said:
    If there is a setting that needs to be made in CCS 5 to utilize the standard run time library please let me know.

    There is no setting that needs to be made in CCS 5 to utilize the standard run time library, the issue is that the standard run time library takes too much RAM to implement printf() via the C stdio to be able to fit in a MSP430G2553.

    Michael Choi said:
    Did you cut and paste (or download) the program and manage to compile the program already?

    I investigated the amount of RAM just required to use putc() from the standard run time library in a MSP430F4793. The minimum RAM required was 1028 bytes, which included 54 bytes of stack as calculated by the cg_xml call_graph utility and 260 bytes of heap required for the stdio buffering used by putc(). i.e. calling just putc() exceeds the amount of memory on a MSP430G2553.

    Michael Choi said:
    To answer your question about how I would like to see the tiny printf output, I would like the tiny printf library call to appear in the CCS CIO console.

    I then created a replacement for the putc() which simply writes characters directly to the CCS CIO console, without supporting the other file I/O functions in the standard run time library.

    I was then able to get tiny_printf test program to only use 94 bytes of memory, i.e. fits in a MSP430G2553, and still display text on the CCS CIO console. The stack space was set to 48 bytes which was the stack space calculated by the call_graph program. A full program might required more stack space. No heap space is required for the tiny printf, putc or puts functions.

    The following is the output on the CCS CIO console from the tiny_printf test running on a MSP430G2553:

    The example project is attached MSP430G2553_tiny_printf.zip

    The project was tested using CCS 7 and the TI MSP430 compiler v16.9.0.LTS. While I haven't tested the code on CCS 5 I think it should also run under CCS 5. CCS 5 won't be able to import the CCS 7 project, so instead copy the following source files into a CCS 5 project:

    tiny_printf.c - contains the tiny printf(), putc() and puts() functions. The value of the MAX_BYTES_PER_WRITE macro may be decreased to lower the memory used.

    main.c - contains the test for the tiny printf() from your referenced http://forum.43oh.com link

  • Dear Chester;

          Wow!!! I am overwhelmed.   Thank you so much for your efforts.  

          I think I will try to download and install CCS 7 and then try to run your program.   There is an issue with downloading and installing CCS onto Windows 7.   I had prior experience with this issue.    I will try to get back to you with the results of how your program ran on CCS 7 (that is, if I get CCS 7 to install correctly).    This will probably take a couple of days , maybe more.    

          I am so overwhelmed by your efforts and your expertise.  You are truly "gifted."   Thank you so much.    

  • Dear Chester;

           I got your program to run on CCS7 with no problems.   

           Downloading and installing CCS7 on Win7 professional 32 bit requires that user type in and save the filename extension, *.exe, when the user initially tries to save and then run the download.    That is  the only hurdle to clear on my system.  

           It is a shame that the MSP430G has so little memory.    I was wondering if TI sells any processor with more memory in a DIP package that will fit into the Launchpad and be pin to pin compatible?    Maybe, I am hoping too much but maybe I will get lucky and there will be one out there.

            Anyway, thanks for your help, you are the greatest! 

  • Michael Choi said:
    I was wondering if TI sells any processor with more memory in a DIP package that will fit into the Launchpad and be pin to pin compatible? 

    Using the Product search for MSP430 ultra-low-power MCUs and filtering on the PDIP package shows the maximum size is 16K flash and 512 bytes of RAM. So the answer is no.

    While not pin compatible with the Launchpad, Olimex sell Header Boards which contain a MSP430 and passive components / crystal and bring the pins to 0.1" pitch connectors which allow the use of a MSP430 in a through hole board.

  • Dear Chester;

         Thank you again for your great replies.

         When TI marketed the Launchpad it was a great idea and the extension PCB development boards were also a great idea.   People like the convenience of purchasing a commercial off the shelf (COTS) development board with their Launchpad.   It is too much time and trouble to make your own.   

         I think TI failed to notice that people like reliable development systems and nothing beats a DIP for prototyping a "repairable" system.     A DIP processor with a lot of memory makes for a convenient and expandable platform.     If TI doesn't market a processor of this type, someone else will (or someone already has and I am just unaware of their product).     Maybe, someone can enlighten us as to what is currently on the market for a DIP embedded processor with lots of memory and similar features as the MSP430g.

          I am going to verify your answer.   However, I still like corresponding with you Chester.    I do have another question, I was hoping you could answer.  I may start another post to answer this question in CCS forum.   This is the first time I ran into a "lack of memory" problem.  

          This is my question:

          After the compiler and linker put together your code and memory is allocated onto the processor.   How does one use CCS to look into your processor to find where free user memory begins.   For example, let's say hypothetically I used your printf program and I wanted to store whatever I printed out in memory, how could I use CCS to find the starting addresses where free memory would begin?