System Initialization

This section walks you through the startup sequence of an ASF4 project. This system initialization sequence relies mainly on root level files, which are described in more detail in Root Level Files.

An empty ASF4 project, generated from Atmel START will contain only the atmel_start_init() function in main().

int main(void)
{
    atmel_start_init();

    /* Replace with your application code */
    while(1) {
    }
}
The atmel_start_init() function is implemented in atmel_start.c and:
  • initializes any middleware libraries, which have been added to the project
  • calls system_init()
void system_init(void)
{
    system_init();
    temperature_sensors_init();
}

The system_init() function is implemented in driver_init.c and:

void system_init(void)
{
    init_mcu();
    USART_0_init();
}

The different initialization functions which are called in system_init(), use the configuration’s parameters that the user has selected during the Atmel START configuration process.

An example initialization of an SPI peripheral is considered in the picture below.
  1. 1.In main.c: main() calls atmel_start_init().
  2. 2.In atmel_start.c: atmel_start_init() calls temperature_sensors_init(), a middleware initialization function, as well as system_init().
  3. 3.In driver_init.c: system_init() calls init_mcu(), pin configuration functions and driver initialization functions, such as SPI_0_init().
  4. 4.SPI_0_init() writes START configuration to the SPI (SERCOM) peripheral registers.