Mesh4all
May the mesh be with you
periph_conf.h File Reference

Peripheral MCU configuration for m4a_mb board. More...

#include <stdint.h>
#include "cpu.h"
#include "periph_cpu.h"
+ Include dependency graph for periph_conf.h:
+ This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Variables

static const tc32_conf_t timer_config []
 Timer peripheral configuration. More...
 
static const uart_conf_t uart_config []
 Settings for UART. More...
 
static const pwm_conf_chan_t pwm_chan0_config []
 By default only channel 0 is enabled, PWM 1 and 2 can be enabled by setting PWM_1_EN and/or PWM_2_EN to 1. More...
 
static const pwm_conf_t pwm_config []
 Settings for PWM peripheral. More...
 
static const spi_conf_t spi_config []
 SPI configuration. More...
 
static const i2c_conf_t i2c_config []
 I2C configuration. More...
 
static const adc_conf_chan_t adc_channels []
 ADC channels. More...
 
static const sam0_common_usb_config_t sam_usbdev_config []
 USB peripheral settings. More...
 

Clock settings

There are three choices for selection of CORECLOCK:

  • Usage of the Phase-Locked Loop (PLL) fed by the internal 8MHz oscillator divided by 8
  • Usage of the 48 MHz DFLL fed by external oscillator running at 32 kHz
  • Usage of the internal 8MHz oscillator directly, divided by N if needed

The PLL option allows for the usage of a wider frequency range and a more stable clock with less jitter. This is why this option is default.

The target frequency is computed from the PLL multiplier and the PLL divisor. Use the following formula to compute your values:

CORECLOCK = ((PLL_MUL + 1) * 1MHz) / PLL_DIV

Note
The PLL circuit does not run with less than 32MHz while the maximum PLL frequency is 96MHz. So PLL_MULL must be between 31 and 95!

The internal Oscillator used directly can lead to a slightly better power efficiency to the cost of a less stable clock. Use this option when you know what you are doing! The actual core frequency is adjusted as follows:

CORECLOCK = 8MHz / DIV

Note
A core clock frequency below 1MHz is not recommended

Default parameters are the following:

  • CLOCK_USE_PLL = True
  • MUL = 47U
  • DIV = 1
#define CLOCK_USE_PLL   (1)
 Use Phase-Locked Loop [PLL] as reference clock: True.
 
#define CLOCK_USE_XOSC32_DFLL   (0)
 Use External OScillator [XOSC32] as reference clock: False.
 
#define GEN2_ULP32K   (0)
 OSCULP32K is factory calibrated to be around 32.768kHz but this values can be of by a couple off % points, so prefer XOSC32K as default configuration. More...
 
#define CLOCK_PLL_MUL   (47U)
 Set [MUL] to 47U if we are using [PLL]. More...
 
#define CLOCK_PLL_DIV   (1U)
 Clock [DIV] 1U if we are using [PLL] This don't need to be changed by now, but it can be adjusted for our requirements.
 
#define CLOCK_CORECLOCK   (((CLOCK_PLL_MUL + 1) * 1000000U) / CLOCK_PLL_DIV)
 Definition for core clock if we are using [PLL] as reference. More...
 

Timers

#define TIMER_0_MAX_VALUE   0xffff
 
#define TIMER_0_ISR   isr_tc3
 
#define TIMER_1_ISR   isr_tc4
 
#define TIMER_NUMOF   ARRAY_SIZE(timer_config)
 

UART configuration

#define UART_0_ISR   isr_sercom3
 
#define UART_1_ISR   isr_sercom4
 
#define UART_2_ISR   isr_sercom5
 
#define UART_NUMOF   ARRAY_SIZE(uart_config)
 

Enabled or Disabled PWM channels

#define PWM_0_EN   1
 
#define PWM_1_EN   0
 
#define PWM_2_EN   0
 

PWM config

#define PWM_NUMOF   ARRAY_SIZE(pwm_config)
 

Number of SPI

#define SPI_NUMOF   ARRAY_SIZE(spi_config)
 

Number of I2C

#define I2C_NUMOF   ARRAY_SIZE(i2c_config)
 

RTT configuration

#define RTT_FREQUENCY   (32768U)
 

ADC Configuration

#define ADC_PRESCALER   ADC_CTRLB_PRESCALER_DIV512
 
#define ADC_NEG_INPUT   ADC_INPUTCTRL_MUXNEG_GND
 
#define ADC_GAIN_FACTOR_DEFAULT   ADC_INPUTCTRL_GAIN_1X
 
#define ADC_REF_DEFAULT   ADC_REFCTRL_REFSEL_INT1V
 

Number of ADC channels

#define ADC_NUMOF   ARRAY_SIZE(adc_channels)
 

DAC Settings

#define DAC_CLOCK   SAM0_GCLK_1MHZ
 
#define DAC_VREF   DAC_CTRLB_REFSEL_AVCC
 

Detailed Description

Peripheral MCU configuration for m4a_mb board.

Definition in file periph_conf.h.

Macro Definition Documentation

◆ ADC_GAIN_FACTOR_DEFAULT

#define ADC_GAIN_FACTOR_DEFAULT   ADC_INPUTCTRL_GAIN_1X

Gain Factor: 1x

Definition at line 432 of file periph_conf.h.

◆ ADC_NEG_INPUT

#define ADC_NEG_INPUT   ADC_INPUTCTRL_MUXNEG_GND

Neg. Input: GND

Definition at line 431 of file periph_conf.h.

◆ ADC_NUMOF

#define ADC_NUMOF   ARRAY_SIZE(adc_channels)

Number of ADC channels is 6

Definition at line 465 of file periph_conf.h.

◆ ADC_PRESCALER

#define ADC_PRESCALER   ADC_CTRLB_PRESCALER_DIV512

Prescaler: DIV 512

Definition at line 430 of file periph_conf.h.

◆ ADC_REF_DEFAULT

#define ADC_REF_DEFAULT   ADC_REFCTRL_REFSEL_INT1V

Reference: Internal 1.0 Volt

Definition at line 433 of file periph_conf.h.

◆ CLOCK_CORECLOCK

#define CLOCK_CORECLOCK   (((CLOCK_PLL_MUL + 1) * 1000000U) / CLOCK_PLL_DIV)

Definition for core clock if we are using [PLL] as reference.

Warning
DO NOT EDIT; Generate the actual used core clock frequency.

Definition at line 101 of file periph_conf.h.

◆ CLOCK_PLL_MUL

#define CLOCK_PLL_MUL   (47U)

Set [MUL] to 47U if we are using [PLL].

Warning
DO NOT EDIT; [MUL] should be between 31 and 95.

Definition at line 91 of file periph_conf.h.

◆ DAC_CLOCK

#define DAC_CLOCK   SAM0_GCLK_1MHZ

Uses 1 MHz clock

Definition at line 472 of file periph_conf.h.

◆ DAC_VREF

#define DAC_VREF   DAC_CTRLB_REFSEL_AVCC

Select VCC as reference

Definition at line 473 of file periph_conf.h.

◆ GEN2_ULP32K

#define GEN2_ULP32K   (0)

OSCULP32K is factory calibrated to be around 32.768kHz but this values can be of by a couple off % points, so prefer XOSC32K as default configuration.

0: use XOSC32K (always 32.768kHz) to clock GCLK2 1: use OSCULP32K factory calibrated (~32.768kHz) to clock GCLK2

Definition at line 84 of file periph_conf.h.

◆ I2C_NUMOF

#define I2C_NUMOF   ARRAY_SIZE(i2c_config)

Number of I2C available

Definition at line 414 of file periph_conf.h.

◆ PWM_0_EN

#define PWM_0_EN   1

PWM 0 is enabled

Definition at line 243 of file periph_conf.h.

◆ PWM_1_EN

#define PWM_1_EN   0

PWM 1 is disabled

Definition at line 244 of file periph_conf.h.

◆ PWM_2_EN

#define PWM_2_EN   0

PWM 2 is disabled

Definition at line 245 of file periph_conf.h.

◆ PWM_NUMOF

#define PWM_NUMOF   ARRAY_SIZE(pwm_config)

Number of PWM channels, default: only chan0

Definition at line 310 of file periph_conf.h.

◆ RTT_FREQUENCY

#define RTT_FREQUENCY   (32768U)

RTT is set to 32768

Definition at line 422 of file periph_conf.h.

◆ SPI_NUMOF

#define SPI_NUMOF   ARRAY_SIZE(spi_config)

3 SPI are available

Definition at line 385 of file periph_conf.h.

◆ TIMER_0_ISR

#define TIMER_0_ISR   isr_tc3

Timer 0 ISR uses tc3

Definition at line 159 of file periph_conf.h.

◆ TIMER_0_MAX_VALUE

#define TIMER_0_MAX_VALUE   0xffff

Max. Value

Definition at line 158 of file periph_conf.h.

◆ TIMER_1_ISR

#define TIMER_1_ISR   isr_tc4

Timer 1 ISR uses tc4

Definition at line 160 of file periph_conf.h.

◆ TIMER_NUMOF

#define TIMER_NUMOF   ARRAY_SIZE(timer_config)

Number of timers available, default: 2

Definition at line 161 of file periph_conf.h.

◆ UART_0_ISR

#define UART_0_ISR   isr_sercom3

UART 0 uses isr_sercom3

Definition at line 233 of file periph_conf.h.

◆ UART_1_ISR

#define UART_1_ISR   isr_sercom4

UART 1 uses isr_sercom4

Definition at line 234 of file periph_conf.h.

◆ UART_2_ISR

#define UART_2_ISR   isr_sercom5

UART 1 uses isr_sercom5

Definition at line 235 of file periph_conf.h.

◆ UART_NUMOF

#define UART_NUMOF   ARRAY_SIZE(uart_config)

Number of available UART ports

Definition at line 236 of file periph_conf.h.

Variable Documentation

◆ adc_channels

const adc_conf_chan_t adc_channels[]
static
Initial value:
= {
{GPIO_PIN(PB, 0), ADC_INPUTCTRL_MUXPOS_PIN8},
{GPIO_PIN(PB, 1), ADC_INPUTCTRL_MUXPOS_PIN9},
{GPIO_PIN(PA, 10), ADC_INPUTCTRL_MUXPOS_PIN18},
{GPIO_PIN(PA, 11), ADC_INPUTCTRL_MUXPOS_PIN19},
{GPIO_PIN(PA, 2), ADC_INPUTCTRL_MUXPOS_PIN0},
{GPIO_PIN(PA, 3), ADC_INPUTCTRL_MUXPOS_PIN1},
}

ADC channels.

[A]nalog-to-[D]igital [C]onverters

Pinout

Channel GPIO pin
0 PB0
1 PB1
2 PA10
3 PA11
4 PA2
5 PA3

Definition at line 452 of file periph_conf.h.

◆ i2c_config

const i2c_conf_t i2c_config[]
static
Initial value:
= {
{
.dev = &(SERCOM2->I2CM),
.speed = I2C_SPEED_NORMAL,
.scl_pin = GPIO_PIN(PA, 9),
.sda_pin = GPIO_PIN(PA, 8),
.mux = GPIO_MUX_D,
.gclk_src = SAM0_GCLK_MAIN,
.flags = I2C_FLAG_NONE,
},
}

I2C configuration.

Pinout

device name pin
I2C_0 SCL PA9
I2C_0 SDA PA8

Definition at line 398 of file periph_conf.h.

◆ pwm_chan0_config

const pwm_conf_chan_t pwm_chan0_config[]
static
Initial value:
= {
{GPIO_PIN(PA, 12), GPIO_MUX_E, 0},
{GPIO_PIN(PA, 13), GPIO_MUX_E, 1},
}

By default only channel 0 is enabled, PWM 1 and 2 can be enabled by setting PWM_1_EN and/or PWM_2_EN to 1.

Pinout

channel GPIO pin TCC Default stat.
0 PA12 0 Enabled
PA13 1 Enabled
1 PB12 0 Disabled
PB13 1 Disabled
2 PB02 0 Disabled
PB03 1 Disabled

Settings for PWM channel 1 if it's enabled

Definition at line 267 of file periph_conf.h.

◆ pwm_config

const pwm_conf_t pwm_config[]
static
Initial value:
= {
{TCC_CONFIG(TCC2), pwm_chan0_config, ARRAY_SIZE(pwm_chan0_config), SAM0_GCLK_MAIN},
}
static const pwm_conf_chan_t pwm_chan0_config[]
By default only channel 0 is enabled, PWM 1 and 2 can be enabled by setting PWM_1_EN and/or PWM_2_EN ...
Definition: periph_conf.h:267

Settings for PWM peripheral.

Definition at line 294 of file periph_conf.h.

◆ sam_usbdev_config

const sam0_common_usb_config_t sam_usbdev_config[]
static
Initial value:
= {
{
.dm = GPIO_PIN(PA, 24),
.dp = GPIO_PIN(PA, 25),
.d_mux = GPIO_MUX_G,
.device = &USB->DEVICE,
.gclk_src = SAM0_GCLK_MAIN,
},
}

USB peripheral settings.

Pinout

function pin
D- PA24
D+ PA25

Definition at line 486 of file periph_conf.h.

◆ spi_config

const spi_conf_t spi_config[]
static

SPI configuration.

SPI Pinout

SPI name pin
0 miso PA4
mosi PA6
clk PA7
1 miso PA16
mosi PA18
clk PA19
2 miso PB16
mosi PB22
clk PB23

Definition at line 330 of file periph_conf.h.

◆ timer_config

const tc32_conf_t timer_config[]
static
Initial value:
= {
{
.dev = TC3,
.irq = TC3_IRQn,
.pm_mask = PM_APBCMASK_TC3,
.gclk_ctrl = GCLK_CLKCTRL_ID_TCC2_TC3,
.gclk_src = SAM0_GCLK_1MHZ,
.flags = TC_CTRLA_MODE_COUNT16,
},
{
.dev = TC4,
.irq = TC4_IRQn,
.pm_mask = PM_APBCMASK_TC4 | PM_APBCMASK_TC5,
.gclk_ctrl = GCLK_CLKCTRL_ID_TC4_TC5,
.gclk_src = SAM0_GCLK_1MHZ,
.flags = TC_CTRLA_MODE_COUNT32,
},
}

Timer peripheral configuration.

Definition at line 127 of file periph_conf.h.

◆ uart_config

const uart_conf_t uart_config[]
static

Settings for UART.

Pinout

UART Function GPIO pin
0 RX PA23
TX PA22
RTS Undefined
CTS Undefined
1 RX PA9
TX PA8
RTS Undefined
CTS Undefined
2 RX PA11
TX PA10
RTS Undefined
CTS Undefined

Definition at line 184 of file periph_conf.h.