periph_conf.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2019 Mesotic SAS
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 
9 #pragma once
10 
22 #include "periph_cpu.h"
23 #include "macros/units.h"
24 
25 #ifdef __cplusplus
26 extern "C" {
27 #endif
28 
32 #define CLOCK_CORECLOCK MHZ(48)
33 
38 #define USE_VREG_BUCK (1)
39 
44 static const tc32_conf_t timer_config[] = {
45  { /* Timer 0 - System Clock */
46  .dev = TC0,
47  .irq = TC0_IRQn,
48  .mclk = &MCLK->APBCMASK.reg,
49  .mclk_mask = MCLK_APBCMASK_TC0_Msk | MCLK_APBCMASK_TC1_Msk,
50  .gclk_id = TC0_GCLK_ID,
51  .gclk_src = SAM0_GCLK_TIMER,
52  .flags = TC_CTRLA_MODE_COUNT32,
53  },
54  {
55  .dev = TC2,
56  .irq = TC2_IRQn,
57  .mclk = &MCLK->APBCMASK.reg,
58  .mclk_mask = MCLK_APBCMASK_TC2_Msk | MCLK_APBCMASK_TC3_Msk,
59  .gclk_id = TC2_GCLK_ID,
60  .gclk_src = SAM0_GCLK_TIMER,
61  .flags = TC_CTRLA_MODE_COUNT32,
62  }
63 };
64 
65 /* Timer 0 configuration */
66 #define TIMER_0_CHANNELS 2
67 #define TIMER_0_ISR isr_tc0
68 #define TIMER_1_CHANNELS 2
69 #define TIMER_1_ISR isr_tc2
70 #define TIMER_NUMOF ARRAY_SIZE(timer_config)
77 static const uart_conf_t uart_config[] = {
78  { /* Virtual COM Port */
79  .dev = &SERCOM0->USART,
80  .rx_pin = GPIO_PIN(PA, 5),
81  .tx_pin = GPIO_PIN(PA, 4),
82 #ifdef MODULE_PERIPH_UART_HW_FC
83  .rts_pin = GPIO_UNDEF,
84  .cts_pin = GPIO_UNDEF,
85 #endif
86  .mux = GPIO_MUX_D,
87  .rx_pad = UART_PAD_RX_1,
88  .tx_pad = UART_PAD_TX_0,
89  .flags = UART_FLAG_NONE,
90  .gclk_src = SAM0_GCLK_MAIN,
91  },
92  { /* EXT1 */
93  .dev = &SERCOM3->USART,
94  .rx_pin = GPIO_PIN(PA, 17),
95  .tx_pin = GPIO_PIN(PA, 16),
96 #ifdef MODULE_PERIPH_UART_HW_FC
97  .rts_pin = GPIO_UNDEF,
98  .cts_pin = GPIO_UNDEF,
99 #endif
100  .mux = GPIO_MUX_D,
101  .rx_pad = UART_PAD_RX_1,
102  .tx_pad = UART_PAD_TX_0,
103  .flags = UART_FLAG_NONE,
104  .gclk_src = SAM0_GCLK_MAIN,
105  }
106 };
107 
108 /* interrupt function name mapping */
109 #define UART_0_ISR isr_sercom0
110 #define UART_1_ISR isr_sercom3
111 
112 #define UART_NUMOF ARRAY_SIZE(uart_config)
119 static const spi_conf_t spi_config[] = {
120  { /* internal, wired to sx1276 */
121  .dev = &(SERCOM4->SPI),
122  .miso_pin = GPIO_PIN(PC, 19),
123  .mosi_pin = GPIO_PIN(PB, 30),
124  .clk_pin = GPIO_PIN(PC, 18),
125  .miso_mux = GPIO_MUX_F,
126  .mosi_mux = GPIO_MUX_F,
127  .clk_mux = GPIO_MUX_F,
128  .miso_pad = SPI_PAD_MISO_0,
129  .mosi_pad = SPI_PAD_MOSI_2_SCK_3,
130  .gclk_src = SAM0_GCLK_MAIN,
131 #ifdef MODULE_PERIPH_DMA
132  .tx_trigger = SERCOM4_DMAC_ID_TX,
133  .rx_trigger = SERCOM4_DMAC_ID_RX,
134 #endif
135  },
136  { /* EXT1, EXT3, NOR Flash */
137  .dev = &(SERCOM5->SPI),
138  .miso_pin = GPIO_PIN(PB, 2),
139  .mosi_pin = GPIO_PIN(PB, 22),
140  .clk_pin = GPIO_PIN(PB, 23),
141  .miso_mux = GPIO_MUX_D,
142  .mosi_mux = GPIO_MUX_D,
143  .clk_mux = GPIO_MUX_D,
144  .miso_pad = SPI_PAD_MISO_0,
145  .mosi_pad = SPI_PAD_MOSI_2_SCK_3,
146  .gclk_src = SAM0_GCLK_MAIN,
147 #ifdef MODULE_PERIPH_DMA
148  .tx_trigger = DMA_TRIGGER_DISABLED,
149  .rx_trigger = DMA_TRIGGER_DISABLED,
150 #endif
151  },
152 };
153 
154 #define SPI_NUMOF ARRAY_SIZE(spi_config)
161 static const i2c_conf_t i2c_config[] = {
162  {
163  .dev = &(SERCOM1->I2CM),
164  .speed = I2C_SPEED_NORMAL,
165  .scl_pin = GPIO_PIN(PA, 17),
166  .sda_pin = GPIO_PIN(PA, 16),
167  .mux = GPIO_MUX_C,
168  .gclk_src = SAM0_GCLK_MAIN,
169  .flags = I2C_FLAG_NONE
170  }
171 };
172 #define I2C_NUMOF ARRAY_SIZE(i2c_config)
179 #define EXTERNAL_OSC32_SOURCE 1
180 #define INTERNAL_OSC32_SOURCE 0
181 #define ULTRA_LOW_POWER_INTERNAL_OSC_SOURCE 0
188 #ifndef RTT_FREQUENCY
189 #define RTT_FREQUENCY (32768U)
190 #endif
198 /* ADC 0 Default values */
199 #define ADC_PRESCALER ADC_CTRLB_PRESCALER_DIV256
200 
201 #define ADC_NEG_INPUT ADC_INPUTCTRL_MUXNEG(0x18u)
202 #define ADC_REF_DEFAULT ADC_REFCTRL_REFSEL_INTVCC2
203 
204 static const adc_conf_chan_t adc_channels[] = {
205  /* port, pin, muxpos */
206  { .inputctrl = ADC_INPUTCTRL_MUXPOS_PA06 },
207  { .inputctrl = ADC_INPUTCTRL_MUXPOS_PA07 }
208 };
209 
210 #define ADC_NUMOF ARRAY_SIZE(adc_channels)
217 static const sam0_common_usb_config_t sam_usbdev_config[] = {
218  {
219  .dm = GPIO_PIN(PA, 24),
220  .dp = GPIO_PIN(PA, 25),
221  .d_mux = GPIO_MUX_G,
222  .device = &USB->DEVICE,
223  .gclk_src = SAM0_GCLK_48MHZ,
224  }
225 };
228 #ifdef __cplusplus
229 }
230 #endif
231 
#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:38
static const spi_conf_t spi_config[]
SPI configuration.
Definition: periph_conf.h:96
static const i2c_conf_t i2c_config[]
I2C configuration.
Definition: periph_conf.h:68
static const timer_conf_t timer_config[]
All timers on board.
Definition: periph_conf.h:39
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_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: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.