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.
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) { } }
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:
initializes the MCU (oscillators, clocks, flash wait states, etc.) using the init_mcu() function
initializes the peripherals, which have been selected (in our case the USART), using the USART_0_init() function
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: