periph_conf.h
Go to the documentation of this file.
1 /*
2  * SPDX-FileCopyrightText: 2021 Franz Freitag, Justus Krebs, Nick Weiler
3  * SPDX-License-Identifier: LGPL-2.1-only
4  */
5 
6 #pragma once
7 
20 #include <stdint.h>
21 
22 #include "cpu.h"
23 #include "periph_cpu.h"
24 
25 #ifdef __cplusplus
26 extern "C" {
27 #endif
28 
60 #define CLOCK_USE_PLL (1)
61 
62 #if CLOCK_USE_PLL
63 /* edit these values to adjust the PLL output frequency */
64 #define CLOCK_PLL_MUL (47U) /* must be >= 31 & <= 95 */
65 #define CLOCK_PLL_DIV (1U) /* adjust to your needs */
66 #define CLOCK_CORECLOCK (((CLOCK_PLL_MUL + 1) * 1000000U) / CLOCK_PLL_DIV)
67 #else
68 /* edit this value to your needs */
69 #define CLOCK_DIV (1U)
70 /* generate the actual core clock frequency */
71 #define CLOCK_CORECLOCK (8000000 / CLOCK_DIV)
72 #endif
79 static const tc32_conf_t timer_config[] = {
80  { /* Timer 0 - System Clock */
81  .dev = TC3,
82  .irq = TC3_IRQn,
83  .pm_mask = PM_APBCMASK_TC3,
84  .gclk_ctrl = GCLK_CLKCTRL_ID_TCC2_TC3,
85 #if CLOCK_USE_PLL || CLOCK_USE_XOSC32_DFLL
86  .gclk_src = SAM0_GCLK_1MHZ,
87 #else
88  .gclk_src = SAM0_GCLK_MAIN,
89 #endif
90  .flags = TC_CTRLA_MODE_COUNT16,
91  },
92  { /* Timer 1 */
93  .dev = TC4,
94  .irq = TC4_IRQn,
95  .pm_mask = PM_APBCMASK_TC4 | PM_APBCMASK_TC5,
96  .gclk_ctrl = GCLK_CLKCTRL_ID_TC4_TC5,
97 #if CLOCK_USE_PLL || CLOCK_USE_XOSC32_DFLL
98  .gclk_src = SAM0_GCLK_1MHZ,
99 #else
100  .gclk_src = SAM0_GCLK_MAIN,
101 #endif
102  .flags = TC_CTRLA_MODE_COUNT32,
103  }
104 };
105 
106 #define TIMER_0_MAX_VALUE 0xffff
107 
108 /* interrupt function name mapping */
109 #define TIMER_0_ISR isr_tc3
110 #define TIMER_1_ISR isr_tc4
111 
112 #define TIMER_NUMOF ARRAY_SIZE(timer_config)
119 static const uart_conf_t uart_config[] = {
120  {
121  .dev = &SERCOM4->USART,
122  .rx_pin = GPIO_PIN(PB, 9), /* D5 */
123  .tx_pin = GPIO_PIN(PB, 8), /* D4 */
124  .mux = GPIO_MUX_D,
125  .rx_pad = UART_PAD_RX_1,
126  .tx_pad = UART_PAD_TX_0,
127  .flags = UART_FLAG_NONE,
128  .gclk_src = SAM0_GCLK_MAIN,
129  }
130 };
131 
132 /* interrupt function name mapping */
133 #define UART_0_ISR isr_sercom4
134 
135 #define UART_NUMOF ARRAY_SIZE(uart_config)
142 static const spi_conf_t spi_config[] = {
143  { /* D0 … D2 (user pins) */
144  .dev = &SERCOM0->SPI,
145  .miso_pin = GPIO_PIN(PA, 5), /* D9 */
146  .mosi_pin = GPIO_PIN(PA, 6), /* D10 */
147  .clk_pin = GPIO_PIN(PA, 7), /* D8 */
148  .miso_mux = GPIO_MUX_D,
149  .mosi_mux = GPIO_MUX_D,
150  .clk_mux = GPIO_MUX_D,
151  .miso_pad = SPI_PAD_MISO_1,
152  .mosi_pad = SPI_PAD_MOSI_2_SCK_3,
153  .gclk_src = SAM0_GCLK_MAIN,
154 #ifdef MODULE_PERIPH_DMA
155  .tx_trigger = SERCOM0_DMAC_ID_TX,
156  .rx_trigger = SERCOM0_DMAC_ID_RX,
157 #endif
158  },
159 };
160 
161 #define SPI_NUMOF ARRAY_SIZE(spi_config)
168 static const i2c_conf_t i2c_config[] = {
169  {
170  .dev = &(SERCOM2->I2CM),
171  .speed = I2C_SPEED_NORMAL,
172  .scl_pin = GPIO_PIN(PA, 9), /* D5 */
173  .sda_pin = GPIO_PIN(PA, 8), /* D4 */
174  .mux = GPIO_MUX_D,
175  .gclk_src = SAM0_GCLK_MAIN,
176  .flags = I2C_FLAG_NONE
177  }
178 };
179 #define I2C_NUMOF ARRAY_SIZE(i2c_config)
186 #ifndef RTT_FREQUENCY
187 #define RTT_FREQUENCY (32768U) /* in Hz. For changes see `rtt.c` */
188 #endif
195 #define ADC_PRESCALER ADC_CTRLB_PRESCALER_DIV512
196 
197 #define ADC_NEG_INPUT ADC_INPUTCTRL_MUXNEG_GND
198 #define ADC_GAIN_FACTOR_DEFAULT ADC_INPUTCTRL_GAIN_1X
199 #define ADC_REF_DEFAULT ADC_REFCTRL_REFSEL_INT1V
200 
201 static const adc_conf_chan_t adc_channels[] = {
202  /* port, pin, muxpos */
203  { .inputctrl = ADC_INPUTCTRL_MUXPOS_PA02 },
204  { .inputctrl = ADC_INPUTCTRL_MUXPOS_PA04 },
205  { .inputctrl = ADC_INPUTCTRL_MUXPOS_PA05 },
206  { .inputctrl = ADC_INPUTCTRL_MUXPOS_PA06 },
207  { .inputctrl = ADC_INPUTCTRL_MUXPOS_PA07 },
208  { .inputctrl = ADC_INPUTCTRL_MUXPOS_PA08 },
209  { .inputctrl = ADC_INPUTCTRL_MUXPOS_PA09 },
210  { .inputctrl = ADC_INPUTCTRL_MUXPOS_PB08 },
211  { .inputctrl = ADC_INPUTCTRL_MUXPOS_PB09 }
212 };
213 
214 #define ADC_NUMOF ARRAY_SIZE(adc_channels)
221 static const sam0_common_usb_config_t sam_usbdev_config[] = {
222  {
223  .dm = GPIO_PIN(PA, 24),
224  .dp = GPIO_PIN(PA, 25),
225  .d_mux = GPIO_MUX_G,
226  .device = &USB->DEVICE,
227  .gclk_src = SAM0_GCLK_MAIN,
228  }
229 };
232 #ifdef __cplusplus
233 }
234 #endif
235 
#define GPIO_PIN(x, y)
Define a CPU specific GPIO pin generator macro.
Definition: periph_cpu.h:42
static const uart_conf_t uart_config[]
UART configuration.
Definition: periph_conf.h:35
static const spi_conf_t spi_config[]
SPI configuration.
Definition: periph_conf.h:93
static const i2c_conf_t i2c_config[]
I2C configuration.
Definition: periph_conf.h:65
static const timer_conf_t timer_config[]
All timers on board.
Definition: periph_conf.h:36
static const gpio_t adc_channels[]
Static array with declared ADC channels.
@ I2C_SPEED_NORMAL
normal mode: ~100 kbit/s
Definition: periph_cpu.h:274
@ UART_PAD_RX_1
select pad 1
@ PB
port B
@ PA
port A
@ I2C_FLAG_NONE
No flags set.
@ SPI_PAD_MISO_1
use pad 1 for MISO line
@ UART_FLAG_NONE
No flags set.
@ UART_PAD_TX_0
select pad 0
@ GPIO_MUX_D
select peripheral function D
@ GPIO_MUX_G
select peripheral function G
@ SPI_PAD_MOSI_2_SCK_3
use pad 2 for MOSI, pad 3 for SCK
#define ADC_INPUTCTRL_MUXPOS_PA05
Alias for PIN5.
Definition: periph_cpu.h:123
#define ADC_INPUTCTRL_MUXPOS_PB08
Alias for PIN2.
Definition: periph_cpu.h:120
@ SAM0_GCLK_1MHZ
1 MHz clock for xTimer
Definition: periph_cpu.h:75
#define ADC_INPUTCTRL_MUXPOS_PA08
Alias for PIN16.
Definition: periph_cpu.h:134
#define ADC_INPUTCTRL_MUXPOS_PB09
Alias for PIN3.
Definition: periph_cpu.h:121
#define ADC_INPUTCTRL_MUXPOS_PA09
Alias for PIN17.
Definition: periph_cpu.h:135
#define ADC_INPUTCTRL_MUXPOS_PA07
Alias for PIN7.
Definition: periph_cpu.h:125
#define ADC_INPUTCTRL_MUXPOS_PA04
Alias for PIN4.
Definition: periph_cpu.h:122
#define ADC_INPUTCTRL_MUXPOS_PA06
Alias for PIN6.
Definition: periph_cpu.h:124
#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
ADC Channel Configuration.
I2C configuration structure.
Definition: periph_cpu.h:295
TWI_t * dev
Pointer to hardware module registers.
Definition: periph_cpu.h:296
USB peripheral parameters.
SPI device configuration.
Definition: periph_cpu.h:333
SPI_t * dev
pointer to the used SPI device
Definition: periph_cpu.h:334
Timer device configuration.
TC0_t * dev
Pointer to the used as Timer device.
Definition: periph_cpu.h:261
UART device configuration.
Definition: periph_cpu.h:214
USART_t * dev
pointer to the used UART device
Definition: periph_cpu.h:215