Download IAR Workbench MSP430 and more Lecture notes Electronics in PDF only on Docsity!
C430-
IAR C/C++ Compiler
User Guide
for the Texas Instruments
MSP430 Microcontroller Family
2
IAR C/C++ Compiler User Guide for MSP
COPYRIGHT NOTICE
© 1996–2017 IAR Systems AB. No part of this document may be reproduced without the prior written consent of IAR Systems AB. The software described in this document is furnished under a license and may only be used or copied in accordance with the terms of such a license.
DISCLAIMER
The information in this document is subject to change without notice and does not represent a commitment on any part of IAR Systems. While the information contained herein is assumed to be accurate, IAR Systems assumes no responsibility for any errors or omissions. In no event shall IAR Systems, its employees, its contractors, or the authors of this document be liable for special, direct, indirect, or consequential damage, losses, costs, charges, claims, demands, claim for lost profits, fees, or expenses of any nature or kind.
TRADEMARKS
IAR Systems, IAR Embedded Workbench, IAR Connect, C-SPY, C-RUN, C-STAT, IAR Visual State, visualSTATE, IAR KickStart Kit, I-jet, I-jet Trace, I-scope, IAR Academy, IAR, and the logotype of IAR Systems are trademarks or registered trademarks owned by IAR Systems AB. Microsoft and Windows are registered trademarks of Microsoft Corporation. Texas Instruments is a registered trademark of Texas Instruments Corporation. MSP is a trademark of Texas Instruments Corporation. Adobe and Acrobat Reader are registered trademarks of Adobe Systems Incorporated. All other product names are trademarks or registered trademarks of their respective owners.
EDITION NOTICE
Thirteenth edition: November 2017 Part number: C430- This guide applies to version 7.x of IAR Embedded Workbench® for the Texas Instruments MSP430 microcontroller family. Internal reference: M23, Mym8.0, docsrc-6.10, V_140324, IMAE.
4
5
Contents
8
10
Contents
Contents
14
16
Contents
Contents
20
- Tables Brief contents
- Preface
- Part 1. Using the compiler
- Introduction to the IAR build tools
- Developing embedded applications
- Data storage
- Functions
- Linking overview
- Linking your application
- The DLIB runtime environment
- The CLIB runtime environment
- Assembler language interface
- Using C
- Using C++
- Application-related considerations
- Efficient coding for embedded applications
- Part 2. Reference information
- External interface details
- Compiler options
- Data representation
- Extended keywords
- for MSP IAR C/C++ Compiler User Guide
- Pragma directives
- Intrinsic functions
- The preprocessor
- C/C++ standard library functions
- Segment reference
- The stack usage control file
- Implementation-defined behavior for Standard C
- Implementation-defined behavior for C89
- Index
- Tables Contents
- Preface
- Who should read this guide
- Required knowledge
- How to use this guide
- What this guide contains
- Part 1. Using the compiler
- Part 2. Reference information
- Other documentation
- User and reference guides
- The online help system
- Further reading
- Web sites
- Document conventions
- Typographic conventions
- Naming conventions
- Part 1. Using the compiler
- Introduction to the IAR build tools
- The IAR build tools—an overview
- IAR C/C++ Compiler
- IAR Assembler
- The IAR XLINK Linker
- External tools
- IAR language overview
- Device support
- Supported MSP430 devices
- Preconfigured support files
- Examples for getting started
- for MSP IAR C/C++ Compiler User Guide
- Special support for embedded systems
- Extended keywords
- Pragma directives
- Predefined symbols
- Accessing low-level features
- Developing embedded applications
- Developing embedded software using IAR build tools
- CPU features and constraints
- Mapping of memory
- Communication with peripheral units
- Event handling
- System startup
- Real-time operating systems
- The build process—an overview
- The translation process
- The linking process
- After linking
- Application execution—an overview
- The initialization phase
- The execution phase
- The termination phase
- Building applications—an overview
- Basic project configuration
- Processor configuration
- Data model (MSP430X only)
- Code model (MSP430X only)
- Size of double floating-point type
- Optimization for speed and size
- Normal or position-independent code
- Data storage
- Introduction
- Different ways to store data
- Memory types (MSP430X only)
- Introduction to memory types
- Using data memory attributes
- Pointers and memory types
- Structures and memory types
- More examples
- C++ and memory types
- Data models
- Specifying a data model
- Storage of auto variables and parameters
- The stack
- Dynamic memory on the heap
- Potential problems
- Functions
- Function-related extensions
- Code models (MSP430X only)
- The Small code model
- The Large code model
- Comparing the code models
- programming Primitives for interrupts, concurrency, and OS-related
- Interrupt functions
- Monitor functions
- Execution in RAM
- Position-independent code and read-only data
- Drawbacks and limitations
- Initialization of pointers
- Non-ROPI code in ROPI systems
- Inlining functions
- C versus C++ semantics
- Features controlling function inlining
- for MSP IAR C/C++ Compiler User Guide
- Linking overview
- Linking—an overview
- Segments and memory
- What is a segment?
- The linking process in detail
- Placing code and data—the linker configuration file
- The contents of the linker configuration file
- Initialization at system startup
- Static data memory segments
- The initialization process
- Stack usage analysis
- Introduction to stack usage analysis
- Performing a stack usage analysis
- Result of an analysis—the map file contents
- Specifying additional stack usage information
- Limitations
- Situations where warnings are issued
- Call graph log
- Linking your application
- Linking considerations
- Placing segments
- Placing data
- Setting up stack memory
- Setting up heap memory
- Placing code
- Keeping modules
- Keeping symbols and segments
- Application startup
- Interaction between XLINK and your application
- Producing other output formats than UBROF
- Verifying the linked result of code and data placement
- Segment too long errors and range errors
- Linker map file
- Checking module consistency
- Runtime model attributes
- Using runtime model attributes
- Predefined runtime attributes
- The DLIB runtime environment
- Introduction to the runtime environment
- Runtime environment functionality
- Briefly about input and output (I/O)
- Briefly about C-SPY emulated I/O
- Briefly about retargeting
- Setting up the runtime environment
- Setting up your runtime environment
- Retargeting—Adapting for your target system
- Overriding library modules
- Customizing and building your own runtime library
- Additional information on the runtime environment
- Runtime library configurations
- Prebuilt runtime libraries
- Formatters for printf
- Formatters for scanf
- The C-SPY emulated I/O mechanism
- Math functions
- The Texas Instruments MathLib library
- System startup and termination
- System initialization
- The DLIB low-level I/O interface
- abort
- clock
- __close
- __exit
- getenv
- __getzone
- __lseek
- for MSP IAR C/C++ Compiler User Guide
- __open
- raise
- __read
- remove
- rename
- _ReportAssert
- signal
- system
- __time32, __time64
- __write
- Configuration symbols for printf and scanf
- Configuration symbols for file input and output
- Locale
- Strtod
- Hardware multiplier support
- MPU/IPE support
- Managing a multithreaded environment
- Multithread support in the DLIB runtime environment
- Enabling multithread support
- TLS in the linker configuration file
- The CLIB runtime environment
- Using a prebuilt runtime library
- Choosing a runtime library
- Runtime library filename syntax
- Input and output
- Character-based I/O
- Formatters used by printf and sprintf
- Formatters used by scanf and sscanf
- System startup and termination
- System startup
- System termination
- Overriding default library modules
- Customizing system initialization
- C-SPY emulated I/O
- The debugger Terminal I/O window
- Termination
- Hardware multiplier support
- MPU/IPE support
- Assembler language interface
- Mixing C and assembler
- Intrinsic functions
- Mixing C and assembler modules
- Inline assembler
- Reference information for inline assembler
- An example of how to use clobbered memory
- Calling assembler routines from C
- Creating skeleton code
- Compiling the skeleton code
- Calling assembler routines from C++
- Calling convention
- Choosing a calling convention
- Function declarations
- Using C linkage in C++ source code
- Preserved versus scratch registers
- Function entrance
- Function exit
- Restrictions for special function types
- Examples
- Assembler instructions used for calling functions
- Normal (non-ROPI) code
- Position-independent code and read-only data
- Interrupt functions
- Module consistency
- Memory access methods
- The data16 memory access method
- The data20 memory access method
- for MSP IAR C/C++ Compiler User Guide
- Call frame information
- CFI directives
- Creating assembler source with CFI support
- Using C
- C language overview
- Extensions overview
- Enabling language extensions
- IAR C language extensions
- Extensions for embedded systems programming
- Relaxations to Standard C
- Using C++
- Overview—EC++ and EEC++
- Embedded C++
- Extended Embedded C++
- Enabling support for C++
- EC++ feature descriptions
- Using IAR attributes with Classes
- Function types
- New and Delete operators
- Using static class objects in interrupts
- Using New handlers
- Templates
- Debug support in C-SPY
- EEC++ feature description
- Templates
- Variants of cast operators
- Mutable
- Namespace
- The STD namespace
- C++ language extensions
- Application-related considerations
- Stack considerations
- Stack size considerations
- Heap considerations
- Heap segments in DLIB
- Heap segments in CLIB
- Heap size and standard I/O
- Interaction between the tools and your application
- Checksum calculation for verifying image integrity
- Briefly about checksum calculation
- Calculating and verifying a checksum
- Troubleshooting checksum calculation
- Efficient coding for embedded applications
- Selecting data types
- Using efficient data types
- Floating-point types
- Alignment of elements in a structure
- Anonymous structs and unions
- Controlling data and function placement in memory
- Data placement at an absolute location
- Data and function placement in segments
- Controlling compiler optimizations
- Scope for performed optimizations
- Multi-file compilation units
- Optimization levels
- Speed versus size
- Fine-tuning enabled transformations
- Facilitating good code generation
- Writing optimization-friendly source code
- Saving stack space and RAM memory
- Function prototypes
- Integer types and bit negation
- Protecting simultaneously accessed variables
- for MSP IAR C/C++ Compiler User Guide
- Accessing special function registers
- Non-initialized variables
- Efficient switch statements
- Part 2. Reference information
- External interface details
- Invocation syntax
- Compiler invocation syntax
- Passing options
- Environment variables
- Include file search procedure
- Compiler output
- Error return codes
- Diagnostics
- Message format
- Severity levels
- Setting the severity level
- Internal error
- Compiler options
- Options syntax
- Types of options
- Rules for specifying parameters
- Summary of compiler options
- Descriptions of compiler options
- --c89
- --char_is_signed
- --char_is_unsigned
- --clib
- --code_model
- --core
- -D
- --data_model
- --debug, -r
- --dependencies
- --diag_error
- --diag_remark
- --diag_suppress
- --diag_warning
- --diagnostics_tables
- --discard_unused_publics
- --dlib
- --dlib_config
- --double
- -e
- --ec++
- --eec++
- --enable_multibytes
- --enable_restrict
- --error_limit
- -f
- --guard_calls
- --header_context
- --hw_workaround
- -I
- -l
- --library_module
- --lock_r4
- --lock_r5
- --macro_positions_in_diagnostics
- --mfc
- --migration_preprocessor_extensions
- --module_name
- --multiplier
- --no_call_frame_info
- --no_code_motion
- --no_cse
- for MSP IAR C/C++ Compiler User Guide
- --no_inline
- --no_path_in_file_macros
- --no_rw_dynamic_init
- --no_size_constraints
- --no_static_destruction
- --no_system_include
- --no_tbaa
- --no_typedefs_in_diagnostics
- --no_ubrof_messages
- --no_unroll
- --no_warnings
- --no_wrap_diagnostics
- -O
- --omit_types
- --only_stdout
- --output, -o
- --pending_instantiations
- --predef_macros
- --preinclude
- --preprocess
- --public_equ
- --reduce_stack_usage
- --regvar_r4
- --regvar_r5
- --relaxed_fp
- --remarks
- --require_prototypes
- --ropi
- --save_reg20
- --segment
- --silent
- --strict
- --system_include_dir
- --use_c++_inline
- --version
- --vla
- --warn_about_c_style_casts
- --warnings_affect_exit_code
- --warnings_are_errors
- Data representation
- Alignment
- Alignment on the MSP430 microcontroller
- Basic data types—integer types
- Integer types—an overview
- Bool
- The long long type
- The enum type
- The char type
- The wchar_t type
- Bitfields
- Basic data types—floating-point types
- Floating-point environment
- 32-bit floating-point format
- 64-bit floating-point format
- Representation of special floating-point numbers
- Pointer types
- Function pointers
- Data pointers
- Casting
- Structure types
- Alignment of structure types
- General layout
- Packed structure types
- Type qualifiers
- Declaring objects volatile
- Declaring objects volatile and const
- Declaring objects const
- for MSP IAR C/C++ Compiler User Guide
- Data types in C++
- Extended keywords
- General syntax rules for extended keywords
- Type attributes
- Object attributes
- Summary of extended keywords
- Descriptions of extended keywords
- __cc_rom
- __cc_version1
- __cc_version2
- __data16
- __data20
- __interrupt
- __intrinsic
- __monitor
- __no_alloc, __no_alloc16
- __no_alloc_str, __no_alloc_str16
- __no_init
- __no_multiplier
- __no_pic
- __noreturn
- __persistent
- __ramfunc
- __raw
- __regvar
- __root
- __ro_placement
- __save_reg20
- __task
- Pragma directives
- Summary of pragma directives
- Descriptions of pragma directives
- basic_template_matching
- bis_nmi_ie1
- bitfields
- calls
- call_graph_root
- constseg
- data_alignment
- dataseg
- default_function_attributes
- default_variable_attributes
- diag_default
- diag_error
- diag_remark
- diag_suppress
- diag_warning
- error
- include_alias
- inline
- language
- location
- message
- no_epilogue
- object_attribute
- optimize
- pack
- public_equ
- __printf_args
- required
- rtmodel
- __scanf_args
- segment
- STDC CX_LIMITED_RANGE
- STDC FENV_ACCESS
- STDC FP_CONTRACT
- type_attribute
- for MSP IAR C/C++ Compiler User Guide
- unroll
- vector
- weak
- Intrinsic functions
- Summary of intrinsic functions
- Descriptions of intrinsic functions
- _bcd_add type
- __bic_SR_register
- __bic_SR_register_on_exit
- __bis_GIE_interrupt_state
- __bis_SR_register
- __bis_SR_register_on_exit
- __code_distance
- __data16_read_addr
- __data16_write_addr
- __data20_longjmp
- _data20_read type
- __data20_setjmp
- _data20_write type
- __delay_cycles
- __disable_interrupt
- __enable_interrupt
- __even_in_range
- __get_interrupt_state
- __get_R4_register
- __get_R5_register
- __get_SP_register
- __get_SR_register
- __get_SR_register_on_exit
- _low_power_mode n
- __low_power_mode_off_on_exit
- __no_operation
- __op_code