MSP 430 Gccuserguide
MSP 430 Gccuserguide
MSP430 GCC
This manual describes the setup and basic operation of the MSP430™ GCC compiler and the software
development environment.
Contents
1 Introduction ................................................................................................................... 6
2 Installing MSP430 GCC Compiler ......................................................................................... 6
2.1 Installing MSP430 GCC in CCS Releases Before v7.2........................................................ 7
2.2 Installing MSP430 GCC as Stand-Alone Package ............................................................. 9
3 Using MSP430 GCC Within CCS ........................................................................................ 10
3.1 Create New Project ............................................................................................... 10
3.2 Debug Using MSP-FET, MSPFET430UIF, eZ-FET, eZ430 ................................................. 11
3.3 Build Options for MSP430 GCC ................................................................................. 11
3.4 Change an Existing CCS project That Uses TI Compiler to MSP430 GCC ............................... 30
3.5 Create a New CDT Project Using MSP430 GCC ............................................................. 30
3.6 GDB With MSP430 and CCSv6 ................................................................................. 30
3.7 CCS Compared to MSP430 GCC ............................................................................... 30
4 MSP430 GCC Stand-Alone Package .................................................................................... 31
4.1 MSP430 GCC Stand-Alone Packages ......................................................................... 31
4.2 Package Content .................................................................................................. 32
4.3 MSP430 GCC Options............................................................................................ 33
4.4 MSP430 Built-in Functions ....................................................................................... 35
4.5 MSP430 GCC Interrupts Definition ............................................................................. 36
4.6 Using MSP430 GCC Support Files ............................................................................. 36
4.7 Quick Start: Blink the LED ....................................................................................... 37
4.8 GDB Settings ...................................................................................................... 39
4.9 Hints for Reducing the Size of MSP430-GCC Programs .................................................... 41
5 Building MSP430 GCC From Sources .................................................................................. 43
5.1 Required Tools .................................................................................................... 43
5.2 Building MSP430 GCC (Mitto Systems Limited) .............................................................. 43
5.3 Building MSP430 GCC Stand-Alone Full Package ........................................................... 44
6 MSP430 GCC and MSPGCC ............................................................................................. 45
6.1 Calling Convention ................................................................................................ 45
6.2 Other Portions of the ABI......................................................................................... 45
7 Appendix..................................................................................................................... 46
7.1 GCC Intrinsic Support ............................................................................................ 46
7.2 GCC Function Attribute Support................................................................................. 47
7.3 GCC Data Attribute Support ..................................................................................... 47
7.4 GCC Section Attribute Support .................................................................................. 47
7.5 NOP Instructions Required Between Interrupt State Changes .............................................. 48
8 References .................................................................................................................. 48
List of Figures
1 MSP430 GCC With CCS Installer ......................................................................................... 7
2 MSP430 GCC With CCS Installer ......................................................................................... 7
3 Installing MSP430 GCC Through CCS Apps Center ................................................................... 8
4 MSP430 GCC Stand-Alone Package Installer ........................................................................... 9
List of Tables
1 MSP430 TI and GCC Compilers Comparison ........................................................................... 6
2 MSP430 GCC Settings .................................................................................................... 12
3 MSP430 GCC Settings: Runtime ........................................................................................ 13
4 MSP430 GCC Settings: Symbols ........................................................................................ 14
5 MSP430 GCC Settings: Directories...................................................................................... 15
6 MSP430 GCC Settings: Optimization ................................................................................... 16
7 MSP430 GCC Settings: Preprocessor .................................................................................. 17
8 MSP430 GCC Settings: Assembler ...................................................................................... 18
9 MSP430 GCC Settings: Debugging ..................................................................................... 19
10 MSP430 GCC Settings: Diagnostic Options ............................................................................ 20
11 MSP430 GCC Settings: Miscellaneous ................................................................................. 21
12 MSP430 GCC Linker Settings ............................................................................................ 22
13 MSP430 GCC Linker Basic Settings .................................................................................... 23
14 MSP430 GCC Linker Libraries Settings ................................................................................. 24
15 MSP430 GCC Linker Symbols Settings ................................................................................. 25
16 MSP430 GCC Linker Miscellaneous Settings .......................................................................... 26
17 MSP430 GCC GNU Objcopy Utility Settings ........................................................................... 27
18 MSP430 GCC GNU Objcopy Utility General Options Settings....................................................... 28
19 MSP430 GCC GNU Objcopy Utility Miscellaneous Settings ......................................................... 29
20 MSP430 GCC Stand-Alone Package.................................................................................... 31
21 MSP430 GCC Command Options ....................................................................................... 33
22 MSP430 GCC Assembler Options ....................................................................................... 35
23 MSP430 GCC Linker Options ............................................................................................ 35
Trademarks
MSP430, Code Composer Studio, E2E, eZ430-Chronos, LaunchPad are trademarks of Texas
Instruments.
macOS is a registered trademark of Apple Inc.
Linux is a registered trademark of Linus Torvalds.
Windows is a registered trademark of Microsoft Corporation.
All other trademarks are the property of their respective owners.
Related Documentation
The primary sources of MSP430 information are the device-specific data sheets and user's guides. The
MSP430 website contains the most recent version of these documents.
The GCC documentation can be found at http://www.gnu.org. All related information for the MSP430 GCC
compiler is available at http://www.ti.com/tool/msp430-gcc-opensource.
Documents that describe the Code Composer Studio tools (CCS IDE, assembler, C compiler, linker, and
librarian) can be found at http://www.ti.com/tool/ccstudio. A CCS-specific Wiki page (FAQ) and the TI
E2E™ Community support forums provide additional help.
MSP430 GCC documentation
Using the GNU Compiler Collection, Richard M. Stallman (http://gcc.gnu.org/onlinedocs/gcc.pdf). Refer
to the MSP430 Options section.
GDB: The GNU Project Debugger, Free Software Foundation, Inc.
(https://sourceware.org/gdb/current/onlinedocs/)
GCC for MSP430™ Microcontrollers Quick Start Guide
Calling Convention and ABI Changes in MSP GCC
CCS documentation
MSP430™ Assembly Language Tools User's Guide
MSP430™ Optimizing C/C++ Compiler User's Guide
Code Composer Studio™ IDE for MSP430™ MCUs User's Guide
MSP430 development tools documentation
MSP430™ Hardware Tools User's Guide
eZ430-F2013 Development Tool User's Guide
eZ430-RF2480 User's Guide
eZ430-RF2500 Development Tool User's Guide
eZ430-RF2500-SEH Development Tool User's Guide
eZ430-Chronos™ Development Tool User's Guide
MSP-EXP430G2 LaunchPad™ Development Kit User's Guide
Advanced debugging using the enhanced emulation module (EEM) with Code Composer Studio IDE
MSP430 device data sheets
MSP430 device family user's guides
MSP430x1xx Family User's Guide
MSP430x2xx Family User's Guide
MSP430x3xx Family User's Guide
MSP430F4xx Family User's Guide
MSP430F5xx and MSP430F6xx Family User's Guide
MSP430FR4xx and MSP430FR2xx Family User's Guide
1 Introduction
TI has partnered with Mitto Systems Limited (http://www.mittosystems.com) to bring you a new and fully
supported open-source compiler as the successor to the community driven MSPGCC. The MSP430 GCC
uses the MSP430 ABI and is compatible with the TI compiler. This free GCC compiler supports all
MSP430 devices and has no code size limit. In addition, this compiler can be used as a stand-alone
package or used within Code Composer Studio (CCS) IDE v6.0 or later. Get started today in Windows,
Linux, or macOS environments.
Table 1 compares the MSP430 TI and GCC compilers.
2. If CCS is already installed without MSP430 GCC, MSP430 GCC can be added at a later time through
the CCS Apps Center (see Figure 3).
1. Go to the menu View → CCS App Center.
2. Select MSP430 GCC
3. Click the Install Software button to start the installation.
3. The GCC compiler tools are installed to the following directory in the CCS installation:
ccsv6\tools\compiler\gcc_msp430_x.x.x (where xxx denotes the version number).
2. Select the install directory and click Next (see Figure 5).
NOTE: For the Linux installer, apply sudo chmod +x <installer> before executing the package.
5. If you are using a USB Flash Emulation Tool such as the MSP-FET, MSP-FET430UIF, eZ-FET, or the
eZ430 Development Tool, they should be already configured by default.
6. For C projects, the setup is complete now.
7. Click Finish to create a new project that is then visible in the Project Explorer view.
Notice that the project contains a .ld file (appropriate for the target selected). This is the linker script
that contains the memory layout and section allocation. This file is the equivalent of the TI linker
command file (.cmd) used by TI MSP430 Compiler and Linker.
8. Enter the program code into the main.c file.
10 MSP430 GCC SLAU646E – September 2015 – Revised June 2019
Submit Documentation Feedback
Copyright © 2015–2019, Texas Instruments Incorporated
www.ti.com Using MSP430 GCC Within CCS
To use an existing source file for the project, click Project → Add Files... and browse to the file of
interest. Single click on the file and click Open or double-click on the file name to complete the addition
of it into the project folder.
Now add the necessary source files to the project and build. Similar to TI tools, additional compiler and
linker options can be set from Project Properties.
9. Build the project (Project → Build Project).
10. Debug the application (Run → Debug (F11)). This starts the debugger, which gains control of the
target, erases the target memory, programs the target memory with the application, and resets the
target.
11. Click Run → Resume (F8) to start the application.
12. Click Run → Terminate to stop the application and to exit the debugger. CCS automatically returns to
the C/C++ view (code editor).
optimizations that don't interfere with debugging. The -Og option reduces code size and improves
performance compared to -O0.
• Specify the search paths for the C preprocessor (Project → Properties → Build → GNU Compiler →
Directories → Include Paths (-I)).
• Specify the search paths for any libraries being used (Project → Properties → Build → GNU Linker
→ Libraries → Library search path (-L, --library-path)).
• Specify the debugger interface (Project → Properties → General → Device → Connection). Select
TI MSP430 USBx for the USB interface.
• Enable the erasure of the Main and Information memories before object code download (Project →
Properties → Debug → MSP430 Properties → Download Options → Erase Main and Information
Memory).
• To ensure proper stand-alone operation, select Hardware Breakpoints (Project → Properties →
Debug → MSP430 Properties). If Software Breakpoints are enabled (Project → Properties →
Debug → Misc/Other Options → Allow software breakpoints to be used), ensure proper
termination of each debug session while the target is connected. Otherwise, the target may not work
as expected stand-alone as the application on the device still contains the software breakpoint
instructions.
Table 2 describes the options that are available for MSP430 GCC Settings.
Table 3 describes the options that are available for MSP430 GCC Runtime settings.
Table 4 describes the options that are available for MSP430 GCC Symbols settings.
Table 5 describes the options that are available for MSP430 GCC Directories settings.
Table 6 describes the options that are available for MSP430 GCC Optimization settings.
NOTE: Use the -ffunction-sections and -fdata-sections options in conjunction with the --gc-sections
linker option to reduce code size by allowing the linker to remove unused sections.
Table 7 describes the options that are available for MSP430 GCC Preprocessor settings.
Table 8 describes the options that are available for MSP430 GCC Assembler settings.
Table 9 describes the options that are available for MSP430 GCC Debugging settings.
Table 10 describes the options that are available for MSP430 GCC Diagnostic Options settings.
Table 11 describes the options that are available for MSP430 GCC Miscellaneous settings.
Table 12 describes the options that are available for MSP430 GCC Linker settings.
Table 13 describes the options that are available for MSP430 GCC Linker Basic settings.
Table 14 describes the options that are available for MSP430 GCC Linker Libraries settings.
Table 15 describes the options that are available for MSP430 GCC Linker Symbols settings.
Table 16 describes the options that are available for MSP430 GCC Linker Miscellaneous settings.
Table 17 describes the options that are available for GNU Objcopy Utility.
Figure 24 shows the MSP430 GCC GNU Objcopy Utility General Options settings window.
Figure 24. MSP430 GCC GNU Objcopy Utility General Options Settings
Table 18 describes the options that are available for GNU Objcopy Utility General Options.
Table 18. MSP430 GCC GNU Objcopy Utility General Options Settings
Option Description
Specify output file name Specifies the output file name
-I bfdname
Assume input file is in format <bfdname> --input-target=bfdname
(-I, --input-target) Consider the source file's object format to be bfdname, rather than attempting to
deduce it.
-O bfdname
Create an output file in format <bfdname>
--output-target=bfdname
(-O, --output-target)
Write the output file using the object format bfdname.
-B bfdarch
Set output arch, when input is arch-less --binary-architecture=bfdarch
(-B, --binary-architecture) Useful when transforming an architecture-less input file into an object file. In this case
the output architecture can be set to bfdarch.
Convert debugging information, if possible Convert debugging information, if possible. This is not the default because only certain
(--debugging) debugging formats are supported, and the conversion process can be time consuming.
Copy modified/access timestamps to the Set the access and modification dates of the output file to be the same as those of the
output (-p, --preserve-dates) input file.
Table 18. MSP430 GCC GNU Objcopy Utility General Options Settings (continued)
Option Description
-R sectionpattern
--remove-section=sectionpattern
Remove section <name> from the output Remove any section matching sectionpattern from the output file. This option may be
(-R, --remove-section) given more than once. Note that using this option inappropriately may make the output
file unusable. Wildcard characters are accepted in sectionpattern. Using the -j and -R
options together results in undefined behavior.
Remove all symbol and relocation
Do not copy relocation and symbol information from the source file.
information (-S, --strip-all)
Remove all debugging symbols sections
Do not copy debugging symbols or sections from the source file.
(-g, --strip-debug)
Remove all symbols not needed by
Strip all symbols that are not needed for relocation processing.
relocations (--strip-unneeded)
Set the start address to <addr> Set the start address of the new file to the specified value. Not all object file formats
(--set-start) support setting the start address.
Verbose output: list all object files modified. In the case of archives, 'objcopy -V' lists all
List all object files modified (-v, --verbose)
members of the archive.
Figure 25 shows the MSP430 GCC GNU Objcopy Utility Miscellaneous settings window.
Table 19 describes the options that are available for GNU Objcopy Utility Miscellaneous.
3.4 Change an Existing CCS project That Uses TI Compiler to MSP430 GCC
An existing CCS project that uses the TI compiler can be changed to use MSP430 GCC. Visit Using
MSP430-GCC with CCSv6 for more details.
– lib
– libexec
– msp430-elf
• lib
• libatomic
• libgcc
• libssp
• libstdC++-v3
• libbacktrace
• libgcc-math
• libgloss
• libiberty
• libsanitizer
• newlib
– msp430.dat
– GCC_xx_manifest.pdf
Most assembler and linker options specific to MSP430 are passed automatically by the GCC wrapper,
depending on the options passed to GCC itself. Table 22 and Table 23 list options that control behavior
specific to the assembler and linker.
When passing an option to the assembler via the GCC wrapper (msp430-elf-gcc), the option must be
prefixed with “-Wa,”. For example, to pass -mU to the assembler, you would pass -Wa,-mU to msp430-elf-
gcc.
The assembler emits warnings when instructions to enable or disable interrupts are used without
surrounding NOP instructions. See Section 7.5 for details. This behavior can be modified using the options
in Table 22.
When passing options to the linker via the GCC wrapper (msp430-elf-gcc), the option must be prefixed
with “-Wl,”. For example, to pass --disable-sec-transformation to the linker, you would pass
-Wl,--disable-sec-transformation to msp430-elf-gcc.
NOTE: The toolchain stops searching for support files once it finds devices.csv. The results may
be different than expected if one of the higher-precedence methods finds out-of-date support
files, despite newer support files being pointed to by one of the lower-precedence methods.
4.7.3 Debugging
GCC_DIR = ../../../bin
SUPPORT_FILE_DIRECTORY = ../../../include
all: ${OBJECTS}
$(CC) $(CFLAGS) $(LFLAGS) $? -o $(DEVICE).out
debug: all
$(GDB) $(DEVICE).out
4.9.3 Making Large Programs Fit Across Upper and Lower Memory
For MSP430X devices with an “upper” memory region (memory above the 0xFFFF boundary), the large
memory model (-mlarge) is supported.
When a program built using the large memory model is too big to fit in the lower memory region
exclusively, rebuilding the program with -mcode-region=either and -mdata-region=either can help it to fit.
See Table 21 for details on how the "either" options shuffle code and data sections between upper and
lower memory. For best results, use these options with the -ffunction-sections and -fdata-sections options,
so that the sections available to be shuffled are smaller.
When using -mlarge with -mcode-region=either and -mdata-region=either, the compiler must generate
MSP430X instructions when handling data. This increases code size and reduces performance, so these
options should only be used if necessary—that is, if the program would not otherwise fit on the device.
NOTE: If less than 2 GB of RAM is available during the build, the build may fail.
NOTE: An alternative to this process is to use the "source-patches" tar archive (for example,
msp430-gcc-7.3.0.9-source-patches.tar.bz2) to apply patches to source tars as
released by the upstream community.
Versions 7.3.0.9 and later include a script (README-apply-patches.sh), which downloads
the upstream releases and applies the patches so the sources are ready for building. The
README-build.sh script can then be used to build a native toolchain.
NOTE: You can confirm that a cross-compiler is available for the target host by running
${HOST}-gcc --version. For example:
> x86_64-w64-mingw32-gcc --version
7 Appendix
8 References
1. Using the GNU Compiler Collection, Richard M. Stallman (http://gcc.gnu.org/onlinedocs/gcc.pdf). Refer
to the MSP430 Options section.
2. GDB: The GNU Project Debugger, Free Software Foundation, Inc.
(https://sourceware.org/gdb/current/onlinedocs/)
Revision History
NOTE: Page numbers for previous revisions may differ from page numbers in the current version.
Changes from March 30, 2019 to June 30, 2019 ............................................................................................................. Page
TI PROVIDES TECHNICAL AND RELIABILITY DATA (INCLUDING DATASHEETS), DESIGN RESOURCES (INCLUDING REFERENCE
DESIGNS), APPLICATION OR OTHER DESIGN ADVICE, WEB TOOLS, SAFETY INFORMATION, AND OTHER RESOURCES “AS IS”
AND WITH ALL FAULTS, AND DISCLAIMS ALL WARRANTIES, EXPRESS AND IMPLIED, INCLUDING WITHOUT LIMITATION ANY
IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT OF THIRD
PARTY INTELLECTUAL PROPERTY RIGHTS.
These resources are intended for skilled developers designing with TI products. You are solely responsible for (1) selecting the appropriate
TI products for your application, (2) designing, validating and testing your application, and (3) ensuring your application meets applicable
standards, and any other safety, security, or other requirements. These resources are subject to change without notice. TI grants you
permission to use these resources only for development of an application that uses the TI products described in the resource. Other
reproduction and display of these resources is prohibited. No license is granted to any other TI intellectual property right or to any third
party intellectual property right. TI disclaims responsibility for, and you will fully indemnify TI and its representatives against, any claims,
damages, costs, losses, and liabilities arising out of your use of these resources.
TI’s products are provided subject to TI’s Terms of Sale (www.ti.com/legal/termsofsale.html) or other applicable terms available either on
ti.com or provided in conjunction with such TI products. TI’s provision of these resources does not expand or otherwise alter TI’s applicable
warranties or warranty disclaimers for TI products.
Mailing Address: Texas Instruments, Post Office Box 655303, Dallas, Texas 75265
Copyright © 2019, Texas Instruments Incorporated