Loading...
Searching...
No Matches
periph_conf.h
Go to the documentation of this file.
1/*
2 * Copyright (C) 2021 ML!PA Consulting GmbH
3 * 2023 Gunar Schorcht
4 *
5 * This file is subject to the terms and conditions of the GNU Lesser
6 * General Public License v2.1. See the file LICENSE in the top level
7 * directory for more details.
8 */
9
21#ifndef PERIPH_CONF_H
22#define PERIPH_CONF_H
23
24#include "periph_cpu.h"
25
26#ifdef __cplusplus
27extern "C" {
28#endif
29
34#ifndef CLOCK_CORECLOCK
35#define CLOCK_CORECLOCK MHZ(120)
36#endif
43#define EXTERNAL_OSC32_SOURCE 1
44#define INTERNAL_OSC32_SOURCE 0
45#define ULTRA_LOW_POWER_INTERNAL_OSC_SOURCE 0
52#define USE_VREG_BUCK (1)
53
59/* ADC Default values */
60#define ADC_GCLK_SRC SAM0_GCLK_PERIPH
61#define ADC_PRESCALER ADC_CTRLA_PRESCALER_DIV8
62
63#define ADC_NEG_INPUT ADC_INPUTCTRL_MUXNEG(0x18u)
64#define ADC_REF_DEFAULT ADC_REFCTRL_REFSEL_INTVCC1
65
66static const adc_conf_chan_t adc_channels[] = {
67 /* port, pin, muxpos, dev */
68 { .inputctrl = ADC0_INPUTCTRL_MUXPOS_PA02, .dev = ADC0 }, /* A0 */
69 { .inputctrl = ADC0_INPUTCTRL_MUXPOS_PA05, .dev = ADC0 }, /* A1 */
70 { .inputctrl = ADC0_INPUTCTRL_MUXPOS_PB03, .dev = ADC0 }, /* A2 */
71 { .inputctrl = ADC1_INPUTCTRL_MUXPOS_PC00, .dev = ADC1 }, /* A3 */
72 { .inputctrl = ADC1_INPUTCTRL_MUXPOS_PC01, .dev = ADC1 }, /* A4 */
73 { .inputctrl = ADC1_INPUTCTRL_MUXPOS_PC02, .dev = ADC1 }, /* A5 */
74 { .inputctrl = ADC1_INPUTCTRL_MUXPOS_PC03, .dev = ADC1 }, /* A6 */
75 { .inputctrl = ADC1_INPUTCTRL_MUXPOS_PB04, .dev = ADC1 }, /* A7 */
76 { .inputctrl = ADC1_INPUTCTRL_MUXPOS_PB05, .dev = ADC1 }, /* A8 */
77 { .inputctrl = ADC1_INPUTCTRL_MUXPOS_PB06, .dev = ADC1 }, /* A9 */
78 { .inputctrl = ADC1_INPUTCTRL_MUXPOS_PB07, .dev = ADC1 }, /* A10 */
79 { .inputctrl = ADC0_INPUTCTRL_MUXPOS_PB08, .dev = ADC0 }, /* A11 */
80 { .inputctrl = ADC0_INPUTCTRL_MUXPOS_PB09, .dev = ADC0 }, /* A12 */
81 { .inputctrl = ADC0_INPUTCTRL_MUXPOS_PA04, .dev = ADC0 }, /* A13 */
82 { .inputctrl = ADC0_INPUTCTRL_MUXPOS_PA06, .dev = ADC0 }, /* A14 */
83 { .inputctrl = ADC0_INPUTCTRL_MUXPOS_PA07, .dev = ADC0 }, /* A15 */
84};
85
86#define ADC_NUMOF ARRAY_SIZE(adc_channels)
93 /* Must not exceed 12 MHz */
94#define DAC_CLOCK SAM0_GCLK_TIMER
95 /* Use external reference voltage on PA03 */
96 /* (You have to manually connect PA03 with Vcc) */
97 /* Internal reference only gives 1V */
98#define DAC_VREF DAC_CTRLB_REFSEL_VREFPU
105static const i2c_conf_t i2c_config[] = {
106 {
107 .dev = &(SERCOM3->I2CM),
108 .speed = I2C_SPEED_NORMAL,
109 .scl_pin = GPIO_PIN(PB, 21), /* D21 (SCL) */
110 .sda_pin = GPIO_PIN(PB, 20), /* D20 (SDA) */
111 .mux = GPIO_MUX_C,
112 .gclk_src = SAM0_GCLK_PERIPH,
113 .flags = I2C_FLAG_NONE
114 },
115 {
116 .dev = &(SERCOM6->I2CM),
117 .speed = I2C_SPEED_NORMAL,
118 .scl_pin = GPIO_PIN(PC, 17), /* D24 */
119 .sda_pin = GPIO_PIN(PC, 16), /* D25 */
120 .mux = GPIO_MUX_C,
121 .gclk_src = SAM0_GCLK_PERIPH,
122 .flags = I2C_FLAG_NONE
123 },
124};
125
126#define I2C_NUMOF ARRAY_SIZE(i2c_config)
133#define PWM_0_EN 1
134
135#if PWM_0_EN
136/* PWM0 channels */
137static const pwm_conf_chan_t pwm_chan0_config[] = {
138 /* GPIO pin, MUX value, TCC channel */
139 { GPIO_PIN(PA, 22), GPIO_MUX_G, 2 },
140};
141#endif
142
143/* PWM device configuration */
144static const pwm_conf_t pwm_config[] = {
145#if PWM_0_EN
146 { .tim = TCC_CONFIG(TCC0),
147 .chan = pwm_chan0_config,
148 .chan_numof = ARRAY_SIZE(pwm_chan0_config),
149 .gclk_src = SAM0_GCLK_PERIPH,
150 },
151#endif
152};
153
154/* number of devices that are actually defined */
155#define PWM_NUMOF ARRAY_SIZE(pwm_config)
162#ifndef RTT_FREQUENCY
163#define RTT_FREQUENCY (32768U)
164#endif
171static const tc32_conf_t timer_config[] = {
172 { /* Timer 0 - System Clock */
173 .dev = TC0,
174 .irq = TC0_IRQn,
175 .mclk = &MCLK->APBAMASK.reg,
176 .mclk_mask = MCLK_APBAMASK_TC0 | MCLK_APBAMASK_TC1,
177 .gclk_id = TC0_GCLK_ID,
178 .gclk_src = SAM0_GCLK_TIMER,
179 .flags = TC_CTRLA_MODE_COUNT32,
180 },
181 { /* Timer 1 */
182 .dev = TC2,
183 .irq = TC2_IRQn,
184 .mclk = &MCLK->APBBMASK.reg,
185 .mclk_mask = MCLK_APBBMASK_TC2 | MCLK_APBBMASK_TC3,
186 .gclk_id = TC2_GCLK_ID,
187 .gclk_src = SAM0_GCLK_TIMER,
188 .flags = TC_CTRLA_MODE_COUNT32,
189 }
190};
191
192/* Timer 0 configuration */
193#define TIMER_0_CHANNELS 2
194#define TIMER_0_ISR isr_tc0
195
196/* Timer 1 configuration */
197#define TIMER_1_CHANNELS 2
198#define TIMER_1_ISR isr_tc2
199
200#define TIMER_NUMOF ARRAY_SIZE(timer_config)
207static const spi_conf_t spi_config[] = {
208 { /* SPI on XIO connector *AND* SPI on ISP */
209 .dev = &(SERCOM7->SPI),
210 .miso_pin = GPIO_PIN(PD, 11), /* D50 MISO */
211 .mosi_pin = GPIO_PIN(PD, 8), /* D51 MOSI */
212 .clk_pin = GPIO_PIN(PD, 9), /* D52 SCK */
213 .miso_mux = GPIO_MUX_C,
214 .mosi_mux = GPIO_MUX_C,
215 .clk_mux = GPIO_MUX_C,
216 .miso_pad = SPI_PAD_MISO_3,
217 .mosi_pad = SPI_PAD_MOSI_0_SCK_1,
218 .gclk_src = SAM0_GCLK_PERIPH,
219#ifdef MODULE_PERIPH_DMA
220 .tx_trigger = SERCOM7_DMAC_ID_TX,
221 .rx_trigger = SERCOM7_DMAC_ID_RX,
222#endif
223 },
224 { /* SD Card */
225 .dev = &(SERCOM2->SPI),
226 .miso_pin = GPIO_PIN(PB, 29),
227 .mosi_pin = GPIO_PIN(PB, 26),
228 .clk_pin = GPIO_PIN(PB, 27),
229 .miso_mux = GPIO_MUX_C,
230 .mosi_mux = GPIO_MUX_C,
231 .clk_mux = GPIO_MUX_C,
232 .miso_pad = SPI_PAD_MISO_3,
233 .mosi_pad = SPI_PAD_MOSI_0_SCK_1,
234 .gclk_src = SAM0_GCLK_PERIPH,
235#ifdef MODULE_PERIPH_DMA
236 .tx_trigger = SERCOM2_DMAC_ID_TX,
237 .rx_trigger = SERCOM2_DMAC_ID_RX,
238#endif
239 },
240#ifdef MODULE_PERIPH_SPI_ON_QSPI
241 { /* QSPI in SPI mode */
242 .dev = QSPI,
243 .miso_pin = SAM0_QSPI_PIN_DATA_1,
244 .mosi_pin = SAM0_QSPI_PIN_DATA_0,
245 .clk_pin = SAM0_QSPI_PIN_CLK,
246 .miso_mux = SAM0_QSPI_MUX,
247 .mosi_mux = SAM0_QSPI_MUX,
248 .clk_mux = SAM0_QSPI_MUX,
249 .miso_pad = SPI_PAD_MISO_0, /* unused */
250 .mosi_pad = SPI_PAD_MOSI_0_SCK_1, /* unused */
251 .gclk_src = SAM0_GCLK_MAIN, /* unused */
252#ifdef MODULE_PERIPH_DMA
253 .tx_trigger = QSPI_DMAC_ID_TX,
254 .rx_trigger = QSPI_DMAC_ID_RX,
255#endif
256 },
257#endif
258};
259
260#define SPI_NUMOF ARRAY_SIZE(spi_config)
267static const sam0_common_usb_config_t sam_usbdev_config[] = {
268 {
269 .dm = GPIO_PIN(PA, 24),
270 .dp = GPIO_PIN(PA, 25),
271 .d_mux = GPIO_MUX_H,
272 .device = &USB->DEVICE,
273 .gclk_src = SAM0_GCLK_PERIPH,
274 }
275};
282static const uart_conf_t uart_config[] = {
283 {
284 .dev = &SERCOM0->USART,
285 .rx_pin = GPIO_PIN(PB, 25), /* D0 (UART0_RX) */
286 .tx_pin = GPIO_PIN(PB, 24), /* D1 (UART0_TX) */
287#ifdef MODULE_PERIPH_UART_HW_FC
288 .rts_pin = GPIO_UNDEF,
289 .cts_pin = GPIO_UNDEF,
290#endif
291 .mux = GPIO_MUX_C,
292 .rx_pad = UART_PAD_RX_1,
293 .tx_pad = UART_PAD_TX_0,
294 .flags = UART_FLAG_NONE,
295 .gclk_src = SAM0_GCLK_PERIPH,
296 },
297 {
298 .dev = &SERCOM4->USART,
299 .rx_pin = GPIO_PIN(PB, 13), /* D19 (UART2_RX) */
300 .tx_pin = GPIO_PIN(PB, 12), /* D18 (UART2_TX) */
301#ifdef MODULE_PERIPH_UART_HW_FC
302 .rts_pin = GPIO_UNDEF,
303 .cts_pin = GPIO_UNDEF,
304#endif
305 .mux = GPIO_MUX_C,
306 .rx_pad = UART_PAD_RX_1,
307 .tx_pad = UART_PAD_TX_0,
308 .flags = UART_FLAG_NONE,
309 .gclk_src = SAM0_GCLK_PERIPH,
310 },
311 {
312 .dev = &SERCOM1->USART,
313 .rx_pin = GPIO_PIN(PC, 23), /* D17 (UART2_RX) */
314 .tx_pin = GPIO_PIN(PC, 22), /* D16 (UART2_TX) */
315#ifdef MODULE_PERIPH_UART_HW_FC
316 .rts_pin = GPIO_UNDEF,
317 .cts_pin = GPIO_UNDEF,
318#endif
319 .mux = GPIO_MUX_C,
320 .rx_pad = UART_PAD_RX_1,
321 .tx_pad = UART_PAD_TX_0,
322 .flags = UART_FLAG_NONE,
323 .gclk_src = SAM0_GCLK_PERIPH,
324 },
325};
326
327/* interrupt function name mapping */
328#define UART_0_ISR isr_sercom0_2
329#define UART_0_ISR_TX isr_sercom0_0
330#define UART_1_ISR isr_sercom4_2
331#define UART_1_ISR_TX isr_sercom4_0
332#define UART_2_ISR isr_sercom1_2
333#define UART_2_ISR_TX isr_sercom1_0
334
335#define UART_NUMOF ARRAY_SIZE(uart_config)
338#ifdef __cplusplus
339}
340#endif
341
342#endif /* PERIPH_CONF_H */
#define GPIO_PIN(x, y)
Define a CPU specific GPIO pin generator macro.
Definition periph_cpu.h:46
#define GPIO_UNDEF
Definition of a fitting UNDEF value.
@ I2C_SPEED_NORMAL
normal mode: ~100 kbit/s
Definition periph_cpu.h:278
#define ARRAY_SIZE(a)
Calculate the number of elements in a static array.
Definition container.h:83
@ UART_PAD_RX_1
select pad 1
@ PB
port B
@ PC
port C
@ PA
port A
@ PD
port D
@ I2C_FLAG_NONE
No flags set.
@ SPI_PAD_MISO_0
use pad 0 for MISO line
@ SPI_PAD_MISO_3
use pad 3 for MISO line
@ UART_FLAG_NONE
No flags set.
@ UART_PAD_TX_0
select pad 0
#define TCC_CONFIG(tim)
Static initializer for TCC timer configuration.
@ GPIO_MUX_H
select peripheral function H
@ GPIO_MUX_G
select peripheral function G
@ GPIO_MUX_C
select peripheral function C
@ SPI_PAD_MOSI_0_SCK_1
use pad 0 for MOSI, pad 1 for SCK
#define ADC1_INPUTCTRL_MUXPOS_PC03
Alias for AIN5.
Definition periph_cpu.h:148
#define SAM0_GCLK_MAIN
120 MHz main clock
Definition periph_cpu.h:74
#define ADC0_INPUTCTRL_MUXPOS_PA04
Alias for AIN4.
Definition periph_cpu.h:130
#define ADC0_INPUTCTRL_MUXPOS_PA07
Alias for AIN7.
Definition periph_cpu.h:133
#define ADC1_INPUTCTRL_MUXPOS_PC02
Alias for AIN4.
Definition periph_cpu.h:147
#define SAM0_QSPI_PIN_CLK
Clock
Definition periph_cpu.h:269
#define ADC1_INPUTCTRL_MUXPOS_PB05
Alias for AIN7.
Definition periph_cpu.h:150
#define ADC1_INPUTCTRL_MUXPOS_PB04
Alias for AIN6.
Definition periph_cpu.h:149
#define ADC1_INPUTCTRL_MUXPOS_PC00
Alias for AIN10.
Definition periph_cpu.h:153
#define ADC0_INPUTCTRL_MUXPOS_PA05
Alias for AIN5.
Definition periph_cpu.h:131
#define SAM0_QSPI_PIN_DATA_0
D0 / MOSI
Definition periph_cpu.h:271
#define ADC1_INPUTCTRL_MUXPOS_PC01
Alias for AIN11.
Definition periph_cpu.h:154
#define SAM0_QSPI_PIN_DATA_1
D1 / MISO
Definition periph_cpu.h:272
#define ADC0_INPUTCTRL_MUXPOS_PB03
Alias for AIN15.
Definition periph_cpu.h:141
#define ADC0_INPUTCTRL_MUXPOS_PB08
Alias for AIN2.
Definition periph_cpu.h:128
#define ADC1_INPUTCTRL_MUXPOS_PB07
Alias for AIN9.
Definition periph_cpu.h:152
#define SAM0_QSPI_MUX
QSPI mux
Definition periph_cpu.h:275
#define ADC0_INPUTCTRL_MUXPOS_PB09
Alias for AIN3.
Definition periph_cpu.h:129
#define ADC0_INPUTCTRL_MUXPOS_PA06
Alias for AIN6.
Definition periph_cpu.h:132
#define SAM0_GCLK_TIMER
4-8 MHz clock for xTimer
Definition periph_cpu.h:79
#define ADC0_INPUTCTRL_MUXPOS_PA02
ADC pin aliases.
Definition periph_cpu.h:126
#define SAM0_GCLK_PERIPH
12-48 MHz (DFLL) clock
Definition periph_cpu.h:82
#define ADC1_INPUTCTRL_MUXPOS_PB06
Alias for AIN8.
Definition periph_cpu.h:151
ADC Channel Configuration.
uint32_t inputctrl
ADC channel pin multiplexer value
I2C configuration structure.
Definition periph_cpu.h:299
TWI_t * dev
Pointer to hardware module registers.
Definition periph_cpu.h:300
PWM channel configuration data structure.
PWM device configuration.
tc_tcc_cfg_t tim
timer configuration
USB peripheral parameters.
SPI device configuration.
Definition periph_cpu.h:337
SPI_t * dev
pointer to the used SPI device
Definition periph_cpu.h:338
Timer device configuration.
Tc * dev
pointer to the used Timer device
UART device configuration.
Definition periph_cpu.h:218
USART_t * dev
pointer to the used UART device
Definition periph_cpu.h:219