System Initialization

This section walks you through the startup sequence of an Foundation Servicesproject.Atmel START will generate one system_init() function initializing the system and all the peripherals. One <driver_name>_init() function per peripheral will be generated, and these will be called by system_init(). The <driver_name>_init() functions are located in the <driver_name>.{c,h}-files, and configure each peripheral according to the choices made by the user in the Atmel START GUI.

For AVR devices with PRR registers, the system_init() function writes the PRR registers so that peripherals not configured in Atmel START are disabled. This is done to reduce the power consumption of unused peripherals, but is the opposite of the reset value of the PRR registers, which enables all peripherals.

Atmel START configures all unused IO pins to input with pull-ups enabled. This is done to reduce power-consumption.

Initialization walk though

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

int main(void)
{
	/* Initializes MCU, drivers and middleware */
	atmel_start_init();

	/* Replace with your application code */
	while (1) {
	}
}
The atmel_start_init() function is implemented in atmel_start.c and:
void atmel_start_init(void)
{
	system_init();
}
void system_init()
{
	mcu_init();

	/* PORT setting on PA2 */

	// Set pin direction to output
	my_pin_set_dir(PORT_DIR_OUT);

	my_pin_set_level(
	    // <y> Initial level
	    // <id> pad_initial_level
	    // <false"> Low
	    // <true"> High
	    false);

	CLKCTRL_init();

	USART_0_initialization();

	CPUINT_init();

	SLPCTRL_init();

	BOD_init();
}

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

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 USART peripheral is considered below:

  1. 1.In main.c: main() calls atmel_start_init().
  2. 2.In atmel_start.c: atmel_start_init() calls system_init().
  3. 3.In driver_init.c: system_init() calls mcu_init(), various other system configuration functions, and driver initialization functions, such as USART_0_initialization().
  4. 4.USART_0_initialization() writes START configuration to the USART peripheral registers.