You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
767 lines
29 KiB
C
767 lines
29 KiB
C
3 years ago
|
/*
|
||
|
* 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 <peripheral_clk_config.h>
|
||
|
#include <utils.h>
|
||
|
#include <hal_init.h>
|
||
|
|
||
|
struct spi_m_sync_descriptor SPI_0;
|
||
|
|
||
|
struct qspi_sync_descriptor QUAD_SPI_0;
|
||
|
|
||
|
struct calendar_descriptor CALENDER_INTERFACE;
|
||
|
|
||
|
struct usart_sync_descriptor USART_DBG;
|
||
|
|
||
|
struct mci_sync_desc IO_BUS;
|
||
|
|
||
|
struct usb_h_desc USB_HOST_INSTANCE_inst;
|
||
|
|
||
|
void QUAD_SPI_0_PORT_init(void)
|
||
|
{
|
||
|
|
||
|
// Set pin direction to input
|
||
|
gpio_set_pin_direction(PB11, GPIO_DIRECTION_IN);
|
||
|
|
||
|
gpio_set_pin_pull_mode(PB11,
|
||
|
// <y> Pull configuration
|
||
|
// <id> pad_pull_config
|
||
|
// <GPIO_PULL_OFF"> Off
|
||
|
// <GPIO_PULL_UP"> Pull-up
|
||
|
// <GPIO_PULL_DOWN"> Pull-down
|
||
|
GPIO_PULL_OFF);
|
||
|
|
||
|
gpio_set_pin_function(PB11, PINMUX_PB11H_QSPI_CS);
|
||
|
|
||
|
gpio_set_pin_direction(PA08,
|
||
|
// <y> Pin direction
|
||
|
// <id> pad_direction
|
||
|
// <GPIO_DIRECTION_OFF"> Off
|
||
|
// <GPIO_DIRECTION_IN"> In
|
||
|
// <GPIO_DIRECTION_OUT"> Out
|
||
|
GPIO_DIRECTION_OUT);
|
||
|
|
||
|
gpio_set_pin_level(PA08,
|
||
|
// <y> Initial level
|
||
|
// <id> pad_initial_level
|
||
|
// <false"> Low
|
||
|
// <true"> High
|
||
|
false);
|
||
|
|
||
|
gpio_set_pin_pull_mode(PA08,
|
||
|
// <y> Pull configuration
|
||
|
// <id> pad_pull_config
|
||
|
// <GPIO_PULL_OFF"> Off
|
||
|
// <GPIO_PULL_UP"> Pull-up
|
||
|
// <GPIO_PULL_DOWN"> Pull-down
|
||
|
GPIO_PULL_OFF);
|
||
|
|
||
|
gpio_set_pin_function(PA08,
|
||
|
// <y> Pin function
|
||
|
// <id> pad_function
|
||
|
// <i> Auto : use driver pinmux if signal is imported by driver, else turn off function
|
||
|
// <PINMUX_PA08H_QSPI_DATA0"> Auto
|
||
|
// <GPIO_PIN_FUNCTION_OFF"> Off
|
||
|
// <GPIO_PIN_FUNCTION_A"> A
|
||
|
// <GPIO_PIN_FUNCTION_B"> B
|
||
|
// <GPIO_PIN_FUNCTION_C"> C
|
||
|
// <GPIO_PIN_FUNCTION_D"> D
|
||
|
// <GPIO_PIN_FUNCTION_E"> E
|
||
|
// <GPIO_PIN_FUNCTION_F"> F
|
||
|
// <GPIO_PIN_FUNCTION_G"> G
|
||
|
// <GPIO_PIN_FUNCTION_H"> H
|
||
|
// <GPIO_PIN_FUNCTION_I"> I
|
||
|
// <GPIO_PIN_FUNCTION_J"> J
|
||
|
// <GPIO_PIN_FUNCTION_K"> K
|
||
|
// <GPIO_PIN_FUNCTION_L"> L
|
||
|
// <GPIO_PIN_FUNCTION_M"> M
|
||
|
// <GPIO_PIN_FUNCTION_N"> N
|
||
|
PINMUX_PA08H_QSPI_DATA0);
|
||
|
|
||
|
gpio_set_pin_direction(PA09,
|
||
|
// <y> Pin direction
|
||
|
// <id> pad_direction
|
||
|
// <GPIO_DIRECTION_OFF"> Off
|
||
|
// <GPIO_DIRECTION_IN"> In
|
||
|
// <GPIO_DIRECTION_OUT"> Out
|
||
|
GPIO_DIRECTION_OUT);
|
||
|
|
||
|
gpio_set_pin_level(PA09,
|
||
|
// <y> Initial level
|
||
|
// <id> pad_initial_level
|
||
|
// <false"> Low
|
||
|
// <true"> High
|
||
|
false);
|
||
|
|
||
|
gpio_set_pin_pull_mode(PA09,
|
||
|
// <y> Pull configuration
|
||
|
// <id> pad_pull_config
|
||
|
// <GPIO_PULL_OFF"> Off
|
||
|
// <GPIO_PULL_UP"> Pull-up
|
||
|
// <GPIO_PULL_DOWN"> Pull-down
|
||
|
GPIO_PULL_OFF);
|
||
|
|
||
|
gpio_set_pin_function(PA09,
|
||
|
// <y> Pin function
|
||
|
// <id> pad_function
|
||
|
// <i> Auto : use driver pinmux if signal is imported by driver, else turn off function
|
||
|
// <PINMUX_PA09H_QSPI_DATA1"> Auto
|
||
|
// <GPIO_PIN_FUNCTION_OFF"> Off
|
||
|
// <GPIO_PIN_FUNCTION_A"> A
|
||
|
// <GPIO_PIN_FUNCTION_B"> B
|
||
|
// <GPIO_PIN_FUNCTION_C"> C
|
||
|
// <GPIO_PIN_FUNCTION_D"> D
|
||
|
// <GPIO_PIN_FUNCTION_E"> E
|
||
|
// <GPIO_PIN_FUNCTION_F"> F
|
||
|
// <GPIO_PIN_FUNCTION_G"> G
|
||
|
// <GPIO_PIN_FUNCTION_H"> H
|
||
|
// <GPIO_PIN_FUNCTION_I"> I
|
||
|
// <GPIO_PIN_FUNCTION_J"> J
|
||
|
// <GPIO_PIN_FUNCTION_K"> K
|
||
|
// <GPIO_PIN_FUNCTION_L"> L
|
||
|
// <GPIO_PIN_FUNCTION_M"> M
|
||
|
// <GPIO_PIN_FUNCTION_N"> N
|
||
|
PINMUX_PA09H_QSPI_DATA1);
|
||
|
|
||
|
gpio_set_pin_direction(PA10,
|
||
|
// <y> Pin direction
|
||
|
// <id> pad_direction
|
||
|
// <GPIO_DIRECTION_OFF"> Off
|
||
|
// <GPIO_DIRECTION_IN"> In
|
||
|
// <GPIO_DIRECTION_OUT"> Out
|
||
|
GPIO_DIRECTION_OUT);
|
||
|
|
||
|
gpio_set_pin_level(PA10,
|
||
|
// <y> Initial level
|
||
|
// <id> pad_initial_level
|
||
|
// <false"> Low
|
||
|
// <true"> High
|
||
|
false);
|
||
|
|
||
|
gpio_set_pin_pull_mode(PA10,
|
||
|
// <y> Pull configuration
|
||
|
// <id> pad_pull_config
|
||
|
// <GPIO_PULL_OFF"> Off
|
||
|
// <GPIO_PULL_UP"> Pull-up
|
||
|
// <GPIO_PULL_DOWN"> Pull-down
|
||
|
GPIO_PULL_OFF);
|
||
|
|
||
|
gpio_set_pin_function(PA10,
|
||
|
// <y> Pin function
|
||
|
// <id> pad_function
|
||
|
// <i> Auto : use driver pinmux if signal is imported by driver, else turn off function
|
||
|
// <PINMUX_PA10H_QSPI_DATA2"> Auto
|
||
|
// <GPIO_PIN_FUNCTION_OFF"> Off
|
||
|
// <GPIO_PIN_FUNCTION_A"> A
|
||
|
// <GPIO_PIN_FUNCTION_B"> B
|
||
|
// <GPIO_PIN_FUNCTION_C"> C
|
||
|
// <GPIO_PIN_FUNCTION_D"> D
|
||
|
// <GPIO_PIN_FUNCTION_E"> E
|
||
|
// <GPIO_PIN_FUNCTION_F"> F
|
||
|
// <GPIO_PIN_FUNCTION_G"> G
|
||
|
// <GPIO_PIN_FUNCTION_H"> H
|
||
|
// <GPIO_PIN_FUNCTION_I"> I
|
||
|
// <GPIO_PIN_FUNCTION_J"> J
|
||
|
// <GPIO_PIN_FUNCTION_K"> K
|
||
|
// <GPIO_PIN_FUNCTION_L"> L
|
||
|
// <GPIO_PIN_FUNCTION_M"> M
|
||
|
// <GPIO_PIN_FUNCTION_N"> N
|
||
|
PINMUX_PA10H_QSPI_DATA2);
|
||
|
|
||
|
gpio_set_pin_direction(PA11,
|
||
|
// <y> Pin direction
|
||
|
// <id> pad_direction
|
||
|
// <GPIO_DIRECTION_OFF"> Off
|
||
|
// <GPIO_DIRECTION_IN"> In
|
||
|
// <GPIO_DIRECTION_OUT"> Out
|
||
|
GPIO_DIRECTION_OUT);
|
||
|
|
||
|
gpio_set_pin_level(PA11,
|
||
|
// <y> Initial level
|
||
|
// <id> pad_initial_level
|
||
|
// <false"> Low
|
||
|
// <true"> High
|
||
|
false);
|
||
|
|
||
|
gpio_set_pin_pull_mode(PA11,
|
||
|
// <y> Pull configuration
|
||
|
// <id> pad_pull_config
|
||
|
// <GPIO_PULL_OFF"> Off
|
||
|
// <GPIO_PULL_UP"> Pull-up
|
||
|
// <GPIO_PULL_DOWN"> Pull-down
|
||
|
GPIO_PULL_OFF);
|
||
|
|
||
|
gpio_set_pin_function(PA11,
|
||
|
// <y> Pin function
|
||
|
// <id> pad_function
|
||
|
// <i> Auto : use driver pinmux if signal is imported by driver, else turn off function
|
||
|
// <PINMUX_PA11H_QSPI_DATA3"> Auto
|
||
|
// <GPIO_PIN_FUNCTION_OFF"> Off
|
||
|
// <GPIO_PIN_FUNCTION_A"> A
|
||
|
// <GPIO_PIN_FUNCTION_B"> B
|
||
|
// <GPIO_PIN_FUNCTION_C"> C
|
||
|
// <GPIO_PIN_FUNCTION_D"> D
|
||
|
// <GPIO_PIN_FUNCTION_E"> E
|
||
|
// <GPIO_PIN_FUNCTION_F"> F
|
||
|
// <GPIO_PIN_FUNCTION_G"> G
|
||
|
// <GPIO_PIN_FUNCTION_H"> H
|
||
|
// <GPIO_PIN_FUNCTION_I"> I
|
||
|
// <GPIO_PIN_FUNCTION_J"> J
|
||
|
// <GPIO_PIN_FUNCTION_K"> K
|
||
|
// <GPIO_PIN_FUNCTION_L"> L
|
||
|
// <GPIO_PIN_FUNCTION_M"> M
|
||
|
// <GPIO_PIN_FUNCTION_N"> N
|
||
|
PINMUX_PA11H_QSPI_DATA3);
|
||
|
|
||
|
// Set pin direction to input
|
||
|
gpio_set_pin_direction(PB10, GPIO_DIRECTION_IN);
|
||
|
|
||
|
gpio_set_pin_pull_mode(PB10,
|
||
|
// <y> Pull configuration
|
||
|
// <id> pad_pull_config
|
||
|
// <GPIO_PULL_OFF"> Off
|
||
|
// <GPIO_PULL_UP"> Pull-up
|
||
|
// <GPIO_PULL_DOWN"> Pull-down
|
||
|
GPIO_PULL_OFF);
|
||
|
|
||
|
gpio_set_pin_function(PB10, PINMUX_PB10H_QSPI_SCK);
|
||
|
}
|
||
|
|
||
|
void QUAD_SPI_0_CLOCK_init(void)
|
||
|
{
|
||
|
hri_mclk_set_AHBMASK_QSPI_bit(MCLK);
|
||
|
hri_mclk_set_AHBMASK_QSPI_2X_bit(MCLK);
|
||
|
hri_mclk_set_APBCMASK_QSPI_bit(MCLK);
|
||
|
}
|
||
|
|
||
|
void QUAD_SPI_0_init(void)
|
||
|
{
|
||
|
QUAD_SPI_0_CLOCK_init();
|
||
|
qspi_sync_init(&QUAD_SPI_0, QSPI);
|
||
|
QUAD_SPI_0_PORT_init();
|
||
|
}
|
||
|
|
||
|
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 SPI_0_PORT_init(void)
|
||
|
{
|
||
|
|
||
|
gpio_set_pin_level(PB26,
|
||
|
// <y> Initial level
|
||
|
// <id> pad_initial_level
|
||
|
// <false"> Low
|
||
|
// <true"> High
|
||
|
false);
|
||
|
|
||
|
// Set pin direction to output
|
||
|
gpio_set_pin_direction(PB26, GPIO_DIRECTION_OUT);
|
||
|
|
||
|
gpio_set_pin_function(PB26, PINMUX_PB26C_SERCOM2_PAD0);
|
||
|
|
||
|
gpio_set_pin_level(PB27,
|
||
|
// <y> Initial level
|
||
|
// <id> pad_initial_level
|
||
|
// <false"> Low
|
||
|
// <true"> High
|
||
|
false);
|
||
|
|
||
|
// Set pin direction to output
|
||
|
gpio_set_pin_direction(PB27, GPIO_DIRECTION_OUT);
|
||
|
|
||
|
gpio_set_pin_function(PB27, PINMUX_PB27C_SERCOM2_PAD1);
|
||
|
|
||
|
// Set pin direction to input
|
||
|
gpio_set_pin_direction(PB29, GPIO_DIRECTION_IN);
|
||
|
|
||
|
gpio_set_pin_pull_mode(PB29,
|
||
|
// <y> Pull configuration
|
||
|
// <id> pad_pull_config
|
||
|
// <GPIO_PULL_OFF"> Off
|
||
|
// <GPIO_PULL_UP"> Pull-up
|
||
|
// <GPIO_PULL_DOWN"> Pull-down
|
||
|
GPIO_PULL_OFF);
|
||
|
|
||
|
gpio_set_pin_function(PB29, PINMUX_PB29C_SERCOM2_PAD3);
|
||
|
}
|
||
|
|
||
|
void SPI_0_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 SPI_0_init(void)
|
||
|
{
|
||
|
SPI_0_CLOCK_init();
|
||
|
spi_m_sync_init(&SPI_0, SERCOM2);
|
||
|
SPI_0_PORT_init();
|
||
|
}
|
||
|
|
||
|
void USART_DBG_PORT_init(void)
|
||
|
{
|
||
|
|
||
|
gpio_set_pin_function(PB12, PINMUX_PB12C_SERCOM4_PAD0);
|
||
|
|
||
|
gpio_set_pin_function(PB13, PINMUX_PB13C_SERCOM4_PAD1);
|
||
|
}
|
||
|
|
||
|
void USART_DBG_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 USART_DBG_init(void)
|
||
|
{
|
||
|
USART_DBG_CLOCK_init();
|
||
|
usart_sync_init(&USART_DBG, SERCOM4, (void *)NULL);
|
||
|
USART_DBG_PORT_init();
|
||
|
}
|
||
|
|
||
|
void IO_BUS_PORT_init(void)
|
||
|
{
|
||
|
|
||
|
gpio_set_pin_direction(PA21,
|
||
|
// <y> Pin direction
|
||
|
// <id> pad_direction
|
||
|
// <GPIO_DIRECTION_OFF"> Off
|
||
|
// <GPIO_DIRECTION_IN"> In
|
||
|
// <GPIO_DIRECTION_OUT"> Out
|
||
|
GPIO_DIRECTION_OUT);
|
||
|
|
||
|
gpio_set_pin_level(PA21,
|
||
|
// <y> Initial level
|
||
|
// <id> pad_initial_level
|
||
|
// <false"> Low
|
||
|
// <true"> High
|
||
|
false);
|
||
|
|
||
|
gpio_set_pin_pull_mode(PA21,
|
||
|
// <y> Pull configuration
|
||
|
// <id> pad_pull_config
|
||
|
// <GPIO_PULL_OFF"> Off
|
||
|
// <GPIO_PULL_UP"> Pull-up
|
||
|
// <GPIO_PULL_DOWN"> Pull-down
|
||
|
GPIO_PULL_OFF);
|
||
|
|
||
|
gpio_set_pin_function(PA21,
|
||
|
// <y> Pin function
|
||
|
// <id> pad_function
|
||
|
// <i> Auto : use driver pinmux if signal is imported by driver, else turn off function
|
||
|
// <PINMUX_PA21I_SDHC1_SDCK"> Auto
|
||
|
// <GPIO_PIN_FUNCTION_OFF"> Off
|
||
|
// <GPIO_PIN_FUNCTION_A"> A
|
||
|
// <GPIO_PIN_FUNCTION_B"> B
|
||
|
// <GPIO_PIN_FUNCTION_C"> C
|
||
|
// <GPIO_PIN_FUNCTION_D"> D
|
||
|
// <GPIO_PIN_FUNCTION_E"> E
|
||
|
// <GPIO_PIN_FUNCTION_F"> F
|
||
|
// <GPIO_PIN_FUNCTION_G"> G
|
||
|
// <GPIO_PIN_FUNCTION_H"> H
|
||
|
// <GPIO_PIN_FUNCTION_I"> I
|
||
|
// <GPIO_PIN_FUNCTION_J"> J
|
||
|
// <GPIO_PIN_FUNCTION_K"> K
|
||
|
// <GPIO_PIN_FUNCTION_L"> L
|
||
|
// <GPIO_PIN_FUNCTION_M"> M
|
||
|
// <GPIO_PIN_FUNCTION_N"> N
|
||
|
PINMUX_PA21I_SDHC1_SDCK);
|
||
|
|
||
|
gpio_set_pin_direction(PA20,
|
||
|
// <y> Pin direction
|
||
|
// <id> pad_direction
|
||
|
// <GPIO_DIRECTION_OFF"> Off
|
||
|
// <GPIO_DIRECTION_IN"> In
|
||
|
// <GPIO_DIRECTION_OUT"> Out
|
||
|
GPIO_DIRECTION_OUT);
|
||
|
|
||
|
gpio_set_pin_level(PA20,
|
||
|
// <y> Initial level
|
||
|
// <id> pad_initial_level
|
||
|
// <false"> Low
|
||
|
// <true"> High
|
||
|
false);
|
||
|
|
||
|
gpio_set_pin_pull_mode(PA20,
|
||
|
// <y> Pull configuration
|
||
|
// <id> pad_pull_config
|
||
|
// <GPIO_PULL_OFF"> Off
|
||
|
// <GPIO_PULL_UP"> Pull-up
|
||
|
// <GPIO_PULL_DOWN"> Pull-down
|
||
|
GPIO_PULL_OFF);
|
||
|
|
||
|
gpio_set_pin_function(PA20,
|
||
|
// <y> Pin function
|
||
|
// <id> pad_function
|
||
|
// <i> Auto : use driver pinmux if signal is imported by driver, else turn off function
|
||
|
// <PINMUX_PA20I_SDHC1_SDCMD"> Auto
|
||
|
// <GPIO_PIN_FUNCTION_OFF"> Off
|
||
|
// <GPIO_PIN_FUNCTION_A"> A
|
||
|
// <GPIO_PIN_FUNCTION_B"> B
|
||
|
// <GPIO_PIN_FUNCTION_C"> C
|
||
|
// <GPIO_PIN_FUNCTION_D"> D
|
||
|
// <GPIO_PIN_FUNCTION_E"> E
|
||
|
// <GPIO_PIN_FUNCTION_F"> F
|
||
|
// <GPIO_PIN_FUNCTION_G"> G
|
||
|
// <GPIO_PIN_FUNCTION_H"> H
|
||
|
// <GPIO_PIN_FUNCTION_I"> I
|
||
|
// <GPIO_PIN_FUNCTION_J"> J
|
||
|
// <GPIO_PIN_FUNCTION_K"> K
|
||
|
// <GPIO_PIN_FUNCTION_L"> L
|
||
|
// <GPIO_PIN_FUNCTION_M"> M
|
||
|
// <GPIO_PIN_FUNCTION_N"> N
|
||
|
PINMUX_PA20I_SDHC1_SDCMD);
|
||
|
|
||
|
gpio_set_pin_direction(PB18,
|
||
|
// <y> Pin direction
|
||
|
// <id> pad_direction
|
||
|
// <GPIO_DIRECTION_OFF"> Off
|
||
|
// <GPIO_DIRECTION_IN"> In
|
||
|
// <GPIO_DIRECTION_OUT"> Out
|
||
|
GPIO_DIRECTION_OUT);
|
||
|
|
||
|
gpio_set_pin_level(PB18,
|
||
|
// <y> Initial level
|
||
|
// <id> pad_initial_level
|
||
|
// <false"> Low
|
||
|
// <true"> High
|
||
|
false);
|
||
|
|
||
|
gpio_set_pin_pull_mode(PB18,
|
||
|
// <y> Pull configuration
|
||
|
// <id> pad_pull_config
|
||
|
// <GPIO_PULL_OFF"> Off
|
||
|
// <GPIO_PULL_UP"> Pull-up
|
||
|
// <GPIO_PULL_DOWN"> Pull-down
|
||
|
GPIO_PULL_OFF);
|
||
|
|
||
|
gpio_set_pin_function(PB18,
|
||
|
// <y> Pin function
|
||
|
// <id> pad_function
|
||
|
// <i> Auto : use driver pinmux if signal is imported by driver, else turn off function
|
||
|
// <PINMUX_PB18I_SDHC1_SDDAT0"> Auto
|
||
|
// <GPIO_PIN_FUNCTION_OFF"> Off
|
||
|
// <GPIO_PIN_FUNCTION_A"> A
|
||
|
// <GPIO_PIN_FUNCTION_B"> B
|
||
|
// <GPIO_PIN_FUNCTION_C"> C
|
||
|
// <GPIO_PIN_FUNCTION_D"> D
|
||
|
// <GPIO_PIN_FUNCTION_E"> E
|
||
|
// <GPIO_PIN_FUNCTION_F"> F
|
||
|
// <GPIO_PIN_FUNCTION_G"> G
|
||
|
// <GPIO_PIN_FUNCTION_H"> H
|
||
|
// <GPIO_PIN_FUNCTION_I"> I
|
||
|
// <GPIO_PIN_FUNCTION_J"> J
|
||
|
// <GPIO_PIN_FUNCTION_K"> K
|
||
|
// <GPIO_PIN_FUNCTION_L"> L
|
||
|
// <GPIO_PIN_FUNCTION_M"> M
|
||
|
// <GPIO_PIN_FUNCTION_N"> N
|
||
|
PINMUX_PB18I_SDHC1_SDDAT0);
|
||
|
|
||
|
gpio_set_pin_direction(PB19,
|
||
|
// <y> Pin direction
|
||
|
// <id> pad_direction
|
||
|
// <GPIO_DIRECTION_OFF"> Off
|
||
|
// <GPIO_DIRECTION_IN"> In
|
||
|
// <GPIO_DIRECTION_OUT"> Out
|
||
|
GPIO_DIRECTION_OUT);
|
||
|
|
||
|
gpio_set_pin_level(PB19,
|
||
|
// <y> Initial level
|
||
|
// <id> pad_initial_level
|
||
|
// <false"> Low
|
||
|
// <true"> High
|
||
|
false);
|
||
|
|
||
|
gpio_set_pin_pull_mode(PB19,
|
||
|
// <y> Pull configuration
|
||
|
// <id> pad_pull_config
|
||
|
// <GPIO_PULL_OFF"> Off
|
||
|
// <GPIO_PULL_UP"> Pull-up
|
||
|
// <GPIO_PULL_DOWN"> Pull-down
|
||
|
GPIO_PULL_OFF);
|
||
|
|
||
|
gpio_set_pin_function(PB19,
|
||
|
// <y> Pin function
|
||
|
// <id> pad_function
|
||
|
// <i> Auto : use driver pinmux if signal is imported by driver, else turn off function
|
||
|
// <PINMUX_PB19I_SDHC1_SDDAT1"> Auto
|
||
|
// <GPIO_PIN_FUNCTION_OFF"> Off
|
||
|
// <GPIO_PIN_FUNCTION_A"> A
|
||
|
// <GPIO_PIN_FUNCTION_B"> B
|
||
|
// <GPIO_PIN_FUNCTION_C"> C
|
||
|
// <GPIO_PIN_FUNCTION_D"> D
|
||
|
// <GPIO_PIN_FUNCTION_E"> E
|
||
|
// <GPIO_PIN_FUNCTION_F"> F
|
||
|
// <GPIO_PIN_FUNCTION_G"> G
|
||
|
// <GPIO_PIN_FUNCTION_H"> H
|
||
|
// <GPIO_PIN_FUNCTION_I"> I
|
||
|
// <GPIO_PIN_FUNCTION_J"> J
|
||
|
// <GPIO_PIN_FUNCTION_K"> K
|
||
|
// <GPIO_PIN_FUNCTION_L"> L
|
||
|
// <GPIO_PIN_FUNCTION_M"> M
|
||
|
// <GPIO_PIN_FUNCTION_N"> N
|
||
|
PINMUX_PB19I_SDHC1_SDDAT1);
|
||
|
|
||
|
gpio_set_pin_direction(PB20,
|
||
|
// <y> Pin direction
|
||
|
// <id> pad_direction
|
||
|
// <GPIO_DIRECTION_OFF"> Off
|
||
|
// <GPIO_DIRECTION_IN"> In
|
||
|
// <GPIO_DIRECTION_OUT"> Out
|
||
|
GPIO_DIRECTION_OUT);
|
||
|
|
||
|
gpio_set_pin_level(PB20,
|
||
|
// <y> Initial level
|
||
|
// <id> pad_initial_level
|
||
|
// <false"> Low
|
||
|
// <true"> High
|
||
|
false);
|
||
|
|
||
|
gpio_set_pin_pull_mode(PB20,
|
||
|
// <y> Pull configuration
|
||
|
// <id> pad_pull_config
|
||
|
// <GPIO_PULL_OFF"> Off
|
||
|
// <GPIO_PULL_UP"> Pull-up
|
||
|
// <GPIO_PULL_DOWN"> Pull-down
|
||
|
GPIO_PULL_OFF);
|
||
|
|
||
|
gpio_set_pin_function(PB20,
|
||
|
// <y> Pin function
|
||
|
// <id> pad_function
|
||
|
// <i> Auto : use driver pinmux if signal is imported by driver, else turn off function
|
||
|
// <PINMUX_PB20I_SDHC1_SDDAT2"> Auto
|
||
|
// <GPIO_PIN_FUNCTION_OFF"> Off
|
||
|
// <GPIO_PIN_FUNCTION_A"> A
|
||
|
// <GPIO_PIN_FUNCTION_B"> B
|
||
|
// <GPIO_PIN_FUNCTION_C"> C
|
||
|
// <GPIO_PIN_FUNCTION_D"> D
|
||
|
// <GPIO_PIN_FUNCTION_E"> E
|
||
|
// <GPIO_PIN_FUNCTION_F"> F
|
||
|
// <GPIO_PIN_FUNCTION_G"> G
|
||
|
// <GPIO_PIN_FUNCTION_H"> H
|
||
|
// <GPIO_PIN_FUNCTION_I"> I
|
||
|
// <GPIO_PIN_FUNCTION_J"> J
|
||
|
// <GPIO_PIN_FUNCTION_K"> K
|
||
|
// <GPIO_PIN_FUNCTION_L"> L
|
||
|
// <GPIO_PIN_FUNCTION_M"> M
|
||
|
// <GPIO_PIN_FUNCTION_N"> N
|
||
|
PINMUX_PB20I_SDHC1_SDDAT2);
|
||
|
|
||
|
gpio_set_pin_direction(PB21,
|
||
|
// <y> Pin direction
|
||
|
// <id> pad_direction
|
||
|
// <GPIO_DIRECTION_OFF"> Off
|
||
|
// <GPIO_DIRECTION_IN"> In
|
||
|
// <GPIO_DIRECTION_OUT"> Out
|
||
|
GPIO_DIRECTION_OUT);
|
||
|
|
||
|
gpio_set_pin_level(PB21,
|
||
|
// <y> Initial level
|
||
|
// <id> pad_initial_level
|
||
|
// <false"> Low
|
||
|
// <true"> High
|
||
|
false);
|
||
|
|
||
|
gpio_set_pin_pull_mode(PB21,
|
||
|
// <y> Pull configuration
|
||
|
// <id> pad_pull_config
|
||
|
// <GPIO_PULL_OFF"> Off
|
||
|
// <GPIO_PULL_UP"> Pull-up
|
||
|
// <GPIO_PULL_DOWN"> Pull-down
|
||
|
GPIO_PULL_OFF);
|
||
|
|
||
|
gpio_set_pin_function(PB21,
|
||
|
// <y> Pin function
|
||
|
// <id> pad_function
|
||
|
// <i> Auto : use driver pinmux if signal is imported by driver, else turn off function
|
||
|
// <PINMUX_PB21I_SDHC1_SDDAT3"> Auto
|
||
|
// <GPIO_PIN_FUNCTION_OFF"> Off
|
||
|
// <GPIO_PIN_FUNCTION_A"> A
|
||
|
// <GPIO_PIN_FUNCTION_B"> B
|
||
|
// <GPIO_PIN_FUNCTION_C"> C
|
||
|
// <GPIO_PIN_FUNCTION_D"> D
|
||
|
// <GPIO_PIN_FUNCTION_E"> E
|
||
|
// <GPIO_PIN_FUNCTION_F"> F
|
||
|
// <GPIO_PIN_FUNCTION_G"> G
|
||
|
// <GPIO_PIN_FUNCTION_H"> H
|
||
|
// <GPIO_PIN_FUNCTION_I"> I
|
||
|
// <GPIO_PIN_FUNCTION_J"> J
|
||
|
// <GPIO_PIN_FUNCTION_K"> K
|
||
|
// <GPIO_PIN_FUNCTION_L"> L
|
||
|
// <GPIO_PIN_FUNCTION_M"> M
|
||
|
// <GPIO_PIN_FUNCTION_N"> N
|
||
|
PINMUX_PB21I_SDHC1_SDDAT3);
|
||
|
}
|
||
|
|
||
|
void IO_BUS_CLOCK_init(void)
|
||
|
{
|
||
|
hri_mclk_set_AHBMASK_SDHC1_bit(MCLK);
|
||
|
hri_gclk_write_PCHCTRL_reg(GCLK, SDHC1_GCLK_ID, CONF_GCLK_SDHC1_SRC | (1 << GCLK_PCHCTRL_CHEN_Pos));
|
||
|
hri_gclk_write_PCHCTRL_reg(GCLK, SDHC1_GCLK_ID_SLOW, CONF_GCLK_SDHC1_SLOW_SRC | (1 << GCLK_PCHCTRL_CHEN_Pos));
|
||
|
}
|
||
|
|
||
|
void IO_BUS_init(void)
|
||
|
{
|
||
|
IO_BUS_CLOCK_init();
|
||
|
mci_sync_init(&IO_BUS, SDHC1);
|
||
|
IO_BUS_PORT_init();
|
||
|
}
|
||
|
|
||
|
/* The USB module requires a GCLK_USB of 48 MHz ~ 0.25% clock
|
||
|
* for low speed and full speed operation. */
|
||
|
#if (CONF_GCLK_USB_FREQUENCY > (48000000 + 48000000 / 400)) || (CONF_GCLK_USB_FREQUENCY < (48000000 - 48000000 / 400))
|
||
|
#warning USB clock should be 48MHz ~ 0.25% clock, check your configuration!
|
||
|
#endif
|
||
|
|
||
|
/** \brief VBus control callback
|
||
|
* VBus must be always turned on if this callback is disabled.
|
||
|
*/
|
||
|
WEAK void my_vbus_ctrl_func(void *drv, uint8_t port, bool onoff)
|
||
|
{
|
||
|
/* Turn on/off your root hub port power */
|
||
|
}
|
||
|
|
||
|
void USB_HOST_INSTANCE_CLOCK_init(void)
|
||
|
{
|
||
|
|
||
|
hri_gclk_write_PCHCTRL_reg(GCLK, USB_GCLK_ID, CONF_GCLK_USB_SRC | GCLK_PCHCTRL_CHEN);
|
||
|
hri_mclk_set_AHBMASK_USB_bit(MCLK);
|
||
|
hri_mclk_set_APBBMASK_USB_bit(MCLK);
|
||
|
}
|
||
|
|
||
|
void USB_HOST_INSTANCE_PORT_init(void)
|
||
|
{
|
||
|
|
||
|
gpio_set_pin_direction(PA24,
|
||
|
// <y> Pin direction
|
||
|
// <id> pad_direction
|
||
|
// <GPIO_DIRECTION_OFF"> Off
|
||
|
// <GPIO_DIRECTION_IN"> In
|
||
|
// <GPIO_DIRECTION_OUT"> Out
|
||
|
GPIO_DIRECTION_OUT);
|
||
|
|
||
|
gpio_set_pin_level(PA24,
|
||
|
// <y> Initial level
|
||
|
// <id> pad_initial_level
|
||
|
// <false"> Low
|
||
|
// <true"> High
|
||
|
false);
|
||
|
|
||
|
gpio_set_pin_pull_mode(PA24,
|
||
|
// <y> Pull configuration
|
||
|
// <id> pad_pull_config
|
||
|
// <GPIO_PULL_OFF"> Off
|
||
|
// <GPIO_PULL_UP"> Pull-up
|
||
|
// <GPIO_PULL_DOWN"> Pull-down
|
||
|
GPIO_PULL_OFF);
|
||
|
|
||
|
gpio_set_pin_function(PA24,
|
||
|
// <y> Pin function
|
||
|
// <id> pad_function
|
||
|
// <i> Auto : use driver pinmux if signal is imported by driver, else turn off function
|
||
|
// <PINMUX_PA24H_USB_DM"> Auto
|
||
|
// <GPIO_PIN_FUNCTION_OFF"> Off
|
||
|
// <GPIO_PIN_FUNCTION_A"> A
|
||
|
// <GPIO_PIN_FUNCTION_B"> B
|
||
|
// <GPIO_PIN_FUNCTION_C"> C
|
||
|
// <GPIO_PIN_FUNCTION_D"> D
|
||
|
// <GPIO_PIN_FUNCTION_E"> E
|
||
|
// <GPIO_PIN_FUNCTION_F"> F
|
||
|
// <GPIO_PIN_FUNCTION_G"> G
|
||
|
// <GPIO_PIN_FUNCTION_H"> H
|
||
|
// <GPIO_PIN_FUNCTION_I"> I
|
||
|
// <GPIO_PIN_FUNCTION_J"> J
|
||
|
// <GPIO_PIN_FUNCTION_K"> K
|
||
|
// <GPIO_PIN_FUNCTION_L"> L
|
||
|
// <GPIO_PIN_FUNCTION_M"> M
|
||
|
// <GPIO_PIN_FUNCTION_N"> N
|
||
|
PINMUX_PA24H_USB_DM);
|
||
|
|
||
|
gpio_set_pin_direction(PA25,
|
||
|
// <y> Pin direction
|
||
|
// <id> pad_direction
|
||
|
// <GPIO_DIRECTION_OFF"> Off
|
||
|
// <GPIO_DIRECTION_IN"> In
|
||
|
// <GPIO_DIRECTION_OUT"> Out
|
||
|
GPIO_DIRECTION_OUT);
|
||
|
|
||
|
gpio_set_pin_level(PA25,
|
||
|
// <y> Initial level
|
||
|
// <id> pad_initial_level
|
||
|
// <false"> Low
|
||
|
// <true"> High
|
||
|
false);
|
||
|
|
||
|
gpio_set_pin_pull_mode(PA25,
|
||
|
// <y> Pull configuration
|
||
|
// <id> pad_pull_config
|
||
|
// <GPIO_PULL_OFF"> Off
|
||
|
// <GPIO_PULL_UP"> Pull-up
|
||
|
// <GPIO_PULL_DOWN"> Pull-down
|
||
|
GPIO_PULL_OFF);
|
||
|
|
||
|
gpio_set_pin_function(PA25,
|
||
|
// <y> Pin function
|
||
|
// <id> pad_function
|
||
|
// <i> Auto : use driver pinmux if signal is imported by driver, else turn off function
|
||
|
// <PINMUX_PA25H_USB_DP"> Auto
|
||
|
// <GPIO_PIN_FUNCTION_OFF"> Off
|
||
|
// <GPIO_PIN_FUNCTION_A"> A
|
||
|
// <GPIO_PIN_FUNCTION_B"> B
|
||
|
// <GPIO_PIN_FUNCTION_C"> C
|
||
|
// <GPIO_PIN_FUNCTION_D"> D
|
||
|
// <GPIO_PIN_FUNCTION_E"> E
|
||
|
// <GPIO_PIN_FUNCTION_F"> F
|
||
|
// <GPIO_PIN_FUNCTION_G"> G
|
||
|
// <GPIO_PIN_FUNCTION_H"> H
|
||
|
// <GPIO_PIN_FUNCTION_I"> I
|
||
|
// <GPIO_PIN_FUNCTION_J"> J
|
||
|
// <GPIO_PIN_FUNCTION_K"> K
|
||
|
// <GPIO_PIN_FUNCTION_L"> L
|
||
|
// <GPIO_PIN_FUNCTION_M"> M
|
||
|
// <GPIO_PIN_FUNCTION_N"> N
|
||
|
PINMUX_PA25H_USB_DP);
|
||
|
}
|
||
|
|
||
|
void USB_HOST_INSTANCE_init(void)
|
||
|
{
|
||
|
USB_HOST_INSTANCE_CLOCK_init();
|
||
|
usb_h_init(&USB_HOST_INSTANCE_inst, USB, NULL);
|
||
|
USB_HOST_INSTANCE_PORT_init();
|
||
|
}
|
||
|
|
||
|
void system_init(void)
|
||
|
{
|
||
|
init_mcu();
|
||
|
|
||
|
QUAD_SPI_0_init();
|
||
|
|
||
|
CALENDER_INTERFACE_init();
|
||
|
|
||
|
SPI_0_init();
|
||
|
|
||
|
USART_DBG_init();
|
||
|
|
||
|
IO_BUS_init();
|
||
|
|
||
|
USB_HOST_INSTANCE_init();
|
||
|
}
|