### XLINK Address Space Sharing Example Source: https://updates.iar.com/SuppDB/Public/UPDINFO/013105/430/doc/infocenter/xlink Provides a practical example of the -U command-line option in XLINK, illustrating how to map code and data segments across different address spaces. This example shows the syntax for declaring shared ranges and placing segments within them. ```linker script -U(CODE)4000-5FFF=(DATA)11000-12FFF -P(CODE)MYCODE=4000-5FFF -P(DATA)MYCONST=11000-12FFF ``` -------------------------------- ### Example: Logging Module Linking Process Source: https://updates.iar.com/SuppDB/Public/UPDINFO/013105/430/doc/infocenter/xman This example illustrates the log output for the 'modules' topic, detailing why specific modules were linked. It shows whether a module is a PROGRAM or LIBRARY type, its definitions, and its references. ```text Loading program module c6x(c6x.rXX) weak def : CE weak def : CKCON (suppressed) definition: ce_def definition: ce_init reference : CeCode reference : stretch ``` -------------------------------- ### Example: Logging Used Object Files Source: https://updates.iar.com/SuppDB/Public/UPDINFO/013105/430/doc/infocenter/xman This example demonstrates the log output for the 'files' topic, showing the object files used in the linking process and their order. It includes the filename as specified in the .xcl file or command line, and the actual path of the file used. ```text File myObject.rXX => C:\Users\TestUser\Documents\IAR Embedded Workbench\TestProject\Debug\Obj\myObject.rXX ``` -------------------------------- ### C Code Example for Scatter Loading Initialization Source: https://updates.iar.com/SuppDB/Public/UPDINFO/013105/430/doc/infocenter/xman This C code example illustrates how to implement scatter loading initialization without using assembler. It defines segments, uses pragmas to place functions and segments, and employs `memcpy` to copy code from the ROM-based segment (ROMCODE) to the RAM-based segment (RAMCODE) before execution. It requires the inclusion of `` and IAR-specific pragmas. ```c /* include memcpy */ #include /* declare that there exists 2 segments, RAMCODE and ROMCODE */ #pragma segment="RAMCODE" #pragma segment="ROMCODE" /* place the next function in RAMCODE */ #pragma location="RAMCODE" /* this function is placed in RAMCODE, it does nothing useful, it's just an example of an function copied from ROM to RAM */ int adder(int a, int b) { return a + b; } /* enable IAR extensions, this is necessary to get __sfb and __sfe, it is of course possible to write this function in assembler instead */ #pragma language=extended void init_ram_code() { void * ram_start = __sfb("RAMCODE"); /* start of RAMCODE */ void * ram_end = __sfe("RAMCODE"); /* end of RAMCODE */ void * rom_start = __sfb("ROMCODE"); /* start of ROMCODE */ /* compute the number of bytes to copy */ unsigned long size = (unsigned long)(ram_end) - (unsigned long)(ram_start); /* copy the contents of ROMCODE to RAMCODE */ memcpy( ram_start, rom_start, size ); } /* restore the previous mode */ #pragma language=default int main() { /* copy ROMCODE to RAMCODE, this needs to be done before anything in RAMCODE is called or referred to */ init_ram_code(); /* call the function in RAMCODE */ return adder( 4, 5 ); } ``` -------------------------------- ### Example: Logging Segment Part Inclusion Source: https://updates.iar.com/SuppDB/Public/UPDINFO/013105/430/doc/infocenter/xman This example shows the log output for the 'segments' topic, explaining the inclusion process for segment parts. It covers ROOT segment parts, references from command line/config, and references between segment parts or external labels. ```text `Marking root seg part (5 INTVEC in CSTARTUP)` `Marking references from command line/config (?ABS_ENTRY_MOD)` `Marking external __program_start` `Seg part (6 CSTART in CSTARTUP) <__program_start>` `Marking from seg part (9 CSTART in ?cstart) <__program_start>` `Marking seg part (18 CSTART in ?cstart) ` `Marking external ?reset_vector` `Seg part (0 RESET in ?reset_vector) ` `Marking sfb/sfe on CSTACK)` `Marking from seg part (18 CSTART in ?cstart) ` `Marking external main` ``` -------------------------------- ### XLINK Segment Placement Example Source: https://updates.iar.com/SuppDB/Public/UPDINFO/013105/430/doc/infocenter/xlink This example demonstrates the usage of sequential segment placement in XLINK, specifically addressing potential issues with empty segments and alignment. It shows how to define segment order and alignment to prevent overlaps. The `-Z` option is used for this purpose. ```text -Z(CODE)EMPTY,NON_EMPTY=... ``` -------------------------------- ### XLINK Segment Placement: New Scheme Examples (-Z and -P) Source: https://updates.iar.com/SuppDB/Public/UPDINFO/013105/430/doc/infocenter/xman Illustrates the updated segment placement scheme in XLINK, emphasizing the combined processing of -Z and -P commands. This new scheme allows for more flexible placement by considering previously occupied memory and the order of commands. Examples demonstrate placing segments with strict requirements first, followed by those with more lenient placement needs. ```linker script -Z(DATA)Z1,Z2=0-FF -Z(DATA)A1,A2,A3=0-1FFF ``` -------------------------------- ### XLINK MISRA C Rule Enabling Examples Source: https://updates.iar.com/SuppDB/Public/UPDINFO/013105/430/doc/infocenter/xman Demonstrates various ways to enable specific MISRA C rules using the `--misrac` command-line option in XLINK. Examples cover enabling individual rules, ranges of rules, and predefined sets like 'all' or 'required'. This facilitates targeted MISRA C compliance checks. ```shell --misrac=4,8,12 --misrac=27,12-23,9 --misrac=all --misrac=required ``` -------------------------------- ### Scatter Loading Segment Placement Example Source: https://updates.iar.com/SuppDB/Public/UPDINFO/013105/430/doc/infocenter/xman This example demonstrates how to use segment placement commands with scatter loading. It shows how to define the memory regions for both the ROM-based initializer segment (ROMCODE) and the RAM-based target segment (RAMCODE). The linker reserves space in both RAM and ROM based on these definitions. ```plaintext -QRAMCODE=ROMCODE -Z(DATA)RAM segments,RAMCODE,Other RAM segments=0-1FFF -Z(CODE)ROM segments,ROMCODE,Other ROM segments=4000-7FFF ``` -------------------------------- ### Checksum Generation Examples (-J) Source: https://updates.iar.com/SuppDB/Public/UPDINFO/013105/430/doc/infocenter/xman These examples demonstrate how to use the -J option to calculate checksums. They show variations in algorithm (crc16, crc32), size (2, 4 bytes), flags (complement, mirror), and range specification. ```linker_script -J2,crc16 Calculate a checksum using the _CRC16_ algorithm, create a segment part of size _2_ in the _CHECKSUM_ segment, defining the symbol ___checksum_. All available bytes in the program are included in the calculation. ``` ```linker_script -J2,crc16,2m,lowsum=(CODE)0-FF Calculate a checksum that is the same value as above, except that it is the _mirrored 2's complement_ of the result of the calculation. Create a segment part of size _2_ in the _CHECKSUM_ segment, defining the symbol _lowsum_. Only include bytes that fall into the range _0-FF_ in the _CODE_ address space. ``` ```linker_script -J2,crc16,,highsum,CHECKSUM2,2=(CODE)F000-FFFF;(DATA)FF00-FFFF Calculate a checksum of all bytes that fall in either of the ranges given. Place it into a segment part of size _2_ with alignment _2_ in the _CHECKSUM2_ segment, defining the symbol _highsum_. ``` ```linker_script -J4,crc32,1 Calculate a 4 byte checksum using the generating polynomial 0x4C11DB7 and output the one's complement of the calculated value. ``` -------------------------------- ### Checksum Value Symbol Example (XLINK) Source: https://updates.iar.com/SuppDB/Public/UPDINFO/013105/430/doc/infocenter/xman Example output from XLINK showing the default checksum symbol (`__checksum`) containing the address and the checksum value symbol (`__checksum__value`) containing the calculated checksum. ```text The crc16 checksum for a program is 0x4711 and resides on the address 0x7FFE. The output file will, by default, contain the symbol `__checksum` with the value 0x7FFE and the symbol `__checksum__value` with the value 0x4711. ``` -------------------------------- ### Mirroring Function Examples Source: https://updates.iar.com/SuppDB/Public/UPDINFO/013105/430/doc/infocenter/xman Examples demonstrating the bitwise mirroring of various hexadecimal numbers. Mirroring involves reversing the order of bits in a binary number. ```text mirror(0x8000) = 0x0001 mirror(0xF010) = 0x080F mirror(0x00000002) = 0x40000000 mirror(0x12345678) = 0x1E6A2C48 ``` -------------------------------- ### Checksum Summary Output Example Source: https://updates.iar.com/SuppDB/Public/UPDINFO/013105/430/doc/infocenter/xman Demonstrates the output format for the `--output_checksum_summary` linker option, which provides a summary of checksums in the program. The verbose option includes complete checksum information. ```text IAR Universal Linker V6.1.3.56 Copyright 1987-2014 IAR Systems AB. 245 bytes of CODE memory (+ 179 range fill ) 130 bytes of DATA memory Crc: __checksum 0xaa09 Errors: none Warnings: none ``` -------------------------------- ### XLINK Memory Addressing Example Source: https://updates.iar.com/SuppDB/Public/UPDINFO/013105/430/doc/infocenter/xman Demonstrates how segment addresses are interpreted and how multiple segments can map to the same physical address, leading to potential conflicts. ```assembly -Z(CODE)SEG1=1000-1FFF -Z(CODE)SEG2=2000-2FFF -M(CODE)1000=2000 ``` -------------------------------- ### Byte-by-Byte CRC16 Checksum Initialization Example (XLINK) Source: https://updates.iar.com/SuppDB/Public/UPDINFO/013105/430/doc/infocenter/xman Demonstrates specifying a 2-byte CRC16 checksum with a specific initial value (0x1D0F) using the byte-by-byte algorithm in XLINK. ```bash -J2,crc16,,,,,#0x1D0F ``` -------------------------------- ### XLINK Command-Line Example for Multiple Output Files with C-SPY Debugging Source: https://updates.iar.com/SuppDB/Public/UPDINFO/013105/430/doc/infocenter/xlink Demonstrates how to use XLINK with options for generating multiple output files (-O) and enabling C-SPY debugger support (-rt). It illustrates two scenarios: one where both output files are intended to have C-SPY modules, and another where only the first file is generated with C-SPY support. This helps users understand the implications of combining these options. ```bash xlink -rt -Omotorola=.mot -o output.dXX ... xlink -rt -o output2.dXX ... xlink -Fmotorola -o output2.mot ... ``` -------------------------------- ### Recommended Debugger Settings (Linker Options) Source: https://updates.iar.com/SuppDB/Public/UPDINFO/013105/430/doc/infocenter/xman This section lists recommended linker options for specific CPU architectures and debuggers. The -yspc and related options are used to configure specific debugging features or memory layouts for different microcontrollers, aiding in the setup of development and debugging environments. ```text -yspc ``` ```text -yspcb ``` ```text -y ``` -------------------------------- ### Range Error Example in ARM Project Source: https://updates.iar.com/SuppDB/Public/UPDINFO/013105/430/doc/infocenter/xman This example demonstrates how XLINK presents range errors (error 18) in ARM projects. It details the instruction causing the error, its location, the evaluated symbolic expression, the allowed range, and the operand involved. This provides comprehensive information for diagnosing issues related to branch targets or address requirements. ```text Error[e18]: Range error, ARM branch target is out of range Where $ = vectorSubtraction + 0xC [0x804C] in module "vectorRoutines" (vectorRoutines.r79), offset 0xC in segment part 5, segment NEARFUNC_A What: vectorNormalization - ($ + 8) [0x866B3FC] Allowed range: 0xFDFFFFFC - 0x2000000 Operand: vectorNormalization [0x8673450] in module VectorNorm (vectorNormalization.r79), Offset 0x0 in segment part 0, segment NEARFUNC_V ``` -------------------------------- ### Filler Byte Generation (-H) Source: https://updates.iar.com/SuppDB/Public/UPDINFO/013105/430/doc/infocenter/xman Demonstrates the use of the -H option to fill linker-introduced gaps with a specified hexadecimal string. The example shows how to fill gaps with 'beef'. ```linker_script -Hhexstring Fill all linker-introduced gaps between segment parts with the repeated hexstring. ``` ```linker_script -HBEEF Fill all the gaps with the value 0xbeef. Even bytes will get the value 0xbe, and odd bytes will get the value 0xef. ``` -------------------------------- ### C-SPY Macro for File Input Simulation Source: https://updates.iar.com/SuppDB/Public/UPDINFO/013105/430/doc/infocenter/AdvancedDebugging/SimulatingSerialPortInput/InterruptSimulation_SerialPort This C-SPY macro defines a setup routine that opens a specified text file for reading, simulating input data for the serial port. It prints a message to the Debug Log window upon successful execution. Error handling for file opening is included. ```cspy_macro execUserSetup() { _ _message "execUserSetup() called\n"; _fileHandle = _ _openFile( "$PROJ_DIR$\\InputData.txt", "r" ); if( !_fileHandle ) { _ _message "could not open file" ; } } ``` -------------------------------- ### XLINK Segment Placement Example (Warning 64) Source: https://updates.iar.com/SuppDB/Public/UPDINFO/013105/430/doc/infocenter/xlink Illustrates a segment placement command in XLINK that incorrectly inherits addresses from a previous command in a different address space. This scenario now generates warning 64, and the segment is placed in its intended address space. ```linker script -Z(CODE)SOMECODE=1000-1FFF -Z(DATA)SOMEDATA ``` -------------------------------- ### Mirrored 4-Byte Checksum Initialization Example (XLINK) Source: https://updates.iar.com/SuppDB/Public/UPDINFO/013105/430/doc/infocenter/xman Illustrates specifying a 4-byte checksum with a mirrored initial value (0x2000). The initial value is treated as a 4-byte quantity for mirroring. ```bash -J4,...,m0x2000 ``` -------------------------------- ### Mirrored CRC16 Checksum Initialization Example (XLINK) Source: https://updates.iar.com/SuppDB/Public/UPDINFO/013105/430/doc/infocenter/xman Shows how to specify a 2-byte CRC16 checksum with a mirrored initial value (0x480A). The value is mirrored before being used as the initial checksum value. ```bash -J2,crc16,,,,,m0x480A ``` -------------------------------- ### Stack Usage Analysis Control File Syntax Source: https://updates.iar.com/SuppDB/Public/UPDINFO/013105/430/doc/infocenter/xman Defines the syntax for specifying stack usage in control files (.suc) for XLINK. It includes examples of function call definitions with stack requirements and a check that directive for stack size validation. ```c function foo : (CSTACK 16, RSTACK 4), calls bar : (CSTACK 8, RSTACK 2); check that (maxstack("Program entry", CSTACK) <= size("CSTACK")); ``` ```c check that ((maxstack("Program entry") + maxstack("interrupt") + 10) < size("CSTACK")); ``` -------------------------------- ### Get Stack Pointer Register Intrinsic Function Source: https://updates.iar.com/SuppDB/Public/UPDINFO/013105/430/doc/infocenter/icc430 Adds an intrinsic function to get the current value of the stack pointer register. This function is useful for understanding stack usage and for debugging. ```c unsigned long __get_SP_register(void); ``` -------------------------------- ### Example of Static Anonymous Union Initialization in C Source: https://updates.iar.com/SuppDB/Public/UPDINFO/013105/430/doc/infocenter/icc430 This example demonstrates the correction related to static anonymous unions placed at an absolute address. Previously, this could cause an internal compiler error. The corrected compiler handles this scenario properly. ```c static union { int a; char b; } myUnion @ 0x1000; // ... usage of myUnion ... ``` -------------------------------- ### Example of Static Initialization of Reference Variable in C Source: https://updates.iar.com/SuppDB/Public/UPDINFO/013105/430/doc/infocenter/icc430 This code snippet illustrates a correction where static initialization of a reference variable to an explicit address no longer causes an internal compiler error. The example shows initializing a reference to an integer pointer at address 0x1000. ```c int & x = *(int *)0x1000; ``` -------------------------------- ### XLINK FAR Placement Example Source: https://updates.iar.com/SuppDB/Public/UPDINFO/013105/430/doc/infocenter/xlink This example illustrates the use of FAR placement for code and constant segments in XLINK. The `-Z(FARCODE)` and `-Z(FARCONST)` options allow for placing these segments in non-contiguous memory ranges, which can be important for memory management and optimization. ```text -Z(FARCODE) -Z(FARCONST) ``` -------------------------------- ### __ramfunc Keyword for RAM Execution (C) Source: https://updates.iar.com/SuppDB/Public/UPDINFO/013105/430/doc/infocenter/icc430 Introduces the `__ramfunc` extended keyword, which allows functions to execute from RAM. The startup code handles copying the function's code from flash memory to RAM. ```c __ramfunc void myFunctionInRAM(void) { // Code to be executed from RAM } ``` -------------------------------- ### Assembler Conditional Assembly with IF Block Example Source: https://updates.iar.com/SuppDB/Public/UPDINFO/013105/430/doc/infocenter/a430 This code snippet demonstrates a scenario where crossing an IF block with a partially or completely unresolved condition can lead to internal assembler errors. The example shows a label, a conditional IF statement, an ENDIF, and a subsequent CALL instruction. ```assembly label1: IF $-label1 ENDIF call #label1 ``` -------------------------------- ### Scatter Loading Command Line Syntax (-Q) Source: https://updates.iar.com/SuppDB/Public/UPDINFO/013105/430/doc/infocenter/xman This command-line option specifies an initializer segment for scatter loading. It tells the linker to create a new segment that holds the data content of a specified source segment. This initializer segment is intended to be copied to the target segment at runtime, typically from ROM to RAM. ```plaintext -Qsegment=initializer_segment ``` -------------------------------- ### Assembler Syntax Error Example for Character Escaping Source: https://updates.iar.com/SuppDB/Public/UPDINFO/013105/430/doc/infocenter/a430 This example illustrates a known issue in the IAR Assembler for MSP430 where the character sequences '\'' and '''' within a string literal do not behave as expected, leading to a syntax error. The expected behavior is to generate a single quote character. ```assembly DB '''ABCD' ; Error[0]: Invalid syntax ``` -------------------------------- ### Non-Transitive Address Space Sharing Example Source: https://updates.iar.com/SuppDB/Public/UPDINFO/013105/430/doc/infocenter/xman Illustrates the non-transitive nature of the '-U' address space sharing option. This example shows that overlapping '-U' declarations do not automatically propagate sharing to all involved address ranges. It highlights the need for explicit declarations to ensure correct sharing across multiple address spaces, providing a workaround for such scenarios. ```shell -U(CODE)1000-1FFF=(DATA)20000-20FFF -U(DATA)20000-20FFF=(CONST)30000-30FFF ``` ```shell -U(CODE)1000-1FFF=(CONST)30000-30FFF ``` -------------------------------- ### PxSEL2 Definition Added to io430x21x2.h Source: https://updates.iar.com/SuppDB/Public/UPDINFO/013105/430/doc/infocenter/icc430 Adds the missing definition for `PxSEL2` to the `io430x21x2.h` header file. This ensures that the register for port selection 2 is correctly declared and accessible for devices in the MSP430x21x2 family. ```c // In io430x21x2.h: // Previously, PxSEL2 might have been undeclared. // Now includes: // extern volatile unsigned int PxSEL2; // or similar declaration for the PxSEL2 register. ``` -------------------------------- ### XLINK New Command Line Options Source: https://updates.iar.com/SuppDB/Public/UPDINFO/013105/430/doc/infocenter/xlink This shows the usage of new command-line options introduced in XLINK. The '-q' option disables Relay Function Optimization, and the '-s' option specifies the entry point of an image. ```bash XLINK -q ... XLINK -s ... ``` -------------------------------- ### Configure Linking Log Output (--log) Source: https://updates.iar.com/SuppDB/Public/UPDINFO/013105/430/doc/infocenter/xman Specifies the topics to include in the linking process log. Topics can include files, modules, segments, and printf_scanf_selection. Multiple topics can be specified, separated by commas. ```console --log topic[,topic][,...] ``` -------------------------------- ### Instruction Flow Example (Assembler) Source: https://updates.iar.com/SuppDB/Public/UPDINFO/013105/430/doc/infocenter/cs430 Presents an assembly instruction sequence that was not processed correctly by the IAR MSP430 C-SPY debugger. This snippet represents a problematic flow. ```assembler CLR R13 ADD R13,PC ``` -------------------------------- ### C-SPY Command Line Options for FET Debugger Source: https://updates.iar.com/SuppDB/Public/UPDINFO/013105/430/doc/infocenter/release_notes This snippet details two C-SPY command line options for the FET Debugger driver. `--erase_exclude_all` prevents FRAM from being erased before download, and `--mspdlogfile` enables logging of debug communication to a file for troubleshooting. ```text Syntax: --erase_exclude_all For use with: The C-SPY FET Debugger driver. Description: Use this option to exclude the whole FRAM from erase before downloading. To set this option, use Project >Options>Debugger>Extra Options. Syntax: --mspdlogfile For use with: The C-SPY FET Debugger driver. Description: Use this option to log the debug communication towards msp430.dll during the current debug session. The logged information will be written to the file mspdcom.log. To set this option, use Project >Options>Debugger>Extra Options. ``` -------------------------------- ### Specifying List Output Directory with -L Source: https://updates.iar.com/SuppDB/Public/UPDINFO/013105/430/doc/infocenter/xman Demonstrates the syntax for the -L option, which generates a list file. Using -L with no arguments creates the list file in the current directory. ```command line -L -L ``` -------------------------------- ### C++ Template Self-Inheritance Example - XLINK Source: https://updates.iar.com/SuppDB/Public/UPDINFO/013105/430/doc/infocenter/xlink This C++ code snippet demonstrates a class inheriting from a template of itself, which previously caused XLINK to terminate without an error message. This issue was present in XLINK 4.60A. ```cpp template class A { T* data; }; class B : public A { }; ``` -------------------------------- ### XLINK Output Formats: Simple-code and Raw-binary Source: https://updates.iar.com/SuppDB/Public/UPDINFO/013105/430/doc/infocenter/xman This section describes two new output formats for XLINK: simple-code and raw-binary. Simple-code is a binary format for flash loading, while raw-binary is a pure binary image with no header information. Both are available for all processors. ```plaintext -Fsimple-code -Fraw-binary ``` -------------------------------- ### XLINK Command Line Options for Output and Diagnostics Source: https://updates.iar.com/SuppDB/Public/UPDINFO/013105/430/doc/infocenter/xman This snippet demonstrates command-line options for XLINK related to output format selection (-F), specific output format variants (-y, -Y), and diagnostics control (-w). ```plaintext -F -y -Y -w ``` -------------------------------- ### Watch Expressions for Defines (C/C++) Source: https://updates.iar.com/SuppDB/Public/UPDINFO/013105/430/doc/infocenter/cs430 Illustrates define statements that were not correctly handled when used in the watch window. This shows the format of defines that previously caused issues. ```c #define MAIN_CLOCK 2000000u #define MAIN_CLOCK 2000000uL ``` -------------------------------- ### XLINK Typedef for Anonymous Enumeration Type Example Source: https://updates.iar.com/SuppDB/Public/UPDINFO/013105/430/doc/infocenter/xlink This snippet demonstrates a C++ typedef used to name an anonymous enumeration type. XLINK previously generated a type conflict warning for variables or functions using this type, but this has been resolved. ```cpp typedef enum { a, b } c; ``` -------------------------------- ### Example of Circular Reference Causing IDE Crash Source: https://updates.iar.com/SuppDB/Public/UPDINFO/013105/430/doc/infocenter/ew430 Demonstrates a preprocessor macro that creates a circular reference, leading to an IDE crash. This is a known issue in IAR Embedded Workbench. ```c #define LIST_SIZE (LIST_SIZE*(4+1)) ``` -------------------------------- ### Enable CPU40 Hardware Workaround on Command Line Source: https://updates.iar.com/SuppDB/Public/UPDINFO/013105/430/doc/infocenter/icc430 Enables a workaround for the hardware bug CPU40 on MSP430F5xx and MSP430F6xx devices when using the IAR Embedded Workbench IDE from the command line. This option must be explicitly used to activate the fix. ```text --hw_workaround=CPU40 ``` -------------------------------- ### Linker Option Syntax Correction Source: https://updates.iar.com/SuppDB/Public/UPDINFO/013105/430/doc/infocenter/ew430 Provides the corrected syntax for the `--stack_usage_control` linker option. This correction applies to the IAR Linker and Library Tools Reference Guide. ```bash --stack_usage_control=filename ```