periph_conf.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2021 Franz Freitag, Justus Krebs, Nick Weiler
3  *
4  * This file is subject to the terms and conditions of the GNU Lesser
5  * General Public License v2.1. See the file LICENSE in the top level
6  * directory for more details.
7  */
8 
9 #pragma once
10 
23 #include <stdint.h>
24 
25 #include "cpu.h"
26 #include "periph_cpu.h"
27 
28 #ifdef __cplusplus
29 extern "C" {
30 #endif
31 
63 #define CLOCK_USE_PLL (1)
64 
65 #if CLOCK_USE_PLL
66 /* edit these values to adjust the PLL output frequency */
67 #define CLOCK_PLL_MUL (47U) /* must be >= 31 & <= 95 */
68 #define CLOCK_PLL_DIV (1U) /* adjust to your needs */
69 #define CLOCK_CORECLOCK (((CLOCK_PLL_MUL + 1) * 1000000U) / CLOCK_PLL_DIV)
70 #else
71 /* edit this value to your needs */
72 #define CLOCK_DIV (1U)
73 /* generate the actual core clock frequency */
74 #define CLOCK_CORECLOCK (8000000 / CLOCK_DIV)
75 #endif
82 static const tc32_conf_t timer_config[] = {
83  { /* Timer 0 - System Clock */
84  .dev = TC3,
85  .irq = TC3_IRQn,
86  .pm_mask = PM_APBCMASK_TC3,
87  .gclk_ctrl = GCLK_CLKCTRL_ID_TCC2_TC3,
88 #if CLOCK_USE_PLL || CLOCK_USE_XOSC32_DFLL
89  .gclk_src = SAM0_GCLK_1MHZ,
90 #else
91  .gclk_src = SAM0_GCLK_MAIN,
92 #endif
93  .flags = TC_CTRLA_MODE_COUNT16,
94  },
95  { /* Timer 1 */
96  .dev = TC4,
97  .irq = TC4_IRQn,
98  .pm_mask = PM_APBCMASK_TC4 | PM_APBCMASK_TC5,
99  .gclk_ctrl = GCLK_CLKCTRL_ID_TC4_TC5,
100 #if CLOCK_USE_PLL || CLOCK_USE_XOSC32_DFLL
101  .gclk_src = SAM0_GCLK_1MHZ,
102 #else
103  .gclk_src = SAM0_GCLK_MAIN,
104 #endif
105  .flags = TC_CTRLA_MODE_COUNT32,
106  }
107 };
108 
109 #define TIMER_0_MAX_VALUE 0xffff
110 
111 /* interrupt function name mapping */
112 #define TIMER_0_ISR isr_tc3
113 #define TIMER_1_ISR isr_tc4
114 
115 #define TIMER_NUMOF ARRAY_SIZE(timer_config)
122 static const uart_conf_t uart_config[] = {
123  {
124  .dev = &SERCOM4->USART,
125  .rx_pin = GPIO_PIN(PB, 9), /* D5 */
126  .tx_pin = GPIO_PIN(PB, 8), /* D4 */
127  .mux = GPIO_MUX_D,
128  .rx_pad = UART_PAD_RX_1,
129  .tx_pad = UART_PAD_TX_0,
130  .flags = UART_FLAG_NONE,
131  .gclk_src = SAM0_GCLK_MAIN,
132  }
133 };
134 
135 /* interrupt function name mapping */
136 #define UART_0_ISR isr_sercom4
137 
138 #define UART_NUMOF ARRAY_SIZE(uart_config)
145 static const spi_conf_t spi_config[] = {
146  { /* D0 … D2 (user pins) */
147  .dev = &SERCOM0->SPI,
148  .miso_pin = GPIO_PIN(PA, 5), /* D9 */
149  .mosi_pin = GPIO_PIN(PA, 6), /* D10 */
150  .clk_pin = GPIO_PIN(PA, 7), /* D8 */
151  .miso_mux = GPIO_MUX_D,
152  .mosi_mux = GPIO_MUX_D,
153  .clk_mux = GPIO_MUX_D,
154  .miso_pad = SPI_PAD_MISO_1,
155  .mosi_pad = SPI_PAD_MOSI_2_SCK_3,
156  .gclk_src = SAM0_GCLK_MAIN,
157 #ifdef MODULE_PERIPH_DMA
158  .tx_trigger = SERCOM0_DMAC_ID_TX,
159  .rx_trigger = SERCOM0_DMAC_ID_RX,
160 #endif
161  },
162 };
163 
164 #define SPI_NUMOF ARRAY_SIZE(spi_config)
171 static const i2c_conf_t i2c_config[] = {
172  {
173  .dev = &(SERCOM2->I2CM),
174  .speed = I2C_SPEED_NORMAL,
175  .scl_pin = GPIO_PIN(PA, 9), /* D5 */
176  .sda_pin = GPIO_PIN(PA, 8), /* D4 */
177  .mux = GPIO_MUX_D,
178  .gclk_src = SAM0_GCLK_MAIN,
179  .flags = I2C_FLAG_NONE
180  }
181 };
182 #define I2C_NUMOF ARRAY_SIZE(i2c_config)
189 #ifndef RTT_FREQUENCY
190 #define RTT_FREQUENCY (32768U) /* in Hz. For changes see `rtt.c` */
191 #endif
198 #define ADC_PRESCALER ADC_CTRLB_PRESCALER_DIV512
199 
200 #define ADC_NEG_INPUT ADC_INPUTCTRL_MUXNEG_GND
201 #define ADC_GAIN_FACTOR_DEFAULT ADC_INPUTCTRL_GAIN_1X
202 #define ADC_REF_DEFAULT ADC_REFCTRL_REFSEL_INT1V
203 
204 static const adc_conf_chan_t adc_channels[] = {
205  /* port, pin, muxpos */
206  { .inputctrl = ADC_INPUTCTRL_MUXPOS_PA02 },
207  { .inputctrl = ADC_INPUTCTRL_MUXPOS_PA04 },
208  { .inputctrl = ADC_INPUTCTRL_MUXPOS_PA05 },
209  { .inputctrl = ADC_INPUTCTRL_MUXPOS_PA06 },
210  { .inputctrl = ADC_INPUTCTRL_MUXPOS_PA07 },
211  { .inputctrl = ADC_INPUTCTRL_MUXPOS_PA08 },
212  { .inputctrl = ADC_INPUTCTRL_MUXPOS_PA09 },
213  { .inputctrl = ADC_INPUTCTRL_MUXPOS_PB08 },
214  { .inputctrl = ADC_INPUTCTRL_MUXPOS_PB09 }
215 };
216 
217 #define ADC_NUMOF ARRAY_SIZE(adc_channels)
224 static const sam0_common_usb_config_t sam_usbdev_config[] = {
225  {
226  .dm = GPIO_PIN(PA, 24),
227  .dp = GPIO_PIN(PA, 25),
228  .d_mux = GPIO_MUX_G,
229  .device = &USB->DEVICE,
230  .gclk_src = SAM0_GCLK_MAIN,
231  }
232 };
235 #ifdef __cplusplus
236 }
237 #endif
238 
#define GPIO_PIN(x, y)
Define a CPU specific GPIO pin generator macro.
Definition: periph_cpu.h:45
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 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
@ 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:298
TWI_t * dev
Pointer to hardware module registers.
Definition: periph_cpu.h:299
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