You are welcome to install TI’s Code Composer Studio (CCS) on your own personal computers. The updated Launchpad you are using this semester appears to be well supported in the Ubuntu version of CCS (as well as Windows). It is not yet known whether the beta OSX version is also working well.
Energia is a clone of the Arduino environment for the MSP430. We will not use the Java-based approach used by Arduino, but the compiling and device programming components are still quite useful. Note that the Instructions for installing Energia can be found at the project home page: http://energia.nu/. We will not officially support Energia users in the class, however, we have found it to be quite usable in a minimal sense. Specifically, by creating a new tab in a sketch with a “.c” extension, one can write C-language code that is properly understood and compiled. You can then delete all the stuff in the original sketch window (though it appears you have to leave the file there for things to work). If you are going to use Energia, please make sure that you do not use the Arduino-style sketch code but rather C-language or assembly.
msp430-gcc is a fork of the gcc compiler which has tools to compile, assemble, disassemble, etc. MSP430 code. By itself, this can be a useful tool for understanding MSP430 code. With the addition of the mspdebug package (available under Ubuntu Linux or Homebrew), code can also be uploaded to a device.
Compile the included
delay_cycles_example.c
file to verify that CCS is setup correctly. (In Energia, you will need to create a new
“sketch”, add a tab with the name lab1.c or somesuch, erase the stuff in the first tab, and
then code away in the second “.c” one.) You should also read through this file: it shows the
minimum amount of code needed to run the MSP430 in an infinite loop. If you ever don’t know
what some variable acronym means, look it up! A useful practice is right clicking the name and
going to “Open Declaration” (instructions for CCS are in red). For instance, in this file,
doing this on CALBC\_1MHZ
brings you to:
SFR\_8BIT(CALCBC1\_1MHZ)/\* BSCTL1 Calibration Data for 1 MHz \*/
And inspecting BSTCTL1
shows:
SFR\_8BIT(BCSCTL1)/\* Basic Clock System Control \*/
What, then, is the “clock system control” that is being referred to? Two resources you should use extensively are the MSP430x2xx Family User Guide and the MSP430G2553 datasheet, both of which can be found on the main 327 page (or by googling). The user guide explains how to use various functions or registers common to most MSP430s, while the data sheet has register values and pin information specific to the G2553. So, searching for “BCSCTL1” on the user guide takes you to Chapter 5 and Chapter 24, from which you can figure out that this line will set the frequency of the DCO to a calibrated 1 MHz.
On the web, you may notice a function called “__delay_cycles”. You will find that documentation of this function is somewhat lacking on the internet. If you look in the MSP430 Optimizing Compiler Guide, you will see that it is not a C function, but rather an “intrinsic”. In hindsight, if its role is to delay the processor a precise number of cycles that can range from 1 to some large number, it could not be a function (because calling a function takes more than one cycle!). A compiler intrinsic is something like a macro - it is something that is replaced by appropriate code at compile time. In this case, __delay_cycles is marked as deprecated, no doubt because its use leads to poor quality code because it blocks the processor but still runs at full power. In this class, you should generally not write code which calls this function.
The goal of the compilation process is to turn a program written in a high-level language into machine code.
Please read this very interesting writeup about what code is generated by a C compiler when it is naively called and after code size optimization is done. We will discuss the operations of the compiler/assembler in class.
For those of you interested in understanding how compiler-to-opcode conversion might have interesting effects in the modern-day context, this is an interesting presentation from the 2017 BlackHat conference.
Using the P1.0 LED on your launchpad, blink a message in Morse code. Look Morse code up on
Wikipedia to find the code for each letter and how to separate letters. Submit your code in a
separate file named morse-code.c
. Every line should have a meaningful comment and extra
comments are welcome! Two example skeletons are given in:
lab1_skeleton.c
and
lab1_skeleton_ver2.c
A few specifications:
Over the course of the semester we will be developing a good schedule for demos. You will be required to demonstrate your code to one of the course staff. You should be prepared to show your code running on a breadboard, as well as changing the Morse code message, reprogramming, and showing the subsequent functioning.
Please reference your answers to one of the authoritative sources.
Questions from the skeleton code:
Questions about the lab:
Upload your code to Canvas. You will demo functionality in class on Monday.