AT09381: SAM D - Debugging Watchdog Timer Reset. Introduction. SMART ARM-based Microcontrollers APPLICATION NOTE

Similar documents
AVR42789: Writing to Flash on the New tinyavr Platform Using Assembly

AT03975: Getting Started with SAM L21. Descripton. Features. SMART ARM-Based Microcontroller APPLICATION NOTE

AT60142H/HT. Rad-Hard 512Kx8 Very Low Power CMOS SRAM ERRATA-SHEET. Active Errata List. Errata History. Abbreviations. 1.

APPLICATION NOTE. AT6486: Using DIVAS on SAMC Microcontroller. SMART ARM-Based Microcontroller. Introduction. Features

ATAES132A Firmware Development Library. Introduction. Features. Atmel CryptoAuthentication USER GUIDE

AT06467: Getting started with SAM D09/D10/D11. Features. Description. SMART ARM-based Microcontrollers APPLICATION NOTE

AT11512: SAM L Brown Out Detector (BOD) Driver. Introduction. SMART ARM-based Microcontrollers APPLICATION NOTE

This user guide describes how to run the Atmel ATWINC3400 Bluetooth Low Energy (BLE) Provisioning demo from out-of-box conditions.

AT03262: SAM D/R/L/C System Pin Multiplexer (SYSTEM PINMUX) Driver. Introduction. SMART ARM-based Microcontrollers APPLICATION NOTE

EDBG. Description. Programmers and Debuggers USER GUIDE

AT10942: SAM Configurable Custom Logic (CCL) Driver. Introduction. SMART ARM-based Microcontrollers APPLICATION NOTE

AVR134: Real Time Clock (RTC) Using the Asynchronous Timer. Features. Introduction. AVR 8-bit Microcontrollers APPLICATION NOTE

APPLICATION NOTE. AT05567: TC Capture on External Interrupt with the Event System on SAM D20. Preface ASF PROJECT DOCUMENTATION

USER GUIDE. Atmel QT6 Xplained Pro. Preface

Ethernet1 Xplained Pro

ATECC108/ATSHA204 USER GUIDE. Atmel Firmware Library. Features. Introduction

Smart RF Device Family - Getting Started Guide. Features. Description. References ATAN0115 APPLICATION NOTE

QT3 Xplained Pro. Preface. Atmel QTouch USER GUIDE

SAMA5D2 Quad SPI (QSPI) Performance. Introduction. SMART ARM-based Microprocessor APPLICATION NOTE

APPLICATION NOTE. Generating Random Secrets. ATSHA204A, ATECC108A, and ATECC508A. Description. Topics

APPLICATION NOTE. AT04470: Differences between SAM D21 Variants A, B, and L. 32-bit Microcontroller. Introduction

AVR42772: Data Logger Demo Application on XMEGA A1U Xplained Pro. Introduction. Features. AVR XMEGA Microcontrollers APPLICATION NOTE

QT2 Xplained Pro. Preface. Atmel QTouch USER GUIDE

APPLICATION NOTE. Atmel QT4 Xplained Pro User Guide ATAN0114. Preface

APPLICATION NOTE. AT11008: Migration from ATxmega16D4/32D4 Revision E to Revision I. Atmel AVR XMEGA. Introduction. Features

DGILib USER GUIDE Atmel-42771A-DGILib_User Guide-09/2016

AT21CS Series Reset and Discovery. Introduction. Serial EEPROM APPLICATION NOTE

APPLICATION NOTE. Atmel AT03304: SAM D20 I 2 C Slave Bootloader SAM D20. Description. Features

APPLICATION NOTE. 3-lead CONTACT Package Usage. ATSHA204A, ATECC108A, and ATECC508A. Introduction. 3-lead CONTACT Package

USER GUIDE. ATWINC1500 Xplained Pro. Preface

SAM4 Reset Controller (RSTC)

APPLICATION NOTE. How to Securely Switch Atmel s LIN Transceiver ATA6662/ATA6662C to Sleep Mode ATA6662/ATA6662C. Concerning Atmel ATA6662

AVR1503: Xplain training - XMEGA Programmable Multi Interrupt Controller 8-bit Microcontrollers Application Note Prerequisites

APPLICATION NOTE. Atmel AT03261: SAM D20 System Interrupt Driver (SYSTEM INTERRUPT) SAM D20 System Interrupt Driver (SYSTEM INTERRUPT)

APPLICATION NOTE. Atmel AT03160: Migrating Bootloader from ATxmega128A1 to other Atmel XMEGA Devices. Atmel AVR XMEGA. Features.

Native route discovery algorithm

ATECC508A Public Key Validation. Introduction. Atmel CryptoAuthentication APPLICATION NOTE

USER GUIDE. Atmel QT1 Xplained Pro. Preface

USER GUIDE EDBG. Description

ATtiny104 Xplained Nano. Preface. AVR 8-bit Microcontrollers USER GUIDE

ATtiny817 QTouch Moisture Demo User Guide. Description. Features. AVR 8-bit Microcontrollers USER GUIDE

AVR1518: XMEGA-A1 Xplained Training - XMEGA Clock System. 8-bit Atmel Microcontrollers. Application Note. Prerequisites.

USER GUIDE. Atmel Segment LCD1 Xplained Pro. Preface

USER GUIDE. Atmel maxtouch Xplained Pro. Preface

APPLICATION NOTE. CryptoAuthentication Personalization Guide. ATSHA204A and ATECC508A. Introduction. Features

OLED display with pixels resolution Ambient light sensor CPU load Analog filter Quadrature Encoder with push button Digital I/O

Hardware Prerequisites Atmel Xplained Pro Evaluation Kit Atmel WINC1500 extension USB Micro Cable (TypeA / MicroB)

APPLICATION NOTE. Atmel AVR1638: XMEGA RTC Calibration. 8-bit Atmel Microcontrollers. Features. Introduction

USER GUIDE. Atmel OLED1 Xplained Pro. Preface

AT88CK101 HARDWARE USER GUIDE. Atmel CryptoAuthentication Development Kit. Atmel CryptoAuthentication AT88CK101 Daughterboard

APPLICATION NOTE. AT03324: Atmel REB212BSMA-EK Quick Start Guide. Atmel MCU Wireless. Introduction

AVR1501: Xplain training XMEGA Timer/Counter 8-bit Microcontrollers Application Note Prerequisites 1 Introduction

APPLICATION NOTE. Atmel AT02260: Driving AT42QT1085. Atmel QTouch. Features. Description

AVR1315: Accessing the XMEGA EEPROM. 8-bit Microcontrollers. Application Note. Features. 1 Introduction

APPLICATION NOTE. Scope. Reference Documents. Software Ethernet Bridge on SAMA5D3/D4. Atmel SMART SAMA5D3/D4 Series

APPLICATION NOTE. Atmel AVR057: Internal RC Oscillator Calibration for ATtiny4/5/9/10/20/40. 8-bit Atmel Microcontrollers. Features.

AT07942: SAM4L Asynchronous Timer (AST) Driver. Introduction. SMART ARM-based Microcontrollers APPLICATION NOTE

AT03664: Getting Started with FreeRTOS on SAM D20/D21/R21/L21/L22. Introduction. Features. SMART ARM-based Microcontrollers APPLICATION NOTE

I/O1 Xplained Pro. Preface. Atmel MCUs USER GUIDE

Atmel AVR1619: XMEGA-B1 Xplained Demonstration. 8-bit Atmel Microcontrollers. Application Note. Features. 1 Introduction

SMART ARM-based Microcontrollers ATSAMD21E16LMOTOR USER GUIDE

APPLICATION NOTE. AT07216: SAM G55 Schematic Checklist. Atmel SMART SAM G55. Introduction

APPLICATION NOTE. Atmel AVR3009: Driving QTouch Device with I 2 C Interface. Atmel QTouch. Introduction

ATZB-SAMR21-XPRO. Preface. SmartConnect USER GUIDE

USER GUIDE. ZigBit USB Stick User Guide. Introduction

Section 5 SERCOM. Tasks SPI. In this section you will learn:

Atmel and the use of Verilator to create uc Device Models

Atmel AVR32847: Migration from/to the UC3L0 64/32/16 from/to the UC3L0 256/ bit Atmel Microcontrollers. Application Note.

64K (8K x 8) Battery-Voltage Parallel EEPROM with Page Write and Software Data Protection AT28BV64B

USER GUIDE. ATmega168 Xplained Mini User Guide. Introduction

AVR1303: Use and configuration of IR communication module. 8-bit Microcontrollers. Application Note. Features. 1 Introduction

APPLICATION NOTE. Atmel AT01080: XMEGA E Schematic Checklist. Atmel AVR XMEGA E. Features. Introduction

RELEASE NOTES. GNU Toolchain for Atmel ARM Embedded Processors. Introduction

USER GUIDE. Atmel PROTO1 Xplained Pro. Preface

AVR32752: Using the AVR32 UC3 Static Memory Controller. 32-bit Microcontrollers. Application Note. Features. 1 Introduction

Application Note Using the ATV750, ATV750B, and ATF750C Erasable Programmable Logic Device Introduction 1.1 Device Names and Pin/Node Assignments

Atmel QT600 Quick Start Guide Touch Solutions

Atmel AVR1926: XMEGA-B1 Xplained Getting Started Guide. 8-bit Atmel Microcontrollers. Application Note. Features. 1 Introduction

AT88RF04C. CryptoRF EEPROM Memory 13.56MHz, 4 Kilobits SUMMARY DATASHEET. Features

Atmel ATtiny1634 MCU Atmel ATA SBC LIN transceiver with integrated voltage regulator Touch. Three Atmel QTouch buttons One Atmel QTouch slider

AVR based 125kHz RFID Evaluation Kit (Re)Programming Guide ATA2270-EK1. Overview. Fuse Settings: ISP Programming

APPLICATION NOTE. Atmel AVR116: Wear Leveling on DataFlash. 32-bit Atmel Microcontrollers. Features. Description. Wear leveling

AT88SC3216CRF. CryptoRF EEPROM Memory 13.56MHz, 32 Kilobits SUMMARY DATASHEET. Features

APPLICATION NOTE. AT06863: SAM4L Peripheral Event Controller (PEVC) SAM4L Peripheral Event Controller (PEVC) ASF PROGRAMMERS MANUAL

APPLICATION NOTE. Atmel AT03782: Using Low Power Modes in SAM4N Microcontroller. Atmel 32-bit Microcontroller. Features.

OLED display Sensors readout. Light sensor Temperature sensor

AVR32401: AVR32 AP7 Linux Interfacing DataFlash. 8-bit Microcontrollers. Application Note. Features. 1 Introduction

AVR1922: Xplain Board Controller Firmware 8-bit Microcontrollers Application Note Features 1 Introduction

APPLICATION NOTE. Atmel AVR536: Migration from ATmega644 to ATmega644A. 8-bit Atmel Microcontrollers. Introduction

USER GUIDE. Wireless Production Test Reference Protocol Specification Document. Atmel MCU Wireless. Description

a clock signal and a bi-directional data signal (SCL, SDA)

SBAT90USB162 Atmel. SBAT90USB162 Development Board User s Manual

LBAT90USB162 Atmel. LBAT90USB162 Development Board User s Manual

SAM4L Asynchronous Timer (AST)

AVR097: Migration between ATmega128 and ATmega1281/ATmega bit Microcontrollers. Application Note. Features. 1 Introduction

AVR32917: picopower Board getting started. 32-bit Microcontrollers. Application Note. Preliminary. Features. 1 Introduction

APPLICATION NOTE. Atmel AVR2131: Lightweight Mesh Getting Started Guide. Atmel MCU Wireless. Features. Description

AVR1508: Xplain training - XMEGA DAC 8-bit Microcontrollers Application Note Features 1 Introduction

Atmel AVR ATxmega384C3 microcontroller OLED display with 128x32 pixels resolution Analog sensors. Ambient light sensor Temperature sensor

TN0132 Technical note

Transcription:

SMART ARM-based Microcontrollers AT09381: SAM D - Debugging Watchdog Timer Reset APPLICATION NOTE Introduction This application note shows how the early warning interrupt can be used to debug a WDT reset situation.

Table of Contents Introduction...1 1. Prerequisites...3 2. SAM D Watchdog Timer Reset Debugging... 4 2.1. The Early Warning Interrupt... 4 2.2. Reading Flash... 7 2.2.1. Intel Hex Files... 8 2.3. Precautions...8 2.4. Determining the Reset Cause... 8 3. Revision History...10 2

1. Prerequisites This application note requires: Atmel Studio 6.1 or newer A SAM D Xplained PRO Example code 3

2. SAM D Watchdog Timer Reset Debugging The Watchdog Timer (WDT) is used to reset the device to recover from error situations such as runaway or deadlocked code. This appnote does not show how to use or setup the WDT. This appnote shows how it is possible to determine what code was being executed before the WDT resets the device. This appnote is bundled with an Atmel Studio project that can be used as a reference to the appnote. This appnote should be applicable to any device with a WDT with the Early Warning Interrupt present. 2.1. The Early Warning Interrupt The WDT in the SAM D has got an Early Warning interrupt. This interrupt can be enabled to indicate an upcoming WDT watchdog time-out condition. This can be used to find out which address the WDT interrupt handler will jump back to when the interrupt handler is done executing. The address that the interrupt handler jumps back to is the address of the code that is being executed. It may be possible to see if the device is stuck in a loop or something else that keeps it from issuing a reset of the WDT timer. The link register value can be checked by placing a breakpoint inside the interrupt handler. When the program enters the handler, the link register can be read by Atmel Studio by checking the Processor View, see the figure below. Figure 2-1. Enabling Processor View 4

When checking the processor view (see the figure below) in Atmel Studio when inside the WDT_Handler() function in the project code, it can be seen that the value of the link register is 0xFFFFFFF9. According to ARM "Cortex -M0+ Devices Generic User Guide" under "Home > The Cortex-M0+ Processor > Exception model > Exception entry and return" this means that the return address of the handler will be found in the stack. Figure 2-2. Processor View In the processor view we can find the main stack pointer. This points to the top of the stack. It is possible to read out what is in the stack when in a debug session by going to Debug->Windows->Memory>"Memory 1" and checking what is at the address pointed to by the main stack pointer. But in order to debug a device that is not connected to a debugger it is necessary to copy the stack to flash. This can be done by copying the main stack address to a pointer and then copying the content of the top of the stack. The following WDT_Handler will do this: #define FLASH_ADDRESS 0x3FF80; uint32_t *spreg; uint32_t *pointer_to_page_in_flash = FLASH_ADDRESS; void WDT_Handler(void) { spreg = get_msp(); //copy 15 top values of stack to flash: for (int i = 0; i < 15; i++) { } *pointer_to_page_in_flash = *spreg; pointer_to_page_in_flash++; spreg++; //write page buffer to flash: NVMCTRL->CTRLA.reg = NVMCTRL_CTRLA_CMDEX_KEY NVMCTRL_CTRLA_CMD_WP; 5

} //Clear EW interrupt flag WDT->INTFLAG.bit.EW = 1; After this code has been executed, the FLASH will be updated at the page starting with address 0x3FF80. In the example project, this flash page is not used by the application code. For a different application or a smaller device the page that is written to should be chosen differently. It is necessary to check what is written in flash by going to the Memory view (in Atmel Studio) and see what is in flash after the interrupt handler has written to flash. This should be done before the WDT has time to reset the device. In order to do this place a break point in the interrupt handler at the end of the write to flash. When looking at the Memory view (see the figure below) we can see that some of the content does not look like addresses to flash and some of it looks like it would point to the interrupt vector table. The reason for this is that the stack is used for temporary storage and that some of the values are register values that are stored in RAM before the device enters the interrupt handler. These values will be popped back before leaving the interrupt handler. Note: Atmel Studio will by default cache what is in flash and RAM so that not all of flash will be read from the device and updated in the Memory view. To be certain that the values shown in Memory view are updated press "Alt + F7" and after the "Cache all flash memory except" write the memory range of flash that is being written to (in the project code this range is 0x3FF80, 0x3FFC0). The reason to not turn of all caching is that debugging will be very slow as the device will then have to transmit all of flash and RAM memory after each break point. Figure 2-3. Processor View 6

To find the return address it is necessary to know where to look in the stack. To start with we should setup a test where we know what to look for. To find this we can force the interrupt to be fired when we know where the code is executing. The easiest way to do this is to add a while(1) loop in the code that will not let us reset the WDT timer. Now that it is known where the code will execute when it is interrupted, it is possible to find the address for this execution. The easiest way to do so is to run the code in a debug session, break it and open the Disassembly view in Atmel Studio (Alt + 8). As can be seen from Figure 2-4 Disassembly in Debug Mode the while loop can be found on address 0x000008AE. Now we can match this with what is in the Memory view. In the Memory view we see that this value can be found in flash address 0x0003FFA0 this is 9 words (a word is 32-bits) below the top of the stack. If we run this code on a project where it is not known where the WDT_Handler returns this is where we can expect to find the return address. Figure 2-4. Disassembly in Debug Mode Note: The use of the breakpoint in the code can help find the correct line in disassembly. Note: How many words below the top of the stack the return address can be found may change with compiler options and the code size of the WDT_Handler() function. Always check this position on the project that is being debugged with the same compiler options and the same interrupt handler. 2.2. Reading Flash When a device has failed and it is not connected to a debugger it is necessary to read out the flash in order to find out what happened. To do this connect the device to a debugger and open Atmel Studio. Open the "Device Programing" view (CTRL+SHIFT+p). Select the tool that is used for debugging the device and select the correct device and press "Apply". Now go into the "Memories" menu and under the flash heeding select "Read". A prompt will open up where it is necessary to select a name of the hex file and the folder where to store it. Save the file. 7

2.2.1. Intel Hex Files The file can now be opened and inspected. The hex file follows the Intel hex standard: :llaaaattffffffffffffffffffffffffffffffffcc The colon starts the record ll is the length of the record aaaa is the last 16-bytes of the address tt is the record type 00 - data record 01 - end-of-file record 02 - extended segment address record 04 - extended linear address record 05 - start linear address record (MDK-ARM only) F is the data field. Can be any length but in this case 16-bytes cc is the one byte checksum of the record Note: The endianes is different for the data in this file than what is seen in Atmel Studios Memory viewer. 2.3. Precautions Some precautions must be taken with this debug method. Writing to flash takes some time and must be factored into how long before the WDT resets the device the early warning interrupt is set to fire. The maximum time of a page write to flash is 2.5ms. The OSCULP32 is designed for low power, not to be highly accurate. If this oscillator is used for the WDT this must be taken into account for the timing. If the WDT does a chip reset due to the CPU trying to access a register in a peripheral where the synchronous APB clock is turned off this will cause a bus stall. In this case the CPU will never enter the interrupt handler and flash will never be written to. If this is the case, check the Power Manager registers in a debug session and see if any of the synchronous clocks are turned off that should not be. In the Atmel Studio project the WDT_Handler writes 15 32-bit values into one flash page. If 16 values had been written the NVM write command can/must be omitted depending on the value of NVM- >CTRLB.bit.MANW. 2.4. Determining the Reset Cause If it is not certain that the device is being reset by the WDT there is a way to check what the reset cause is. In the device there is a Reset Cause (RCAUSE) register that contains the latest reset source. What peripheral the RCAUSE register is located in may differ from device to device, see the datasheet for the device for more information. This register shows the last reset cause and for that reason it is not possible to use a debug session in studio to show the last reset cause. This because Atmel Studio will reset the device before entering 8

debug mode. It is possible to write the reset cause to flash and then read out the hex file without causing a reset. The register value can be written to flash each time main is entered. Note that bits in flash that are not written contains a one. The register value should therefore be inverted to get as few one-to-zero transition as possible. If this is done then all the ways in which a device has been reset can be stored in one 8-bit value in flash. Note: Check the cache settings in Atmel Studio before reading values from flash in the Memory view. 9

3. Revision History Doc. Rev. Date Comments 42248B 04/2016 New template and some minor corrections 42248A 04/2015 Initial document release 10

Atmel Corporation 1600 Technology Drive, San Jose, CA 95110 USA T: (+1)(408) 441.0311 F: (+1)(408) 436.4200 www.atmel.com 2016 Atmel Corporation. / Rev.: 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 logo and others are the registered trademarks or 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.