periph_conf.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2017 Inria
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 
21 #include <stdint.h>
22 
23 #include "cpu.h"
24 #include "periph_cpu.h"
25 
26 #ifdef __cplusplus
27 extern "C" {
28 #endif
29 
61 #define CLOCK_USE_PLL (1)
62 
63 #if CLOCK_USE_PLL
64 /* edit these values to adjust the PLL output frequency */
65 #define CLOCK_PLL_MUL (47U) /* must be >= 31 & <= 95 */
66 #define CLOCK_PLL_DIV (1U) /* adjust to your needs */
67 #define CLOCK_CORECLOCK (((CLOCK_PLL_MUL + 1) * 1000000U) / CLOCK_PLL_DIV)
68 #else
69 /* edit this value to your needs */
70 #define CLOCK_DIV (1U)
71 /* generate the actual core clock frequency */
72 #define CLOCK_CORECLOCK (8000000 / CLOCK_DIV)
73 #endif
80 static const tc32_conf_t timer_config[] = {
81  { /* Timer 0 - System Clock */
82  .dev = TC3,
83  .irq = TC3_IRQn,
84  .pm_mask = PM_APBCMASK_TC3,
85  .gclk_ctrl = GCLK_CLKCTRL_ID_TCC2_TC3,
86 #if CLOCK_USE_PLL || CLOCK_USE_XOSC32_DFLL
87  .gclk_src = SAM0_GCLK_1MHZ,
88 #else
89  .gclk_src = SAM0_GCLK_MAIN,
90 #endif
91  .flags = TC_CTRLA_MODE_COUNT16,
92  },
93  { /* Timer 1 */
94  .dev = TC4,
95  .irq = TC4_IRQn,
96  .pm_mask = PM_APBCMASK_TC4 | PM_APBCMASK_TC5,
97  .gclk_ctrl = GCLK_CLKCTRL_ID_TC4_TC5,
98 #if CLOCK_USE_PLL || CLOCK_USE_XOSC32_DFLL
99  .gclk_src = SAM0_GCLK_1MHZ,
100 #else
101  .gclk_src = SAM0_GCLK_MAIN,
102 #endif
103  .flags = TC_CTRLA_MODE_COUNT32,
104  }
105 };
106 
107 #define TIMER_0_MAX_VALUE 0xffff
108 
109 /* interrupt function name mapping */
110 #define TIMER_0_ISR isr_tc3
111 #define TIMER_1_ISR isr_tc4
112 
113 #define TIMER_NUMOF ARRAY_SIZE(timer_config)
120 static const uart_conf_t uart_config[] = {
121  {
122  .dev = &SERCOM0->USART,
123  .rx_pin = GPIO_PIN(PA, 11), /* RX pin */
124  .tx_pin = GPIO_PIN(PA, 10), /* TX pin */
125 #ifdef MODULE_PERIPH_UART_HW_FC
126  .rts_pin = GPIO_UNDEF,
127  .cts_pin = GPIO_UNDEF,
128 #endif
129  .mux = GPIO_MUX_C,
130  .rx_pad = UART_PAD_RX_3,
131  .tx_pad = UART_PAD_TX_2,
132  .flags = UART_FLAG_NONE,
133  .gclk_src = SAM0_GCLK_MAIN,
134  }
135 };
136 
137 /* interrupt function name mapping */
138 #define UART_0_ISR isr_sercom0
139 
140 #define UART_NUMOF ARRAY_SIZE(uart_config)
147 #define PWM_0_EN 1
148 #define PWM_1_EN 1
149 
150 #if PWM_0_EN
151 /* PWM0 channels */
152 static const pwm_conf_chan_t pwm_chan0_config[] = {
153  /* GPIO pin, MUX value, TCC channel */
154  { GPIO_PIN(PA, 7), GPIO_MUX_E, 1 }, /* ~9 */
155 };
156 #endif
157 #if PWM_1_EN
158 /* PWM1 channels */
159 static const pwm_conf_chan_t pwm_chan1_config[] = {
160  /* GPIO pin, MUX value, TCC channel */
161  { GPIO_PIN(PA, 16), GPIO_MUX_E, 0 }, /* ~11 */
162 };
163 #endif
164 
165 /* PWM device configuration */
166 static const pwm_conf_t pwm_config[] = {
167 #if PWM_0_EN
168  {TCC_CONFIG(TCC0), pwm_chan0_config, ARRAY_SIZE(pwm_chan0_config), SAM0_GCLK_MAIN},
169 #endif
170 #if PWM_1_EN
171  {TCC_CONFIG(TCC2), pwm_chan1_config, ARRAY_SIZE(pwm_chan1_config), SAM0_GCLK_MAIN},
172 #endif
173 };
174 
175 /* number of devices that are actually defined */
176 #define PWM_NUMOF ARRAY_SIZE(pwm_config)
184 /* ADC Default values */
185 #define ADC_PRESCALER ADC_CTRLB_PRESCALER_DIV512
186 
187 #define ADC_NEG_INPUT ADC_INPUTCTRL_MUXNEG_GND
188 #define ADC_GAIN_FACTOR_DEFAULT ADC_INPUTCTRL_GAIN_DIV2
189 #define ADC_REF_DEFAULT ADC_REFCTRL_REFSEL_INTVCC1
190 
191 static const adc_conf_chan_t adc_channels[] = {
192  /* port, pin, muxpos */
193  { .inputctrl = ADC_INPUTCTRL_MUXPOS_PA02 }, /* A0 */
194  { .inputctrl = ADC_INPUTCTRL_MUXPOS_PB08 }, /* A1 */
195  { .inputctrl = ADC_INPUTCTRL_MUXPOS_PB09 }, /* A2 */
196  { .inputctrl = ADC_INPUTCTRL_MUXPOS_PA04 }, /* A3 */
197  { .inputctrl = ADC_INPUTCTRL_MUXPOS_PA05 }, /* A4 */
198  { .inputctrl = ADC_INPUTCTRL_MUXPOS_PB02 }, /* A5 */
199  { .inputctrl = ADC_INPUTCTRL_MUXPOS_PA07 }, /* A7 */
200 };
201 
202 #define ADC_NUMOF ARRAY_SIZE(adc_channels)
209 static const spi_conf_t spi_config[] = {
210  {
211  .dev = &SERCOM4->SPI,
212  .miso_pin = GPIO_PIN(PA, 12),
213  .mosi_pin = GPIO_PIN(PB, 10),
214  .clk_pin = GPIO_PIN(PB, 11),
215  .miso_mux = GPIO_MUX_D,
216  .mosi_mux = GPIO_MUX_D,
217  .clk_mux = GPIO_MUX_D,
218  .miso_pad = SPI_PAD_MISO_0,
219  .mosi_pad = SPI_PAD_MOSI_2_SCK_3,
220  .gclk_src = SAM0_GCLK_MAIN,
221 #ifdef MODULE_PERIPH_DMA
222  .tx_trigger = SERCOM4_DMAC_ID_TX,
223  .rx_trigger = SERCOM4_DMAC_ID_RX,
224 #endif
225  }
226 };
227 
228 #define SPI_NUMOF ARRAY_SIZE(spi_config)
235 static const i2c_conf_t i2c_config[] = {
236  {
237  .dev = &(SERCOM3->I2CM),
238  .speed = I2C_SPEED_NORMAL,
239  .scl_pin = GPIO_PIN(PA, 23),
240  .sda_pin = GPIO_PIN(PA, 22),
241  .mux = GPIO_MUX_C,
242  .gclk_src = SAM0_GCLK_MAIN,
243  .flags = I2C_FLAG_NONE
244  }
245 };
246 #define I2C_NUMOF ARRAY_SIZE(i2c_config)
253 #ifndef RTT_FREQUENCY
254 #define RTT_FREQUENCY (32768U) /* in Hz. For changes see `rtt.c` */
255 #endif
262 static const sam0_common_usb_config_t sam_usbdev_config[] = {
263  {
264  .dm = GPIO_PIN(PA, 24),
265  .dp = GPIO_PIN(PA, 25),
266  .d_mux = GPIO_MUX_G,
267  .device = &USB->DEVICE,
268  .gclk_src = SAM0_GCLK_MAIN,
269  }
270 };
273 #ifdef __cplusplus
274 }
275 #endif
276 
#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 pwm_conf_t pwm_config[]
Actual PWM configuration.
Definition: periph_conf.h:221
#define ARRAY_SIZE(a)
Calculate the number of elements in a static array.
Definition: container.h:82
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
@ PA
port A
@ I2C_FLAG_NONE
No flags set.
@ SPI_PAD_MISO_0
use pad 0 for MISO line
@ UART_FLAG_NONE
No flags set.
@ UART_PAD_TX_2
select pad 2
#define TCC_CONFIG(tim)
Static initializer for TCC timer configuration.
@ GPIO_MUX_E
select peripheral function E
@ GPIO_MUX_D
select peripheral function D
@ GPIO_MUX_G
select peripheral function G
@ GPIO_MUX_C
select peripheral function C
@ SPI_PAD_MOSI_2_SCK_3
use pad 2 for MOSI, pad 3 for SCK
#define ADC_INPUTCTRL_MUXPOS_PA05
Alias for PIN5.
Definition: periph_cpu.h:123
#define ADC_INPUTCTRL_MUXPOS_PB08
Alias for PIN2.
Definition: periph_cpu.h:120
@ SAM0_GCLK_1MHZ
1 MHz clock for xTimer
Definition: periph_cpu.h:75
#define ADC_INPUTCTRL_MUXPOS_PB02
Alias for PIN10.
Definition: periph_cpu.h:128
#define ADC_INPUTCTRL_MUXPOS_PB09
Alias for PIN3.
Definition: periph_cpu.h:121
#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_PA02
ADC pin aliases.
Definition: periph_cpu.h:118
#define SAM0_GCLK_MAIN
120 MHz main clock
Definition: periph_cpu.h:73
ADC Channel Configuration.
I2C configuration structure.
Definition: periph_cpu.h:298
TWI_t * dev
Pointer to hardware module registers.
Definition: periph_cpu.h:299
PWM channel configuration data structure.
PWM device configuration.
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