SMART ARM-based Microcontrollers AT13485: SAM C System (SYSTEM) Driver APPLICATION NOTE Introduction ® ® 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: • PM (Power Manager) • RSTC (Reset Controller) • SUPC (Supply Controller) The following devices can use this module: • Atmel | SMART SAM C20/C21 The outline of this documentation is as follows: • Prerequisites • Module Overview • Special Considerations • Extra Information • Examples • API Overview Atmel-42484A-SAM-System-SYSTEM-Driver_AT13485_Application Note-12/2015 Table of Contents Introduction......................................................................................................................1 1. Software License....................................................................................................... 3 2. Prerequisites..............................................................................................................4 3. Module Overview....................................................................................................... 5 3.1. 3.2. 3.3. 3.4. Voltage Regulator.........................................................................................................................5 Voltage References...................................................................................................................... 5 System Reset Cause....................................................................................................................5 Sleep Modes.................................................................................................................................5 4. Special Considerations.............................................................................................. 7 5. Extra Information....................................................................................................... 8 6. Examples................................................................................................................... 9 7. API Overview........................................................................................................... 10 7.1. 7.2. 7.3. Structure Definitions................................................................................................................... 10 7.1.1. Struct system_standby_config.....................................................................................10 7.1.2. Struct system_voltage_references_config...................................................................10 7.1.3. Struct system_voltage_regulator_config......................................................................10 Function Definitions....................................................................................................................10 7.2.1. Voltage Regulator........................................................................................................ 10 7.2.2. Voltage References......................................................................................................11 7.2.3. Device Sleep Control................................................................................................... 12 7.2.4. Standby Configuration................................................................................................. 13 7.2.5. Reset Control...............................................................................................................13 7.2.6. System Debugger........................................................................................................ 14 7.2.7. System Identification....................................................................................................14 7.2.8. System Initialization..................................................................................................... 14 Enumeration Definitions............................................................................................................. 15 7.3.1. Enum system_reset_cause......................................................................................... 15 7.3.2. Enum system_sleepmode........................................................................................... 15 7.3.3. Enum system_voltage_reference................................................................................ 15 7.3.4. 7.3.5. Enum system_voltage_references_sel........................................................................16 Enum system_vreg_switch_mode............................................................................... 16 8. Extra Information for SYSTEM Driver......................................................................17 8.1. 8.2. 8.3. 8.4. Acronyms....................................................................................................................................17 Dependencies.............................................................................................................................17 Errata..........................................................................................................................................17 Module History............................................................................................................................17 9. Document Revision History..................................................................................... 18 Atmel AT13485: SAM C System (SYSTEM) Driver [APPLICATION NOTE] Atmel-42484A-SAM-System-SYSTEM-Driver_AT13485_Application Note-12/2015 2 1. Software License Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. 3. The name of Atmel may not be used to endorse or promote products derived from this software without specific prior written permission. 4. This software may only be redistributed and used in connection with an Atmel microcontroller product. THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE EXPRESSLY AND SPECIFICALLY DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. Atmel AT13485: SAM C System (SYSTEM) Driver [APPLICATION NOTE] Atmel-42484A-SAM-System-SYSTEM-Driver_AT13485_Application Note-12/2015 3 2. Prerequisites There are no prerequisites for this module. Atmel AT13485: SAM C System (SYSTEM) Driver [APPLICATION NOTE] Atmel-42484A-SAM-System-SYSTEM-Driver_AT13485_Application Note-12/2015 4 3. 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: • • • • 3.1. System Core (this module) System Clock Control (sub-module) System Interrupt Control (sub-module) System Pin Multiplexer Control (sub-module) Voltage Regulator The SAM device controls the voltage regulators for the core (VDDCORE). It sets the voltage regulators according to the sleep modes. There are a selectable reference voltage and voltage dependent on the temperature which can be used by analog modules like the ADC. 3.2. 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 bandgap voltage source. When enabled, the associated voltage reference can be selected within the desired peripheral where applicable. 3.3. 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. 3.4. 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. Table 3-1 SAM Device Sleep Modes on page 6 lists the clock settings of the different sleep modes. Atmel AT13485: SAM C System (SYSTEM) Driver [APPLICATION NOTE] Atmel-42484A-SAM-System-SYSTEM-Driver_AT13485_Application Note-12/2015 5 Table 3-1 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. Atmel AT13485: SAM C System (SYSTEM) Driver [APPLICATION NOTE] Atmel-42484A-SAM-System-SYSTEM-Driver_AT13485_Application Note-12/2015 6 4. Special Considerations Most of the functions in this driver have device specific restrictions and caveats; refer to your device datasheet. Atmel AT13485: SAM C System (SYSTEM) Driver [APPLICATION NOTE] Atmel-42484A-SAM-System-SYSTEM-Driver_AT13485_Application Note-12/2015 7 5. Extra Information For extra information, see Extra Information for SYSTEM Driver. This includes: • Acronyms • Dependencies • Errata • Module History Atmel AT13485: SAM C System (SYSTEM) Driver [APPLICATION NOTE] Atmel-42484A-SAM-System-SYSTEM-Driver_AT13485_Application Note-12/2015 8 6. Examples For SYSTEM module related examples, refer to the sub-modules listed in the Module Overview. Atmel AT13485: SAM C System (SYSTEM) Driver [APPLICATION NOTE] Atmel-42484A-SAM-System-SYSTEM-Driver_AT13485_Application Note-12/2015 9 7. API Overview 7.1. Structure Definitions 7.1.1. Struct system_standby_config Configuration structure for standby mode. Table 7-1 Members Type Name Description bool hmcramchs_back_bias Back bias for HMCRAMCHS (false: no, true: standby) enum system_vreg_switch_mode vreg_switch_mode 7.1.2. Regulator switch mode in standby Struct system_voltage_references_config Configuration structure for VREF. Table 7-2 Members 7.1.3. Type Name Description bool on_demand On demand control bool run_in_standby Run in standby enum system_voltage_references_sel sel Voltage references selection Struct system_voltage_regulator_config Configuration structure for VREG. Table 7-3 Members Type Name Description bool run_in_standby Run in standby in standby sleep mode 7.2. Function Definitions 7.2.1. Voltage Regulator 7.2.1.1. Function system_voltage_regulator_get_config_defaults() Retrieve the default configuration for voltage regulator. void system_voltage_regulator_get_config_defaults( struct system_voltage_regulator_config *const config) Fills a configuration structure with the default configuration: Atmel AT13485: SAM C System (SYSTEM) Driver [APPLICATION NOTE] Atmel-42484A-SAM-System-SYSTEM-Driver_AT13485_Application Note-12/2015 10 • The voltage regulator is in low power mode in Standby sleep mode Table 7-4 Parameters 7.2.1.2. Data direction Parameter name Description [out] config Configuration structure to fill with default values Function system_voltage_regulator_set_config() Configure voltage regulator. void system_voltage_regulator_set_config( struct system_voltage_regulator_config *const config) Configures voltage regulator with the given configuration. Table 7-5 Parameters Data direction Parameter name Description [in] 7.2.1.3. config Voltage regulator configuration structure containing the new config Function system_voltage_regulator_enable() Enable the selected voltage regulator. void system_voltage_regulator_enable( void ) Enables the selected voltage regulator source. 7.2.1.4. Function system_voltage_regulator_disable() Disable the selected voltage regulator. void system_voltage_regulator_disable( void ) Disables the selected voltage regulator. 7.2.2. Voltage References 7.2.2.1. Function system_voltage_reference_get_config_defaults() Retrieve the default configuration for voltage reference. void system_voltage_reference_get_config_defaults( struct system_voltage_references_config *const config) 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 Table 7-6 Parameters Data direction Parameter name Description [out] config Configuration structure to fill with default values Atmel AT13485: SAM C System (SYSTEM) Driver [APPLICATION NOTE] Atmel-42484A-SAM-System-SYSTEM-Driver_AT13485_Application Note-12/2015 11 7.2.2.2. Function system_voltage_reference_set_config() Configure voltage reference. void system_voltage_reference_set_config( struct system_voltage_references_config *const config) Configures voltage reference with the given configuration. Table 7-7 Parameters Data direction Parameter name Description [in] 7.2.2.3. config Voltage reference configuration structure containing the new config Function system_voltage_reference_enable() Enable the selected voltage reference. void system_voltage_reference_enable( const enum system_voltage_reference vref) Enables the selected voltage reference source, making the voltage reference available on a pin as well as an input source to the analog peripherals. Table 7-8 Parameters 7.2.2.4. Data direction Parameter name Description [in] vref Voltage reference to enable Function system_voltage_reference_disable() Disable the selected voltage reference. void system_voltage_reference_disable( const enum system_voltage_reference vref) Disables the selected voltage reference source. Table 7-9 Parameters Data direction Parameter name Description [in] vref Voltage reference to disable 7.2.3. Device Sleep Control 7.2.3.1. Function system_set_sleepmode() Set the sleep mode of the device. void system_set_sleepmode( const enum system_sleepmode sleep_mode) 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. Atmel AT13485: SAM C System (SYSTEM) Driver [APPLICATION NOTE] Atmel-42484A-SAM-System-SYSTEM-Driver_AT13485_Application Note-12/2015 12 Table 7-10 Parameters 7.2.3.2. Data direction Parameter name Description [in] sleep_mode Sleep mode to configure for the next sleep operation Function system_sleep() Put the system to sleep waiting for interrupt. void system_sleep( void ) 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. 7.2.4. Standby Configuration 7.2.4.1. Function system_standby_get_config_defaults() Retrieve the default configuration for standby. void system_standby_get_config_defaults( struct system_standby_config *const config) Fills a configuration structure with the default configuration for standby: • Automatic VREG switching is used • Retention back biasing mode for HMCRAMCHS Table 7-11 Parameters 7.2.4.2. Data direction Parameter name Description [out] config Configuration structure to fill with default values Function system_standby_set_config() Configure standby mode. void system_standby_set_config( struct system_standby_config *const config) Configures standby with the given configuration. Table 7-12 Parameters Data direction Parameter name Description [in] config Standby configuration structure containing the new config 7.2.5. Reset Control 7.2.5.1. Function system_reset() Reset the MCU. void system_reset( void ) Atmel AT13485: SAM C System (SYSTEM) Driver [APPLICATION NOTE] Atmel-42484A-SAM-System-SYSTEM-Driver_AT13485_Application Note-12/2015 13 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. 7.2.5.2. Function system_get_reset_cause() Get the reset cause. enum system_reset_cause system_get_reset_cause( void ) Retrieves the cause of the last system reset. Returns An enum value indicating the cause of the last system reset. 7.2.6. System Debugger 7.2.6.1. Function system_is_debugger_present() Check if debugger is present. bool system_is_debugger_present( void ) Check if debugger is connected to the onboard debug system (DAP). Returns A bool identifying if a debugger is present. Table 7-13 Return Values Return value Description true Debugger is connected to the system false Debugger is not connected to the system 7.2.7. System Identification 7.2.7.1. Function system_get_device_id() Retrieve the device identification signature. uint32_t system_get_device_id( void ) Retrieves the signature of the current device. Returns Device ID signature as a 32-bit integer. 7.2.8. System Initialization 7.2.8.1. Function system_init() Initialize system. void system_init( void ) 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). Atmel AT13485: SAM C System (SYSTEM) Driver [APPLICATION NOTE] Atmel-42484A-SAM-System-SYSTEM-Driver_AT13485_Application Note-12/2015 14 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) 7.3. Enumeration Definitions 7.3.1. Enum system_reset_cause List of possible reset causes of the system. Table 7-14 Members Enum value Description 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 7.3.2. 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) Enum system_sleepmode List of available sleep modes in the device. A table of clocks available in different sleep modes can be found in Sleep Modes. Table 7-15 Members 7.3.3. Enum value Description 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 Enum system_voltage_reference List of available voltage references (VREF) that may be used within the device. Atmel AT13485: SAM C System (SYSTEM) Driver [APPLICATION NOTE] Atmel-42484A-SAM-System-SYSTEM-Driver_AT13485_Application Note-12/2015 15 Table 7-16 Members 7.3.4. Enum value Description SYSTEM_VOLTAGE_REFERENCE_TEMPSENSE Temperature sensor voltage reference SYSTEM_VOLTAGE_REFERENCE_OUTPUT Voltage reference output for ADC/DAC Enum system_voltage_references_sel Voltage references selection for ADC/DAC. Table 7-17 Members 7.3.5. Enum value Description 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 Enum system_vreg_switch_mode Table 7-18 Members Enum value Description SYSTEM_VREG_SWITCH_AUTO Automatic mode SYSTEM_VREG_SWITCH_PERFORMANCE Performance oriented SYSTEM_VREG_SWITCH_LP Low Power consumption oriented Atmel AT13485: SAM C System (SYSTEM) Driver [APPLICATION NOTE] Atmel-42484A-SAM-System-SYSTEM-Driver_AT13485_Application Note-12/2015 16 8. Extra Information for SYSTEM Driver 8.1. Acronyms Below is a table listing the acronyms used in this module, along with their intended meanings. 8.2. Acronym Definition PM Power Manager SUPC Supply Controller RSTC Reset Controller Dependencies This driver has the following dependencies: • 8.3. None Errata There are no errata related to this driver. 8.4. Module History An overview of the module history is presented in the table below, with details on the enhancements and fixes made to the module since its first release. The current version of this corresponds to the newest version in the table. Changelog Initial Release Atmel AT13485: SAM C System (SYSTEM) Driver [APPLICATION NOTE] Atmel-42484A-SAM-System-SYSTEM-Driver_AT13485_Application Note-12/2015 17 9. Document Revision History Doc. Rev. Date Comments 42484A 12/2015 Initial document release. Atmel AT13485: SAM C System (SYSTEM) Driver [APPLICATION NOTE] Atmel-42484A-SAM-System-SYSTEM-Driver_AT13485_Application Note-12/2015 18 Atmel Corporation © 1600 Technology Drive, San Jose, CA 95110 USA T: (+1)(408) 441.0311 F: (+1)(408) 436.4200 | www.atmel.com 2015 Atmel Corporation. / Rev.: Atmel-42484A-SAM-System-SYSTEM-Driver_AT13485_Application Note-12/2015 ® ® Atmel , Atmel logo and combinations thereof, Enabling Unlimited Possibilities , and others are registered trademarks or trademarks of Atmel Corporation in U.S. and ® ® other countries. ARM , ARM Connected , and others are registered trademarks of ARM Ltd. Other terms and product names may be trademarks of others. DISCLAIMER: The information in this document is provided in connection with Atmel products. No license, express or implied, by estoppel or otherwise, to any intellectual property right is granted by this document or in connection with the sale of Atmel products. EXCEPT AS SET FORTH IN THE ATMEL TERMS AND CONDITIONS OF SALES LOCATED ON THE ATMEL WEBSITE, ATMEL ASSUMES NO LIABILITY WHATSOEVER AND DISCLAIMS ANY EXPRESS, IMPLIED OR STATUTORY WARRANTY RELATING TO ITS PRODUCTS INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT. IN NO EVENT SHALL ATMEL BE LIABLE FOR ANY DIRECT, INDIRECT, CONSEQUENTIAL, PUNITIVE, SPECIAL OR INCIDENTAL DAMAGES (INCLUDING, WITHOUT LIMITATION, DAMAGES FOR LOSS AND PROFITS, BUSINESS INTERRUPTION, OR LOSS OF INFORMATION) ARISING OUT OF THE USE OR INABILITY TO USE THIS DOCUMENT, EVEN IF ATMEL HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. Atmel makes no representations or warranties with respect to the accuracy or completeness of the contents of this document and reserves the right to make changes to specifications and products descriptions at any time without notice. Atmel does not make any commitment to update the information contained herein. Unless specifically provided otherwise, Atmel products are not suitable for, and shall not be used in, automotive applications. Atmel products are not intended, authorized, or warranted for use as components in applications intended to support or sustain life. SAFETY-CRITICAL, MILITARY, AND AUTOMOTIVE APPLICATIONS DISCLAIMER: Atmel products are not designed for and will not be used in connection with any applications where the failure of such products would reasonably be expected to result in significant personal injury or death (“Safety-Critical Applications”) without an Atmel officer's specific written consent. Safety-Critical Applications include, without limitation, life support devices and systems, equipment or systems for the operation of nuclear facilities and weapons systems. Atmel products are not designed nor intended for use in military or aerospace applications or environments unless specifically designated by Atmel as military-grade. Atmel products are not designed nor intended for use in automotive applications unless specifically designated by Atmel as automotive-grade.