Microchip® Advanced Software Framework

 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
SAM System (SYSTEM) Driver

This driver for Atmel® | SMART ARM®-based microcontrollers provides an interface for the configuration and management of the device's system relation functionality, necessary for the basic device operation.

This is not limited to a single peripheral, but extends across multiple hardware peripherals.

The following peripherals are used by this module:

The following devices can use this module:

The outline of this documentation is as follows:

Prerequisites

There are no prerequisites for this module.

Module Overview

The System driver provides a collection of interfaces between the user application logic, and the core device functionality (such as clocks, reset cause determination, etc.) that is required for all applications. It contains a number of sub-modules that control one specific aspect of the device:

Voltage References

The various analog modules within the SAM devices (such as AC, ADC, and DAC) require a voltage reference to be configured to act as a reference point for comparisons and conversions.

The SAM devices contain multiple references, including an internal temperature sensor and a fixed band-gap voltage source. When enabled, the associated voltage reference can be selected within the desired peripheral where applicable.

System Reset Cause

In some applications there may be a need to execute a different program flow based on how the device was reset. For example, if the cause of reset was the Watchdog timer (WDT), this might indicate an error in the application, and a form of error handling or error logging might be needed.

For this reason, an API is provided to retrieve the cause of the last system reset, so that appropriate action can be taken.

Sleep Modes

The SAM devices have several sleep modes. The sleep mode controls which clock systems on the device will remain enabled or disabled when the device enters a low power sleep mode. The table below lists the clock settings of the different sleep modes.

SAM Device Sleep Modes
Sleep mode CPU clock AHB clock APB clocks Clock sources System clock 32KHz Reg mode RAM mode
Idle 0 Stop Run Run Run Run Run Normal Normal
Idle 1 Stop Stop Run Run Run Run Normal Normal
Idle 2 Stop Stop Stop Run Run Run Normal Normal
Standby Stop Stop Stop Stop Stop Stop Low Power Source/Drain biasing

Before entering device sleep, one of the available sleep modes must be set. The device will automatically wake up in response to an interrupt being generated or upon any other sleep mode exit condition.

Some peripheral clocks will remain enabled during sleep, depending on their configuration. If desired, the modules can remain clocked during sleep to allow them continue to operate while other parts of the system are powered down to save power.

Special Considerations

Most of the functions in this driver have device specific restrictions and caveats; refer to your device datasheet.

Extra Information

For extra information, see Extra Information for SYSTEM Driver. This includes:

Examples

For SYSTEM module related examples, refer to the sub-modules listed in the Module Overview.

API Overview

Data Structures

struct  system_standby_config
 Standby configuration. More...
 
struct  system_voltage_references_config
 Voltage References System (VREF) Control configuration. More...
 
struct  system_voltage_regulator_config
 Voltage Regulator System (VREG) Control configuration. More...
 

Enumerations

enum  system_reset_cause {
  SYSTEM_RESET_CAUSE_SOFTWARE = RSTC_RCAUSE_SYST,
  SYSTEM_RESET_CAUSE_WDT = RSTC_RCAUSE_WDT,
  SYSTEM_RESET_CAUSE_EXTERNAL_RESET = RSTC_RCAUSE_EXT,
  SYSTEM_RESET_CAUSE_BODVDD = RSTC_RCAUSE_BODVDD,
  SYSTEM_RESET_CAUSE_BODCORE = RSTC_RCAUSE_BODCORE,
  SYSTEM_RESET_CAUSE_POR = RSTC_RCAUSE_POR
}
 Reset causes of the system. More...
 
enum  system_sleepmode {
  SYSTEM_SLEEPMODE_IDLE_0 = PM_SLEEPCFG_SLEEPMODE(0),
  SYSTEM_SLEEPMODE_IDLE_1 = PM_SLEEPCFG_SLEEPMODE(0x1),
  SYSTEM_SLEEPMODE_IDLE_2 = PM_SLEEPCFG_SLEEPMODE(0x2),
  SYSTEM_SLEEPMODE_STANDBY = PM_SLEEPCFG_SLEEPMODE(0x4)
}
 Device sleep modes. More...
 
enum  system_voltage_reference {
  SYSTEM_VOLTAGE_REFERENCE_TEMPSENSE,
  SYSTEM_VOLTAGE_REFERENCE_OUTPUT
}
 Voltage reference. More...
 
enum  system_voltage_references_sel {
  SYSTEM_VOLTAGE_REFERENCE_1V024 = SUPC_VREF_SEL_1V024_Val,
  SYSTEM_VOLTAGE_REFERENCE_2V048 = SUPC_VREF_SEL_2V048_Val,
  SYSTEM_VOLTAGE_REFERENCE_4V096 = SUPC_VREF_SEL_4V096_Val
}
 Voltage reference value for ADC/DAC. More...
 
enum  system_vreg_switch_mode {
  SYSTEM_VREG_SWITCH_AUTO = PM_STDBYCFG_VREGSMOD_AUTO_Val,
  SYSTEM_VREG_SWITCH_PERFORMANCE = PM_STDBYCFG_VREGSMOD_PERFORMANCE_Val,
  SYSTEM_VREG_SWITCH_LP = PM_STDBYCFG_VREGSMOD_LP_Val
}
 Voltage Regulator switch in Standby mode. More...
 

System Debugger

static bool system_is_debugger_present (void)
 Check if debugger is present. More...
 

System Identification

static uint32_t system_get_device_id (void)
 Retrieve the device identification signature. More...
 

System Initialization

void system_init (void)
 Initialize system. More...
 

Voltage Regulator

static void system_voltage_regulator_get_config_defaults (struct system_voltage_regulator_config *const config)
 Retrieve the default configuration for voltage regulator. More...
 
static void system_voltage_regulator_set_config (struct system_voltage_regulator_config *const config)
 Configure voltage regulator. More...
 
static void system_voltage_regulator_enable (void)
 Enable the selected voltage regulator. More...
 
static void system_voltage_regulator_disable (void)
 Disable the selected voltage regulator. More...
 

Voltage References

static void system_voltage_reference_get_config_defaults (struct system_voltage_references_config *const config)
 Retrieve the default configuration for voltage reference. More...
 
static void system_voltage_reference_set_config (struct system_voltage_references_config *const config)
 Configure voltage reference. More...
 
static void system_voltage_reference_enable (const enum system_voltage_reference vref)
 Enable the selected voltage reference. More...
 
static void system_voltage_reference_disable (const enum system_voltage_reference vref)
 Disable the selected voltage reference. More...
 

Device Sleep Control

static void system_set_sleepmode (const enum system_sleepmode sleep_mode)
 Set the sleep mode of the device. More...
 
static void system_sleep (void)
 Put the system to sleep waiting for interrupt. More...
 

Standby Configuration

static void system_standby_get_config_defaults (struct system_standby_config *const config)
 Retrieve the default configuration for standby. More...
 
static void system_standby_set_config (struct system_standby_config *const config)
 Configure standby mode. More...
 

Reset Control

static void system_reset (void)
 Reset the MCU. More...
 
static enum system_reset_cause system_get_reset_cause (void)
 Get the reset cause. More...
 

Reset causes of the system.

List of possible reset causes of the system.

Enumerator
SYSTEM_RESET_CAUSE_SOFTWARE 

The system was last reset by a software reset.

SYSTEM_RESET_CAUSE_WDT 

The system was last reset by the watchdog timer.

SYSTEM_RESET_CAUSE_EXTERNAL_RESET 

The system was last reset because the external reset line was pulled low.

SYSTEM_RESET_CAUSE_BODVDD 

The system was last reset by VDD brown out detector.

SYSTEM_RESET_CAUSE_BODCORE 

The system was last reset by VDDCORE brown out detector.

SYSTEM_RESET_CAUSE_POR 

The system was last reset by the POR (Power on reset)

Device sleep modes.

List of available sleep modes in the device. A table of clocks available in different sleep modes can be found in Sleep Modes.

Enumerator
SYSTEM_SLEEPMODE_IDLE_0 

IDLE 0 sleep mode.

SYSTEM_SLEEPMODE_IDLE_1 

IDLE 1 sleep mode.

SYSTEM_SLEEPMODE_IDLE_2 

IDLE 2 sleep mode.

SYSTEM_SLEEPMODE_STANDBY 

Standby sleep mode.

Voltage reference.

List of available voltage references (VREF) that may be used within the device.

Enumerator
SYSTEM_VOLTAGE_REFERENCE_TEMPSENSE 

Temperature sensor voltage reference.

SYSTEM_VOLTAGE_REFERENCE_OUTPUT 

Voltage reference output for ADC/DAC.

Voltage reference value for ADC/DAC.

Voltage references selection for ADC/DAC.

Enumerator
SYSTEM_VOLTAGE_REFERENCE_1V024 

1.024V voltage reference typical value

SYSTEM_VOLTAGE_REFERENCE_2V048 

2.048V voltage reference typical value

SYSTEM_VOLTAGE_REFERENCE_4V096 

4.096V voltage reference typical value

Voltage Regulator switch in Standby mode.

Enumerator
SYSTEM_VREG_SWITCH_AUTO 

Automatic mode.

SYSTEM_VREG_SWITCH_PERFORMANCE 

Performance oriented.

SYSTEM_VREG_SWITCH_LP 

Low Power consumption oriented.

static uint32_t system_get_device_id ( void  )
inlinestatic

Retrieve the device identification signature.

Retrieves the signature of the current device.

Returns
Device ID signature as a 32-bit integer.
static enum system_reset_cause system_get_reset_cause ( void  )
inlinestatic

Get the reset cause.

Retrieves the cause of the last system reset.

Returns
An enum value indicating the cause of the last system reset.
void system_init ( void  )

Initialize system.

This function will call the various initialization functions within the system namespace. If a given optional system module is not available, the associated call will effectively be a NOP (No Operation).

Currently the following initialization functions are supported:

  • System clock initialization (via the SYSTEM CLOCK sub-module)
  • Board hardware initialization (via the Board module)
  • Event system driver initialization (via the EVSYS module)
  • External Interrupt driver initialization (via the EXTINT module)

References _system_events_init(), system_board_init(), and system_clock_init().

static bool system_is_debugger_present ( void  )
inlinestatic

Check if debugger is present.

Check if debugger is connected to the onboard debug system (DAP).

Returns
A bool identifying if a debugger is present.
Return values
trueDebugger is connected to the system
falseDebugger is not connected to the system
static void system_reset ( void  )
inlinestatic

Reset the MCU.

Resets the MCU and all associated peripherals and registers, except RTC, OSC32KCTRL, RSTC, GCLK(if WRTLOCK is set) and I/O retention state of PM.

static void system_set_sleepmode ( const enum system_sleepmode  sleep_mode)
inlinestatic

Set the sleep mode of the device.

Sets the sleep mode of the device; the configured sleep mode will be entered upon the next call of the system_sleep() function.

For an overview of which systems are disabled in sleep for the different sleep modes, see Sleep Modes.

Parameters
[in]sleep_modeSleep mode to configure for the next sleep operation
static void system_sleep ( void  )
inlinestatic

Put the system to sleep waiting for interrupt.

Executes a device DSB (Data Synchronization Barrier) instruction to ensure all ongoing memory accesses have completed, then a WFI (Wait For Interrupt) instruction to place the device into the sleep mode specified by system_set_sleepmode until woken by an interrupt.

static void system_standby_get_config_defaults ( struct system_standby_config *const  config)
inlinestatic

Retrieve the default configuration for standby.

Fills a configuration structure with the default configuration for standby:

  • Automatic VREG switching is used
  • Retention back biasing mode for HMCRAMCHS
Parameters
[out]configConfiguration structure to fill with default values

References Assert, system_standby_config::hmcramchs_back_bias, SYSTEM_VREG_SWITCH_AUTO, and system_standby_config::vreg_switch_mode.

static void system_standby_set_config ( struct system_standby_config *const  config)
inlinestatic

Configure standby mode.

Configures standby with the given configuration.

Parameters
[in]configStandby configuration structure containing the new config

References Assert, system_standby_config::hmcramchs_back_bias, and system_standby_config::vreg_switch_mode.

static void system_voltage_reference_disable ( const enum system_voltage_reference  vref)
inlinestatic

Disable the selected voltage reference.

Disables the selected voltage reference source.

Parameters
[in]vrefVoltage reference to disable

References Assert, SYSTEM_VOLTAGE_REFERENCE_OUTPUT, and SYSTEM_VOLTAGE_REFERENCE_TEMPSENSE.

static void system_voltage_reference_enable ( const enum system_voltage_reference  vref)
inlinestatic

Enable the selected voltage reference.

Enables the selected voltage reference source, making the voltage reference available on a pin as well as an input source to the analog peripherals.

Parameters
[in]vrefVoltage reference to enable

References Assert, SYSTEM_VOLTAGE_REFERENCE_OUTPUT, and SYSTEM_VOLTAGE_REFERENCE_TEMPSENSE.

Referenced by dac_enable().

static void system_voltage_reference_get_config_defaults ( struct system_voltage_references_config *const  config)
inlinestatic

Retrieve the default configuration for voltage reference.

Fill a configuration structure with the default configuration:

  • 1.024V voltage reference typical value
  • On demand control:disabled
  • The voltage reference and the temperature sensor are halted during standby sleep mode
Parameters
[out]configConfiguration structure to fill with default values

References Assert, system_voltage_references_config::on_demand, system_voltage_references_config::run_in_standby, system_voltage_references_config::sel, and SYSTEM_VOLTAGE_REFERENCE_1V024.

static void system_voltage_reference_set_config ( struct system_voltage_references_config *const  config)
inlinestatic

Configure voltage reference.

Configures voltage reference with the given configuration.

Parameters
[in]configVoltage reference configuration structure containing the new config

References Assert, system_voltage_references_config::on_demand, system_voltage_references_config::run_in_standby, and system_voltage_references_config::sel.

static void system_voltage_regulator_disable ( void  )
inlinestatic

Disable the selected voltage regulator.

Disables the selected voltage regulator.

static void system_voltage_regulator_enable ( void  )
inlinestatic

Enable the selected voltage regulator.

Enables the selected voltage regulator source.

static void system_voltage_regulator_get_config_defaults ( struct system_voltage_regulator_config *const  config)
inlinestatic

Retrieve the default configuration for voltage regulator.

Fills a configuration structure with the default configuration:

  • The voltage regulator is in low power mode in Standby sleep mode
Parameters
[out]configConfiguration structure to fill with default values

References Assert, and system_voltage_regulator_config::run_in_standby.

static void system_voltage_regulator_set_config ( struct system_voltage_regulator_config *const  config)
inlinestatic

Configure voltage regulator.

Configures voltage regulator with the given configuration.

Parameters
[in]configVoltage regulator configuration structure containing the new config

References system_voltage_regulator_config::run_in_standby.