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)
114static const can_conf_t candev_conf[] = {
115 {
116 .can = CAN1,
117 .rx_pin = GPIO_PIN(PB, 13),
118 .tx_pin = GPIO_PIN(PB, 12),
119 .gclk_src = SAM0_GCLK_PERIPH,
120 }
121};
122
124#define ISR_CAN1 isr_can1
125
127#define CAN_NUMOF ARRAY_SIZE(candev_conf)
134static const uart_conf_t uart_config[] = {
135 { /* Virtual COM Port */
136 .dev = &SERCOM2->USART,
137 .rx_pin = GPIO_PIN(PB, 24),
138 .tx_pin = GPIO_PIN(PB, 25),
139 .mux = GPIO_MUX_D,
140 .rx_pad = UART_PAD_RX_1,
141 .tx_pad = UART_PAD_TX_0,
142 .flags = UART_FLAG_NONE,
143 .gclk_src = SAM0_GCLK_PERIPH,
144 },
145 { /* EXT1 */
146 .dev = &SERCOM0->USART,
147 .rx_pin = GPIO_PIN(PA, 5),
148 .tx_pin = GPIO_PIN(PA, 4),
149#ifdef MODULE_PERIPH_UART_HW_FC
150 .rts_pin = GPIO_PIN(PA, 6),
151 .cts_pin = GPIO_PIN(PA, 7),
152#endif
153 .mux = GPIO_MUX_D,
154 .rx_pad = UART_PAD_RX_1,
155#ifdef MODULE_PERIPH_UART_HW_FC
157#else
158 .tx_pad = UART_PAD_TX_0,
159#endif
160 .flags = UART_FLAG_NONE,
161 .gclk_src = SAM0_GCLK_PERIPH,
162 },
163 { /* EXT2 */
164 .dev = &SERCOM5->USART,
165 .rx_pin = GPIO_PIN(PB, 17),
166 .tx_pin = GPIO_PIN(PB, 16),
167 .mux = GPIO_MUX_C,
168 .rx_pad = UART_PAD_RX_1,
169 .tx_pad = UART_PAD_TX_0,
170 .flags = UART_FLAG_NONE,
171 .gclk_src = SAM0_GCLK_PERIPH,
172 },
173 { /* EXT3 */
174 .dev = &SERCOM1->USART,
175 .rx_pin = GPIO_PIN(PC, 23),
176 .tx_pin = GPIO_PIN(PC, 22),
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};
184
185/* interrupt function name mapping */
186#define UART_0_ISR isr_sercom2_2
187#define UART_0_ISR_TX isr_sercom2_0
188
189#define UART_1_ISR isr_sercom0_2
190#define UART_1_ISR_TX isr_sercom0_0
191
192#define UART_2_ISR isr_sercom5_2
193#define UART_2_ISR_TX isr_sercom5_0
194
195#define UART_3_ISR isr_sercom1_2
196#define UART_3_ISR_TX isr_sercom1_0
197
198#define UART_NUMOF ARRAY_SIZE(uart_config)
206/* PWM0 channels */
207static const pwm_conf_chan_t pwm_chan0_config[] = {
208 /* GPIO pin, MUX value, TCC channel */
209 {
210 .pin = GPIO_PIN(PC, 18),
211 .mux = GPIO_MUX_F,
212 .chan = 2
213 },
214};
215
216/* PWM device configuration */
217static const pwm_conf_t pwm_config[] = {
218 {
219 .tim = TCC_CONFIG(TCC0),
220 .chan = pwm_chan0_config,
221 .chan_numof = ARRAY_SIZE(pwm_chan0_config),
222 .gclk_src = SAM0_GCLK_48MHZ,
223 },
224};
225
226/* number of devices that are actually defined */
227#define PWM_NUMOF ARRAY_SIZE(pwm_config)
234static const spi_conf_t spi_config[] = {
235 { /* EXT1 */
236 .dev = &(SERCOM4->SPI),
237 .miso_pin = GPIO_PIN(PB, 29),
238 .mosi_pin = GPIO_PIN(PB, 27),
239 .clk_pin = GPIO_PIN(PB, 26),
240 .miso_mux = GPIO_MUX_D,
241 .mosi_mux = GPIO_MUX_D,
242 .clk_mux = GPIO_MUX_D,
243 .miso_pad = SPI_PAD_MISO_3,
244 .mosi_pad = SPI_PAD_MOSI_0_SCK_1,
245 .gclk_src = SAM0_GCLK_PERIPH,
246#ifdef MODULE_PERIPH_DMA
247 .tx_trigger = SERCOM4_DMAC_ID_TX,
248 .rx_trigger = SERCOM4_DMAC_ID_RX,
249#endif
250
251 },
252 { /* EXT2, EXT3 */
253 .dev = &(SERCOM6->SPI),
254 .miso_pin = GPIO_PIN(PC, 7),
255 .mosi_pin = GPIO_PIN(PC, 4),
256 .clk_pin = GPIO_PIN(PC, 5),
257 .miso_mux = GPIO_MUX_C,
258 .mosi_mux = GPIO_MUX_C,
259 .clk_mux = GPIO_MUX_C,
260 .miso_pad = SPI_PAD_MISO_3,
261 .mosi_pad = SPI_PAD_MOSI_0_SCK_1,
262 .gclk_src = SAM0_GCLK_48MHZ,
263#ifdef MODULE_PERIPH_DMA
264 .tx_trigger = SERCOM6_DMAC_ID_TX,
265 .rx_trigger = SERCOM6_DMAC_ID_RX,
266#endif
267 },
268#ifdef MODULE_PERIPH_SPI_ON_QSPI
269 { /* QSPI in SPI mode */
270 .dev = QSPI,
271 .miso_pin = SAM0_QSPI_PIN_DATA_1,
272 .mosi_pin = SAM0_QSPI_PIN_DATA_0,
273 .clk_pin = SAM0_QSPI_PIN_CLK,
274 .miso_mux = SAM0_QSPI_MUX,
275 .mosi_mux = SAM0_QSPI_MUX,
276 .clk_mux = SAM0_QSPI_MUX,
277 .miso_pad = SPI_PAD_MISO_0, /* unused */
278 .mosi_pad = SPI_PAD_MOSI_0_SCK_1, /* unused */
279 .gclk_src = SAM0_GCLK_MAIN, /* unused */
280#ifdef MODULE_PERIPH_DMA
281 .tx_trigger = QSPI_DMAC_ID_TX,
282 .rx_trigger = QSPI_DMAC_ID_RX,
283#endif
284 },
285#endif
286};
287
288#define SPI_NUMOF ARRAY_SIZE(spi_config)
295static const i2c_conf_t i2c_config[] = {
296 { /* EXT1 */
297 .dev = &(SERCOM3->I2CM),
298 .speed = I2C_SPEED_NORMAL,
299 .scl_pin = GPIO_PIN(PA, 23),
300 .sda_pin = GPIO_PIN(PA, 22),
301 .mux = GPIO_MUX_C,
302 .gclk_src = SAM0_GCLK_PERIPH,
303 .flags = I2C_FLAG_NONE
304 },
305 { /* EXT2, EXT3 */
306 .dev = &(SERCOM7->I2CM),
307 .speed = I2C_SPEED_NORMAL,
308 .scl_pin = GPIO_PIN(PD, 9),
309 .sda_pin = GPIO_PIN(PD, 8),
310 .mux = GPIO_MUX_C,
311 .gclk_src = SAM0_GCLK_PERIPH,
312 .flags = I2C_FLAG_NONE
313 }
314};
315
316#define I2C_NUMOF ARRAY_SIZE(i2c_config)
323#ifndef RTT_FREQUENCY
324#define RTT_FREQUENCY (32768U)
325#endif
332static const sam0_common_usb_config_t sam_usbdev_config[] = {
333 {
334 .dm = GPIO_PIN(PA, 24),
335 .dp = GPIO_PIN(PA, 25),
336 .d_mux = GPIO_MUX_H,
337 .device = &USB->DEVICE,
338 .gclk_src = SAM0_GCLK_PERIPH,
339 }
340};
348/* ADC Default values */
349#define ADC_GCLK_SRC SAM0_GCLK_PERIPH
350#define ADC_PRESCALER ADC_CTRLA_PRESCALER_DIV8
351
352#define ADC_NEG_INPUT ADC_INPUTCTRL_MUXNEG(0x18u)
353#define ADC_REF_DEFAULT ADC_REFCTRL_REFSEL_INTVCC1
354
355static const adc_conf_chan_t adc_channels[] = {
356 /* port, pin, muxpos, dev */
357 { .inputctrl = ADC0_INPUTCTRL_MUXPOS_PA03, .dev = ADC0 },
358 { .inputctrl = ADC0_INPUTCTRL_MUXPOS_PA05, .dev = ADC0 },
359 { .inputctrl = ADC0_INPUTCTRL_MUXPOS_PA07, .dev = ADC0 }
360};
361
362#define ADC_NUMOF ARRAY_SIZE(adc_channels)
369 /* Must not exceed 12 MHz */
370#define DAC_CLOCK SAM0_GCLK_TIMER
371 /* Use external reference voltage on PA03 */
372 /* (You have to manually connect PA03 with Vcc) */
373 /* Internal reference only gives 1V */
374#define DAC_VREF DAC_CTRLB_REFSEL_VREFPU
384#define SDHC_DEV SDHC1
385#define SDHC_DEV_ISR isr_sdhc1
388static const sdhc_conf_t sdhc_config[] = {
389 {
390 .sdhc = SDHC1,
391 .cd = GPIO_PIN(PD, 20),
392 .wp = GPIO_UNDEF,
393 },
394};
395
397#define SDHC_CONFIG_NUMOF 1
404static const sam0_common_gmac_config_t sam_gmac_config[] = {
405 {
406 .dev = GMAC,
407 .refclk = GPIO_PIN(PA, 14),
408 .txen = GPIO_PIN(PA, 17),
409 .txd0 = GPIO_PIN(PA, 18),
410 .txd1 = GPIO_PIN(PA, 19),
411 .crsdv = GPIO_PIN(PC, 20),
412 .rxd0 = GPIO_PIN(PA, 13),
413 .rxd1 = GPIO_PIN(PA, 12),
414 .rxer = GPIO_PIN(PA, 15),
415 .mdc = GPIO_PIN(PC, 11),
416 .mdio = GPIO_PIN(PC, 12),
417 .rst_pin = GPIO_PIN(PC, 21),
418 .int_pin = GPIO_PIN(PD, 12),
419 }
420};
427static const freqm_config_t freqm_config[] = {
428 {
429 .pin = GPIO_PIN(PB, 17),
430 .gclk_src = SAM0_GCLK_32KHZ
431 }
432};
435#ifdef __cplusplus
436}
437#endif
438
439#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
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.
uint32_t inputctrl
ADC channel pin multiplexer value
ESP CAN device configuration.
Definition can_esp.h:88
Linux candev configuration.
Frequency meter configuration.
gpio_t pin
GPIO at which the frequency is to be measured.
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.
gpio_t pin
GPIO pin.
PWM device configuration.
tc_tcc_cfg_t tim
timer configuration
Ethernet parameters struct.
Gmac * dev
ptr to the device registers
USB peripheral parameters.
SDHC peripheral configuration.
void * sdhc
SDHC peripheral.
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