Jump to content

New CCS vs Energia discussion.

Recommended Posts

"@yyrkoon that adafruit library code is using doubles which hauls in all the floating point libs. That is causing your bloat. How did you determine that this code would be smaller with CCS?



Rick, I had just considered going fixed-point right before your comment. Or just dropping the decimal. period. After all how often would one need multiples of 0.25 after the decimal ? Well, for temperature readings. However, I still have one multiplication by .25 needing to be done so .  ..


As far as where I got the idea about code size being smaller in CCS. This is from experience. I have written very similar code in the last couple of weeks, which is much larger including (someones ) Nokia 5110 driver library, with the TI image table still intact. Then I also at one point had stdlib, stdint, and one other include i can not think of offhand loaded up. code size was around 2100 bytes, on the target. Once i removed all the includes, code size was under 1800 bytes. I want to say 1500 but . . ..


Granted, I was using just C, and not C++.


Hopefully this is my doing. Maybe we can figure this out.


FWIW, im using CCS 5.3, code size limited "free" licence

Link to post
Share on other sites

Ok I found part of the problem.


each call to Serial.println(); uses like 500 bytes of code space !


I can understand each object instance is going to use some code space, but ~500 bytes each call ? wow.


Yeah that needed to be fixed, if possible. Still, after removing 3-4 of those, I am still at -> Done, 2798 bytes total  With no way to easily / cheaply debug my code.

Link to post
Share on other sites

Well i guess I'll have to forget about Serial then and just write my own Serial UART debugger.


Serial.begin() seem to use up around 1500 bytes. println() on a float brings it up another 1600 or so, then each repeat of same float is minimal. println() on a string afterwards goes minimally as well.


There is after all, no such thing as a free lunch.


Thanks for you time, and I still like Energia. Will keep using it where it makes sense. It did after all help me rapidly debug a faulty SPI connection.

Link to post
Share on other sites

The library I was looking at was around their thermistor. It had a range of -40 deg C C to 200 deg C. All being within the analog input values 0-1023 (which once i put it through the calculation in Groovy indicated that the calculation was useless for a lot of numbers as the thermistor couldn't return that temperature - 0 was like 400 deg C).


My solution at the moment is to have a byte array sized at 240, with a base value (from the 1023) and store the difference between each degree (again, the array is calculated using the adafruit steinhart algorithm) - and start with an offset. The basic algorithm then just reads the average, and steps through the array from a starting value comparing with the analog value it just read - if the calculated value goes above the read value, it knows that slot is what the temperature is. Explanation appears confusing.


I also found however that the Serial took a lot of memory, so I was hoping I might be able to swap to a 16x2 LCD :-)


My understanding is that on the MSP430 the code and data share the same space, so the array will taek 240 bytes, the algorithm maybe another 200-300 bytes. I didn't get that far last night :-)

Link to post
Share on other sites

Rickta, yes of course. Serial out over UART is really trivial. All you need is a printf() function, and point putc() to the TX output buffer. So what I had imagined was using RobG's printf() code mentioned on his webpage, and just tossing it out over UCx0TXBUF. 


That may be quick and dirty, but who needs it to be  perfect, when in the end it will just be removed anyhow. However with all that said, for Energia, I have no idea how much would be dragged in as a side effect. In CCS ( again not a peeing war ) the code required is very small, in text, and on the target.

Again, this isn't about "they got this and you don't" It is just how it is. Trust me when I say in concept I find Energia much more attractive than CCS. Practically . . . it really depends on what needs you have.


What I really need, personally, is a few ( couple maybe ) very descriptive examples of how MSP430 specific "things" are done in Energia. Like it would be very cool, if there were some way to use mspgcc exact statements for say interrupt callbacks etc. instead of using attributes. Or even a reference manual with Energia specific ways of doing various things (actually all compilers / IDE out there for MSP430s could use this ). Yes, I understand there are various appnotes, user guides, etc. But these are not geared for developers used to picking things up at a very quick pace. Actually, I've been thinking about ripping through various MSP430 user guides as I go, and doing this for myself. Time permitting . . .that is the problem though. So much material, and so little time.


@Richard, If  I can find some way to make a UART Serial out for energia. It would be a one time only, reasonably small in code space type thing. Thing is however, I do not know how much time I will be able to dedicate to such a project at this time. Basically, use someones printf() library, point it to TXBUF, and use string literals( and the occasional variable perhaps ) for debugging purposes. As for the other stuff you were saying . . . yeah I have no idea lol.

Link to post
Share on other sites

The title of this conversation was "CCS vs Energia" so I was trying to focus my responses towards that topic.  However comparing CCS and Energia is like comparing apples and oranges. Energia is an IDE + examples + a peripheral Framework + a compiler + a libc/libm.  CCS is an IDE + a compiler + a libc/libm.  Most of the questions and posts have been really about the Energia Framework, specifically the Serial class for the msp430g2553.  So maybe the topic should be Energia classes vs low level peripheral register level coding.  The Energia Framework just packages up general purpose classes for ease of use that happen to conform to the existing Arduino API. This allows you to defer learning about the low level details of the msp430 peripherals and concentrate on making something.
In Energia using an msp430g2553, Serial is implemented using HardwareSerial. The HardwareSerial class handles the generic case of reading and writing to the USCI peripheral. It is a general class not that isn't optimized for read or write. It doesn't know if you are going to do blocking reads or blocking writes so it automatically provides you will a TX and RX ring buffer.  You can insert or extract serial data with the ring buffers without worrying about dealing with interrupts or the USCI peripheral.  HardwareSerial inherits the Print class. The Print class provides generalized routines that can print any data type with many different base numbers. It doesn't optimize for a specific base implementation.
If all you want to do is output characters on the USCI peripheral you can implement that in either CCS or msp430-gcc with about the same efficiency.  Energia really doesn't come into play.  If you did want to stick with Energia, you don't have to use the HardwareSerial class. You can use printf and putc.  Although if you use the msp430-gcc printf(), it will suck up an extra ~2k of code. But back to the comparison part of this topic, that 2k is still much less than the CCS printf version which also uses an insane amount of data space. You could use oPossum's or robg's printf() code. Although I think both of those require some minor changes to work with msp430-gcc.
A third option is to write your own MinimalSerial output only class.  This one I sketched below only outputs const char strings or hex digits. However it adds less than 300 bytes to the size of your code. I implemented an insertion operator << overload so you can get the feeling that you are using an iostream class. However, it is just an illusion. There is no iostream on msp430-gcc.
This example below weighs in at 470 bytes. The bare minumum sketch is 233 so I'm not adding too much to get debug output.  I'm sure you could write straight C code using either CCS or msp430-gcc that would be slightly smaller but I'm guessing it will still be around 350-400 bytes.

 * MinimalSerial.ino - output only Serial template class example for msp430g2553
#if !defined(__MSP430_HAS_USCI__)
 #error "This code only works on the msp430g2553 chip"

namespace {
  const char ascii_digits[] = "0123456789ABCDEF";

template<uint32_t BPS=9600>
struct USCISerial {
  void begin(uint32_t dummy /* be consistent with Serial class begin() */) {
    const uint32_t baud_rate_20_bits = (F_CPU + (BPS >> 1)) / BPS; // Bit rate divisor
    UCA0CTL1 = UCSWRST;                             // Hold USCI in reset to allow configuration
    UCA0CTL0 = 0;                                   // No parity, LSB first, 8 bits, one stop bit, UART (async)
    UCA0BR1 = (baud_rate_20_bits >> 12) & 0xFF;     // High byte of whole divisor
    UCA0BR0 = (baud_rate_20_bits >> 4) & 0xFF;      // Low byte of whole divisor
    UCA0MCTL = ((baud_rate_20_bits << 4) & 0xF0) | UCOS16; // Fractional divisor, over sampling mode
    UCA0CTL1 = UCSSEL_2;                            // Use SMCLK for bit rate generator, then release reset

                                             // Configure P1.2 as UART controlled pin
    P1SEL = BIT2;                            // P1.2=TXD
    P1SEL2 = BIT2;                           // P1.2=TXD

  void printHex(uint32_t n, uint16_t bits=32) {
    uint16_t mask = 0x0F;
    do {  
      bits -= 4;
      write(ascii_digits[(n >> bits) & mask]);
    } while( bits );
  void print(const char *s) {
    while(*s) {

  void print(int8_t n) {

  void print(uint8_t n) {

  void print(int16_t n) {

  void print(uint16_t n) {

  void print(int32_t n) {
  void print(uint32_t n) {

  void print(float f) {

  void write(uint8_t c) {
    while(!(IFG2 & UCA0TXIFG)); // wait for TX buffer to empty
    UCA0TXBUF = c;


typedef USCISerial<9600> USCISerial9600;
USCISerial9600 DebugSerial;

template<class T> inline USCISerial9600 &operator <<(USCISerial9600 &obj, T arg) { obj.print(arg); return obj; }

void setup()
  DebugSerial << "\nMinimalSerial @ 9600 Baud\n";

void loop() {
  uint16_t count=1;
  while ( 1 ) {
    DebugSerial << "count=0x" << count << "\n";
    if ( count == 0x200 ) {

#if 0
// you could implement printf with something like this
#include <stdio.h>

int putchar(int c) {
  return 1;

... then later

printf("count=%d\n", count);


Link to post
Share on other sites

Rickta, well i only named this post as such to keep it obvious where I was posting. I was tired, and not thinking too straight, and yeah I was being lazy too i guess. You're welcome to change the topic name if you have the powers to do so. Also, I posted a question in the libraries by accident. Please delete it. I've answered most or all of the questions, and no one has replied to it in 3-4 days anyhow.


I do not really agree with your assessment of what each development tool *is*  They're both IDE's, you can not have an IDE without a compiler, otherwise, it would just be an over glorified text editor. but I do agree that they are not very much alike. No one says we have to agree on that point though, or any other for that matter.  edit - after re-reading *exactly* what you said, seems I was just mirroring what you said in your previous post. ( I really do need to get my eyes checked for real ). the rest below, I'll leave in in case it helps someone determine what they want to use. Basically, my very own love / hate relationship with CSS.


CCS being based on eclipse has huge plugin potential, and as such you can create a multitude of very useful plugins. Texas instruments has made just that. Several very useful plugins. This is also a problem though. The IDE is dog slow, hangs randomly for several seconds to a few minutes. Exactly why, I am not sure. Then, updating can be a very mixed blessing.


Also, CCS at times will just stop working for what seems like random reasons, requiring  "hocus pocus" to fix. Nothing worse than firing up your development machine after having it work all the previous day, only to have CCS barf on start up. Some times, all you have to do is restart, other times, you have to find a fix on your own or by other means ( maybe google ). This can be extremely upsetting at times, especially since all you wanted to do was continue writing code. For what it is worth, I expect this is an eclipse thing, since similar problems happen on vanilla eclipse once in a while too.


Honestly, I wish large corporations such as TI would just ditch java / JRE all together, and use something like Mono. JRE is garbage, and always will be, and Java is such a poor excuse for a language as well. Yet, CS courses nation wide here anyhow, use Java as a teaching tool, so I guess we'll be forever stuck with it. But I guess technically, TI is using Eclipse, and then JRE / JVM by extension.


Anyways, this is not to say that there are not any good points concerning CCS, because there are. Many actually.


Energia on the other hand is much smaller, with fewer "features",  At the same time, there is less to get in your way, and slow the IDE down because of this. Personally, the only thing I do not like about Energia, is the default very high level abstraction, without advanced documentation to instruct on how to work around this. I suppose I could figure it all out on my own, but not  while I am writing code for an active project. Especially considering that my development time is often limited each day.


Nice example you seem to have up there. I will have to give it a more in depth look-see when time permits.


EDIT: About the Energia high level abstraction. I guess what I would like to see as a feature more than anything. Is perhaps a feature that allows the user to toggle between pure mspgcc code, and high level "arduino" library abstraction. No doubt I could possibly attempt this myself, but again, time is an issue. Honestly, and in the end, I would probably never get around to even attempting such a feat.

Link to post
Share on other sites

If you would like to get rid of the entire framework and just want gcc then just create a tab called main.c and leave the main Sketch empty as Rick posted in this thread http://forum.43oh.com/topic/3204-changing-the-maincpp/. From that point on you are on your own and are responsible for configuring the peripherals, clocks, etc yourself. It seems though that is what you want so you should be golden with a main.c.


A Sketch with main.c weighs in at 107 bytes.



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...