periph_conf.h
Go to the documentation of this file.
1 /*
2  * SPDX-FileCopyrightText: 2020 ML!PA Consulting GmbH
3  * SPDX-License-Identifier: LGPL-2.1-only
4  */
5 
6 #pragma once
7 
19 #include <stdint.h>
20 
21 #include "cpu.h"
22 #include "periph_cpu.h"
23 
24 #ifdef __cplusplus
25 extern "C" {
26 #endif
27 
60 #define CLOCK_USE_PLL (1)
61 #define CLOCK_USE_XOSC32_DFLL (0)
62 /*
63  * 0: use XOSC32K (always 32.768kHz) to clock GCLK2
64  * 1: use OSCULP32K factory calibrated (~32.768kHz) to clock GCLK2
65  *
66  * OSCULP32K is factory calibrated to be around 32.768kHz but this values can
67  * be of by a couple off % points, so prefer XOSC32K as default configuration.
68  */
69 #define GEN2_ULP32K (1)
70 
71 #if CLOCK_USE_PLL
72 /* edit these values to adjust the PLL output frequency */
73 #define CLOCK_PLL_MUL (47U) /* must be >= 31 & <= 95 */
74 #define CLOCK_PLL_DIV (1U) /* adjust to your needs */
75 /* generate the actual used core clock frequency */
76 #define CLOCK_CORECLOCK (((CLOCK_PLL_MUL + 1) * 1000000U) / CLOCK_PLL_DIV)
77 #elif CLOCK_USE_XOSC32_DFLL
78 /* Settings for 32 kHz external oscillator and 48 MHz DFLL */
79 #define CLOCK_CORECLOCK (48000000U)
80 #define CLOCK_XOSC32K (32768UL)
81 #define CLOCK_8MHZ (1)
82 #else
83 /* edit this value to your needs */
84 #define CLOCK_DIV (1U)
85 /* generate the actual core clock frequency */
86 #define CLOCK_CORECLOCK (8000000 / CLOCK_DIV)
87 #endif
94 static const tc32_conf_t timer_config[] = {
95  { /* Timer 0 - System Clock */
96  .dev = TC1,
97  .irq = TC1_IRQn,
98  .pm_mask = PM_APBCMASK_TC1 | PM_APBCMASK_TC2,
99  .gclk_ctrl = GCLK_CLKCTRL_ID_TC1_TC2,
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 0xffffffff
110 
111 /* interrupt function name mapping */
112 #define TIMER_0_ISR isr_tc1
113 
114 #define TIMER_NUMOF ARRAY_SIZE(timer_config)
121 static const uart_conf_t uart_config[] = {
122  { /* Virtual COM Port */
123  .dev = &SERCOM0->USART,
124  .rx_pin = GPIO_PIN(PA, 11),
125  .tx_pin = GPIO_PIN(PA, 10),
126 #ifdef MODULE_PERIPH_UART_HW_FC
127  .rts_pin = GPIO_UNDEF,
128  .cts_pin = GPIO_UNDEF,
129 #endif
130  .mux = GPIO_MUX_C,
131  .rx_pad = UART_PAD_RX_3,
132  .tx_pad = UART_PAD_TX_2,
133  .flags = UART_FLAG_NONE,
134  .gclk_src = SAM0_GCLK_MAIN,
135  },
136 };
137 
138 /* interrupt function name mapping */
139 #define UART_0_ISR isr_sercom0
140 
141 #define UART_NUMOF ARRAY_SIZE(uart_config)
148 #define PWM_0_EN 1
149 
150 #if PWM_0_EN
151 /* PWM0 channels */
152 static const pwm_conf_chan_t pwm_chan0_config[] = {
153  /* GPIO pin, MUX value, TCC channel */
154  { GPIO_PIN(PA, 17), GPIO_MUX_F, 7 },
155  { GPIO_PIN(PA, 22), GPIO_MUX_F, 4 },
156  { GPIO_PIN(PA, 23), GPIO_MUX_F, 5 },
157  { GPIO_PIN(PA, 24), GPIO_MUX_E, 2 },
158 };
159 #endif
160 
161 /* PWM device configuration */
162 static const pwm_conf_t pwm_config[] = {
163 #if PWM_0_EN
164  {TCC_CONFIG(TCC0), pwm_chan0_config, ARRAY_SIZE(pwm_chan0_config), SAM0_GCLK_MAIN},
165 #endif
166 };
167 
168 /* number of devices that are actually defined */
169 #define PWM_NUMOF ARRAY_SIZE(pwm_config)
176 static const spi_conf_t spi_config[] = {
177  { /* SPI header */
178  .dev = &SERCOM1->SPI,
179  .miso_pin = GPIO_PIN(PA, 24),
180  .mosi_pin = GPIO_PIN(PA, 22),
181  .clk_pin = GPIO_PIN(PA, 9),
182  .miso_mux = GPIO_MUX_C,
183  .mosi_mux = GPIO_MUX_C,
184  .clk_mux = GPIO_MUX_C,
185  .miso_pad = SPI_PAD_MISO_2,
186  .mosi_pad = SPI_PAD_MOSI_0_SCK_3,
187  .gclk_src = SAM0_GCLK_MAIN,
188  },
189 };
190 
191 #define SPI_NUMOF ARRAY_SIZE(spi_config)
198 static const i2c_conf_t i2c_config[] = {
199  {
200  .dev = &(SERCOM2->I2CM),
201  .speed = I2C_SPEED_NORMAL,
202  .scl_pin = GPIO_PIN(PA, 15),
203  .sda_pin = GPIO_PIN(PA, 14),
204  .mux = GPIO_MUX_D,
205  .gclk_src = SAM0_GCLK_MAIN,
206  .flags = I2C_FLAG_NONE
207  }
208 };
209 #define I2C_NUMOF ARRAY_SIZE(i2c_config)
216 #ifndef RTT_FREQUENCY
217 #define RTT_FREQUENCY (32768U) /* in Hz. For changes see `rtt.c` */
218 #endif
226 /* ADC Default values */
227 #define ADC_PRESCALER ADC_CTRLB_PRESCALER_DIV512
228 
229 #define ADC_NEG_INPUT ADC_INPUTCTRL_MUXNEG_GND
230 #define ADC_GAIN_FACTOR_DEFAULT ADC_INPUTCTRL_GAIN_1X
231 #define ADC_REF_DEFAULT ADC_REFCTRL_REFSEL_INT1V
232 
233 static const adc_conf_chan_t adc_channels[] = {
234  /* port, pin, muxpos */
235  { .inputctrl = ADC_INPUTCTRL_MUXPOS_PA02 },
236  { .inputctrl = ADC_INPUTCTRL_MUXPOS_PA03 },
237  { .inputctrl = ADC_INPUTCTRL_MUXPOS_PA04 },
238  { .inputctrl = ADC_INPUTCTRL_MUXPOS_PA05 },
239  { .inputctrl = ADC_INPUTCTRL_MUXPOS_PA06 },
240  { .inputctrl = ADC_INPUTCTRL_MUXPOS_PA07 },
241 };
242 
243 #define ADC_NUMOF ARRAY_SIZE(adc_channels)
250 #define DAC_CLOCK SAM0_GCLK_1MHZ
251  /* use Vcc as reference voltage */
252 #define DAC_VREF DAC_CTRLB_REFSEL_AVCC
255 #ifdef __cplusplus
256 }
257 #endif
258 
#define GPIO_PIN(x, y)
Define a CPU specific GPIO pin generator macro.
Definition: periph_cpu.h:42
#define GPIO_UNDEF
Definition of a fitting UNDEF value.
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 pwm_conf_t pwm_config[]
Actual PWM configuration.
Definition: periph_conf.h:218
#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:274
@ UART_PAD_RX_3
select pad 3
@ PA
port A
@ I2C_FLAG_NONE
No flags set.
@ SPI_PAD_MISO_2
use pad 2 for MISO line
@ UART_FLAG_NONE
No flags set.
@ UART_PAD_TX_2
select pad 2
#define TCC_CONFIG(tim)
Static initializer for TCC timer configuration.
@ GPIO_MUX_E
select peripheral function E
@ GPIO_MUX_D
select peripheral function D
@ GPIO_MUX_C
select peripheral function C
@ GPIO_MUX_F
select peripheral function F
@ SPI_PAD_MOSI_0_SCK_3
use pad 0 for MOSI, pad 3 for SCK
#define ADC_INPUTCTRL_MUXPOS_PA05
Alias for PIN5.
Definition: periph_cpu.h:123
@ SAM0_GCLK_1MHZ
1 MHz clock for xTimer
Definition: periph_cpu.h:75
#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 ADC_INPUTCTRL_MUXPOS_PA03
Alias for PIN1.
Definition: periph_cpu.h:119
#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
PWM channel configuration data structure.
PWM device configuration.
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