periph_conf.h
Go to the documentation of this file.
1 /*
2  * SPDX-FileCopyrightText: 2019 Mesotic SAS
3  * SPDX-License-Identifier: LGPL-2.1-only
4  */
5 
6 #pragma once
7 
19 #include "periph_cpu.h"
20 #include "macros/units.h"
21 
22 #ifdef __cplusplus
23 extern "C" {
24 #endif
25 
29 #define CLOCK_CORECLOCK MHZ(48)
30 
35 #define USE_VREG_BUCK (1)
36 
41 static const tc32_conf_t timer_config[] = {
42  { /* Timer 0 - System Clock */
43  .dev = TC0,
44  .irq = TC0_IRQn,
45  .mclk = &MCLK->APBCMASK.reg,
46  .mclk_mask = MCLK_APBCMASK_TC0_Msk | MCLK_APBCMASK_TC1_Msk,
47  .gclk_id = TC0_GCLK_ID,
48  .gclk_src = SAM0_GCLK_TIMER,
49  .flags = TC_CTRLA_MODE_COUNT32,
50  },
51  {
52  .dev = TC2,
53  .irq = TC2_IRQn,
54  .mclk = &MCLK->APBCMASK.reg,
55  .mclk_mask = MCLK_APBCMASK_TC2_Msk | MCLK_APBCMASK_TC3_Msk,
56  .gclk_id = TC2_GCLK_ID,
57  .gclk_src = SAM0_GCLK_TIMER,
58  .flags = TC_CTRLA_MODE_COUNT32,
59  }
60 };
61 
62 /* Timer 0 configuration */
63 #define TIMER_0_CHANNELS 2
64 #define TIMER_0_ISR isr_tc0
65 #define TIMER_1_CHANNELS 2
66 #define TIMER_1_ISR isr_tc2
67 #define TIMER_NUMOF ARRAY_SIZE(timer_config)
74 static const uart_conf_t uart_config[] = {
75  { /* Virtual COM Port */
76  .dev = &SERCOM0->USART,
77  .rx_pin = GPIO_PIN(PA, 5),
78  .tx_pin = GPIO_PIN(PA, 4),
79 #ifdef MODULE_PERIPH_UART_HW_FC
80  .rts_pin = GPIO_UNDEF,
81  .cts_pin = GPIO_UNDEF,
82 #endif
83  .mux = GPIO_MUX_D,
84  .rx_pad = UART_PAD_RX_1,
85  .tx_pad = UART_PAD_TX_0,
86  .flags = UART_FLAG_NONE,
87  .gclk_src = SAM0_GCLK_MAIN,
88  },
89  { /* EXT1 */
90  .dev = &SERCOM3->USART,
91  .rx_pin = GPIO_PIN(PA, 17),
92  .tx_pin = GPIO_PIN(PA, 16),
93 #ifdef MODULE_PERIPH_UART_HW_FC
94  .rts_pin = GPIO_UNDEF,
95  .cts_pin = GPIO_UNDEF,
96 #endif
97  .mux = GPIO_MUX_D,
98  .rx_pad = UART_PAD_RX_1,
99  .tx_pad = UART_PAD_TX_0,
100  .flags = UART_FLAG_NONE,
101  .gclk_src = SAM0_GCLK_MAIN,
102  }
103 };
104 
105 /* interrupt function name mapping */
106 #define UART_0_ISR isr_sercom0
107 #define UART_1_ISR isr_sercom3
108 
109 #define UART_NUMOF ARRAY_SIZE(uart_config)
116 static const spi_conf_t spi_config[] = {
117  { /* internal, wired to sx1276 */
118  .dev = &(SERCOM4->SPI),
119  .miso_pin = GPIO_PIN(PC, 19),
120  .mosi_pin = GPIO_PIN(PB, 30),
121  .clk_pin = GPIO_PIN(PC, 18),
122  .miso_mux = GPIO_MUX_F,
123  .mosi_mux = GPIO_MUX_F,
124  .clk_mux = GPIO_MUX_F,
125  .miso_pad = SPI_PAD_MISO_0,
126  .mosi_pad = SPI_PAD_MOSI_2_SCK_3,
127  .gclk_src = SAM0_GCLK_MAIN,
128 #ifdef MODULE_PERIPH_DMA
129  .tx_trigger = SERCOM4_DMAC_ID_TX,
130  .rx_trigger = SERCOM4_DMAC_ID_RX,
131 #endif
132  },
133  { /* EXT1, EXT3, NOR Flash */
134  .dev = &(SERCOM5->SPI),
135  .miso_pin = GPIO_PIN(PB, 2),
136  .mosi_pin = GPIO_PIN(PB, 22),
137  .clk_pin = GPIO_PIN(PB, 23),
138  .miso_mux = GPIO_MUX_D,
139  .mosi_mux = GPIO_MUX_D,
140  .clk_mux = GPIO_MUX_D,
141  .miso_pad = SPI_PAD_MISO_0,
142  .mosi_pad = SPI_PAD_MOSI_2_SCK_3,
143  .gclk_src = SAM0_GCLK_MAIN,
144 #ifdef MODULE_PERIPH_DMA
145  .tx_trigger = DMA_TRIGGER_DISABLED,
146  .rx_trigger = DMA_TRIGGER_DISABLED,
147 #endif
148  },
149 };
150 
151 #define SPI_NUMOF ARRAY_SIZE(spi_config)
158 static const i2c_conf_t i2c_config[] = {
159  {
160  .dev = &(SERCOM1->I2CM),
161  .speed = I2C_SPEED_NORMAL,
162  .scl_pin = GPIO_PIN(PA, 17),
163  .sda_pin = GPIO_PIN(PA, 16),
164  .mux = GPIO_MUX_C,
165  .gclk_src = SAM0_GCLK_MAIN,
166  .flags = I2C_FLAG_NONE
167  }
168 };
169 #define I2C_NUMOF ARRAY_SIZE(i2c_config)
176 #define EXTERNAL_OSC32_SOURCE 1
177 #define INTERNAL_OSC32_SOURCE 0
178 #define ULTRA_LOW_POWER_INTERNAL_OSC_SOURCE 0
185 #ifndef RTT_FREQUENCY
186 #define RTT_FREQUENCY (32768U)
187 #endif
195 /* ADC 0 Default values */
196 #define ADC_PRESCALER ADC_CTRLB_PRESCALER_DIV256
197 
198 #define ADC_NEG_INPUT ADC_INPUTCTRL_MUXNEG(0x18u)
199 #define ADC_REF_DEFAULT ADC_REFCTRL_REFSEL_INTVCC2
200 
201 static const adc_conf_chan_t adc_channels[] = {
202  /* port, pin, muxpos */
203  { .inputctrl = ADC_INPUTCTRL_MUXPOS_PA06 },
204  { .inputctrl = ADC_INPUTCTRL_MUXPOS_PA07 }
205 };
206 
207 #define ADC_NUMOF ARRAY_SIZE(adc_channels)
214 static const sam0_common_usb_config_t sam_usbdev_config[] = {
215  {
216  .dm = GPIO_PIN(PA, 24),
217  .dp = GPIO_PIN(PA, 25),
218  .d_mux = GPIO_MUX_G,
219  .device = &USB->DEVICE,
220  .gclk_src = SAM0_GCLK_48MHZ,
221  }
222 };
225 #ifdef __cplusplus
226 }
227 #endif
228 
#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 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_1
select pad 1
@ PB
port B
@ PC
port C
@ PA
port A
@ I2C_FLAG_NONE
No flags set.
@ 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_0
select pad 0
@ 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
#define ADC_INPUTCTRL_MUXPOS_PA07
Alias for PIN7.
Definition: periph_cpu.h:125
#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:295
TWI_t * dev
Pointer to hardware module registers.
Definition: periph_cpu.h:296
USB peripheral parameters.
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
Unit helper macros.