Migration Guide: Migrating From Atmel Studio Toolchain For 8-Bit AVR To IAR Embedded W Orkbench® For AVR
Migration Guide: Migrating From Atmel Studio Toolchain For 8-Bit AVR To IAR Embedded W Orkbench® For AVR
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.
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.
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
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.
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");
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.
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
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;
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
#pragma location="MyFunctions"
void func(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;
Example:
/ My_Array start address will be 4
bytes aligned*/
#pragma data_alignment=4
char My_Array[100];
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
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)]
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
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
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
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.
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