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

Enumerations

enum  system_reset_cause {
  SYSTEM_RESET_CAUSE_SOFTWARE = PM_RCAUSE_SYST,
  SYSTEM_RESET_CAUSE_WDT = PM_RCAUSE_WDT,
  SYSTEM_RESET_CAUSE_EXTERNAL_RESET = PM_RCAUSE_EXT,
  SYSTEM_RESET_CAUSE_BOD33 = PM_RCAUSE_BOD33,
  SYSTEM_RESET_CAUSE_BOD12 = PM_RCAUSE_BOD12,
  SYSTEM_RESET_CAUSE_POR = PM_RCAUSE_POR
}
 Reset causes of the system. More...
 
enum  system_sleepmode {
  SYSTEM_SLEEPMODE_IDLE_0,
  SYSTEM_SLEEPMODE_IDLE_1,
  SYSTEM_SLEEPMODE_IDLE_2,
  SYSTEM_SLEEPMODE_STANDBY
}
 Device sleep modes. More...
 
enum  system_voltage_reference {
  SYSTEM_VOLTAGE_REFERENCE_TEMPSENSE,
  SYSTEM_VOLTAGE_REFERENCE_BANDGAP
}
 Voltage references within the device. 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 References

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 enum status_code 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...
 

Reset Control

static void system_reset (void)
 Reset the MCU. More...
 
static enum system_reset_cause system_get_reset_cause (void)
 Return 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_BOD33 

The system was last reset by the BOD33.

SYSTEM_RESET_CAUSE_BOD12 

The system was last reset by the BOD12.

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 references within the device.

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_BANDGAP 

Bandgap voltage reference.

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

Return 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_board_init(), and system_clock_init().

Referenced by main().

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

Referenced by _usart_set_config().

static void system_reset ( void  )
inlinestatic

Reset the MCU.

Resets the MCU and all associated peripherals and registers, except RTC, all 32KHz sources, WDT (if ALWAYSON is set) and GCLK (if WRTLOCK is set).

static enum status_code 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
Return values
STATUS_OKOperation completed successfully
STATUS_ERR_INVALID_ARGThe requested sleep mode was invalid or not available

References _SYSTEM_MCU_REVISION_D, _SYSTEM_MCU_REVISION_E, STATUS_ERR_INVALID_ARG, STATUS_OK, SYSTEM_SLEEPMODE_IDLE_0, SYSTEM_SLEEPMODE_IDLE_1, SYSTEM_SLEEPMODE_IDLE_2, and SYSTEM_SLEEPMODE_STANDBY.

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_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_BANDGAP, 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_BANDGAP, and SYSTEM_VOLTAGE_REFERENCE_TEMPSENSE.