-
Notifications
You must be signed in to change notification settings - Fork 7
/
driver_init.c
65 lines (52 loc) · 1.47 KB
/
driver_init.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
/*
* 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 USART_0_BUFFER_SIZE 32
struct usart_async_descriptor USART_0;
static uint8_t USART_0_buffer[USART_0_BUFFER_SIZE];
/**
* \brief USART Clock initialization function
*
* Enables register interface and peripheral clock
*/
void USART_0_CLOCK_init()
{
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_APBCMASK_SERCOM4_bit(MCLK);
}
/**
* \brief USART pinmux initialization function
*
* Set each required pin to USART functionality
*/
void USART_0_PORT_init()
{
gpio_set_pin_function(PB08, PINMUX_PB08D_SERCOM4_PAD0);
gpio_set_pin_function(PB09, PINMUX_PB09D_SERCOM4_PAD1);
}
/**
* \brief USART initialization function
*
* Enables USART peripheral, clocks and initializes USART driver
*/
void USART_0_init(void)
{
USART_0_CLOCK_init();
usart_async_init(&USART_0, SERCOM4, USART_0_buffer, USART_0_BUFFER_SIZE, (void *)NULL);
USART_0_PORT_init();
}
void system_init(void)
{
init_mcu();
USART_0_init();
}