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

Configuration of CPU peripherals for the m4a-24g 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 []
 UART config.
 
static const pwm_conf_chan_t pwm_chan0_config []
 IF PWM_0 is enabled then the following values are configured: More...
 
static const pwm_conf_chan_t pwm_chan1_config []
 IF PWM_1 is enabled then the following values are configured: More...
 
static const pwm_conf_t pwm_config []
 PWM device configuration. More...
 
static const spi_conf_t spi_config []
 SPI config.
 
static const i2c_conf_t i2c_config []
 I2C devices configuration. More...
 
static const adc_conf_chan_t adc_channels []
 ADC configuration. More...
 
static const sam0_common_usb_config_t sam_usbdev_config []
 USB peripheral configuration. More...
 

External oscillator and clock configuration

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 = 1U
#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...
 

name defined settings for 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)
 

interrupt function name mapping and number of UART peripherals defined

#define UART_0_ISR   isr_sercom0
 
#define UART_1_ISR   isr_sercom5
 
#define UART_NUMOF   ARRAY_SIZE(uart_config)
 

PWM configuration

#define PWM_0_EN   1
 
#define PWM_1_EN   1
 

Number of PWM devices defined

#define PWM_NUMOF   ARRAY_SIZE(pwm_config)
 

Number of SPI devices defined

#define SPI_NUMOF   ARRAY_SIZE(spi_config)
 

Number of I2C devices defined, default is 1

#define I2C_NUMOF   ARRAY_SIZE(i2c_config)
 

RTT configuration

#define RTT_FREQUENCY   (32768U)
 The desired frequency for the Real Time Timer peripheral in Hz. More...
 
#define RTT_MIN_OFFSET   (10U)
 

Default ADC values

#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 ADCs available

#define ADC_NUMOF   ARRAY_SIZE(adc_channels)
 

Detailed Description

Macro Definition Documentation

◆ ADC_GAIN_FACTOR_DEFAULT

#define ADC_GAIN_FACTOR_DEFAULT   ADC_INPUTCTRL_GAIN_1X

Gain Factor: 1x

Definition at line 369 of file periph_conf.h.

◆ ADC_NEG_INPUT

#define ADC_NEG_INPUT   ADC_INPUTCTRL_MUXNEG_GND

Neg. Input: GND

Definition at line 368 of file periph_conf.h.

◆ ADC_NUMOF

#define ADC_NUMOF   ARRAY_SIZE(adc_channels)

Number of ADCs available

Definition at line 406 of file periph_conf.h.

◆ ADC_PRESCALER

#define ADC_PRESCALER   ADC_CTRLB_PRESCALER_DIV512

Prescaler: 512

Definition at line 367 of file periph_conf.h.

◆ ADC_REF_DEFAULT

#define ADC_REF_DEFAULT   ADC_REFCTRL_REFSEL_INT1V

Reference: Internal 1.0 Volt

Definition at line 370 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 105 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 95 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 88 of file periph_conf.h.

◆ I2C_NUMOF

#define I2C_NUMOF   ARRAY_SIZE(i2c_config)

1 I2C peripheral is available

Definition at line 345 of file periph_conf.h.

◆ PWM_0_EN

#define PWM_0_EN   1

PWM_0 is enabled by default

Definition at line 222 of file periph_conf.h.

◆ PWM_1_EN

#define PWM_1_EN   1

PWM_1 is enabled by default

Definition at line 223 of file periph_conf.h.

◆ PWM_NUMOF

#define PWM_NUMOF   ARRAY_SIZE(pwm_config)

Number of SPI peripheral available

Definition at line 278 of file periph_conf.h.

◆ RTT_FREQUENCY

#define RTT_FREQUENCY   (32768U)

The desired frequency for the Real Time Timer peripheral in Hz.

See also
For changes checkout rtt.c and rtt.h

Definition at line 358 of file periph_conf.h.

◆ RTT_MIN_OFFSET

#define RTT_MIN_OFFSET   (10U)

??

Definition at line 360 of file periph_conf.h.

◆ SPI_NUMOF

#define SPI_NUMOF   ARRAY_SIZE(spi_config)

SPI available

Definition at line 323 of file periph_conf.h.

◆ TIMER_0_ISR

#define TIMER_0_ISR   isr_tc3

Internal function name

Definition at line 163 of file periph_conf.h.

◆ TIMER_0_MAX_VALUE

#define TIMER_0_MAX_VALUE   0xffff

Max. value for TIMER 0

Definition at line 162 of file periph_conf.h.

◆ TIMER_1_ISR

#define TIMER_1_ISR   isr_tc4

Internal function name

Definition at line 164 of file periph_conf.h.

◆ TIMER_NUMOF

#define TIMER_NUMOF   ARRAY_SIZE(timer_config)

Number of TIMER peripherals, 2

Definition at line 165 of file periph_conf.h.

◆ UART_0_ISR

#define UART_0_ISR   isr_sercom0

Internal function name

Definition at line 213 of file periph_conf.h.

◆ UART_1_ISR

#define UART_1_ISR   isr_sercom5

Internal function name

Definition at line 214 of file periph_conf.h.

◆ UART_NUMOF

#define UART_NUMOF   ARRAY_SIZE(uart_config)

Number of UARTs available

Definition at line 215 of file periph_conf.h.

Variable Documentation

◆ adc_channels

const adc_conf_chan_t adc_channels[]
static
Initial value:
= {
{GPIO_PIN(PA, 6), ADC_INPUTCTRL_MUXPOS_PIN6},
{GPIO_PIN(PA, 7), ADC_INPUTCTRL_MUXPOS_PIN7},
}

ADC configuration.

Definition at line 397 of file periph_conf.h.

◆ i2c_config

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

I2C devices configuration.

I2C SCL pin SDA pin
0 PA17 PA16

Definition at line 333 of file periph_conf.h.

◆ pwm_chan0_config

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

IF PWM_0 is enabled then the following values are configured:

Note
Default value for PWM_0_EN is 1, ENABLED
PWM GPIO pin MUX value Channel
0 PA6 GPIO_MUX_E 0
1 PA7 GPIO_MUX_E 1

Definition at line 237 of file periph_conf.h.

◆ pwm_chan1_config

const pwm_conf_chan_t pwm_chan1_config[]
static
Initial value:
= {
{GPIO_PIN(PA, 16), GPIO_MUX_F, 0},
{GPIO_PIN(PA, 18), GPIO_MUX_F, 2},
{GPIO_PIN(PA, 19), GPIO_MUX_F, 3},
}

IF PWM_1 is enabled then the following values are configured:

Note
Default value for PWM_1_EN is 1, ENABLED
PWM GPIO pin MUX value Channel
0 PA16 GPIO_MUX_F 0
1 PA18 GPIO_MUX_F 2
2 PA19 GPIO_MUX_F 3

Definition at line 255 of file periph_conf.h.

◆ pwm_config

const pwm_conf_t pwm_config[]
static
Initial value:
= {
{TCC_CONFIG(TCC1), pwm_chan0_config, ARRAY_SIZE(pwm_chan0_config), SAM0_GCLK_MAIN},
{TCC_CONFIG(TCC0), pwm_chan1_config, ARRAY_SIZE(pwm_chan1_config), SAM0_GCLK_MAIN},
}
static const pwm_conf_chan_t pwm_chan1_config[]
IF PWM_1 is enabled then the following values are configured:
Definition: periph_conf.h:255
static const pwm_conf_chan_t pwm_chan0_config[]
IF PWM_0 is enabled then the following values are configured:
Definition: periph_conf.h:237

PWM device configuration.

Definition at line 265 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 configuration.

Definition at line 412 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 131 of file periph_conf.h.