periph_conf.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2015 Kaspar Schleiser <kaspar@schleiser.de>
3  * 2015 FreshTemp, LLC.
4  * 2014-2016 Freie Universität Berlin
5  *
6  * This file is subject to the terms and conditions of the GNU Lesser
7  * General Public License v2.1. See the file LICENSE in the top level
8  * directory for more details.
9  */
10 
11 #pragma once
12 
25 #include "periph_cpu.h"
26 
27 #ifdef __cplusplus
28 extern "C" {
29 #endif
30 
34 #define CLOCK_CORECLOCK (48000000U)
35 
40 #define USE_VREG_BUCK (1)
41 
46 static const tc32_conf_t timer_config[] = {
47  { /* Timer 0 - System Clock */
48  .dev = TC0,
49  .irq = TC0_IRQn,
50  .mclk = &MCLK->APBCMASK.reg,
51  .mclk_mask = MCLK_APBCMASK_TC0_Msk | MCLK_APBCMASK_TC1_Msk,
52  .gclk_id = TC0_GCLK_ID,
53  .gclk_src = SAM0_GCLK_TIMER,
54  .flags = TC_CTRLA_MODE_COUNT32,
55  }
56 };
57 
58 /* Timer 0 configuration */
59 #define TIMER_0_CHANNELS 2
60 #define TIMER_0_ISR isr_tc0
61 #define TIMER_NUMOF ARRAY_SIZE(timer_config)
68 static const uart_conf_t uart_config[] = {
69  { /* Virtual COM Port */
70  .dev = &SERCOM3->USART,
71  .rx_pin = GPIO_PIN(PA,23),
72  .tx_pin = GPIO_PIN(PA,22),
73 #ifdef MODULE_PERIPH_UART_HW_FC
74  .rts_pin = GPIO_UNDEF,
75  .cts_pin = GPIO_UNDEF,
76 #endif
77  .mux = GPIO_MUX_C,
78  .rx_pad = UART_PAD_RX_1,
79  .tx_pad = UART_PAD_TX_0,
80  .flags = UART_FLAG_NONE,
81  .gclk_src = SAM0_GCLK_MAIN,
82  },
83  { /* EXT1 header */
84  .dev = &SERCOM4->USART,
85  .rx_pin = GPIO_PIN(PB, 9),
86  .tx_pin = GPIO_PIN(PB, 8),
87 #ifdef MODULE_PERIPH_UART_HW_FC
88  .rts_pin = GPIO_UNDEF,
89  .cts_pin = GPIO_UNDEF,
90 #endif
91  .mux = GPIO_MUX_D,
92  .rx_pad = UART_PAD_RX_1,
93  .tx_pad = UART_PAD_TX_0,
94  .flags = UART_FLAG_NONE,
95  .gclk_src = SAM0_GCLK_MAIN,
96  },
97  { /* EXT2 header */
98  .dev = &SERCOM1->USART,
99  .rx_pin = GPIO_PIN(PA, 19),
100  .tx_pin = GPIO_PIN(PA, 18),
101 #ifdef MODULE_PERIPH_UART_HW_FC
102  .rts_pin = GPIO_UNDEF,
103  .cts_pin = GPIO_UNDEF,
104 #endif
105  .mux = GPIO_MUX_C,
106  .rx_pad = UART_PAD_RX_3,
107  .tx_pad = UART_PAD_TX_2,
108  .flags = UART_FLAG_NONE,
109  .gclk_src = SAM0_GCLK_MAIN,
110  }
111 };
112 
113 /* interrupt function name mapping */
114 #define UART_0_ISR isr_sercom3
115 #define UART_1_ISR isr_sercom4
116 #define UART_2_ISR isr_sercom1
117 
118 #define UART_NUMOF ARRAY_SIZE(uart_config)
125 /* PWM0 channels */
126 static const pwm_conf_chan_t pwm_chan0_config[] = {
127  /* GPIO pin, MUX value, TCC channel */
128  {
129  .pin = GPIO_PIN(PB, 10),
130  .mux = GPIO_MUX_F,
131  .chan = 4
132  },
133 };
134 
135 /* PWM device configuration */
136 static const pwm_conf_t pwm_config[] = {
137  {
138  .tim = TCC_CONFIG(TCC0),
139  .chan = pwm_chan0_config,
140  .chan_numof = ARRAY_SIZE(pwm_chan0_config),
141  .gclk_src = SAM0_GCLK_TIMER,
142  },
143 };
144 
145 /* number of devices that are actually defined */
146 #define PWM_NUMOF ARRAY_SIZE(pwm_config)
153 static const spi_conf_t spi_config[] = {
154  { /* EXT1 header */
155  .dev = &(SERCOM0->SPI),
156  .miso_pin = GPIO_PIN(PA, 4),
157  .mosi_pin = GPIO_PIN(PA, 6),
158  .clk_pin = GPIO_PIN(PA, 7),
159  .miso_mux = GPIO_MUX_D,
160  .mosi_mux = GPIO_MUX_D,
161  .clk_mux = GPIO_MUX_D,
162  .miso_pad = SPI_PAD_MISO_0,
163  .mosi_pad = SPI_PAD_MOSI_2_SCK_3,
164  .gclk_src = SAM0_GCLK_MAIN,
165 #ifdef MODULE_PERIPH_DMA
166  .tx_trigger = SERCOM0_DMAC_ID_TX,
167  .rx_trigger = SERCOM0_DMAC_ID_RX,
168 #endif
169  },
170  { /* EXT2, EXT3 header */
171  .dev = &(SERCOM5->SPI),
172  .miso_pin = GPIO_PIN(PB, 16),
173  .mosi_pin = GPIO_PIN(PB, 22),
174  .clk_pin = GPIO_PIN(PB, 23),
175  .miso_mux = GPIO_MUX_C,
176  .mosi_mux = GPIO_MUX_D,
177  .clk_mux = GPIO_MUX_D,
178  .miso_pad = SPI_PAD_MISO_0,
179  .mosi_pad = SPI_PAD_MOSI_2_SCK_3,
180  .gclk_src = SAM0_GCLK_MAIN,
181 #ifdef MODULE_PERIPH_DMA
182  /* no DMA on SERCOM5 */
183  .tx_trigger = DMA_TRIGGER_DISABLED,
184  .rx_trigger = DMA_TRIGGER_DISABLED,
185 #endif
186  }
187 };
188 
189 #define SPI_NUMOF ARRAY_SIZE(spi_config)
196 static const i2c_conf_t i2c_config[] = {
197  {
198  .dev = &(SERCOM2->I2CM),
199  .speed = I2C_SPEED_NORMAL,
200  .scl_pin = GPIO_PIN(PA, 9),
201  .sda_pin = GPIO_PIN(PA, 8),
202  .mux = GPIO_MUX_D,
203  .gclk_src = SAM0_GCLK_MAIN,
204  .flags = I2C_FLAG_NONE
205  }
206 };
207 
208 #define I2C_NUMOF ARRAY_SIZE(i2c_config)
215 #define EXTERNAL_OSC32_SOURCE 1
216 #define INTERNAL_OSC32_SOURCE 0
217 #define ULTRA_LOW_POWER_INTERNAL_OSC_SOURCE 0
224 #ifndef RTT_FREQUENCY
225 #define RTT_FREQUENCY (32768U)
226 #endif
234 /* ADC Default values */
235 #define ADC_PRESCALER ADC_CTRLB_PRESCALER_DIV256
236 
237 #define ADC_NEG_INPUT ADC_INPUTCTRL_MUXNEG(0x18u)
238 #define ADC_REF_DEFAULT ADC_REFCTRL_REFSEL_INTVCC2
239 
240 static const adc_conf_chan_t adc_channels[] = {
241  /* port, pin, muxpos */
242  { .inputctrl = ADC_INPUTCTRL_MUXPOS_PA10 },
243  { .inputctrl = ADC_INPUTCTRL_MUXPOS_PA11 },
244  { .inputctrl = ADC_INPUTCTRL_MUXPOS_PA02 }
245 };
246 
247 #define ADC_NUMOF ARRAY_SIZE(adc_channels)
254  /* Must not exceed 12 MHz */
255 #define DAC_CLOCK SAM0_GCLK_TIMER
256  /* use Vcc as reference voltage */
257 #define DAC_VREF DAC_CTRLB_REFSEL_VDDANA
264 static const sam0_common_usb_config_t sam_usbdev_config[] = {
265  {
266  .dm = GPIO_PIN(PA, 24),
267  .dp = GPIO_PIN(PA, 25),
268  .d_mux = GPIO_MUX_G,
269  .device = &USB->DEVICE,
270  .gclk_src = SAM0_GCLK_48MHZ,
271  }
272 };
275 #ifdef __cplusplus
276 }
277 #endif
278 
#define GPIO_PIN(x, y)
Define a CPU specific GPIO pin generator macro.
Definition: periph_cpu.h:45
#define GPIO_UNDEF
Definition of a fitting UNDEF value.
static const uart_conf_t uart_config[]
UART configuration.
Definition: periph_conf.h:38
static const spi_conf_t spi_config[]
SPI configuration.
Definition: periph_conf.h:96
static const i2c_conf_t i2c_config[]
I2C configuration.
Definition: periph_conf.h:68
static const timer_conf_t timer_config[]
All timers on board.
Definition: periph_conf.h:39
static const pwm_conf_t pwm_config[]
Actual PWM configuration.
Definition: periph_conf.h:221
#define ARRAY_SIZE(a)
Calculate the number of elements in a static array.
Definition: container.h:82
static const gpio_t adc_channels[]
Static array with declared ADC channels.
@ I2C_SPEED_NORMAL
normal mode: ~100 kbit/s
Definition: periph_cpu.h:277
@ UART_PAD_RX_1
select pad 1
@ UART_PAD_RX_3
select pad 3
@ PB
port B
@ PA
port A
@ I2C_FLAG_NONE
No flags set.
@ SPI_PAD_MISO_0
use pad 0 for MISO line
#define DMA_TRIGGER_DISABLED
Indicates that the peripheral doesn't utilize the DMA controller.
@ UART_FLAG_NONE
No flags set.
@ UART_PAD_TX_0
select pad 0
@ UART_PAD_TX_2
select pad 2
#define TCC_CONFIG(tim)
Static initializer for TCC timer configuration.
@ GPIO_MUX_D
select peripheral function D
@ GPIO_MUX_G
select peripheral function G
@ GPIO_MUX_C
select peripheral function C
@ GPIO_MUX_F
select peripheral function F
@ SPI_PAD_MOSI_2_SCK_3
use pad 2 for MOSI, pad 3 for SCK
#define ADC_INPUTCTRL_MUXPOS_PA10
Alias for PIN18.
Definition: periph_cpu.h:136
#define ADC_INPUTCTRL_MUXPOS_PA11
Alias for PIN19.
Definition: periph_cpu.h:137
#define ADC_INPUTCTRL_MUXPOS_PA02
ADC pin aliases.
Definition: periph_cpu.h:118
#define SAM0_GCLK_MAIN
120 MHz main clock
Definition: periph_cpu.h:73
@ SAM0_GCLK_TIMER
4/8MHz clock for timers
Definition: periph_cpu.h:70
@ SAM0_GCLK_48MHZ
48MHz clock
Definition: periph_cpu.h:72
ADC Channel Configuration.
I2C configuration structure.
Definition: periph_cpu.h:298
TWI_t * dev
Pointer to hardware module registers.
Definition: periph_cpu.h:299
PWM channel configuration data structure.
gpio_t pin
GPIO pin.
PWM device configuration.
tc_tcc_cfg_t tim
timer configuration
USB peripheral parameters.
SPI device configuration.
Definition: periph_cpu.h:336
SPI_t * dev
pointer to the used SPI device
Definition: periph_cpu.h:337
Timer device configuration.
TC0_t * dev
Pointer to the used as Timer device.
Definition: periph_cpu.h:264
UART device configuration.
Definition: periph_cpu.h:217
USART_t * dev
pointer to the used UART device
Definition: periph_cpu.h:218