IAR Embedded Workbench Tutorial for MSP430
A short tutorial on how to use the IAR Embedded Workbench 5.3 to program and debug MSP430 microcontrollers on a windows box.The article teaches the reader to create and compile a simple C Project to blink the LED on a launchpad development board from Texas Instruments.The article can also be used with other MSP430 emulators like MSP430 Flash Emulation Tool (MSP-FET).
IAR Embedded Workbench for MSP430 is a commercial integrated development environment developed by IAR Systems. The IDE comes in a paid full version and a code limited trial version.The free version can be downloaded from the IAR website free of charge and supports all the MSP430 derivatives. It is limited to a program size of 4KB.This would sufficient for programming most MSP430G2xxx series that comes with Launchpad development kit.
Installation is simple, you can download the .exe file from the IAR website to your computer. They may ask you to register first before downloading. After the executable is downloaded run it and complete the installation. Please restart your computer after the installation is completed otherwise the drivers may not function properly.
Creating a Project in IAR
After the installation is complete double click on the IAR EW icon in the desktop. This will launch the IDE with a blank workspace and some release notes .
We are going to create a small C project to blink an LED on a Launch pad Development board from TI. You can download the sample codes for the appropriate controller (here MSP430G2553) from Texas instrument Website.
Now click on the “Project “ menu from the menu bar and select “Create New Project....” which will open a new window called “Create New Project”.
On this window we can see templates for creating Assembly language, C, and C++ projects. If we select the “asm” template it would create default assembler project with a *.s43 file (assembly language source file).Here we want to create a C project ,So click on “main” and press ok. Now the IDE will ask you to save the project. Please create a folder and save your project files in it.
Now IDE will show a file called “ main.c” with some default code in it.
Now either you can edit the “main.c” or you can remove it by right clicking on it and selecting “Remove “ option. In this case we are going to remove the “main.c” .Removing the file will not delete file from the directory so open your project directory and manually delete “main.c”.
Now click on the new document icon on the menu bar
It would create a new file called “untitled”, Save the file in your project directory as “led_blink.c” by right clicking on it.
Now Type / Paste the following code into led_blink.c and save it.
// A simple program to blink LED on P1.0
#include "msp430g2553.h" //header file for msp430g2553void main(void)
Now right click on “test -debug” inside the workspace and add “led_blink.c” to the project.
The file “led_blink.c” can be compiled by clicking on either “make” or “Rebuild All”.If there are no errors the file would compile successfully.
In order to download the code into the micro controller we have to select the correct header file belonging to the micro controller and the debugger for downloading the file.
Right click on the “test -debug” inside the workspace and select “Options...”A new window would open called “ Options for node “test” “ will appear.
Under “General options “ Select the required device for your project(here MSP430G2553).
Now under the “Debugger “ option , Select “FET Debugger”
Normally for debugging with Launchpad development board or with MSP-FET emulator you don’t have to change the “FET Debugger” option. But if you are using parallel port based emulator or other supported emulators you will have to change this option.
After configuring all the options. Press “OK” and rebuild the whole project again.
Now connect your launchpad with the PC and start debugging.
Debugging with IAR
To download the code into launchpad /development board and start debugging you can got to “Project” → “Download and Debugger”
or use the download and debug button on the menu bar (The green arrow)
Press CTRL + D
After this IDE will go into the debug mode where you can control the execution of the program, Stop and examine the contents of the registers and memory units.
Debug mode Commands
Viewing the Registers
IAR embedded workbench allows to view and change the registers inside the selected MSP430 microcontroller .It is extremely helpful while debugging the software during development.The view registers option is available in the debug mode only.
It can be accessed from the menu “View → Register” in the debug mode .
On selecting “Register” another docked window named “Register” will appear near your code window.It will show CPU registers by default,you can use the pull down menu to access the register you want to view.Here we are going to select the Port 1 register .
On selecting the “Port 1/2” all the registers related to Port1 and Port2 can be seen with corresponding values in the window.
You can use the single stepping option or to execute the program line by line and can observe the changes in the registers. When the value inside the register changes it is highlighted in red .
For eg: when the program executes the “toggle P1.0” instruction. The value at P0 in the register P1OUT changes to “1 “ and is highlighted in red (above figure).
You can also see the LED connected to P1.0 lighting up if you are using launchpad.
It is also possible to manually change the value of the Registers by clicking on the desired register or the individual bit you wishes to change. The changes are immediately reflected in the hardware.
Viewing the Memory
In IAR it is also possible to view and manipulate the various memories (RAM, FLASH, SFR, INFOrmation memory) present in MSP430 micro controller. The view “Memory” option is available in the debug mode only. It can be accessed from the menu “View → Memory” in the debug mode .
You can access RAM, FLASH, SFR, INFOrmation memory by pulling down the “Memory”.The “Go to “ entry box helps you to go to a specified memory location of
a particular window.
It is possible to see how your program is organized in the Flash memory through the memory window by selecting the “FLASH” option in the pull down menu.
If you are writing the code in assembly you already know where the code is situated (since you have specified it using ORG directive) but in C compiler
automatically allocates the start address .
It is possible to view the start address by looking at the disassembly of the compiled code in the “Disassembly” window. It can be accessed from the menu “View → Disassembly” in the debug mode .
In this example we can see that the program starts at “00C000” ,you can see that in the FLASH section of the memory window .
If we are storing some values in RAM ,It can be seen by selecting the “RAM” option in the pull down menu. You can clear the ram by selecting address range and right clicking on it.Select the “Memory Fill “ option if you want to fill the selected range with whatever hex value you choose. Please note that clearing the RAM also clears the Device RAM deleting whatever you have stored in the selected range.
It is also possible to save the RAM to an external “*.txt” file.