TI MSP430: Setup without an IDE on Windows 10

Overview for setting up TI MSP430

Traditionally, we select a microcontroller and use the IDE provided along with it. In our case, we are working with an TI MSP430 from Texas Instruments (TI), and they provide Code Composer Studio (CCS) IDE for development.
The usually approach would be to download and install CCS, then write, build and upload an executable onto the target device (TI MSP430) using the Flash Programmer.
This form of abstraction removes a majority of underlying commands from our control for instance compile time switching. In this article we will see how knowing the build process is useful. The approach will primarily be based on Windows 10 for majority of the audience. 

Requirements for TI MSP430

  • Install Make to automate the build process.
  • Install MSP430-GCC-OPENSOURCE toolchain, and include files from Texas Instruments. The include files contain Header (msp430fxxx.h) and Linker Script (msp430xxxx.ld) files, which simplifies the build process. To write your own header and linker script files can be done. In most cases, this is not recommended.
  • Install your favorite Text Editor. I happen to use Sublime Text.

 
PART 1:

1.1 Downloading MingGW

It contains Make that we will be using in Command Prompt on Windows 10.

1.2 Installing MinGW

Keep the Installation Directory the same as shown below.

 

1.2.1 Navigate to your Desktop

Open MinGW Installer. Select Basic Setup, navigate to Packages and Right click on “mingw-developer-toolkit-bin”, “mingw32-base-bin” and “msys-base-bin” Packages and select Mark for Installation.

 

1.2.2 Navigate to the Top left corner and Left click on Installation then click Apply Changes.

 

1.2.3 The packages should now be Green (if not, just repeat the process), if they are successfully installed then close the Installation Manager. 

1.3 Rename to Make

Navigate to C:\MingGW\bin. Rename “mingw32-make” to “make”. This will make it easier to use Make in the Command Prompt.

 

1.3.1 Let’s add Make for usage in Command Prompt.

Press the “Windows Icon” on your keyboard, search and open “Edit the system environment variables”.

 

1.3.2 Click on “Environment Variables

 

1.3.2 Under “System variables”, scroll down to “Path” and double-click.

 

1.3.3 Click on “New” and add the location “C:\MingGW\bin” to environment variable and press “OK”.

1.4 Testing Make

Press the “Windows Icon” on your keyboard, search and open “Command Prompt”.

 

1.4.1 Type “make –version” to confirm that it works. Recheck Step 1.3 – 1.4 if it doesn’t work.

 

PART 2: 

2.1 Downloading MSP430-GCC-OPENSOURCE

 

2.1.1 Under GCC ALL-IN-ONE INSTALLER

Install Mitto Systems GCC Windows installer incl. support files

 

2.2 Installing MSP430-GCC-OPENSOURCE

Keep the Installation Directory the same as below.

 

2.2.1 Let’s add MSP430-GCC for usage in Command Prompt.

Press the “Windows Icon” on your keyboard, search and open “Edit the system environment variables”.

 

2.2.2 Click on “Environment Variables”.

 

2.2.3 Under “System variables”, scroll down to “Path” and double-click.

 

2.2.4 Click on “New” and add the location “C:\ti\msp430-gcc\bin” to environment variable and press “OK”.

2.3 Testing MSP430

Type “msp430-elf-gcc –version” to confirm that it works.

Recheck Step 2.2 – 2.3 if it doesn’t work.

 

PART 3:

We are ready to start coding and creating a Makefile. Enjoy!

In this example, we will start with the most popular project of all time, the blinky project.

3.1 TI MSP430 Blinky Project

3.1.1 Lets create a project folder on our Desktop called Msp430, and inside it we create our first project folder called Blinky. This will be our working directory for this project.

 

3.1.2 Open up your favorite Text Editor, create a New File and save it as blinky.c .

 

 

3.1.3 Here, I assume you know the basics of setting up a Pin as an output and toggling it on a TI MSP430.

#include <msp430.h>
#define CYCLES 1000000L

int main(void){
  /* Stop the watchdog timer */
  WDTCTL = WDTPW | WDTHOLD;

  P2DIR |= BIT3;  // Set Pin 2.3 as an Output
  P2OUT &= ~BIT3; // Clear Pin 2.3
  
  while(1){
    __delay_cycles(CYCLES); // Time delay
    P2OUT ^= BIT3;          // Toggle Pin 2.3 
  }
}

 

3.1.4 This is the format used to make comments:

       /* Comments are placed here */  and   // Comments.

  •  Comments just tell us why we wrote a specific line of code.

 

3.2 TI MSP430 Makefile Creation

3.2.1 It is essential that we great a Makefile to automate the build process. Below illustrates the command to run in Command Prompt that build’s a project without a Makefile. This manual entry method is tedious if we add or remove more header and source files from a large project over time.

  • msp430-elf-gcc -I “C:\ti\msp430-gcc\include” -std=c99 -Og -Wall -g -mmcu=msp430f2416  -L “C:\ti\msp430-gcc\include”  -Wl,-Map,blinky.map,–gc-sections blinky.c -o blinky.elf

 

3.2.2 Now, let’s create the Makefile to automate the process for our single source file.

 

3.2.3 Copy the code below and read the comments in grey to understand what each line means.

  • CC is a variable which stores the compiler option msp430-elf-gcc.
  • The usage of $(CC) replaces the CC value in its position, which in our case is msp430-elf-gcc.
  • Define variables and values accurately, because no type-checking’s done when running the make command, causing a built failure to occur.
MSPGCCDIR=$(HOMEDRIVE)/ti/msp430-gcc
# Contains the header and linker script files needed
INCLUDES_DIRECTORY=$(MSPGCCDIR)/include
# The specific MSP430 device being used
DEVICE=msp430f2416
# Provides memory usage details
MAP=blinky.map
# Compiler options
CC=msp430-elf-gcc
GDB=msp430-elf-gdb
# FLAGS
CFLAGS = -I $(INCLUDES_DIRECTORY) -std=c99 -Og -Wall -g -mmcu=$(DEVICE)
LFLAGS = -L $(INCLUDES_DIRECTORY) -Wl,-Map,$(MAP),--gc-sections
all: blinky.elf
# Builds an 'elf' file
blinky.elf : blinky.c
    $(CC) $(CFLAGS) $(LFLAGS) blinky.c -o blinky.elf
# Debug
debug:
    $(GDB) blinky.elf
# Remove compiled files
clean:
    del *.elf *.map
# This prevents MAKE to think of these commands as target files
.PHONY: all debug clean
    

 

3.2.4 Open Command Prompt in the working directory, type make all, and press enter.

If you get this error: Makefile:17: *** missing separator. Stop.

Then, Replace single spaces with Tab spaces in Line 17, 20 and 23.

  • This generates 2 files in your working directory, called blinky.elf and blinky.map.
  • The blinky.elf is the executable file that we upload to the target.
  • The blinky.map is a table of symbols, their location and size. It summarizes memory usage for static data and code space on the target.
  • That’s it! You’ve installed, coded, and built your first executable without an IDE.

 

 

3.3 Upload the executable onto your TI MSP430 device

3.3.1 Navigate to C:\ti\msp430-gcc\bin and start gdb_agent_gui.exe .

 

3.3.2 Click on Configure, navigate to C:\ti\msp430-gcc and open the msp430.dat file.

 

3.3.3 Plug your TI MSP430 into your computer, click on Targets and select your specific TI MSP430. Press start and in the log section you should see Waiting for client.

3.3.4 Open Command Prompt in your working directory, type make debug and press enter.

3.3.5 Lets connect the TI MSP430 to the GDB agent:

  • Type target remote :55000 and press enter. 

3.3.6 Let’s load the executable onto the TI MSP430:

  • Type load and press enter.

3.3.7 Lets run the program now on the TI MSP430!

  • Type continue, and press enter. Now you should see the L.E.D blinking.
  • Type help to learn about more commands that are available.
  • Once you are done you can type quit to exit the debugger.

3.3.8 Now lets clean up our working directory:

  • Type make clean, and press enter to remove all the files we created during the build.
  • Now close the GUI agent if it was used with your TI MSP430.

That’s all the basics out of the way for setting up, building and running an executable on a TI MSP430 on Windows 10 without an IDE. 

3.4 Upload the executable onto TI MSP430 Simulator

3.4.1 Open Command Prompt in your working directory, type make debug and press enter.

 

3.4.2 Let’s use the simulator to run the executable.

  • Type target sim, and press enter to switch to the simulator.
  • Type load, and press enter to upload the code to the simulator.
  • Type start, and press enter to begin executing the code on the simulator.
  • Type step or next, and press enter to step through the code.
  • Type quit, and press enter to exit.

3.4.3 Now lets clean up our working directory.

  • Type make clean, and press enter to remove all the files we created during the build.

That’s all the basics out of the way for setting up, building and running an executable on a simulator for TI MSP430 on Windows 10 without an IDE. 

Sharing is Caring!!

Leave a Reply

Your email address will not be published.