periph_conf.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2020 ML!PA Consulting GmbH
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 
24 #include <stdint.h>
25 
26 #include "cpu.h"
27 #include "periph_cpu.h"
28 
29 #ifdef __cplusplus
30 extern "C" {
31 #endif
32 
65 #define CLOCK_USE_PLL (0)
66 #define CLOCK_USE_XOSC32_DFLL (1)
67 /*
68  * 0: use XOSC32K (always 32.768kHz) to clock GCLK2
69  * 1: use OSCULP32K factory calibrated (~32.768kHz) to clock GCLK2
70  *
71  * OSCULP32K is factory calibrated to be around 32.768kHz but this values can
72  * be of by a couple off % points, so prefer XOSC32K as default configuration.
73  */
74 #define GEN2_ULP32K (0)
75 
76 #if CLOCK_USE_PLL
77 /* edit these values to adjust the PLL output frequency */
78 #define CLOCK_PLL_MUL (47U) /* must be >= 31 & <= 95 */
79 #define CLOCK_PLL_DIV (1U) /* adjust to your needs */
80 /* generate the actual used core clock frequency */
81 #define CLOCK_CORECLOCK (((CLOCK_PLL_MUL + 1) * 1000000U) / CLOCK_PLL_DIV)
82 #elif CLOCK_USE_XOSC32_DFLL
83 /* Settings for 32 kHz external oscillator and 48 MHz DFLL */
84 #define CLOCK_CORECLOCK (48000000U)
85 #define CLOCK_XOSC32K (32768UL)
86 #define CLOCK_8MHZ (1)
87 #else
88 /* edit this value to your needs */
89 #define CLOCK_DIV (1U)
90 /* generate the actual core clock frequency */
91 #define CLOCK_CORECLOCK (8000000 / CLOCK_DIV)
92 #endif
99 static const tc32_conf_t timer_config[] = {
100  { /* Timer 0 - System Clock */
101  .dev = TC0,
102  .irq = TC0_IRQn,
103  .pm_mask = PM_APBCMASK_TC0 | PM_APBCMASK_TC1,
104  .gclk_ctrl = GCLK_CLKCTRL_ID_TC0_TC1,
105 #if CLOCK_USE_PLL || CLOCK_USE_XOSC32_DFLL
106  .gclk_src = SAM0_GCLK_1MHZ,
107 #else
108  .gclk_src = SAM0_GCLK_MAIN,
109 #endif
110  .flags = TC_CTRLA_MODE_COUNT32,
111  },
112  { /* Timer 1 */
113  .dev = TC4,
114  .irq = TC4_IRQn,
115  .pm_mask = PM_APBCMASK_TC4 | PM_APBCMASK_TC5,
116  .gclk_ctrl = GCLK_CLKCTRL_ID_TC4_TC5,
117 #if CLOCK_USE_PLL || CLOCK_USE_XOSC32_DFLL
118  .gclk_src = SAM0_GCLK_1MHZ,
119 #else
120  .gclk_src = SAM0_GCLK_MAIN,
121 #endif
122  .flags = TC_CTRLA_MODE_COUNT32,
123  }
124 };
125 
126 /* interrupt function name mapping */
127 #define TIMER_0_ISR isr_tc0
128 #define TIMER_1_ISR isr_tc4
129 
130 #define TIMER_NUMOF ARRAY_SIZE(timer_config)
137 static const uart_conf_t uart_config[] = {
138  { /* Virtual COM Port */
139  .dev = &SERCOM3->USART,
140  .rx_pin = GPIO_PIN(PA,25),
141  .tx_pin = GPIO_PIN(PA,24),
142 #ifdef MODULE_PERIPH_UART_HW_FC
143  .rts_pin = GPIO_UNDEF,
144  .cts_pin = GPIO_UNDEF,
145 #endif
146  .mux = GPIO_MUX_C,
147  .rx_pad = UART_PAD_RX_3,
148  .tx_pad = UART_PAD_TX_2,
149  .flags = UART_FLAG_NONE,
150  .gclk_src = SAM0_GCLK_MAIN,
151  },
152  { /* EXT1 */
153  .dev = &SERCOM4->USART,
154  .rx_pin = GPIO_PIN(PB,9),
155  .tx_pin = GPIO_PIN(PB,8),
156 #ifdef MODULE_PERIPH_UART_HW_FC
157  .rts_pin = GPIO_UNDEF,
158  .cts_pin = GPIO_UNDEF,
159 #endif
160  .mux = GPIO_MUX_D,
161  .rx_pad = UART_PAD_RX_1,
162  .tx_pad = UART_PAD_TX_0,
163  .flags = UART_FLAG_NONE,
164  .gclk_src = SAM0_GCLK_MAIN,
165  },
166  { /* EXT2 */
167  .dev = &SERCOM0->USART,
168  .rx_pin = GPIO_PIN(PA,9),
169  .tx_pin = GPIO_PIN(PA,8),
170 #ifdef MODULE_PERIPH_UART_HW_FC
171  .rts_pin = GPIO_UNDEF,
172  .cts_pin = GPIO_UNDEF,
173 #endif
174  .mux = GPIO_MUX_C,
175  .rx_pad = UART_PAD_RX_1,
176  .tx_pad = UART_PAD_TX_0,
177  .flags = UART_FLAG_NONE,
178  .gclk_src = SAM0_GCLK_MAIN,
179  },
180 };
181 
182 /* interrupt function name mapping */
183 #define UART_0_ISR isr_sercom3
184 #define UART_1_ISR isr_sercom4
185 #define UART_2_ISR isr_sercom0
186 
187 #define UART_NUMOF ARRAY_SIZE(uart_config)
194 static const spi_conf_t spi_config[] = {
195  { /* EXT1 */
196  .dev = &SERCOM0->SPI,
197  .miso_pin = GPIO_PIN(PA, 4),
198  .mosi_pin = GPIO_PIN(PA, 6),
199  .clk_pin = GPIO_PIN(PA, 7),
200  .miso_mux = GPIO_MUX_D,
201  .mosi_mux = GPIO_MUX_D,
202  .clk_mux = GPIO_MUX_D,
203  .miso_pad = SPI_PAD_MISO_0,
204  .mosi_pad = SPI_PAD_MOSI_2_SCK_3,
205  .gclk_src = SAM0_GCLK_MAIN,
206  },
207  { /* EXT2 */
208  .dev = &SERCOM1->SPI,
209  .miso_pin = GPIO_PIN(PA, 16),
210  .mosi_pin = GPIO_PIN(PA, 18),
211  .clk_pin = GPIO_PIN(PA, 19),
212  .miso_mux = GPIO_MUX_C,
213  .mosi_mux = GPIO_MUX_C,
214  .clk_mux = GPIO_MUX_C,
215  .miso_pad = SPI_PAD_MISO_0,
216  .mosi_pad = SPI_PAD_MOSI_2_SCK_3,
217  .gclk_src = SAM0_GCLK_MAIN,
218  },
219  { /* EXT3 */
220  .dev = &SERCOM5->SPI,
221  .miso_pin = GPIO_PIN(PB, 16),
222  .mosi_pin = GPIO_PIN(PB, 22),
223  .clk_pin = GPIO_PIN(PB, 23),
224  .miso_mux = GPIO_MUX_C,
225  .mosi_mux = GPIO_MUX_D,
226  .clk_mux = GPIO_MUX_D,
227  .miso_pad = SPI_PAD_MISO_0,
228  .mosi_pad = SPI_PAD_MOSI_2_SCK_3,
229  .gclk_src = SAM0_GCLK_MAIN,
230  },
231 };
232 
233 #define SPI_NUMOF ARRAY_SIZE(spi_config)
240 static const i2c_conf_t i2c_config[] = {
241  {
242  .dev = &(SERCOM2->I2CM),
243  .speed = I2C_SPEED_NORMAL,
244  .scl_pin = GPIO_PIN(PA, 9),
245  .sda_pin = GPIO_PIN(PA, 8),
246  .mux = GPIO_MUX_D,
247  .gclk_src = SAM0_GCLK_MAIN,
248  .flags = I2C_FLAG_NONE
249  }
250 };
251 #define I2C_NUMOF ARRAY_SIZE(i2c_config)
258 #ifndef RTT_FREQUENCY
259 #define RTT_FREQUENCY (32768U) /* in Hz. For changes see `rtt.c` */
260 #endif
267 #define PWM_0_EN 1
268 
269 #if PWM_0_EN
270 /* PWM0 channels */
271 static const pwm_conf_chan_t pwm_chan0_config[] = {
272  /* GPIO pin, MUX value, TCC channel */
273  { GPIO_PIN(PA, 14), GPIO_MUX_E, 0 },
274 };
275 #endif
276 
277 /* PWM device configuration */
278 static const pwm_conf_t pwm_config[] = {
279 #if PWM_0_EN
280  { .tim = TC_CONFIG(TC3),
281  .chan = pwm_chan0_config,
282  .chan_numof = ARRAY_SIZE(pwm_chan0_config),
283  .gclk_src = SAM0_GCLK_1MHZ,
284  },
285 #endif
286 };
287 
288 /* number of devices that are actually defined */
289 #define PWM_NUMOF ARRAY_SIZE(pwm_config)
297 /* ADC Default values */
298 #define ADC_PRESCALER ADC_CTRLB_PRESCALER_DIV128
299 
300 #define ADC_NEG_INPUT ADC_INPUTCTRL_MUXNEG_GND
301 #define ADC_GAIN_FACTOR_DEFAULT ADC_INPUTCTRL_GAIN_1X
302 #define ADC_REF_DEFAULT ADC_REFCTRL_REFSEL_INT1V
303 
304 static const adc_conf_chan_t adc_channels[] = {
305  /* port, pin, muxpos */
306  { .inputctrl = ADC_INPUTCTRL_MUXPOS_PB00 }, /* EXT1, pin 3 */
307  { .inputctrl = ADC_INPUTCTRL_MUXPOS_PB01 }, /* EXT1, pin 4 */
308  { .inputctrl = ADC_INPUTCTRL_MUXPOS_PA10 }, /* EXT2, pin 3 */
309  { .inputctrl = ADC_INPUTCTRL_MUXPOS_PA11 }, /* EXT2, pin 4 */
310  { .inputctrl = ADC_INPUTCTRL_MUXPOS_PA02 }, /* EXT3, pin 3 */
311  { .inputctrl = ADC_INPUTCTRL_MUXPOS_PA03 } /* EXT3, pin 4.*/
312 };
313 
314 #define ADC_NUMOF ARRAY_SIZE(adc_channels)
321 #define DAC_CLOCK SAM0_GCLK_1MHZ
322  /* use Vcc as reference voltage */
323 #define DAC_VREF DAC_CTRLB_REFSEL_AVCC
326 #ifdef __cplusplus
327 }
328 #endif
329 
#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.
#define TC_CONFIG(tim)
Static initializer for TC timer configuration.
@ SPI_PAD_MISO_0
use pad 0 for MISO line
@ UART_FLAG_NONE
No flags set.
@ UART_PAD_TX_0
select pad 0
@ UART_PAD_TX_2
select pad 2
@ GPIO_MUX_E
select peripheral function E
@ GPIO_MUX_D
select peripheral function D
@ GPIO_MUX_C
select peripheral function C
@ SPI_PAD_MOSI_2_SCK_3
use pad 2 for MOSI, pad 3 for SCK
@ SAM0_GCLK_1MHZ
1 MHz clock for xTimer
Definition: periph_cpu.h:75
#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_PB01
Alias for PIN9.
Definition: periph_cpu.h:127
#define ADC_INPUTCTRL_MUXPOS_PA02
ADC pin aliases.
Definition: periph_cpu.h:118
#define ADC_INPUTCTRL_MUXPOS_PA03
Alias for PIN1.
Definition: periph_cpu.h:119
#define ADC_INPUTCTRL_MUXPOS_PB00
Alias for PIN8.
Definition: periph_cpu.h:126
#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
PWM channel configuration data structure.
PWM device configuration.
tc_tcc_cfg_t tim
timer configuration
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