periph_conf.h
Go to the documentation of this file.
1 /*
2  * SPDX-FileCopyrightText: 2019 Lokotius Filzer
3  * SPDX-License-Identifier: LGPL-2.1-only
4  */
5 
6 #pragma once
7 
18 #include "periph_cpu.h"
19 #include "macros/units.h"
20 
21 #ifdef __cplusplus
22 extern "C" {
23 #endif
24 
28 #define CLOCK_CORECLOCK MHZ(48)
29 
34 #define USE_VREG_BUCK (1)
35 
40 static const tc32_conf_t timer_config[] = {
41  { /* Timer 0 - System Clock */
42  .dev = TC0,
43  .irq = TC0_IRQn,
44  .mclk = &MCLK->APBCMASK.reg,
45  .mclk_mask = MCLK_APBCMASK_TC0_Msk | MCLK_APBCMASK_TC1_Msk,
46  .gclk_id = TC0_GCLK_ID,
47  .gclk_src = SAM0_GCLK_TIMER,
48  .flags = TC_CTRLA_MODE_COUNT32,
49  }
50 };
51 
52 /* Timer 0 configuration */
53 #define TIMER_0_CHANNELS 2
54 #define TIMER_0_ISR isr_tc0
55 #define TIMER_NUMOF ARRAY_SIZE(timer_config)
62 static const uart_conf_t uart_config[] = {
63  { /* Virtual COM Port */
64  .dev = &SERCOM3->USART,
65  .rx_pin = GPIO_PIN(PA, 18),
66  .tx_pin = GPIO_PIN(PA, 19),
67 #ifdef MODULE_PERIPH_UART_HW_FC
68  .rts_pin = GPIO_UNDEF,
69  .cts_pin = GPIO_UNDEF,
70 #endif
71  .mux = GPIO_MUX_D,
72  .rx_pad = UART_PAD_RX_3,
73  .tx_pad = UART_PAD_TX_2,
74  .flags = UART_FLAG_NONE,
75  .gclk_src = SAM0_GCLK_MAIN,
76  }
77 };
78 
79 /* interrupt function name mapping */
80 #define UART_0_ISR isr_sercom3
81 #define UART_NUMOF ARRAY_SIZE(uart_config)
88 /* SERCOM5 does not support DMA at the moment. See Datasheet samr34, Figure 4-2 */
89 static const spi_conf_t spi_config[] = {
90  {
91  .dev = &(SERCOM5->SPI),
92  .miso_pin = GPIO_PIN(PA, 23),
93  .mosi_pin = GPIO_PIN(PB, 02),
94  .clk_pin = GPIO_PIN(PB, 23),
95  .miso_mux = GPIO_MUX_D,
96  .mosi_mux = GPIO_MUX_D,
97  .clk_mux = GPIO_MUX_D,
98  .miso_pad = SPI_PAD_MISO_1,
99  .mosi_pad = SPI_PAD_MOSI_0_SCK_3,
100  .gclk_src = SAM0_GCLK_MAIN,
101 #ifdef MODULE_PERIPH_DMA
102  .tx_trigger = DMA_TRIGGER_DISABLED,
103  .rx_trigger = DMA_TRIGGER_DISABLED,
104 #endif
105  },
106  {
107  .dev = &(SERCOM4->SPI),
108  .miso_pin = GPIO_PIN(PC, 19),
109  .mosi_pin = GPIO_PIN(PB, 30),
110  .clk_pin = GPIO_PIN(PC, 18),
111  .miso_mux = GPIO_MUX_F,
112  .mosi_mux = GPIO_MUX_F,
113  .clk_mux = GPIO_MUX_F,
114  .miso_pad = SPI_PAD_MISO_0,
115  .mosi_pad = SPI_PAD_MOSI_2_SCK_3,
116  .gclk_src = SAM0_GCLK_MAIN,
117 #ifdef MODULE_PERIPH_DMA
118  .tx_trigger = SERCOM4_DMAC_ID_TX,
119  .rx_trigger = SERCOM4_DMAC_ID_RX,
120 #endif
121  }
122 };
123 
124 #define SPI_NUMOF ARRAY_SIZE(spi_config)
131 static const i2c_conf_t i2c_config[] = {
132  {
133  .dev = &(SERCOM1->I2CM),
134  .speed = I2C_SPEED_NORMAL,
135  .scl_pin = GPIO_PIN(PA, 17),
136  .sda_pin = GPIO_PIN(PA, 16),
137  .mux = GPIO_MUX_C,
138  .gclk_src = SAM0_GCLK_MAIN,
139  .flags = I2C_FLAG_NONE
140  }
141 };
142 #define I2C_NUMOF ARRAY_SIZE(i2c_config)
148 #define EXTERNAL_OSC32_SOURCE 1
149 #define INTERNAL_OSC32_SOURCE 0
150 #define ULTRA_LOW_POWER_INTERNAL_OSC_SOURCE 0
157 #ifndef RTT_FREQUENCY
158 #define RTT_FREQUENCY (32768U)
159 #endif
167 /* ADC 0 Default values */
168 #define ADC_PRESCALER ADC_CTRLB_PRESCALER_DIV256
169 
170 #define ADC_NEG_INPUT ADC_INPUTCTRL_MUXNEG(0x18u)
171 #define ADC_REF_DEFAULT ADC_REFCTRL_REFSEL_INTVCC2
172 
173 static const adc_conf_chan_t adc_channels[] = {
174  /* port, pin, muxpos */
175  { .inputctrl = ADC_INPUTCTRL_MUXPOS_PA09 },
176  { .inputctrl = ADC_INPUTCTRL_MUXPOS_PA08 },
177  { .inputctrl = ADC_INPUTCTRL_MUXPOS_PA07 },
178  { .inputctrl = ADC_INPUTCTRL_MUXPOS_PA06 },
179  { .inputctrl = ADC_INPUTCTRL_MUXPOS_PA04 }
180 };
181 
182 #define ADC_NUMOF ARRAY_SIZE(adc_channels)
189 static const sam0_common_usb_config_t sam_usbdev_config[] = {
190  {
191  .dm = GPIO_PIN(PA, 24),
192  .dp = GPIO_PIN(PA, 25),
193  .d_mux = GPIO_MUX_G,
194  .device = &USB->DEVICE,
195  .gclk_src = SAM0_GCLK_48MHZ,
196  }
197 };
200 #ifdef __cplusplus
201 }
202 #endif
203 
#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: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 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_3
select pad 3
@ PB
port B
@ PC
port C
@ PA
port A
@ I2C_FLAG_NONE
No flags set.
@ SPI_PAD_MISO_1
use pad 1 for MISO line
@ SPI_PAD_MISO_0
use pad 0 for MISO line
#define DMA_TRIGGER_DISABLED
Indicates that the peripheral doesn't utilize the DMA controller.
@ UART_FLAG_NONE
No flags set.
@ UART_PAD_TX_2
select pad 2
@ GPIO_MUX_D
select peripheral function D
@ GPIO_MUX_G
select peripheral function G
@ GPIO_MUX_C
select peripheral function C
@ GPIO_MUX_F
select peripheral function F
@ SPI_PAD_MOSI_2_SCK_3
use pad 2 for MOSI, pad 3 for SCK
@ SPI_PAD_MOSI_0_SCK_3
use pad 0 for MOSI, pad 3 for SCK
#define ADC_INPUTCTRL_MUXPOS_PA08
Alias for PIN16.
Definition: periph_cpu.h:134
#define ADC_INPUTCTRL_MUXPOS_PA09
Alias for PIN17.
Definition: periph_cpu.h:135
#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 SAM0_GCLK_MAIN
120 MHz main clock
Definition: periph_cpu.h:73
@ SAM0_GCLK_TIMER
4/8MHz clock for timers
Definition: periph_cpu.h:70
@ SAM0_GCLK_48MHZ
48MHz clock
Definition: periph_cpu.h:72
ADC Channel Configuration.
I2C configuration structure.
Definition: periph_cpu.h:298
TWI_t * dev
Pointer to hardware module registers.
Definition: periph_cpu.h:299
USB peripheral parameters.
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
Unit helper macros.