Skip to content Skip to navigation

OpenStax_CNX

You are here: Home » Content » Software Setup and Introductory Assembly programs for the MSP430

Navigation

Lenses

What is a lens?

Definition of a lens

Lenses

A lens is a custom view of the content in the repository. You can think of it as a fancy kind of list that will let you see content through the eyes of organizations and people you trust.

What is in a lens?

Lens makers point to materials (modules and collections), creating a guide that includes their own comments and descriptive tags about the content.

Who can create a lens?

Any individual member, a community, or a respected organization.

What are tags? tag icon

Tags are descriptors added by lens makers to help label content, attaching a vocabulary that is meaningful in the context of the lens.

This content is ...

Affiliated with (What does "Affiliated with" mean?)

This content is either by members of the organizations listed or about topics related to the organizations listed. Click each link to see a list of all content affiliated with the organization.
  • TI MSP430 display tagshide tags

    This module is included inLens: Texas Instruments MSP430
    By: Texas Instruments

    Comments:

    "This introductory lab will walk you through the process of creating an assembly project, assembling a program, downloading it to the EZ430 (the development kit for the TI-MSP430F2012) and […]"

    Click the "TI MSP430" link to see all content affiliated with them.

    Click the tag icon tag icon to display tags associated with this content.

Recently Viewed

This feature requires Javascript to be enabled.

Tags

(What is a tag?)

These tags come from the endorsement, affiliation, and other lenses that include this content.
 

Software Setup and Introductory Assembly programs for the MSP430

Module by: Texas Instruments. E-mail the author

Summary: This is Lab 3 of the Colorado State University Microprocessors course using the eZ430-F2012 development tool. This introductory lab will walk you through the process of creating an assembly project, assembling a program, downloading it to the EZ430 (the development kit for the TI-MSP430F2012) and executing / debugging the program. When you complete this lab, you should be able to: - Understand the IAR Embedded Workbench IDE. - Assemble (build) a program using the IAR Embedded Workbench. - Download a program onto your EZ430. - Run a program and examine memory registers. - Use stepping and breakpoints to debug the program. Because you will perform all of these procedures in every lab you do after this, a complete understanding of the material in this lab is necessary.

3.1 - Objectives

This introductory lab will walk you through the process of creating an assembly project, assembling a program, downloading it to the EZ430 (the development kit for the TI-MSP430F2012) and executing / debugging the program. When you complete this lab, you should be able to:

  • Understand the IAR Embedded Workbench IDE.
  • Assemble (build) a program using the IAR Embedded Workbench.
  • Download a program onto your EZ430.
  • Run a program and examine memory registers.
  • Use stepping and breakpoints to debug the program.

Because you will perform all of these procedures in every lab you do after this, a complete understanding of the material in this lab is necessary.

3.2 - Reading Material

You will need to read the following introduction material prior to completing this lab, all are available on the ECE 251 website.

  1. Introduction to the MSP430-F2012 controller
  2. Introduction to assembly programming
  3. MSP430 Instruction Reference Sheet

3.3 - Hardware / Software Setup

The eZ430 debugger/emulator should install its drivers automatically. To install IAR Embedded Workbench Kickstart Version, please visit www.ti.com or www.iar.com for the latest version of the software with installation instructions.

3.4 - Introduction to IAR Embedded Workbench IDE

Invoke the IAR Embedded Workbench in one of the following two ways:

  1. Left click your mouse on the START menu on the bottom left of your screen. Then follow the path, Programs -> IAR Systems -> IAR Embedded Workbench Kickstart for MSP430 V4.1-> IAR Embedded Workbench.
  2. Open Windows explorer and locate IAR Embedded Workbench.exe in the folder C:\Program Files\IAR Systems\Embedded Workbench 4.1\common\bin\IarIdePm.exe

To create the shortcut on your desktop, right click the mouse on IarIdePm.exe and then left click on create shortcut. Then click on this shortcut to invoke the IAR Embedded Workbench application.

Step 1 – Creating a Project

The first thing you will see is the Embedded Workbench Startup screen. This screen will be a good shortcut to open existing workspaces and create new projects in the future, but for now, click the Cancel button. Note that a workspace can hold one or more projects, each which can hold groups of source files (the files that contain your assembly code).

Click on File -> New -> Workspace. This opens a new workspace in which to place your projects. You must always open a workspace before you can create a new project. To create a new project, click Project -> Create New Project… The Create New Project box will appear. IAR lets you choose whether you want to create an assembly (asm), C, or C++ project. Expand the asm tab and click OK once you have selected the asm option.

Figure 1
New Project Window
New Project Window (graphics1.png)

IAR will ask you to specify where you would like to save your .ewp project file. It is recommended you create a folder for your workspaces on your u: drive such as u:\ee251\Labs\ in which you can store all your future labs. Create a folder called Lab 3, name your project Lab 3, and click Save. At this point, you should also download the add_primes.s43 file provided on the class webpage into the same folder.

Look at the left of your screen. You will see the workspace window where your projects and source files are organized.

Figure 2
Workspace Window
Workspace Window (graphics2.png)

On the right is the project window. The project window shows the assembly file template discussed in Introduction To Assembly Programming from the pre-lab material. You will not be using this file for this tutorial. Before anything else, click on File -> Save Workspace and save your workspace in the same folder as the project.

Now add the file we are going to examine in the tutorial. In your workspace window, right click on the project name and select Add -> Add Files… At the bottom of the page, change the Files of type tab to the Assembler Files option. If you downloaded the file from the class webpage, go ahead and select the add_primes.s43 file and click Open. You should see the file added to your workspace window. Right click on the asm.s43 template and remove it from the project then take a look at the add_primes.s43 code. This assembly program has stored the first six prime numbers in an array in memory and adds them up into register six. See if you understand what is going on by referencing the pre-lab material.

Step 2 – Setting the Project Options

Before we can compile our code into an executable object file, we need to set the project options. Using the Project pull-down menu select Options or simply right click on the project and select Options… This will bring you to the Options for node “<project_name>” screen.

Figure 3
Project Options Screen
Project Options Screen (graphics3.png)
  • In the General Options menu:
    • Set the Device to the MSP430F2012 or whatever MSP430 device number you are using.
  • In the Debugger menu:
    • Set the Driver to FET Debugger. This makes sure that once compiled into an object file, the program will be loaded onto your physical microcontroller, not the IAR simulator.
    • If you would ever like to work on your code but you do not have your EZ430, you can set the Driver option to Simulator and the IAR Embedded Workbench will simulate your microcontroller.
  • Under the actual FET Debugger menu:
    • Change the Connection from LPT -> LPT1 to TI USB FET. This tells IAR to look for your USB stick and not a port on your computer.
    • Change the Target VCC option at the bottom of the screen to 3.0
  • Click OK to finalize your settings. You are now ready to build and compile your project.

Step 3 – Running the Program

Before we compile the project, make sure to save your project to preserve its settings. Select the add_primes.s43 file in the workspace window and click Project -> Compile. Alternatively, you can right click on the source file and select Compile. When the workbench is finished compiling your source code, you will see a new window at the bottom of the screen called your Build Messages Window. It should say that there are 0 errors and 0 warnings.

Figure 4
The "build message" window
The "build message" window (graphics4.png)

To see what happens when your code contains an error, erase one of the semicolons preceding a comment in the add_primes.s43 code and re-compile. The build message window displays:

  • Any errors/warnings in your code
  • The assembler’s best attempts of an explanation
  • The name of the files in which the errors/warnings occurred
  • The line number where the errors/warnings occurred

Double click the line that says “Error[0]: Invalid syntax.” In the file, your cursor will be placed close to the location of the error. Fix the error, and then re-compile.

Now make sure that your EZ430 is plugged in and click Project -> Debug. This will run your code on the EZ430 and put you in debugging mode.

Step 4 – Debugging A Project

A new window has been added to the screen in debugging mode. It is called the Disassembly Window. After the assembler compiles your code into machine code, a disassembler program does the opposite and creates the contents of the disassembly window. You can apply the debugging commands to either the coded assembly file or the disassembly window. Generally, this tool is more useful when the developer has written his/her application using the C programming language and wants to see how the machine interpreted his/her code in assembly.

The workbench allows users to move and dock windows as they wish. To see this, click View -> Memory and View -> Registers. Click on the window labels to drag and dock them in the same tab group as the Debug Log and Build windows. These windows are updated as the program executes, giving the user extremely useful insight to the inner workings of his/her program.

NOTE: If the contents of the window selected in each tab group ever change, the changed contents will be highlighted red to show the change.

The Memory Window

The memory window allows the user to navigate the entire memory map of the MSP430. Since we used assembler directives to load the array of prime numbers starting at memory location 0200h, type 0x0200 into the Go to box. You will see the array stored in consecutive words in memory.

Figure 5
Memory Window
Memory Window (graphics5.png)

Instead of Memory, IAR also gives you the option to looking at:

  • SFR: The special function and peripheral registers
  • RAM: Memory
  • INFO: Information FLASH memory (ROM)
  • FLASH: Main FLASH memory (ROM)

NOTE_01: You can use the information and main memories just the same. The only difference is how the memory is physically segmented and the address.

NOTE_02: If you look at the FLASH memory, notice that this is where the main program is stored. The numbers you see are the instructions of the program that have been stored for program execution.

The Register Window

The register window shows the user any of the important registers whether they be peripheral control registers, special function registers, or just the basic CPU registers. For the most part, you will only be interested in the CPU Registers, but know that the other registers are available for viewing. Also note that the Status Register (SR) containing the status bits can be expanded to see each individually labeled bit.

While stepping through the program, periodically check the Memory and Register windows to see how they change according to your code.

Inspecting Source Statements

Run your mouse over these buttons in the top left corner of your debugging session and read their function in the bottom left corner of the IAR workbench frame.

Figure 6
The Debug Buttons
(a)
Figure 6(a) (graphics6.png)
(b) Program Reset Resets the execution of your program. Takes you back to the instruction address located in the reset interrupt vector.
Figure 6(b) (graphics7.png)
(c) Step Over - Steps over the current step point.
Figure 6(c) (graphics8.png)
(d) Step Into - When you debug a program with subroutines in assembly, you can choose to “Step Over” the subroutines, meaning that the subroutine is executed but you don’t step through it in the debugger, or you can choose to “Step Into” the subroutine. Stepping into a subroutine will allow the user to see the individual op-codes executed.
Figure 6(d) (graphics9.png)
(e) Step Out Of - If you have stepped into a subroutine, steps out of the subroutine and to the next instruction after the subroutine call.
Figure 6(e) (graphics10.png)
(f) Step to Next - Steps to the next statement, regardless of the circumstances.
Figure 6(f) (graphics11.png)
(g) Execute to Current Cursor Position - Executes the program to the line at which the cursor is currently located.
Figure 6(g) (graphics12.png)
(h) Run - Runs the program straight through or until a breakpoint.
Figure 6(h) (graphics13.png)
(i) Stop Debugging - Stops the debugging session returns the user to programming mode. At the top right-hand side of the page, note this button as well:
Figure 6(i) (graphics14.png)
(j) Make and Reset - Press when code has been modified so that it needs to be re-compiled and the debugger needs to be reset.
Figure 6(j) (graphics15.png)

Breakpoints

Sometimes it is beneficial, if you want to know how your program is executing at a certain point in its execution, to use breakpoints. To place a breakpoint in the program, double click on the margin next to the line at which you wish to set a breakpoint (or right click on the line and select toggle breakpoint (conditional)).

For example, the initial operators in every assembly code project that initialize the controller after a Power Up Clear can often be assumed to work properly. If you would like to run the program starting immediately after this section of code, add a breakpoint at the line labeled main. Since we have two clear operators in the beginning of our code that we know will work, place a breakpoint at the first mov.w instruction line of the main program. Press the Program Reset button to restart program execution and then press the Run to execute until the breakpoint. From here on, play with the other buttons to gain some intuition as to their function.

NOTE: Debugging can also be done in the disassembly window. Try it out and see if you can follow what all the numbers mean in regards to the CPU registers and memory.

For more information on debugging, reference the EZ430_UserGuide. An in-depth understanding of the debugging module is a truly powerful tool for future programming.

After completing this tutorial, you should feel comfortable working with the IAR Embedded Workbench. If you do not, you may want to go back and do it again. Also, make sure you have read and understand the material from lab section 3.2. It will be critical to the execution of future labs.

3.5 – Procedure

1. Set up the EZ430, IAR Embedded Workbench, and all necessary hardware.

2. Complete the tutorial.

Call the lab TA and repeat the tutorial in their presence, without reading the directions. When you can do this without looking at the instructions, the TA will check you off. Review any part of this lab you are not sure about.

3.6 – Questions

  1. Describe the register set for the MSP430F2012. What are the Special Function Registers (SFRs) and their functions? Where are they located?
  2. How are single stepping and breakpoints used to debug a program? Why might you use breakpoints rather than single stepping?
  3. In the “Disassembler” window, what do the numbers on the far left mean? What does this have to do with the contents in R0 during program execution?

3.7. – Lab Report

The lab report is due at the beginning of the next lab. For the lab write up, include the following:

  1. Your marked up version of this document.
  2. A brief discussion of the objectives of the lab and the procedures performed in the lab.
  3. Answer to any questions in the discussion, procedure or question sections of the lab.

Bibliography

"Msp430x2xx Family User's Guide." Dallas, Texas: Texas Instruments Incorporated, 2005.

.

Content actions

Download module as:

PDF | EPUB (?)

What is an EPUB file?

EPUB is an electronic book format that can be read on a variety of mobile devices.

Downloading to a reading device

For detailed instructions on how to download this content's EPUB to your specific device, click the "(?)" link.

| More downloads ...

Add module to:

My Favorites (?)

'My Favorites' is a special kind of lens which you can use to bookmark modules and collections. 'My Favorites' can only be seen by you, and collections saved in 'My Favorites' can remember the last module you were on. You need an account to use 'My Favorites'.

| A lens I own (?)

Definition of a lens

Lenses

A lens is a custom view of the content in the repository. You can think of it as a fancy kind of list that will let you see content through the eyes of organizations and people you trust.

What is in a lens?

Lens makers point to materials (modules and collections), creating a guide that includes their own comments and descriptive tags about the content.

Who can create a lens?

Any individual member, a community, or a respected organization.

What are tags? tag icon

Tags are descriptors added by lens makers to help label content, attaching a vocabulary that is meaningful in the context of the lens.

| External bookmarks