197 lines
6.4 KiB
C
197 lines
6.4 KiB
C
/*
|
|
* 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>
|
|
|
|
/*! The buffer size for USART */
|
|
#define TARGET_IO_BUFFER_SIZE 16
|
|
|
|
struct usart_async_descriptor TARGET_IO;
|
|
|
|
static uint8_t TARGET_IO_buffer[TARGET_IO_BUFFER_SIZE];
|
|
|
|
/**
|
|
* \brief USART Clock initialization function
|
|
*
|
|
* Enables register interface and peripheral clock
|
|
*/
|
|
void TARGET_IO_CLOCK_init()
|
|
{
|
|
|
|
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);
|
|
}
|
|
|
|
/**
|
|
* \brief USART pinmux initialization function
|
|
*
|
|
* Set each required pin to USART functionality
|
|
*/
|
|
void TARGET_IO_PORT_init()
|
|
{
|
|
|
|
gpio_set_pin_function(PB26, PINMUX_PB26C_SERCOM2_PAD0);
|
|
|
|
gpio_set_pin_function(PB27, PINMUX_PB27C_SERCOM2_PAD1);
|
|
}
|
|
|
|
/**
|
|
* \brief USART initialization function
|
|
*
|
|
* Enables USART peripheral, clocks and initializes USART driver
|
|
*/
|
|
void TARGET_IO_init(void)
|
|
{
|
|
TARGET_IO_CLOCK_init();
|
|
usart_async_init(&TARGET_IO, SERCOM2, TARGET_IO_buffer, TARGET_IO_BUFFER_SIZE, (void *)NULL);
|
|
TARGET_IO_PORT_init();
|
|
}
|
|
|
|
void USB_DEVICE_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);
|
|
}
|
|
|
|
/* 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
|
|
|
|
void USB_DEVICE_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_DEVICE_INSTANCE_init(void)
|
|
{
|
|
USB_DEVICE_INSTANCE_CLOCK_init();
|
|
usb_d_init();
|
|
USB_DEVICE_INSTANCE_PORT_init();
|
|
}
|
|
|
|
void system_init(void)
|
|
{
|
|
init_mcu();
|
|
|
|
// GPIO on PA15
|
|
|
|
gpio_set_pin_level(LED0,
|
|
// <y> Initial level
|
|
// <id> pad_initial_level
|
|
// <false"> Low
|
|
// <true"> High
|
|
false);
|
|
|
|
// Set pin direction to output
|
|
gpio_set_pin_direction(LED0, GPIO_DIRECTION_OUT);
|
|
|
|
gpio_set_pin_function(LED0, GPIO_PIN_FUNCTION_OFF);
|
|
|
|
TARGET_IO_init();
|
|
|
|
USB_DEVICE_INSTANCE_init();
|
|
}
|