Toolchain and Device-specific Support

System Startup Sequence

An ASF4 project executes the following startup sequence:
  1. 1.

    The initial value of the stack pointer is read from the linker script, and written to the first 32-bit address in the exception vector. The startup sequencing hardware will write this value to the stack pointer (SP) in the register file, before releasing the CPU from reset.

  2. 2.

    The address of the Reset_Handler() is placed as the second 32-bit word in the exception vector. The ARM hardware will execute the code in this function immediately after releasing the CPU from reset.

The Reset_Handler() function can be found in the /Device_Startup/startup_{device}.c file, where {device} is the name of the device chosen. The reset handler:
  1. 1.

    Initializes various memory segments

  2. 2.

    Configures the bus matrix if applicable

  3. 3.

    Initializes data structures in the C library

  4. 4.

    Jumps to the main() function

Portability of Generated ASF4 Code Between Devices

An ASF4 project generated for one device should in general not be compiled for other devices. There may be differences between devices so that the code may not compile, or may compile but not behave as intended.

CMSIS-CORE Library

The CMSIS-CORE library is provided as part of the Device Family Packages (DFPs) for all Microchip SAM devices. Functions in CMSIS-CORE, for example __set_BASEPRI() can be called from the ASF4 code. ASF4 also provides an HPL library abstracting the CPU core. This core-specific library is part of the *.atzip file exported from Atmel START. The library can be found in the /hpl/core/ directory. The device header file, named {device}.h, present in the device DFP directory, configures the CMSIS-CORE parameters and includes the CMSIS-CORE header file, named core_{core_name}.h. An example of a {device-file, CMSIS-CORE file}-pair is {samd21e15a.h, core_cm0plus.h}.

Interrupt Vectors

The interrupt vector table can be found in the /Device_Startup/startup_{device}.c file, where {device} is the name of the device chosen, e.g. samd21. The vector table is populated with jumps to a Dummy_Handler(), performing an eternal while-loop. The Dummy_Handler() has the GCC attribute "weak", and is intended to be overridden by the appropriate handler provided by ASF4, or defined by the user.

ASF4 does not assign a specific priority to the IRQs, but instead uses the default priority as assigned by the NVIC. Different ARM cores have NVIC interrupt controllers with individual specifications and features. Refer to the device data sheet and NVIC documentation for the ARM core being used in the selected target device for more information on manipulating interrupt priorities and masking interrupts.

The ARM CMSIS-CORE specification has functions for manipulating the NVIC in order to prioritize IRQs and mask interrupts. Refer to the CMSIS specification and CMSIS-CORE library(doc_driver_hal_intro_toolchain_1s_ds_cmsis) for more information.

C Library

Atmel START generates code to be used together with the GCC tool suite for ARM. This includes system call implementations for the GCC newlib C library, such as _exit() and _close(). The system call implementations can be found in /hal/utils/src/utils_syscalls.c. Other compilers, such as IAR or Keil, may use proprietary C-libraries, and not use these syscall implementations.

Linker Scripts

A set of default linker scripts for the GCC compiler are provided by Atmel START. The scripts are tailored to the device selected in Atmel START. They can be found in the /Device_Startup/*.ld files. Multiple scripts may be provided, e.g. one script for placing code in flash, another for placing code in RAM. Other compilers, such as IAR or Keil, may use proprietary linker scripts and formats, and not use these linker scripts implementations. Atmel START does not generate linker scripts for other compilers than GCC.

Support for Various Toolchains

ASF4 consists of generic C-code and can in be compiled using any ARM C-compiler. However, Atmel START includes support for exporting projects into the following toolchains:
  • Atmel Studio/GCC

  • IAR Embedded Workbench

  • Keil uVision

  • Standalone makefile system

GCC and Atmel Studio

When generating output for Atmel Studio, an *.atzip file is generated. This file can be opened directly in Studio.

Compiler options

The various compiler and toolchain options set by default by Atmel START can be examined by right-clicking on the project name in Studio. The default build configuration is Debug, with debug symbol generation enabled (-g) and minimum optimization (-O1).

Build system

The project in the *.atzip file can be built directly using Studio's build system. Refer to the Studio documentation for more information.

IAR Embedded Workbench (EW)

The ASF4 code can be imported into IAR EW. Refer to the Atmel START documentation for more information.

Keil uVision

The ASF4 code can be imported into Keil uVision. Refer to the Atmel START documentation for more information.