Author Topic: MSP430 Programming with Debugging  (Read 367 times)

Offline glen-the-grey

  • Single posting newcomer
  • *
  • Posts: 1
MSP430 Programming with Debugging
« on: July 22, 2025, 11:05:31 am »
Thought I'd document this in case anyone else is interested but also in case I need to set up my computer again!

First thing to note is that the bundled version of mspdebug with Debian 12 does not work effectively so I had to build one from source.  The version of mspdebug that I'm using is 0.25 (Debian 12 ships with mspdebug 0.22-2+b3 which doesn't work for me)

I also downloaded the latest GCC compiler from Texas Instruments and installed it locally so you'll need to change any of the local paths I've used.  The MSP430 GCC version I'm using is 9.3.1.11

Step 1 - Set Up the Debugger
Go to Settings->Debugger and add a new GDB/CDB debugger, I called mine MSP430-GDB.  Set the "Executable path" to "/home/glen/bin/ti/msp430-gcc/bin/msp430-elf-gdb"

Step 2 - Set Up the Compiler
Next set up the compiler by going to Settings->Compiler, make sure to select "GNU GCC Compiler for MSP430 (HighTec)" then change the following:
  • Search Directories->Compiler, add "/home/glen/bin/ti/msp430-gcc/bin" and "/home/glen/bin/ti/msp430-gcc/include"
  • Search Directories->Linker, add "/home/glen/bin/ti/msp430-gcc/include"
  • Toolchain executables->Compilers installation directory, change to "/home/glen/bin/ti/msp430-gcc/bin"
  • Toolchain executables->Program Files, change the names of the executables and add "-elf-" into each one. (e.g., change "msp430-gcc" to "msp430-elf-gcc")
  • Toolchain executables->Program Files, Debugger, set to MSP430-GDB (created in Step 1)
  • Toolchain executables->Additional Paths, add "/home/glen/bin/ti/msp430-gcc/bin"

Step 3 - Create a Tool to Launch mspdebug
This will create a tool that opens a console window running mspdebug with the gdb server (default to port 2000)

Got to Tools->Configure Tools and create a new tool, I called it "Launch mspdebug" and it should have the following as the executable "/usr/local/bin/mspdebug tilib gdb".  This uses the "tilib" parameter which is the library provided by Texas Instruments.  I need this for the MSP-EXP430G2ET Launchpad but if you are using another launchpad such as the older MSP-EXP430G2 then you might need to change the executable to "/usr/local/bin/mspdebug rf2500 gdb".

Note that to use the tilib option you might have to install libmsp430.so, I think I must have done this by installing the "msp430mcu" package on Debian, although it might have other names on Red Hat based distros.

Step 4 - Create a Project
Use the Wizard to create an MSP430 project, if you are lucky your MCU will be listed in the drop-down list.  If not, select something close and then modify it later by going to Project->Build Options and select the project name (i.e., don't select "Debug" or "Release") then click on "Other compiler options" and enter the appropriate flag for the MCU.  For example mine is "-mmcu=msp430g2553".  Make sure to also [em]deselect[/em] the -mmcu flag from "Compiler Flags"

Step 5 - Configure Project Build Options
Again select Project->Build Options and click on the project name.  Then go to "Pre/post build steps" and add 'mspdebug tilib "prog $(TARGET_OUTPUT_FILE).hex"' (make sure to replace "tilib" with something else depending on your programmer, e.g., it could be rf2500 if using a different Launchpad board.

For completeness my post-build steps are:

msp430-elf-objcopy -O ihex -R .eeprom -R .eesafe $(TARGET_OUTPUT_FILE) $(TARGET_OUTPUT_FILE).hex
msp430-elf-objcopy --no-change-warnings -j .eeprom --change-section-lma .eeprom=0 -O ihex $(TARGET_OUTPUT_FILE) $(TARGET_OUTPUT_FILE).eep.hex
msp430-elf-objdump -h -S $(TARGET_OUTPUT_FILE) > $(TARGET_OUTPUT_FILE).lss
mspdebug tilib "prog $(TARGET_OUTPUT_FILE).hex"


Step 6 - Set the Debugger to use GDB Server
Finally make sure that GDB can connect to the server set up in Step 3.  Go to Project->Properties and scroll along to the Debugger settings.  Click on <project> and set the connection to TCP with the address of "localhost" and the port of "2000"

Using for Development
If all the above works then you should be able to build and program the MSP430 in one step by connecting the programmer/Launchpad to USB and then clicking on the "Build" button in Code::Blocks. 

Then to debug this after programming go to Tools->Launch mspdebug and wait for it to open the connection in a new window and then click on Debug->Start/Continue

Happy coding and hopefully this works for you :-)
« Last Edit: July 22, 2025, 11:09:21 am by glen-the-grey »