0% found this document useful (0 votes)
161 views15 pages

Migration Guide: Migrating From Atmel Studio Toolchain For 8-Bit AVR To IAR Embedded W Orkbench® For AVR

atmel studio to mplab

Uploaded by

Tanvir Khan
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
161 views15 pages

Migration Guide: Migrating From Atmel Studio Toolchain For 8-Bit AVR To IAR Embedded W Orkbench® For AVR

atmel studio to mplab

Uploaded by

Tanvir Khan
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 15

Migration guide

Migrating from Atmel Studio toolchain for 8-bit AVR to IAR Embedded Workbench® for AVR

Use this guide as a guideline when converting source code written for the 8-bit AVR GNU toolchain for 8-bit
AVR to IAR Embedded Workbench® for AVR.

Product Version number


Migrating from Atmel studio 6.2 and newer
Migrating to IAR Embedded Workbench for AVR 6.50 and newer

Migration overview
Converting a project to a different toolchain can be divided into project file conversion and source code conversion. Migrating
an existing project from 8-bit AVR GNU toolchain for 8-bit AVR requires that you collect information about your current
project settings in Atmel Studio and then apply this information to the new IAR Embedded
Workbench for AVR project. In addition, you need to make some changes in the actual source
code. The information in this document is intended to simplify this process.

Note: Basic introduction to IAR Embedded Workbench and how to work in the IDE can be
found in the document Getting Started with IAR Embedded Workbench under
Help>Information Center>Getting Started.

How to use this guide


Start by following the steps outlined in the section Project conversion to make a basic conversion of your project. The section
Building your project helps you configure the project settings. Now, all that remains are source code and linker modifications.
To find the equivalent functionality in IAR Systems’ compiler, assembler and linker for AVR refer to the sections Compiler-
specific details, Assembler-specific details and Linker and library details. If the specific functionality is not mentioned in this
guide you can find complete documentation in the IAR C/C++ Compiler User Guide for AVR found under Help>C/C++
Compiler Reference Guide and in the AVR IAR Assembler Reference Guide found under Help>Assembler Reference Guide.

Project conversion
To migrate existing Atmel Studio AVR applications to IAR Embedded Workbench for AVR use the tool Convert To IAR.
This is a GUI application that can be installed from the web, available via ConvertToIAR.

Part number: Atmel Studio to IAR Embedded Workbench for AVR Page 1 of 15
Migrating from Atmel studio AVR 8-bit to IAR Embedded W orkbench AVR 8-bit

The Convert To IAR tool converts Atmel Studio project


files into IAR Embedded Workbench for AVR project
files without changing the original project file.
Information about source files, include paths, defined
symbols and build configuration is transferred. As an
option, also source code text substitutions are performed
and you can add your own substitution rules including
support for regular expressions.

Procedure
1. Download and install the converter.
2. Double-click the new shortcut Convert To
IAR.
3. Navigate to the Atmel Studio project to convert
by clicking the browse button.
4. Click the Execute button.
5. In the dialog Choose destination directory
select the destination directory for the
converted project. The original source code is
untouched.
6. Start IAR Embedded Workbench for AVR.
7. Add the new project to an IAR Embedded
Workbench for AVR workspace by choosing
Project>Add Existing Project….
8. Edit the code according to the section Basic
code differences below.
9. Continue to the section Building your project
for information about how to configure the
project settings and build the project.
When converting a project, the converter adds a header file called libc_macros.h to your project. It is located in the same
directory as the project file. libc_macros.h contains some defines that are compatible with defines and functions in AVR
Libc. This is basically to make the conversion process a bit easier. This file will only be copied into the destination folder if the
converter found a .cproj in any of the subfolders of the selected source project directory. If one would only want to do the
source code substitution you would also have to copy the file
INSTALL_DIR\avr\config\template\ConvertToIAR\libc_macros.h into your project.
Basic code differences
This table shows some of the basic differences between code written for Atmel studio and IAR Embedded Workbench for AVR
that you need to handle before building your converted project.

Atmel studio IAR Embedded W orkbench


SFR I/O files
#include <avr/io.h> Same:
Points to the specific header file for a device by using the #include <ioavr.h>
-mmcu=processor flag. Register and bit names are almost always fully compatible
between AVR GCC and IAR Embedded Workbench for
AVR.
Interrupt declarations
ISR(OFFSET) #pragma vector=<OFFSET>
{ __interrupt [__nested] void func_name (void)
} {
}
ISR requires <avr/interrupt.h> and the offset is defined in The interrupt vectors automatically included by including
<avr/io.h>. <ioavr.h>.
The interrupt vectors (OFFSET) are fully compatible and no Example:
modifications to these names are required for porting to your #pragma vector=TIMER0_OVF_vect
__interrupt void MotorPWMBottom(void)
application to IAR Embedded Workbench for AVR.
{
}
The vector offset symbol is declared in the device header

Part number Atmel Studio to IAR Embedded Workbench for AVR: Page 2 of 15
Migrating from Atmel studio AVR 8-bit to IAR Embedded W orkbench AVR 8-bit

file.
Intrinsic routines
To use intrinsic functions include: <intrinsics.h>.
Enable interrupt: Enable interrupt:
sei(); (requires <avr/interrupts.h>) __enable_interrupt();
Disable interrupt: Disable interrupt:
__disable_interrupt();
cli(); (requires <avr/interrupts.h>)
Reset watchdog timer:
Reset watchdog timer:
__watchdog_reset();
wdt_reset(); (requires <avr/wdt.h>)
Flash variables
int mydata[] __attribute__ ((progmem)) __flash int mydata[] =....
int mydata[] PROGMEM = ....
Non-returning main()
void main(void) __attribute__((noreturn)); __noreturn void main(void)
{
void main(void) ...
{ }
...
}
Locking registers
register char counter asm(“r15”); Locking registers requires the compiler option
-–lock_regs=N. This is used for locking global variables to
specific registers. N specifies the number of registers. The
locked registers are R15 and downwards.
--lock_regs=1
_regvar __no_init char counter @15;
Using the USART with printf
One way to do this: Overwrite the function:
Define your put char function and link it to the stream. size_t __write(int handle, const unsigned
char * buffer, size_t size);
static int usart_putc(char c, FILE *stream);
Loop the buffer and call your usart_putc(char c);
static FILE stream = FDEV_SETUP_STREAM
(usart_putc, NULL, _FDEV_SETUP_WRITE); printf("Hello World");

1. Initialize the UART The basic implementation of __write can be found under:
2. Write to standard out and standard err. INSTALL_DIR\avr\src\lib\dlib\write.c. More
stdout = &stream; information can be found in the IAR C/C++ Compiler User
stderr = &stream; Guide for AVR.

printf("Hello World");

Building your project


After successfully converting the Atmel Studio project and considered the basic code differences described above, you will still
most likely need to fine-tune parts of the source code so that it follows the IAR Embedded Workbench for AVR syntax.

1. Select your device under Project>Options>General Options>Target.


2. Set the heap size under Project>Options>General Options>Heap Configuration
3. Set the stack size under Project>Options>General Options>System
4. Specify the language under Project>Options>C/C++ Compiler>Language 1
5. Set the optimization level under Project>Options>C/C++ Compiler>Optimizations
6. Set the library configuration under Project>Options>General Options>Library Configuration
If your application uses stdint.h you must use DLIB. Information about library configuration can be found in the
IAR C/C++ Compiler User Guide for AVR in the sections:
Part 1. Using the compiler>The DLIB runtime environment
Part 1. Using the compiler>The CLIB runtime environment
Part 2. Reference information>Library functions
7. Choose Project>Make.
8. To find the different errors/warnings, press F4 (Next Error/Tag).
This will bring you to the location in the source code that generated this error/warning.

Part number Atmel Studio to IAR Embedded Workbench for AVR: Page 3 of 15
Migrating from Atmel studio AVR 8-bit to IAR Embedded W orkbench AVR 8-bit

9. For each error/warning, modify the source code to match the IAR Embedded Workbench for AVR syntax.
Note: See the Reference information section below for this step.
10. After correcting one or more errors/warnings, repeat the procedure.

Note: It is a good idea to first compile the different sources separately and when all sources successfully compile you build the
complete project.
Note: It is always a good idea to correct errors from top to bottom. This is because errors and warnings later in the code can be
a result of errors earlier in the code.

Important tool settings


This is an overview of the most important tool settings. Make sure that they match your original Atmel Studio project.
Atmel studio IAR Embedded W orkbench
Device selection and Memory model

Heap settings

Stack settings

Part number Atmel Studio to IAR Embedded Workbench for AVR: Page 4 of 15
Migrating from Atmel studio AVR 8-bit to IAR Embedded W orkbench AVR 8-bit

Language settings

Defined symbols

Include directories

Part number Atmel Studio to IAR Embedded Workbench for AVR: Page 5 of 15
Migrating from Atmel studio AVR 8-bit to IAR Embedded W orkbench AVR 8-bit

Linker configuration

Additional output format

Note: We recommend that you verify all settings to make sure they match your project needs.

Part number Atmel Studio to IAR Embedded Workbench for AVR: Page 6 of 15
Migrating from Atmel studio AVR 8-bit to IAR Embedded W orkbench AVR 8-bit

Compiler-specific details
Atmel studio IAR Systems
Programming languages
C, C++, Assembler. Supported programming languages:
Assembler, C, Embedded C++, IAR Extended Embedded
C++.

For C the compiler supports many standards. The default is For C, the C99 standard is the default, but C89 can optionally
the GNU dialect of ISO C99. be used. C99 is supported by the library.
Memory models
Supported memory models (option --memory_model):
Specifies the default data pointer size.
Tiny: Address range 0x0-0xFF
Small: Address range 0x0-0xFFFF
Large: Address range 0x0-0xFFFFFF
Huge: Address range 0x0-0xFFFFFF
Overriding default placement of given memory model
__attribute__((section("section-name"))) To override the default placement of the selected memory
model, use any of these memory attributes:
__eeprom, __ext_io, __far, __farflash,
__farfunc, __flash, __huge, __hugeflash, __io,
__near, __nearfunc, __tiny, __tinyflash,

For example:
__flash char str_msg[ ] = "Message1";
__farfunc void myfunction(void);
Absolute placement of variables
To place variables at an absolute address:
volatile int porta __attribute__((address The @ operator or the #pragma location directive.
(0x600))); The variable must be declared using one of these
combinations:
 __no_init
 __no_init const
 const

Examples:
volatile __no_init int porta @ 0x600;

#pragma location=0x600
volatile__no_init int porta;

It is also possible to place variables in named segments. If


the segment is user-defined, it must also be defined in the
linker configuration file using the –Z or the –P option.

#pragma segment ="PORTA"


#pragma location = "PORTA"
volatile __no_init int porta;

In the linker configuration file


-D_..PORTA_START=600
-D_..PORTA_END=601
-Z(DATA)PORTA=_..PORTA_START-_..PORTA_END
Absolute placement of functions
void func(void)
__attribute__((section("MyFunctions")); The @ operator or the #pragma location directive can be
used for placing variables or functions in named segments. If
In the linker configuration file:
the segment is user defined it must also be defined in the
SECTIONS
{ linker configuration file using the –Z or the –P option.
.MY_BLOCK 0x300 :
{ /*Define user segment*/

Part number Atmel Studio to IAR Embedded Workbench for AVR: Page 7 of 15
Migrating from Atmel studio AVR 8-bit to IAR Embedded W orkbench AVR 8-bit

KEEP(*(.MyFunctions)) #pragma segment = "MyFunctions"


} > text
/*Place functions in segments*/
} void func(void) @ "MyFunctions";

void func(void) @ "MyFunctions"


{
}

#pragma location="MyFunctions"
void func(void);

/*Define segment in linker configuration file


*/
-Z(CODE)MyFunctions=0300-03FF
Constants in ROM
#include <avr/pgmspace.h> __flash unsigned int = 5;
const unsigned int PROGMEM = 5;
Interrupt functions
<avr/interrupts.h> #pragma vector = ADC_vect
ISR(ADC_vect) __interrupt void MyInterruptRoutine(void)
{ {
/* Do something here.*/ /* Do something here.*/
} }
Note that an interrupt function must have the return type
void, and it cannot specify any parameters.
Inline assembler
asm volatile("nop\n\t" asm("NOP \n\t"
"nop\n\t" "NOP \n\t"
"nop\n\t" "NOP \n\t"
"nop\n\t" "NOP \n\t");
::);

Atmel studio IAR Systems


Sizes on integers and floating-point
8 bits char 8 bits
16 bits int 16 bits
16 bits short 16 bits
32 bits long 32 bits
64 bits long long 64 bits
32 bits float 32 bits
32 bits double 32 bits or 64 bits depending on project options.
Extended keywords
AVR GCC uses avr-libc instead: Disable interrupts during __monitor void my_function(void)
#include <util/atomic.h> {
function entry.
void my_function(void) /* My code here */
{ }
ATOMIC_BLOCK(ATOMIC_RESTORESTATE)
{
/*My code here */
}
}
#include <avr/eeprom.h> Places the variable in the __eeprom char a;
char EEMEM a;
built-in EEPROM
(overrides default
placement).
char msg[] PROGMEM = “Hello” Places the individual __flash char msg[] = “Hello”;
variables and constants in
flash memory (overrides
the default placement).
#include <avr/interrupt.h> Specifies an interrupt /*Requires an interrupt vector*/
ISR(ADC_vect) #pragma vector= ADC_vect
function.
{ __interrupt void f_int(void)
{
}

Part number Atmel Studio to IAR Embedded Workbench for AVR: Page 8 of 15
Migrating from Atmel studio AVR 8-bit to IAR Embedded W orkbench AVR 8-bit

}
#include <avr/interrupt.h> Sets the interrupt function #pragma vector = ADC_vect
ISR(ADC_vect, ISR_NOBLOCK) __nested __interrupt void func(void)
to a nested interrupt.
{ {
Allows other interrupts to
} trigger while inside this }
interrupt.
int array[10] Places a data object in __no_init int array[10];
__attribute__((section(".noinit")))
non-initialized memory.
;
This means no
initialization of the
variable is done.
void main Informs the compiler that __noreturn void main(void);
(void)__attribute__((noreturn));
the function will not
return (for optimization
purposes).
register char counter asm("r3"); Specify that a global or Allowed registers: R4-R15 provided
they have been locked with the –
static variable should be
lock_regs compiler option.
placed permanently in the
specified register(s). __regvar __no_init
int counter @ 14;

counter is now stored in R15:R14.


void func(void) Specify that a function or __root void func(void);
__attribute__((used));
variable is kept whether
or not it is referenced
from the rest of the
application, provided that
its module is included.
Pragma directives
const int factorySettings[] = Places constants in a named #pragma constseg=[__memoryattribute]
{2,3,49,-10} {SEGMENT_NAME|default}
segment.
__attribute__((section("MY_CONS
TANTS"))); Example:
#pragma constseg=MY_CONSTANTS
const int factorySettings[] =
{2,3,49,-10};
#pragma constseg=default

char My_Array[100] Data alignment #pragma data_alignment=expression


__attribute__((aligned(4))); Expression is a constant that is a power of two.

Example:
/ My_Array start address will be 4
bytes aligned*/
#pragma data_alignment=4
char My_Array[100];

char mybuffer[1000] Place variables in a named #pragma dataseg={SEGMENT_NAME|default}


__attribute__((section
segment.
("MY_DATASEGMENT"))); Example:
#pragma dataseg=MY_DATASEGMENT
__no_init char mybuffer[1000];
#pragma dataseg=default

void func(void) Sets the default segment #pragma


__attribute__((section("MYSEG") default_function_attributes=[attribute
placement, type attributes,
); ..]
and object attributes for
function declarations and attribute can be type_attribute,
definition. object_attribute and @ segment_name.

Example:
/*Place following functions in segment
"MYSEG" */
#pragma default_function_attributes =
@ “MySEG”

Part number Atmel Studio to IAR Embedded Workbench for AVR: Page 9 of 15
Migrating from Atmel studio AVR 8-bit to IAR Embedded W orkbench AVR 8-bit

int fun1(int x){return x + 1;}


int fun2(int x){return x – 1;}
/*Stop placing functions into MYSEG*/
#pragma default_function_attributes=

#if CONFIG_VALUE>10000 Generates a compile error if #pragma error message


#error Reduce the config value.
a code block is parsed.
#endif #if CONFIG_VALUE>10000
#pragma error "Reduce the config
value"
#endif
Intrinsic functions These functions require #include instrinsics.h
void Inserts a time delay. void __delay_cycles(unsigned long);
__builtin_avr_delay_cycles
(unsigned long);
void Disables interrupts. void
__builtin_avr_cli __disable_interrupt
(void); (void);
void Enables interrupts. void
__builtin_avr_sei __enable_interrupt
(void); (void);
int Generates an FMULS signed int
__builtin_avr_fmuls __fractional_multiply_signed
instruction.
(char, (signed char,
char); signed char);
int Generates an FMULSU signed int
__builtin_avr_fmulsu __fractional_multiply_signed_with_unsi
instruction. gned
(char,
unsigned char); (signed char,
signed char);
unsigned int Generates an FMUL unsigned int
__builtin_avr_fmul __fractional_multiply_unsigned
instruction.
(unsigned char, (unsigned char,
unsigned char); unsigned char);
void Inserts a sleep instruction. void
__builtin_avr_sleep __sleep
(void); (void);
unsigned char Swaps bit 0-3 with bit 4-7 unsigned char
__builtin_avr_swap of the parameter and returns __swap_nibbles
(unsigned char); the swapped value. (unsigned char);
void Inserts a watchdog reset void
__builtin_avr_wdr instruction. __watchdog_reset
(void); (void);
Preprocessor symbols
__AVR_ATmega88__ Device symbol Device symbols can be found in ioavr.h.
__ATmega88__

__AVR__HAVE_ELPM__ Symbol to determine __HAS_ELPM__


whether the instruction
ELPM is available or not.
__AVR_ENHANCED__ Symbol to determine __HAS_ENHANCED_CORE__
whether the enhanced
core is used or not.
__AVR_HAVE_MUL__ Symbol to determine __HAS_MUL__
whether the instruction
MUL is available or not.
__AVR_HAVE_RAMPZ__ Symbol to determine __HAS_RAMPZ__
whether the instruction
RAMPZ is available or not.
Compiler options
std=[c90|c++98|gnu90|gnu++98|c99 Sets the language --c89/ --ec++/ --eec++
|gnu99...]
standard
-I<path> Include file directory -I<path>
-morder{1|2} Changes the order of Not supported.

Part number Atmel Studio to IAR Embedded Workbench for AVR: Page 10 of 15
Migrating from Atmel studio AVR 8-bit to IAR Embedded W orkbench AVR 8-bit

register assignment.
-mint8 Set int to be an 8-bit Not supported.
integer.
-O[s|0|1|2|3] Optimization -O[n|l|m|h|hs|hZ]
s – size optimization n – none (Best debug support)
0 – no optimization l – Low (default)
1 – medium, balanced m – medium
2 – high, balanced h – high, balanced
3 – high, speed hs – high favoring speed
hz – high favoring size
-mmcu=MCU type Specifies the device. --cpu=processor
-g Generates debug info. --debug
-funsigned-char Make any unqualified --char_is_unsigned
char type an unsigned
char.
-fpack-struct Pack all structure Default.
members together without
padding.
-W{format} Changes the severity level --diag_error=tag[,tag,...]
-Werror=format --diag_remark=tag[,tag,...]
or turns on/off warnings.
--diag_suppress=tag[,tag,...]
--diag_warning=tag[,tag,...]

Assembler-specific details
Atmel studio IAR Systems
Interrupt functions in assembler
The interrupt labels can be found in the device header file. Interrupt functions should be declared as ROOT so that they
.global tells the linker where to find the interrupt service cannot be discarded by the linker even if no symbols in the
segment are referred to.
routine. So just create your interrupt service routine and Vector table:
declare the label global. EXTERN EINT1
COMMON INTVEC:CODE:ROOT(1)
.global EINT1_vect; ORG 144h
JMP_EINT2:
EINT1_vect: JMP EINT2
reti
Assembler interrupt routine:
PUBLIC EINT2

RSEG CODE:CODE:NOROOT(1)
EINT2:
JMP EINT2
END

Segments/Sections
Code sections are defined using directive: Code segments are defined using the assembler directives
section name [,"flags" ASEG, ASEGN, COMMON, and RSEG, which means absolute,
[,@type[,flag_specific_arguments]]] named absolute, common, and relocatable segments. A
flags: [a|e|w|x|M|S|G|T|?]
STACK segment can also be defined.
types: [@progbits, @nobits, @note] ASEG[start|[(align)]]
ASEGN segment[:type] , address
COMMON segment [:type] [(align)]
RSEG segment[:type] [flag] [(align)]
RSEG segment[:type] , address
STACK segment [:type] , [(align)]

Bit segments cannot be defined explicitly, but can easily be


defined using bit operators in code or data segments. Because
a byte is the smallest allocatable memory segment, no
memory is lost or gained using either tool.
Binary representation

Part number Atmel Studio to IAR Embedded Workbench for AVR: Page 11 of 15
Migrating from Atmel studio AVR 8-bit to IAR Embedded W orkbench AVR 8-bit

Yes supported. Not supported, should be replaced by hexadecimal notation.


Atmel studio IAR Systems
Integer constants
'0b' or '0B' followed by zero or Binary Not supported, should be replaced by
more of the binary digits 0b1010. hexadecimal notation.
A decimal integer starts with a non-zero Octal Not supported, should be replaced by
digit followed by zero or more digits. hexadecimal notation.
052
A decimal integer starts with a non-zero Decimal 42
digit followed by zero or more digits.
42
A hexadecimal integer is ' 0x' or '0X' Hexadecimal 0x2a
0xADA
followed by one or more hexadecimal
digits.
0x2a
0xADA
Assembler directives
CSEG Code segment COMMON:CODE
BYTE n Allocate space for byte(s) DS – 8 bits integers
DS16 – 16 bits integers
DS24 – 24 bits integers
DS32 – 32 bits integers
DS8 – 8 bit integers
DB Define constant bytes DB – 8 bits (including strings)
DC16 - 16 bits
DC24 – 24 bits
DC32 – 32 bits
DC8 – 8 bits (including strings)
DD – 32 bits
DP – 24 bits
DW – 16 bits
ORG Set the location counter ORG
DSEG Data segment COMMON:DATA
DW Define word constants DC32 – 32 bits
DD – 32 bits
DW – 16 bits
DC16 - 16 bits
ENDM End macro ENDM
ENDMACRO
EQU Set a symbol equal to a value EQU
EXIT Terminate the assembly END
INCLUDE Read source from another file #Include
MACRO Begins a macro MACRO
SET Set a symbol to an expression DEFINE, EQU and VAR depending on
scope.
ELSE Conditional assembly ELSE
ELIF ELSEIF
ENDIF ENDIF
IF IF
IFDEF C-style preprocessor:
IFNDEF #elif
#else
#endif
#if
#ifdef
#ifndef
ERROR Outputs and error #error
MESSAGE Outputs a message string #message
DD Define double word DS32
DQ Define quadword DS32 2
DEF Define a symbolic name on a register Not supported.

Part number Atmel Studio to IAR Embedded Workbench for AVR: Page 12 of 15
Migrating from Atmel studio AVR 8-bit to IAR Embedded W orkbench AVR 8-bit

UNDEF Undefine register symbol Not supported.


WARNING Generates a warning message Not supported.
Assembler options
-f [O|M|I|G|-] Define output file format Via the IAR XLINK Linker (xlink.exe)
-Fformat
-d Debug information -r
-C Core version -v[0|1|2|3|4|5|6]
-I Include paths -Iprefix
-D name[=value] Defines symbol -Dsymbol[=value]
-v0 Disable warnings -w[string][s]

Linker and library details


Atmel studio IAR Systems
Device-specific header files
<avr/io.h> <ioavr.h>
Atmel studio IAR Systems
Linker options
--architecture=architecture Specify architecture -c[name]
--format=input-format Specify input format Not supported.
--entry=entry Specifies new application entry -s symbol
point
--library=namespec Input library No specific option. Just list the files.
--library-path=searchdir
--output=output Output file -o [file path]
--oformat=output-format Specify the output format -F[format]
--start-group[archives]--end- Input files No specific option. Just list the files.
group
Include directory to search for -I[pathname]
object files and libraries.
Generates a checksum -Jsize,algo[,flags[,sym[,seg[,
align[,[m][#]val]]]]][{=|==}ranges}
Segments/Sections
.text Program section CODE
[FAR|HUGE|NEAR|TINY]_[C|F|ID]
C – constants
F – static and global initialized variables
ID – initial values for static and global
variables (segment _I).
FARCODE
.data Static data section FAR_I
HUGE_I
NEAR_I
TINY_I
.bss Zero-initialized global and static FAR_Z
HUGE_Z
variables
NEAR_Z
TINY_Z
.eeprom Variables in EEPROM EEPROM_I (initialized)
EEPROM_N (Not zero initialized)
Part of .bss Not zero-initialized variables FAR_N
HUGE_N
.noinit
NEAR_N
TINY_N
Part of .text Startup code CODE
.initN
Part of .text Exit code CODE
.finiN
Checksum CHECKSUM

.data Stack section CSTACK


.text Pointers to code Typically used for eC++ constructors that
should be executed at startup.
DIFUNCT

Part number Atmel Studio to IAR Embedded Workbench for AVR: Page 13 of 15
Migrating from Atmel studio AVR 8-bit to IAR Embedded W orkbench AVR 8-bit

.data Heap section Holds the heap used for dynamically


allocated data using the CLIB library.
HEAP
HUGE_HEAP
.text Vector table INTVEC
Compiler-generated table entries INITTAB
that describe the segment
initialization that will be
performed at system startup.
Switch tables SWITCH

Runtime environment
Atmel studio IAR Systems
Calling convention
Parameters passed on the stack
Functions with a variable number of registers.
Register R16-R23 are available for passing parameters.
Parameters passed in registers
8-bit values in: R24, 8-bit values in: R16, R17, R18, R19, R20, R21, R22,
R22,R20,R18,R16,R14,R12,R10,R8 R23
16-bit values in: R25:R24, R23:R22, R21:R20, 16-bit values in: R17:R16, R19:R18, R21:R20,
R19:R18, R17:R16, R15:R14, R13:R12, R11:R10, R23:R22
R9:R8
24-bit values in: Any even register less than R23. 24-bit values in: R18:R17:R16, R22:R21:R20
32-bit values in: Any even register less than R23 32-bit values in: R19:R18:R17:R16, R23:R22:R21:R20
64-bit values in: Any even register less than R19 64-bit values in: R19:R18:R17:R16: R23:R22:R21:R20
Return values
8-bit values in: R24 8-bit values in: R16
16-bit values in: R25:R24 16-bit values in: R17:R16
24-bit values in: R24:R23:R22 24-bit values in: R18:R17:R16
32-bit values in: R25:R24:R23:R22 32-bit values in: R19:R18:R17:R16
64-bit values in: R25:R24:R23:R22:R21:R20:R19:R18 64-bit values in: R23:R22:R21:R20:R19:R18:R17:R16
Preserved registers
R2-R17, R28-R29 R4-R15 and R24-R27
Scratch registers
R18-R27, R30-R31 R0-R3, R16-R23 and R30-R31
System startup and exit code
Available as object file crt<device>.o or crt1.o in the The code for handling startup and termination is located in
toolchain package. Assembly source can be found in the avr- the source files cstartup.s90, _exit.s90 and
libc repository low_level_init.c located in the avr\src\lib
(http://svn.savannah.nongnu.org/viewvc/trunk/avr- directory.
libc/crt1/gcrt1.S?root=avr-libc&view=markup). It is likely that you need to customize the code for system
initialization. For example, your application needs to
Refer to https://gcc.gnu.org/wiki/avr- initialize memory-mapped special function registers, or omit
gcc#Compiling_the_Code for information about how to use the default initialization of data segments performed by
startup code source. cstartup.

You can do this by providing a customized version of the


routine __low_level_init, which is called from cstartup
before the data segments are initialized. Modifying
cstartup directly should be avoided.
Global variable initialization
Static and global variables are zero-initialized. Variables Static and global variables are initialized except for
declared in .noinit section are not zero-initialized. __no_init, __tinyflash, __flash, __farflash,
__hugeflash and __eeprom declared variables. That is,
zero-initialized variables are cleared and the values of other
initialized variables are copied from ROM to RAM memory.
This step is skipped if by returning 0 from the
__low_level_init function (which can be overridden).
Reentrancy and recursive functions
The code generated natively by gcc is reentrant. But, only The compiler always generates reentrant code when using the
some of the libraries in avr-libc are explicitly reentrant, and DLIB library.
some are known not to be reentrant.
Other operations

Part number Atmel Studio to IAR Embedded Workbench for AVR: Page 14 of 15
Migrating from Atmel studio AVR 8-bit to IAR Embedded W orkbench AVR 8-bit

IAR Systems, IAR Embedded Workbench, C-SPY, C-RUN, C-STAT, visualState, Focus on Your Code, IAR KickStart Kit,
IAR Experiment!, 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. J-Link and J-Trace are trademarks owned by IAR Systems AB.
All information is subject to change without notice. IAR Systems assumes no responsibility for errors and shall not be liable for
any damage or expenses.
© 2015 IAR Systems AB. Part number: AtmelStudiotoIAREmbeddedWorkbenchforAVR. First edition: April 2015

Part number Atmel Studio to IAR Embedded Workbench for AVR: Page 15 of 15

You might also like