/* * Code generated from Atmel Start. * * This file will be overwritten when reconfiguring your Atmel Start project. * Please copy examples or other code you want to keep to a separate file * to avoid losing it when reconfiguring. */ #include "driver_init.h" #include #include #include struct spi_m_sync_descriptor SPI_SD_MMC; struct calendar_descriptor CALENDER_INTERFACE; struct usart_sync_descriptor USART_DBG; struct mci_sync_desc IO_BUS; void CALENDER_INTERFACE_CLOCK_init(void) { hri_mclk_set_APBAMASK_RTC_bit(MCLK); } void CALENDER_INTERFACE_init(void) { CALENDER_INTERFACE_CLOCK_init(); calendar_init(&CALENDER_INTERFACE, RTC); } void USART_DBG_PORT_init(void) { gpio_set_pin_function(PB25, PINMUX_PB25D_SERCOM2_PAD0); gpio_set_pin_function(PB24, PINMUX_PB24D_SERCOM2_PAD1); } void USART_DBG_CLOCK_init(void) { hri_gclk_write_PCHCTRL_reg(GCLK, SERCOM2_GCLK_ID_CORE, CONF_GCLK_SERCOM2_CORE_SRC | (1 << GCLK_PCHCTRL_CHEN_Pos)); hri_gclk_write_PCHCTRL_reg(GCLK, SERCOM2_GCLK_ID_SLOW, CONF_GCLK_SERCOM2_SLOW_SRC | (1 << GCLK_PCHCTRL_CHEN_Pos)); hri_mclk_set_APBBMASK_SERCOM2_bit(MCLK); } void USART_DBG_init(void) { USART_DBG_CLOCK_init(); usart_sync_init(&USART_DBG, SERCOM2, (void *)NULL); USART_DBG_PORT_init(); } void SPI_SD_MMC_PORT_init(void) { gpio_set_pin_level(PB27, // Initial level // pad_initial_level // Low // High false); // Set pin direction to output gpio_set_pin_direction(PB27, GPIO_DIRECTION_OUT); gpio_set_pin_function(PB27, PINMUX_PB27D_SERCOM4_PAD0); gpio_set_pin_level(PB26, // Initial level // pad_initial_level // Low // High false); // Set pin direction to output gpio_set_pin_direction(PB26, GPIO_DIRECTION_OUT); gpio_set_pin_function(PB26, PINMUX_PB26D_SERCOM4_PAD1); // Set pin direction to input gpio_set_pin_direction(PB29, GPIO_DIRECTION_IN); gpio_set_pin_pull_mode(PB29, // Pull configuration // pad_pull_config // Off // Pull-up // Pull-down GPIO_PULL_OFF); gpio_set_pin_function(PB29, PINMUX_PB29D_SERCOM4_PAD3); } void SPI_SD_MMC_CLOCK_init(void) { hri_gclk_write_PCHCTRL_reg(GCLK, SERCOM4_GCLK_ID_CORE, CONF_GCLK_SERCOM4_CORE_SRC | (1 << GCLK_PCHCTRL_CHEN_Pos)); hri_gclk_write_PCHCTRL_reg(GCLK, SERCOM4_GCLK_ID_SLOW, CONF_GCLK_SERCOM4_SLOW_SRC | (1 << GCLK_PCHCTRL_CHEN_Pos)); hri_mclk_set_APBDMASK_SERCOM4_bit(MCLK); } void SPI_SD_MMC_init(void) { SPI_SD_MMC_CLOCK_init(); spi_m_sync_init(&SPI_SD_MMC, SERCOM4); SPI_SD_MMC_PORT_init(); } void IO_BUS_PORT_init(void) { gpio_set_pin_direction(PB11, // Pin direction // pad_direction // Off // In // Out GPIO_DIRECTION_OUT); gpio_set_pin_level(PB11, // Initial level // pad_initial_level // Low // High false); gpio_set_pin_pull_mode(PB11, // Pull configuration // pad_pull_config // Off // Pull-up // Pull-down GPIO_PULL_OFF); gpio_set_pin_function(PB11, // Pin function // pad_function // Auto : use driver pinmux if signal is imported by driver, else turn off function // Auto // Off // A // B // C // D // E // F // G // H // I // J // K // L // M // N PINMUX_PB11I_SDHC0_SDCK); gpio_set_pin_direction(PA08, // Pin direction // pad_direction // Off // In // Out GPIO_DIRECTION_OUT); gpio_set_pin_level(PA08, // Initial level // pad_initial_level // Low // High false); gpio_set_pin_pull_mode(PA08, // Pull configuration // pad_pull_config // Off // Pull-up // Pull-down GPIO_PULL_OFF); gpio_set_pin_function(PA08, // Pin function // pad_function // Auto : use driver pinmux if signal is imported by driver, else turn off function // Auto // Off // A // B // C // D // E // F // G // H // I // J // K // L // M // N PINMUX_PA08I_SDHC0_SDCMD); gpio_set_pin_direction(PA09, // Pin direction // pad_direction // Off // In // Out GPIO_DIRECTION_OUT); gpio_set_pin_level(PA09, // Initial level // pad_initial_level // Low // High false); gpio_set_pin_pull_mode(PA09, // Pull configuration // pad_pull_config // Off // Pull-up // Pull-down GPIO_PULL_OFF); gpio_set_pin_function(PA09, // Pin function // pad_function // Auto : use driver pinmux if signal is imported by driver, else turn off function // Auto // Off // A // B // C // D // E // F // G // H // I // J // K // L // M // N PINMUX_PA09I_SDHC0_SDDAT0); gpio_set_pin_direction(PA10, // Pin direction // pad_direction // Off // In // Out GPIO_DIRECTION_OUT); gpio_set_pin_level(PA10, // Initial level // pad_initial_level // Low // High false); gpio_set_pin_pull_mode(PA10, // Pull configuration // pad_pull_config // Off // Pull-up // Pull-down GPIO_PULL_OFF); gpio_set_pin_function(PA10, // Pin function // pad_function // Auto : use driver pinmux if signal is imported by driver, else turn off function // Auto // Off // A // B // C // D // E // F // G // H // I // J // K // L // M // N PINMUX_PA10I_SDHC0_SDDAT1); gpio_set_pin_direction(PA11, // Pin direction // pad_direction // Off // In // Out GPIO_DIRECTION_OUT); gpio_set_pin_level(PA11, // Initial level // pad_initial_level // Low // High false); gpio_set_pin_pull_mode(PA11, // Pull configuration // pad_pull_config // Off // Pull-up // Pull-down GPIO_PULL_OFF); gpio_set_pin_function(PA11, // Pin function // pad_function // Auto : use driver pinmux if signal is imported by driver, else turn off function // Auto // Off // A // B // C // D // E // F // G // H // I // J // K // L // M // N PINMUX_PA11I_SDHC0_SDDAT2); gpio_set_pin_direction(PB10, // Pin direction // pad_direction // Off // In // Out GPIO_DIRECTION_OUT); gpio_set_pin_level(PB10, // Initial level // pad_initial_level // Low // High false); gpio_set_pin_pull_mode(PB10, // Pull configuration // pad_pull_config // Off // Pull-up // Pull-down GPIO_PULL_OFF); gpio_set_pin_function(PB10, // Pin function // pad_function // Auto : use driver pinmux if signal is imported by driver, else turn off function // Auto // Off // A // B // C // D // E // F // G // H // I // J // K // L // M // N PINMUX_PB10I_SDHC0_SDDAT3); } void IO_BUS_CLOCK_init(void) { hri_mclk_set_AHBMASK_SDHC0_bit(MCLK); hri_gclk_write_PCHCTRL_reg(GCLK, SDHC0_GCLK_ID, CONF_GCLK_SDHC0_SRC | (1 << GCLK_PCHCTRL_CHEN_Pos)); hri_gclk_write_PCHCTRL_reg(GCLK, SDHC0_GCLK_ID_SLOW, CONF_GCLK_SDHC0_SLOW_SRC | (1 << GCLK_PCHCTRL_CHEN_Pos)); } void IO_BUS_init(void) { IO_BUS_CLOCK_init(); mci_sync_init(&IO_BUS, SDHC0); IO_BUS_PORT_init(); } void delay_driver_init(void) { delay_init(SysTick); } void system_init(void) { init_mcu(); CALENDER_INTERFACE_init(); USART_DBG_init(); SPI_SD_MMC_init(); IO_BUS_init(); delay_driver_init(); }