Using the terminal to return "hello world" with MSP430 Launchpad and CCStudio

2.9k Views Asked by At

I am trying to run "Hello world", the most simple and basic code there is, on an MSP430 Launchpad (specifically, the MSP430FR5994 Launchpad). I want to run this and have it be displayed on the CCStudio console or another screen. However, I can't find any information on running "hello world" for the Launchpad and having it print on a computer screen.

This feels like it should be simple, but I can't seem to find an explanation anywhere.

Current code, which includes blinking the lights:

#include <msp430.h>
#include <stdio.h>

int main(void) {
    WDTCTL = WDTPW | WDTHOLD;// Stop watchdog timer
    P1OUT &= ~BIT0;    // Meant to clear P1
    P1DIR = 0b00000010;     // Set P1.0 to output direction, p.131

    unsigned int i;   //Delay variable
    PM5CTL0 &= ~LOCKLPM5; //The datasheet told me to include it. Haven't found out why the datasheet asked me to do this.

    printf("Not C programming again!\n");

    while(1)
    {
        for(i=0;i<20000;i++){
        }

        P1OUT = 0x02;    //Turn on Port 1.1
        for(i=0;i<20000;i++){
        }

        P1OUT = 0x01;   //Turn on Port 1.0
    }
    return 0;
}

I am trying to do this as a way to familiarize myself with the board and to get an easier method of debugging. I eventually want to create a low frequency triangle wave, and compare two analog inputs with the comparator then displaying that comparator information on a computer screen. Don't know how this helps but better to let you know.

Please let me know if this question needs more explanation. I apologize if this question turns out to be mindbogglingly simple, I have spent hours looking for explanations and only found blinking lights.

2

There are 2 best solutions below

1
On BEST ANSWER

I found out why my terminal was not displaying the text. This is an issue with dynamic memory allocation, where not enough of it was allocated for printf to be successfully run. As it turns out printf is more computationally expensive than I could have expected.

In order to deal with the allocation issue, the heap size (explained in page 155 of the MSP C Compiler Manual) needs to be increased to 320. This can be done by (I am using CCStudio 11.1) opening your project or a file in your project, going to Project (which is on the top bar), opening properties, and opening Build/MSP430 Linker/Basic Options.

It's very important to use the properties in Project instead of the one in File, as the properties in File does not contain the linker.

enter image description here enter image description here

If it works, the printed text should come out of a CIO terminal.

0
On

The statment:

"the most simple and basic code there"

is to to really underestimate complexity of printf().

First of all you have to define what output device is associated with stdout. For output in the debug console, you need to enable CIO in the project debug properties (apparently... I am just Googling this stuff).

Outputting that way however is only useful in debug because you need CCSTUDIO debugger running to see the output.

With respect to your ultimate goal:

"displaying that comparator information on a computer screen."

... for that you will need to implement the low level I/O required to support stdio streams. You might for example map stdio to the Launchpad's "Application/Backchannel UART" (§2.2.4 of the Launchpad manual) which is an MSP430 UART1/USB bridge. Then you can interact with the board using a terminal emulator such as TeraTerm or PuTTY on the PC. That has the advantage of appearing on your host as a virtual serial port via the Launchpad's USB connection.

To see how to create a suitable device driver and redirect stdio from the debugger to the Application UART see §7.2.4 of the Compiler reference manual, and the preceding section on the required device driver interface.

You might choose not to go to the complexity of integrating the Application UART with stdio (though I find it hard to believe someone has not already done that work), and simply read/write directly to the UART. You could also bypass the standard library's stdio implementation and implement your own simplified formatted I/O. For example this TinyPrint implementation where for tfp_printf() to work you need only implement a single putc() function to write a character to whatever output device you choose (UART1 in this case).

Note that the application UART is used for the Launchpad's Out-of-Box Demo to communicate with a GUI interface on the host. If you have the necessary PC GUI and serial I/O development skills, you could ultimately do something similar, which might be more compelling than simple terminal I/O. The source code for that demo (the embedded here).