Using Visual Studio to develop MSP430 firmware

In this tutorial we will show you how to develop and debug a simple “LED blinking” firmware for TI MSP430 microcontrollers using VisualGDB. We use the EZ430-RF2500 development board to demonstrate the integration with debugging tools; however, you can use any of those tools/programmers supported by the MSP430.DLL provided by TI.

Step-by-step guide

Before you begin, please ensure that you installed the latest version of VisualGDB. If you are targeting one of the newer devices we recommend downloading and installing the repackaged version of the TI toolchain from gnutoolchains.com that includes all necessary device definitions for VisualGDB:01-toolchainOnce it’s installed, follow the steps below:

  1. Start Visual Studio, select “File->New->Project”. Then select “Visual C++->VisualGDB->VisualGDB Embedded Project Wizard”.02-prj Please avoid spaces in directory names, as GDB does not support it.
  2. On the first page of the wizard proceed with the default settings and click “Next”:03-bin

     

  3. Select “MSP430″ from the toolchain list. If the MSP430 toolchain has not been installed before, VisualGDB will download and install it automatically. You can also download it yourself from http://gnutoolchains.com/msp430. Then select the MCU type that you want to target. The EZ430-RF2500 kit has the msp430f2274 MCU. The LaunchPad board comes with msp430g2553. You can use the “Filter” textbox to simplify finding the right MCU:
  4. 04-deviceOn the next page enter the location of the LED. The EZ430-RF2500 and LaunchPad have a LED connected to P1.0, so the default settings will work.05-sample

     

  5. On the debug settings page select “JTAG (gdbproxy++)”.06-debugPress Finish when done.
  6.  

    Congratulations! You have created a Visual Studio project for a simple MSP430 firmware. Press Ctrl+Shift+B or select Build->Build Solution to build the project.

  7. 07-sectionsIf you are using the TI toolchain, VisualGDB will warn you that the toolchain does not support the -ffunction-settings flag. Open VisualGDB Project Properties and remove the flag from both CFLAGS and CXXFLAGS:08-nosections
  8. Then remove the error directive from the main file. The project should now build successfully:09-build
  9. To start debugging, put a breakpoint on the line assigning P1OUT, connect your device to the USB port and start the debug session by pressing F5. When the breakpoint is hit, open the Hardware Registers window via Debug->Windows->Hardware Registers:10-out

     

  10. Step over the assignment line and observe how the register value in the Hardware Registers window got changed:11-toggledYou can step through your program, modify variable values, change next statement, just like you are debugging a Windows application. When done, press Shift+F5 to stop debugging.
  11. The MSP430 header files heavily rely on the complex preprocessor macros. You can simplify understanding them by right-clicking on the lines using them and selecting “Preprocess selected lines”. E.g. you can expand the ‘sfrb’ macro and quickly understand how the P1OUT variable is defined:12-prepro