Common CPU specific definitions for all SAMx21 based CPUs. More...
Common CPU specific definitions for all SAMx21 based CPUs.
Common CPU specific definitions for all SAMx21 based CPUs
Definition in file periph_cpu_common.h.
#include "cpu.h"
#include "exti_config.h"
#include "timer_config.h"
Go to the source code of this file.
Data Structures | |
struct | uart_conf_t |
UART device configuration. More... | |
struct | tc_tcc_cfg_t |
Common configuration for timer devices. More... | |
struct | pwm_conf_chan_t |
PWM channel configuration data structure. More... | |
struct | pwm_conf_t |
PWM device configuration. More... | |
struct | spi_conf_t |
SPI configuration structure type. More... | |
struct | i2c_conf_t |
I2C configuration options. More... | |
struct | tc32_conf_t |
Timer device configuration. More... | |
struct | adc_conf_chan_t |
ADC Channel Configuration. More... | |
struct | sam0_common_usb_config_t |
USB peripheral parameters. More... | |
Macros | |
#define | GPIO_UNDEF (0xffffffff) |
Definition of a fitting UNDEF value. | |
#define | TIMER_CHANNEL_NUMOF (2) |
Number of available timer channels. | |
#define | WDT_HAS_STOP (1) |
Watchdog can be stopped. | |
#define | WDT_HAS_INIT (1) |
Watchdog has to be initialized. | |
Enumerations | |
enum | i2c_flag_t { I2C_FLAG_NONE = 0x0, I2C_FLAG_RUN_STANDBY = 0x1 } |
Available SERCOM I2C flag selections. More... | |
enum | sam0_supc_t { SAM0_VREG_LDO, SAM0_VREG_BUCK } |
Available voltage regulators on the supply controller. | |
Functions | |
void | gpio_init_mux (gpio_t pin, gpio_mux_t mux) |
Set up alternate function (PMUX setting) for a PORT pin. More... | |
void | gpio_pm_cb_enter (int deep) |
Called before the power management enters a power mode. More... | |
void | gpio_pm_cb_leave (int deep) |
Called after the power management left a power mode. More... | |
void | cpu_pm_cb_enter (int deep) |
Called before the power management enters a power mode. More... | |
void | cpu_pm_cb_leave (int deep) |
Called after the power management left a power mode. More... | |
static void | sam0_cortexm_sleep (int deep) |
Wrapper for cortexm_sleep calling power management callbacks. More... | |
void | gpio_disable_mux (gpio_t pin) |
Disable alternate function (PMUX setting) for a PORT pin. More... | |
static void | sam0_set_voltage_regulator (sam0_supc_t src) |
Switch the internal voltage regulator used for generating the internal MCU voltages. More... | |
uint32_t | sam0_gclk_freq (uint8_t id) |
Returns the frequency of a GCLK provider. More... | |
void | sam0_gclk_enable (uint8_t id) |
Enables an on-demand GCLK that has been configured in cpu.c. More... | |
static uint8_t | sercom_id (const void *sercom) |
Return the numeric id of a SERCOM device derived from its address. More... | |
static void | sercom_clk_en (void *sercom) |
Enable peripheral clock for given SERCOM device. More... | |
static void | sercom_clk_dis (void *sercom) |
Disable peripheral clock for given SERCOM device. More... | |
static void | sercom_set_gen (void *sercom, uint8_t gclk) |
Configure generator clock for given SERCOM device. More... | |
static bool | cpu_woke_from_backup (void) |
Returns true if the CPU woke deep sleep (backup/standby) | |
#define | CPUID_LEN (16U) |
Length of the CPU_ID in octets. | |
#define | PERIPH_SPI_NEEDS_INIT_CS |
Use shared SPI functions. | |
#define | PERIPH_SPI_NEEDS_TRANSFER_BYTE |
#define | PERIPH_SPI_NEEDS_TRANSFER_REG |
#define | PERIPH_SPI_NEEDS_TRANSFER_REGS |
#define | HAVE_GPIO_T |
Override GPIO type. | |
typedef uint32_t | gpio_t |
#define | GPIO_PIN(x, y) (((gpio_t)(&PORT->Group[x])) | y) |
Macro for accessing GPIO pins. | |
#define | GPIO_MODE(pr, ie, pe) (pr | (ie << 1) | (pe << 2)) |
Generate GPIO mode bitfields. More... | |
#define | UART_TXBUF_SIZE (64) |
Size of the UART TX buffer for non-blocking mode. | |
#define | TC_CONFIG(tim) |
Static initializer for TC timer configuration. More... | |
#define | TCC_CONFIG(tim) |
Static initializer for TCC timer configuration. More... | |
enum | { PA = 0, PB = 1, PC = 2, PD = 3 } |
Available ports on the SAMD21 & SAML21. More... | |
enum | gpio_mux_t { GPIO_MUX_A = 0x0, GPIO_MUX_B = 0x1, GPIO_MUX_C = 0x2, GPIO_MUX_D = 0x3, GPIO_MUX_E = 0x4, GPIO_MUX_F = 0x5, GPIO_MUX_G = 0x6, GPIO_MUX_H = 0x7, GPIO_MUX_A = 0, GPIO_MUX_B = 1 } |
Available MUX values for configuring a pin's alternate function. More... | |
enum | uart_rxpad_t { UART_PAD_RX_0 = 0x0, UART_PAD_RX_1 = 0x1, UART_PAD_RX_2 = 0x2, UART_PAD_RX_3 = 0x3 } |
Available values for SERCOM UART RX pad selection. More... | |
enum | uart_txpad_t { UART_PAD_TX_0 = 0x0, UART_PAD_TX_2 = 0x1, UART_PAD_TX_0_RTS_2_CTS_3 = 0x2 } |
Available values for SERCOM UART TX pad selection. More... | |
enum | uart_flag_t { UART_FLAG_NONE = 0x0, UART_FLAG_RUN_STANDBY = 0x1, UART_FLAG_WAKEUP = 0x2, UART_FLAG_RXINV = 0x4, UART_FLAG_TXINV = 0x8 } |
Available SERCOM UART flag selections. More... | |
enum | { TIMER_TYPE_TC, TIMER_TYPE_TCC } |
enum | spi_misopad_t { SPI_PAD_MISO_0 = 0x0, SPI_PAD_MISO_1 = 0x1, SPI_PAD_MISO_2 = 0x2, SPI_PAD_MISO_3 = 0x3 } |
Available values for SERCOM SPI MISO pad selection. More... | |
enum | spi_mosipad_t { SPI_PAD_MOSI_0_SCK_1 = 0x0, SPI_PAD_MOSI_2_SCK_3 = 0x1, SPI_PAD_MOSI_3_SCK_1 = 0x2, SPI_PAD_MOSI_0_SCK_3 = 0x3 } |
Available values for SERCOM SPI MOSI and SCK pad selection. More... | |
WDT upper and lower bound times in ms | |
#define | NWDT_TIME_LOWER_LIMIT (8U) |
#define | NWDT_TIME_UPPER_LIMIT (16384U) |
sam0 DMA peripheral | |
The sam0 DMA peripheral has a number of channels. Each channel is a separate data stream, triggered by a configurable trigger when enabled, or triggered by software (not yet supported). In theory each DMA channel is equal and can have a configurable priority and can be triggered by the full set of triggers available. DMA descriptors, specifying a single transfer with size, source and destination, are kept in RAM and are read when the channel is enabled and triggered. On the SAML21 platform, these descriptors must reside in the LP SRAM. The DMA addresses supplied must point to the end of the array to be transferred. When address increment is enabled this means that the supplied src or dst argument must point to array + length. When increment is disabled, the source or destination address can be used directly. The calculation of the end of the array must be done by the calling function, because the beatsize and the increment can usually be hardcoded there and doesn't have to be retrieved from the DMA register configuration. See also section 20.6.2.7 of the SAM D21/DA1 Family Data Sheet. Example: void transfer_data(void *src, void *dst, size_t len)
{
dma_t channel = dma_acquire_channel()
if (channel == 0xff) {
return -E_BUSY;
}
dma_setup(channel, DMA_TRIGGER_MY_PERIH, 0, true);
dma_prepare(channel, DMAC_BTCTRL_BEATSIZE_BYTE_Val,
(uint8_t*)src + len, (uint8_t*)dst + len, len);
dma_start(channel);
dma_wait(channel);
dma_release_channel(channel);
}
| |
#define | DMA_TRIGGER_DISABLED 0 |
Indicates that the peripheral doesn't utilize the DMA controller. More... | |
#define | DMA_DESCRIPTOR_IN_LPSRAM |
Move the DMA descriptors to the LP SRAM. More... | |
#define | DMA_DESCRIPTOR_ATTRS __attribute__((section(".backup.bss"))) |
Extra attributes required for instantiating DMA descriptors. | |
enum | dma_incr_t { DMA_INCR_NONE = 0, DMA_INCR_SRC = 1, DMA_INCR_DEST = 2, DMA_INCR_BOTH = 3 } |
Available DMA address increment modes. More... | |
typedef unsigned | dma_t |
DMA channel type. | |
void | dma_init (void) |
Initialize DMA. | |
dma_t | dma_acquire_channel (void) |
Acquire a DMA channel. More... | |
void | dma_release_channel (dma_t dma) |
Release a previously acquired DMA channel. More... | |
void | dma_setup (dma_t dma, unsigned trigger, uint8_t prio, bool irq) |
Initialize a previously allocated DMA channel with one-time settings. More... | |
void | dma_prepare (dma_t dma, uint8_t width, const void *src, void *dst, size_t num, dma_incr_t incr) |
Prepare the DMA channel for an individual transfer. More... | |
void | dma_prepare_src (dma_t dma, const void *src, size_t num, bool incr) |
Prepare a transfer without modifying the destination address settings. More... | |
void | dma_prepare_dst (dma_t dma, void *dst, size_t num, bool incr) |
Prepare a transfer without modifying the source address settings. More... | |
void | dma_append (dma_t dma, DmacDescriptor *descriptor, uint8_t width, const void *src, void *dst, size_t num, dma_incr_t incr) |
Append a second transfer descriptor after the default channel descriptor. More... | |
void | dma_append_src (dma_t dma, DmacDescriptor *next, const void *src, size_t num, bool incr) |
Append a second transfer descriptor after the default channel descriptor, copying destination and block size from the initial descriptor. More... | |
void | dma_append_dst (dma_t dma, DmacDescriptor *next, void *dst, size_t num, bool incr) |
Append a second transfer descriptor after the default channel descriptor, copying source and block size from the initial descriptor. More... | |
void | dma_start (dma_t dma) |
Start a DMA transfer. More... | |
void | dma_wait (dma_t dma) |
Wait for a DMA channel to finish the transfer. More... | |
void | dma_cancel (dma_t dma) |
Cancel an active DMA transfer. More... | |
sam0 RTC Tamper Detection | |
void | rtc_tamper_init (void) |
Power on the RTC (if the RTC/RTT is not otherwise used) | |
int | rtc_tamper_register (gpio_t pin, gpio_flank_t flank) |
Enable Tamper Detection IRQs. More... | |
void | rtc_tamper_enable (void) |
Enable Tamper Detection IRQs. | |
sam0 User Configuration | |
The MCUs of this family contain a region of memory that is used to store CPU configuration & calibration data. It can be used to set persistent settings and has some additional space to store user configuration data. | |
#define | FLASH_USER_PAGE_AUX_SIZE (AUX_PAGE_SIZE * AUX_NB_OF_PAGES - sizeof(nvm_user_page_t)) |
Size of the free to use auxiliary area in the user page. | |
#define | sam0_flashpage_aux_get(offset) (const void*)((uint8_t*)NVMCTRL_USER + sizeof(nvm_user_page_t) + (offset)) |
Get pointer to data in the user configuration area. More... | |
#define | sam0_flashpage_aux_cfg() ((const nvm_user_page_t*)NVMCTRL_USER) |
Get pointer to data in the CPU configuration struct. More... | |
typedef struct sam0_aux_cfg_mapping | nvm_user_page_t |
MCU configuration applied on start. More... | |
void | sam0_flashpage_aux_reset (const nvm_user_page_t *cfg) |
Reset the configuration area, apply a new configuration. More... | |
void | sam0_flashpage_aux_write (uint32_t offset, const void *data, size_t len) |
Write data to the user configuration area. More... | |
#define DMA_DESCRIPTOR_IN_LPSRAM |
Move the DMA descriptors to the LP SRAM.
Required on the SAML21
Definition at line 858 of file periph_cpu_common.h.
#define DMA_TRIGGER_DISABLED 0 |
Indicates that the peripheral doesn't utilize the DMA controller.
Matches with the register configuration for software based triggers.
Definition at line 852 of file periph_cpu_common.h.
#define GPIO_MODE | ( | pr, | |
ie, | |||
pe | |||
) | (pr | (ie << 1) | (pe << 2)) |
Generate GPIO mode bitfields.
We use 3 bit to determine the pin functions:
Definition at line 102 of file periph_cpu_common.h.
#define sam0_flashpage_aux_cfg | ( | ) | ((const nvm_user_page_t*)NVMCTRL_USER) |
Get pointer to data in the CPU configuration struct.
Definition at line 1165 of file periph_cpu_common.h.
#define sam0_flashpage_aux_get | ( | offset | ) | (const void*)((uint8_t*)NVMCTRL_USER + sizeof(nvm_user_page_t) + (offset)) |
Get pointer to data in the user configuration area.
offset | Byte offset after |
FLASH_USER_PAGE_AUX_SIZE
Definition at line 1157 of file periph_cpu_common.h.
#define TC_CONFIG | ( | tim | ) |
Static initializer for TC timer configuration.
Definition at line 279 of file periph_cpu_common.h.
#define TCC_CONFIG | ( | tim | ) |
Static initializer for TCC timer configuration.
Definition at line 297 of file periph_cpu_common.h.
typedef struct sam0_aux_cfg_mapping nvm_user_page_t |
MCU configuration applied on start.
The contents of this struct differ between families.
Definition at line 1112 of file periph_cpu_common.h.
anonymous enum |
Available ports on the SAMD21 & SAML21.
Enumerator | |
---|---|
PA | port A |
PB | port B |
PC | port C |
PD | port D |
Definition at line 87 of file periph_cpu_common.h.
anonymous enum |
Enumerator | |
---|---|
TIMER_TYPE_TC | Timer is a TC timer |
TIMER_TYPE_TCC | Timer is a TCC timer. |
Definition at line 241 of file periph_cpu_common.h.
enum dma_incr_t |
Available DMA address increment modes.
Definition at line 878 of file periph_cpu_common.h.
enum gpio_mux_t |
Available MUX values for configuring a pin's alternate function.
Definition at line 135 of file periph_cpu_common.h.
enum i2c_flag_t |
Available SERCOM I2C flag selections.
Enumerator | |
---|---|
I2C_FLAG_NONE | No flags set. |
I2C_FLAG_RUN_STANDBY | run SERCOM in standby mode |
Definition at line 406 of file periph_cpu_common.h.
enum spi_misopad_t |
Available values for SERCOM SPI MISO pad selection.
Enumerator | |
---|---|
SPI_PAD_MISO_0 | use pad 0 for MISO line |
SPI_PAD_MISO_1 | use pad 0 for MISO line |
SPI_PAD_MISO_2 | use pad 0 for MISO line |
SPI_PAD_MISO_3 | use pad 0 for MISO line |
Definition at line 326 of file periph_cpu_common.h.
enum spi_mosipad_t |
Available values for SERCOM SPI MOSI and SCK pad selection.
Definition at line 336 of file periph_cpu_common.h.
enum uart_flag_t |
Available SERCOM UART flag selections.
Enumerator | |
---|---|
UART_FLAG_NONE | No flags set. |
UART_FLAG_RUN_STANDBY | run SERCOM in standby mode |
UART_FLAG_WAKEUP | wake from sleep on receive |
UART_FLAG_RXINV | invert RX signal |
UART_FLAG_TXINV | invert TX signal |
Definition at line 170 of file periph_cpu_common.h.
enum uart_rxpad_t |
Available values for SERCOM UART RX pad selection.
Enumerator | |
---|---|
UART_PAD_RX_0 | use pad 0 for RX line |
UART_PAD_RX_1 | select pad 1 |
UART_PAD_RX_2 | select pad 2 |
UART_PAD_RX_3 | select pad 3 |
Definition at line 150 of file periph_cpu_common.h.
enum uart_txpad_t |
Available values for SERCOM UART TX pad selection.
Enumerator | |
---|---|
UART_PAD_TX_0 | select pad 0 |
UART_PAD_TX_2 | select pad 2 |
UART_PAD_TX_0_RTS_2_CTS_3 | TX is pad 0, on top RTS on pad 2 and CTS on pad 3. |
Definition at line 160 of file periph_cpu_common.h.
void cpu_pm_cb_enter | ( | int | deep | ) |
Called before the power management enters a power mode.
[in] | deep |
void cpu_pm_cb_leave | ( | int | deep | ) |
Called after the power management left a power mode.
[in] | deep |
dma_t dma_acquire_channel | ( | void | ) |
Acquire a DMA channel.
A free DMA channel is marked as allocated and a reference is returned. DMA channels can be acquired for long periods of time, e.g. from the start to end of a number of transfers or directly at boot and never released.
void dma_append | ( | dma_t | dma, |
DmacDescriptor * | descriptor, | ||
uint8_t | width, | ||
const void * | src, | ||
void * | dst, | ||
size_t | num, | ||
dma_incr_t | incr | ||
) |
Append a second transfer descriptor after the default channel descriptor.
next
must remain valid throughout the full transfer durationsrc
and/or dst
must point to the end of the array.dma | DMA channel reference to add the descriptor to |
descriptor | Extra transfer descriptor to append |
width | Transfer beat size to use |
src | Source address for the transfer |
dst | Destination address for the transfer |
num | Number of beats to transfer |
incr | Which of the addresses to increment after a beat |
void dma_append_dst | ( | dma_t | dma, |
DmacDescriptor * | next, | ||
void * | dst, | ||
size_t | num, | ||
bool | incr | ||
) |
Append a second transfer descriptor after the default channel descriptor, copying source and block size from the initial descriptor.
next
must remain valid throughout the full transfer durationdst
must point to the end of the array.dma | DMA channel reference to add the descriptor to |
next | Extra transfer descriptor to append |
dst | Destination address for the transfer |
num | Number of beats to transfer |
incr | Whether to increment the source address after a beat |
void dma_append_src | ( | dma_t | dma, |
DmacDescriptor * | next, | ||
const void * | src, | ||
size_t | num, | ||
bool | incr | ||
) |
Append a second transfer descriptor after the default channel descriptor, copying destination and block size from the initial descriptor.
next
must remain valid throughout the full transfer durationsrc
must point to the end of the array.dma | DMA channel reference to add the descriptor to |
next | Extra transfer descriptor to append |
src | Source address for the transfer |
num | Number of beats to transfer |
incr | Whether to increment the source address after a beat |
void dma_cancel | ( | dma_t | dma | ) |
Cancel an active DMA transfer.
It is not harmful to call this on an inactive channel, but it will waste some processing time
dma | DMA channel reference |
void dma_prepare | ( | dma_t | dma, |
uint8_t | width, | ||
const void * | src, | ||
void * | dst, | ||
size_t | num, | ||
dma_incr_t | incr | ||
) |
Prepare the DMA channel for an individual transfer.
src
and/or dst
must point to the end of the array.dma | DMA channel reference |
width | Transfer beat size to use |
src | Source address for the transfer |
dst | Destination address for the transfer |
num | Number of beats to transfer |
incr | Which of the addresses to increment after a beat |
void dma_prepare_dst | ( | dma_t | dma, |
void * | dst, | ||
size_t | num, | ||
bool | incr | ||
) |
Prepare a transfer without modifying the source address settings.
Can be used when repeatedly using a dma channel to transfer from the same peripheral address, leaving the source address and related settings untouched
dst
must point to the end of the array.dma | DMA channel reference |
dst | Destination address for the transfer |
num | Number of beats to transfer |
incr | Whether to increment the destination address after a beat |
void dma_prepare_src | ( | dma_t | dma, |
const void * | src, | ||
size_t | num, | ||
bool | incr | ||
) |
Prepare a transfer without modifying the destination address settings.
Can be used when repeatedly using a dma channel to transfer to the same peripheral address, leaving the destination address and related settings untouched
src
must point to the end of the array.dma | DMA channel reference |
src | Source address for the transfer |
num | Number of beats to transfer |
incr | Whether to increment the source address after a beat |
void dma_release_channel | ( | dma_t | dma | ) |
Release a previously acquired DMA channel.
dma | DMA channel to release |
void dma_setup | ( | dma_t | dma, |
unsigned | trigger, | ||
uint8_t | prio, | ||
bool | irq | ||
) |
Initialize a previously allocated DMA channel with one-time settings.
dma | DMA channel reference |
trigger | Trigger to use for this DMA channel |
prio | Channel priority |
irq | Whether to enable the interrupt handler for this channel |
void dma_start | ( | dma_t | dma | ) |
Start a DMA transfer.
dma | DMA channel reference |
void dma_wait | ( | dma_t | dma | ) |
Wait for a DMA channel to finish the transfer.
This function uses a blocking mutex to wait for the transfer to finish
dma | DMA channel reference |
void gpio_disable_mux | ( | gpio_t | pin | ) |
Disable alternate function (PMUX setting) for a PORT pin.
[in] | pin | Pin to reset the multiplexing for |
void gpio_init_mux | ( | gpio_t | pin, |
gpio_mux_t | mux | ||
) |
Set up alternate function (PMUX setting) for a PORT pin.
[in] | pin | Pin to set the multiplexing for |
[in] | mux | Mux value |
void gpio_pm_cb_enter | ( | int | deep | ) |
Called before the power management enters a power mode.
[in] | deep |
void gpio_pm_cb_leave | ( | int | deep | ) |
Called after the power management left a power mode.
[in] | deep |
int rtc_tamper_register | ( | gpio_t | pin, |
gpio_flank_t | flank | ||
) |
Enable Tamper Detection IRQs.
pin | The GPIO pin to be used for tamper detection |
flank | The Flank to trigger the even |
|
inlinestatic |
Wrapper for cortexm_sleep calling power management callbacks.
[in] | deep |
Definition at line 522 of file periph_cpu_common.h.
void sam0_flashpage_aux_reset | ( | const nvm_user_page_t * | cfg | ) |
Reset the configuration area, apply a new configuration.
cfg | New MCU configuration, may be NULL. If cfg is NULL, this will clear the configuration area and apply the current configuration again. |
void sam0_flashpage_aux_write | ( | uint32_t | offset, |
const void * | data, | ||
size_t | len | ||
) |
Write data to the user configuration area.
This will write data to the remaining space after
Will only write bits 1 -> 0. To reset bits to 1, call
Arbitrary data lengths and offsets are supported.
offset | Byte offset after |
FLASH_USER_PAGE_AUX_SIZE
data | The data to write |
len | Size of the data |
void sam0_gclk_enable | ( | uint8_t | id | ) |
Enables an on-demand GCLK that has been configured in cpu.c.
[in] | id | The ID of the GCLK |
uint32_t sam0_gclk_freq | ( | uint8_t | id | ) |
Returns the frequency of a GCLK provider.
[in] | id | The ID of the GCLK |
|
inlinestatic |
Switch the internal voltage regulator used for generating the internal MCU voltages.
Available options are:
[in] | src |
Definition at line 568 of file periph_cpu_common.h.
|
inlinestatic |
Disable peripheral clock for given SERCOM device.
[in] | sercom | SERCOM device |
Definition at line 686 of file periph_cpu_common.h.
|
inlinestatic |
Enable peripheral clock for given SERCOM device.
[in] | sercom | SERCOM device |
Definition at line 656 of file periph_cpu_common.h.
|
inlinestatic |
Return the numeric id of a SERCOM device derived from its address.
[in] | sercom | SERCOM device |
Definition at line 602 of file periph_cpu_common.h.
|
inlinestatic |
Configure generator clock for given SERCOM device.
[in] | sercom | SERCOM device |
[in] | gclk | Generator clock |
Definition at line 728 of file periph_cpu_common.h.