All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
Loading...
Searching...
No Matches
periph_conf.h
Go to the documentation of this file.
1/*
2 * Copyright (C) 2019 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
20#ifndef PERIPH_CONF_H
21#define PERIPH_CONF_H
22
23#include "periph_cpu.h"
24
25#ifdef __cplusplus
26extern "C" {
27#endif
28
35#ifndef USE_XOSC_ONLY
36#define USE_XOSC_ONLY (0)
37#endif
38
43#define XOSC1_FREQUENCY MHZ(12)
50#ifndef CLOCK_CORECLOCK
51#if USE_XOSC_ONLY
52#define CLOCK_CORECLOCK XOSC1_FREQUENCY
53#else
54#define CLOCK_CORECLOCK MHZ(120)
55#endif
56#endif
63#define EXTERNAL_OSC32_SOURCE 1
64#define ULTRA_LOW_POWER_INTERNAL_OSC_SOURCE 0
71#define USE_VREG_BUCK (1)
72
77static const tc32_conf_t timer_config[] = {
78 { /* Timer 0 - System Clock */
79 .dev = TC0,
80 .irq = TC0_IRQn,
81 .mclk = &MCLK->APBAMASK.reg,
82 .mclk_mask = MCLK_APBAMASK_TC0 | MCLK_APBAMASK_TC1,
83 .gclk_id = TC0_GCLK_ID,
84 .gclk_src = SAM0_GCLK_TIMER,
85 .flags = TC_CTRLA_MODE_COUNT32,
86 },
87 { /* Timer 1 */
88 .dev = TC2,
89 .irq = TC2_IRQn,
90 .mclk = &MCLK->APBBMASK.reg,
91 .mclk_mask = MCLK_APBBMASK_TC2 | MCLK_APBBMASK_TC3,
92 .gclk_id = TC2_GCLK_ID,
93 .gclk_src = SAM0_GCLK_TIMER,
94 .flags = TC_CTRLA_MODE_COUNT32,
95 }
96};
97
98/* Timer 0 configuration */
99#define TIMER_0_CHANNELS 2
100#define TIMER_0_ISR isr_tc0
101
102/* Timer 1 configuration */
103#define TIMER_1_CHANNELS 2
104#define TIMER_1_ISR isr_tc2
105
106#define TIMER_NUMOF ARRAY_SIZE(timer_config)
113#define AT6561_STBY_PIN GPIO_PIN(PC, 13)
121static const can_conf_t candev_conf[] = {
122 {
123 .can = CAN1,
124 .rx_pin = GPIO_PIN(PB, 13),
125 .tx_pin = GPIO_PIN(PB, 12),
126 .gclk_src = SAM0_GCLK_PERIPH,
127 .enable_pin = AT6561_STBY_PIN,
128 .enable_pin_mode = GPIO_OUT,
129 .enable_pin_active_low = true,
130 }
131};
132
134#define ISR_CAN1 isr_can1
135
137#define CAN_NUMOF ARRAY_SIZE(candev_conf)
144static const uart_conf_t uart_config[] = {
145 { /* Virtual COM Port */
146 .dev = &SERCOM2->USART,
147 .rx_pin = GPIO_PIN(PB, 24),
148 .tx_pin = GPIO_PIN(PB, 25),
149 .mux = GPIO_MUX_D,
150 .rx_pad = UART_PAD_RX_1,
151 .tx_pad = UART_PAD_TX_0,
152 .flags = UART_FLAG_NONE,
153 .gclk_src = SAM0_GCLK_PERIPH,
154 },
155 { /* EXT1 */
156 .dev = &SERCOM0->USART,
157 .rx_pin = GPIO_PIN(PA, 5),
158 .tx_pin = GPIO_PIN(PA, 4),
159#ifdef MODULE_PERIPH_UART_HW_FC
160 .rts_pin = GPIO_PIN(PA, 6),
161 .cts_pin = GPIO_PIN(PA, 7),
162#endif
163 .mux = GPIO_MUX_D,
164 .rx_pad = UART_PAD_RX_1,
165#ifdef MODULE_PERIPH_UART_HW_FC
167#else
168 .tx_pad = UART_PAD_TX_0,
169#endif
170 .flags = UART_FLAG_NONE,
171 .gclk_src = SAM0_GCLK_PERIPH,
172 },
173 { /* EXT2 */
174 .dev = &SERCOM5->USART,
175 .rx_pin = GPIO_PIN(PB, 17),
176 .tx_pin = GPIO_PIN(PB, 16),
177 .mux = GPIO_MUX_C,
178 .rx_pad = UART_PAD_RX_1,
179 .tx_pad = UART_PAD_TX_0,
180 .flags = UART_FLAG_NONE,
181 .gclk_src = SAM0_GCLK_PERIPH,
182 },
183 { /* EXT3 */
184 .dev = &SERCOM1->USART,
185 .rx_pin = GPIO_PIN(PC, 23),
186 .tx_pin = GPIO_PIN(PC, 22),
187 .mux = GPIO_MUX_C,
188 .rx_pad = UART_PAD_RX_1,
189 .tx_pad = UART_PAD_TX_0,
190 .flags = UART_FLAG_NONE,
191 .gclk_src = SAM0_GCLK_PERIPH,
192 }
193};
194
195/* interrupt function name mapping */
196#define UART_0_ISR isr_sercom2_2
197#define UART_0_ISR_TX isr_sercom2_0
198
199#define UART_1_ISR isr_sercom0_2
200#define UART_1_ISR_TX isr_sercom0_0
201
202#define UART_2_ISR isr_sercom5_2
203#define UART_2_ISR_TX isr_sercom5_0
204
205#define UART_3_ISR isr_sercom1_2
206#define UART_3_ISR_TX isr_sercom1_0
207
208#define UART_NUMOF ARRAY_SIZE(uart_config)
216/* PWM0 channels */
217static const pwm_conf_chan_t pwm_chan0_config[] = {
218 /* GPIO pin, MUX value, TCC channel */
219 {
220 .pin = GPIO_PIN(PC, 18),
221 .mux = GPIO_MUX_F,
222 .chan = 2
223 },
224};
225
226/* PWM device configuration */
227static const pwm_conf_t pwm_config[] = {
228 {
229 .tim = TCC_CONFIG(TCC0),
230 .chan = pwm_chan0_config,
231 .chan_numof = ARRAY_SIZE(pwm_chan0_config),
232 .gclk_src = SAM0_GCLK_48MHZ,
233 },
234};
235
236/* number of devices that are actually defined */
237#define PWM_NUMOF ARRAY_SIZE(pwm_config)
244static const spi_conf_t spi_config[] = {
245 { /* EXT1 */
246 .dev = &(SERCOM4->SPI),
247 .miso_pin = GPIO_PIN(PB, 29),
248 .mosi_pin = GPIO_PIN(PB, 27),
249 .clk_pin = GPIO_PIN(PB, 26),
250 .miso_mux = GPIO_MUX_D,
251 .mosi_mux = GPIO_MUX_D,
252 .clk_mux = GPIO_MUX_D,
253 .miso_pad = SPI_PAD_MISO_3,
254 .mosi_pad = SPI_PAD_MOSI_0_SCK_1,
255 .gclk_src = SAM0_GCLK_PERIPH,
256#ifdef MODULE_PERIPH_DMA
257 .tx_trigger = SERCOM4_DMAC_ID_TX,
258 .rx_trigger = SERCOM4_DMAC_ID_RX,
259#endif
260
261 },
262 { /* EXT2, EXT3 */
263 .dev = &(SERCOM6->SPI),
264 .miso_pin = GPIO_PIN(PC, 7),
265 .mosi_pin = GPIO_PIN(PC, 4),
266 .clk_pin = GPIO_PIN(PC, 5),
267 .miso_mux = GPIO_MUX_C,
268 .mosi_mux = GPIO_MUX_C,
269 .clk_mux = GPIO_MUX_C,
270 .miso_pad = SPI_PAD_MISO_3,
271 .mosi_pad = SPI_PAD_MOSI_0_SCK_1,
272 .gclk_src = SAM0_GCLK_48MHZ,
273#ifdef MODULE_PERIPH_DMA
274 .tx_trigger = SERCOM6_DMAC_ID_TX,
275 .rx_trigger = SERCOM6_DMAC_ID_RX,
276#endif
277 },
278#ifdef MODULE_PERIPH_SPI_ON_QSPI
279 { /* QSPI in SPI mode */
280 .dev = QSPI,
281 .miso_pin = SAM0_QSPI_PIN_DATA_1,
282 .mosi_pin = SAM0_QSPI_PIN_DATA_0,
283 .clk_pin = SAM0_QSPI_PIN_CLK,
284 .miso_mux = SAM0_QSPI_MUX,
285 .mosi_mux = SAM0_QSPI_MUX,
286 .clk_mux = SAM0_QSPI_MUX,
287 .miso_pad = SPI_PAD_MISO_0, /* unused */
288 .mosi_pad = SPI_PAD_MOSI_0_SCK_1, /* unused */
289 .gclk_src = SAM0_GCLK_MAIN, /* unused */
290#ifdef MODULE_PERIPH_DMA
291 .tx_trigger = QSPI_DMAC_ID_TX,
292 .rx_trigger = QSPI_DMAC_ID_RX,
293#endif
294 },
295#endif
296};
297
298#define SPI_NUMOF ARRAY_SIZE(spi_config)
305static const i2c_conf_t i2c_config[] = {
306 { /* EXT1 */
307 .dev = &(SERCOM3->I2CM),
308 .speed = I2C_SPEED_NORMAL,
309 .scl_pin = GPIO_PIN(PA, 23),
310 .sda_pin = GPIO_PIN(PA, 22),
311 .mux = GPIO_MUX_C,
312 .gclk_src = SAM0_GCLK_PERIPH,
313 .flags = I2C_FLAG_NONE
314 },
315 { /* EXT2, EXT3 */
316 .dev = &(SERCOM7->I2CM),
317 .speed = I2C_SPEED_NORMAL,
318 .scl_pin = GPIO_PIN(PD, 9),
319 .sda_pin = GPIO_PIN(PD, 8),
320 .mux = GPIO_MUX_C,
321 .gclk_src = SAM0_GCLK_PERIPH,
322 .flags = I2C_FLAG_NONE
323 }
324};
325
326#define I2C_NUMOF ARRAY_SIZE(i2c_config)
333#ifndef RTT_FREQUENCY
334#define RTT_FREQUENCY (32768U)
335#endif
342static const sam0_common_usb_config_t sam_usbdev_config[] = {
343 {
344 .dm = GPIO_PIN(PA, 24),
345 .dp = GPIO_PIN(PA, 25),
346 .d_mux = GPIO_MUX_H,
347 .device = &USB->DEVICE,
348 .gclk_src = SAM0_GCLK_PERIPH,
349 }
350};
358/* ADC Default values */
359#define ADC_GCLK_SRC SAM0_GCLK_PERIPH
360#define ADC_PRESCALER ADC_CTRLA_PRESCALER_DIV8
361
362#define ADC_NEG_INPUT ADC_INPUTCTRL_MUXNEG(0x18u)
363#define ADC_REF_DEFAULT ADC_REFCTRL_REFSEL_INTVCC1
364
365static const adc_conf_chan_t adc_channels[] = {
366 /* port, pin, muxpos, dev */
367 { .inputctrl = ADC0_INPUTCTRL_MUXPOS_PA03, .dev = ADC0 },
368 { .inputctrl = ADC0_INPUTCTRL_MUXPOS_PA05, .dev = ADC0 },
369 { .inputctrl = ADC0_INPUTCTRL_MUXPOS_PA07, .dev = ADC0 }
370};
371
372#define ADC_NUMOF ARRAY_SIZE(adc_channels)
379 /* Must not exceed 12 MHz */
380#define DAC_CLOCK SAM0_GCLK_TIMER
381 /* Use external reference voltage on PA03 */
382 /* (You have to manually connect PA03 with Vcc) */
383 /* Internal reference only gives 1V */
384#define DAC_VREF DAC_CTRLB_REFSEL_VREFPU
394#define SDHC_DEV SDHC1
395#define SDHC_DEV_ISR isr_sdhc1
398static const sdhc_conf_t sdhc_config[] = {
399 {
400 .sdhc = SDHC1,
401 .cd = GPIO_PIN(PD, 20),
402 .wp = GPIO_UNDEF,
403 },
404};
405
407#define SDHC_CONFIG_NUMOF 1
414static const sam0_common_gmac_config_t sam_gmac_config[] = {
415 {
416 .dev = GMAC,
417 .refclk = GPIO_PIN(PA, 14),
418 .txen = GPIO_PIN(PA, 17),
419 .txd0 = GPIO_PIN(PA, 18),
420 .txd1 = GPIO_PIN(PA, 19),
421 .crsdv = GPIO_PIN(PC, 20),
422 .rxd0 = GPIO_PIN(PA, 13),
423 .rxd1 = GPIO_PIN(PA, 12),
424 .rxer = GPIO_PIN(PA, 15),
425 .mdc = GPIO_PIN(PC, 11),
426 .mdio = GPIO_PIN(PC, 12),
427 .rst_pin = GPIO_PIN(PC, 21),
428 .int_pin = GPIO_PIN(PD, 12),
429 }
430};
437static const freqm_config_t freqm_config[] = {
438 {
439 .pin = GPIO_PIN(PB, 17),
440 .gclk_src = SAM0_GCLK_32KHZ
441 }
442};
445#ifdef __cplusplus
446}
447#endif
448
449#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.
@ GPIO_OUT
select GPIO MASK as output
Definition periph_cpu.h:165
@ I2C_SPEED_NORMAL
normal mode: ~100 kbit/s
Definition periph_cpu.h:278
#define AT6561_STBY_PIN
ATA6561 STANDBY pin definition.
static const sdhc_conf_t sdhc_config[]
SDHC devices.
#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_RTS_2_CTS_3
TX is pad 0, on top RTS on pad 2 and CTS on pad 3.
@ 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_D
select peripheral function D
@ GPIO_MUX_C
select peripheral function C
@ GPIO_MUX_F
select peripheral function F
@ SPI_PAD_MOSI_0_SCK_1
use pad 0 for MOSI, pad 1 for SCK
#define SAM0_GCLK_MAIN
120 MHz main clock
Definition periph_cpu.h:74
#define ADC0_INPUTCTRL_MUXPOS_PA07
Alias for AIN7.
Definition periph_cpu.h:133
#define SAM0_QSPI_PIN_CLK
Clock
Definition periph_cpu.h:269
#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 SAM0_QSPI_PIN_DATA_1
D1 / MISO
Definition periph_cpu.h:272
#define SAM0_QSPI_MUX
QSPI mux
Definition periph_cpu.h:275
#define ADC0_INPUTCTRL_MUXPOS_PA03
Alias for AIN1.
Definition periph_cpu.h:127
#define SAM0_GCLK_TIMER
4-8 MHz clock for xTimer
Definition periph_cpu.h:79
#define SAM0_GCLK_32KHZ
32 kHz clock
Definition periph_cpu.h:76
#define SAM0_GCLK_PERIPH
12-48 MHz (DFLL) clock
Definition periph_cpu.h:82
ADC Channel Configuration.
ESP CAN device configuration.
Definition can_esp.h:88
Linux candev configuration.
Frequency meter configuration.
I2C configuration structure.
Definition periph_cpu.h:299
PWM channel configuration data structure.
PWM device configuration.
Ethernet parameters struct.
USB peripheral parameters.
SDHC peripheral configuration.
SPI device configuration.
Definition periph_cpu.h:337
Timer device configuration.
UART device configuration.
Definition periph_cpu.h:218