Jump to content

Read a line of input from the Code Composer Studio (CCS) console using an MSP430

Recommended Posts

This turned out to be an interesting one, and you're probably going to kick yourself when you see why fgets wasn't working for you...
Initially my gut feeling was that there was no support for reading from the console window on the target*. Having dug a little further I found that the CIO system does support reading from the target side, so I set up a test program to try it out. It didn't work. I noticed that you'd mentioned setting the heap size, so I set mine. That fixed printf but not fgets.
Stepping into the library code revealed that the problem was with allocating the stream buffer for stdin. I'd set the heap to 512 bytes, and each stream requires 256 bytes buffer space plus 32 bytes of header. The printf call was allocating a buffer for stdout and then the heap had insufficient space to allocate a buffer for stdin. While printf causes the program to exit when it fails to initialise the buffer, fgets and getc just return immediately.
Setting the heap size greater than 576 bytes fixed the issue for me.

* Mainly because I've never seen anyone else even try it - stdio.h is commonly regarded as being a bit "heavyweight" for MSP430. The default stream buffer size is bigger than the ram on the msp430g2553! Most example code I've seen uses the UART backchannel instead, or at least a very cut-down printf implementation with a much smaller buffer.
Link to post
Share on other sites

tripwire, thanks for thinking about my question and taking the time to investigate and figure out the issue!


Set my heap > 576 and it worked like a charm.


I am using the printf(...) and fgets(...) to enable a simple command line interpreter from the CCS debugger.  This allows me to dynamically read/write to I2C slaves, trigger interrupts, start timers, do resets to other chips on my board etc

Link to post
Share on other sites
  • 9 months later...

I am curious as to where you got the specific code for the fgets.c for a specific MSP430xxx?  In my CCS environment trying to step into those routines I don't have the source but can see the assembly.  I used Eclipse in the past for other development so attaching source and such is a familiar activity.

I just noticed that I never got around to answering this question. Sorry about that!


In case anyone else finds this post in future and wants to know where the library source code lives, you should find it in:


{CCS Install Folder}\ccsv6\tools\compiler\msp430_4.3.5\lib\src


The "ccsv6" and "msp430_4.3.5" parts of the path might have different version numbers depending on your CCS install.


If that folder doesn't exist or is empty, look in the \lib folder and there will be an rtssrc.zip that you can unpack to get the full source.

Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Create New...