Using the CoreSight ITM for debug and testing in RTX applications



Similar documents
STMicroelectronics: Cortex -M4 Training STM32F429 Discovery evaluation board using ARM Keil MDK toolkit

AN LPC1700 timer triggered memory to GPIO data transfer. Document information. LPC1700, GPIO, DMA, Timer0, Sleep Mode

ARM-Architektur. Toni Reber Redacom AG, 2560 Nidau.

Migrating Application Code from ARM Cortex-M4 to Cortex-M7 Processors

ARM Ltd 110 Fulbourn Road, Cambridge, CB1 9NJ, UK.

EE8205: Embedded Computer System Electrical and Computer Engineering, Ryerson University. Multitasking ARM-Applications with uvision and RTX

Atmel Lab: Cortex -M4 Training featuring Serial Wire Viewer SAM4S-EK evaluation board using ARM Keil MDK Toolkit

STMicroelectronics: Cortex -M4 Training STM32F407 Discovery evaluation board using ARM Keil MDK Toolkit

Infineon XMC4000: Cortex -M4 Lab

1) The Keil Blinky example: 6

UM1680 User manual. Getting started with STM32F429 Discovery software development tools. Introduction

Embedded Software development Process and Tools:

Overview of the Cortex-M3

Software based Finite State Machine (FSM) with general purpose processors

Embedded Component Based Programming with DAVE 3

EE8205: Embedded Computer System Electrical and Computer Engineering, Ryerson University. Introduction to Keil uvision and ARM Cortex M3

Lab Experiment 1: The LPC 2148 Education Board

What is LOG Storm and what is it useful for?

Debugging Network Communications. 1 Check the Network Cabling

Digitale Signalverarbeitung mit FPGA (DSF) Soft Core Prozessor NIOS II Stand Mai Jens Onno Krah

TN0072 Technical note

Keil Debugger Tutorial

IEC Algorithmic Alert Tone Demo

Bootloader with AES Encryption

Freescale Semiconductor, I

Hello and welcome to this presentation of the STM32L4 Firewall. It covers the main features of this system IP used to secure sensitive code and data.

Programmazione Microcontrollori

Embedded Development Tools

DRV8312-C2-KIT How to Run Guide

How To Port A Program To Dynamic C (C) (C-Based) (Program) (For A Non Portable Program) (Un Portable) (Permanent) (Non Portable) C-Based (Programs) (Powerpoint)

Silabs Ember Development Tools

AN AES encryption and decryption software on LPC microcontrollers. Document information

Software development and debugging for NXP ARM7 MCUs

This tutorial material is part of a series to be published progressively by Doulos.

CSC 2405: Computer Systems II

National CR16C Family On-Chip Emulation. Contents. Technical Notes V

Complete Integrated Development Platform Copyright Atmel Corporation

Serial Communications

An Introduction to MPLAB Integrated Development Environment

Development With ARM DS-5. Mervyn Liu FAE Aug. 2015

Last Class: OS and Computer Architecture. Last Class: OS and Computer Architecture

LPCXpresso v7 User Guide

CodeWarrior Development Studio for Microcontrollers Version 10.x Profiling and Analysis Tools Users Guide

EMBEDDED C USING CODEWARRIOR Getting Started Manual

Project Manager Editor & Debugger

Keil C51 Cross Compiler

APPLICATION NOTE. AT07175: SAM-BA Bootloader for SAM D21. Atmel SAM D21. Introduction. Features

Control III Programming in C (small PLC)

USER GUIDE EDBG. Description

DsPIC HOW-TO GUIDE Creating & Debugging a Project in MPLAB

Developing an Application on Core8051s IP-Based Embedded Processor System Using Firmware Catalog Drivers. User s Guide

An Introduction To Simple Scheduling (Primarily targeted at Arduino Platform)

Debugging A MotoHawk Application using the Application Monitor

Next-Generation Switch/Router Diagnostics and Debugging

Technical Note. Micron NAND Flash Controller via Xilinx Spartan -3 FPGA. Overview. TN-29-06: NAND Flash Controller on Spartan-3 Overview

SKP16C62P Tutorial 1 Software Development Process using HEW. Renesas Technology America Inc.

AVR Butterfly Training. Atmel Norway, AVR Applications Group

Getting Started. Create Applications with MDK Version 5 for ARM Cortex -M Microcontrollers

Using the NicheStack TCP/IP Stack - Nios II Edition Tutorial

DS-5 ARM. Using the Debugger. Version 5.7. Copyright 2010, 2011 ARM. All rights reserved. ARM DUI 0446G (ID092311)

Better Trace for Better Software

DS-5 ARM. Using the Debugger. Version Copyright ARM. All rights reserved. ARM DUI0446P

Using DAVE with MDK Version 5

C Programming. for Embedded Microcontrollers. Warwick A. Smith. Postbus 11. Elektor International Media BV. 6114ZG Susteren The Netherlands

LiteOS Application Note AN-103: LiteOS Event Logging. Last updated: Jan

RTOS Debugger for ecos

11.1. Performance Monitoring

The BSN Hardware and Software Platform: Enabling Easy Development of Body Sensor Network Applications

An Introduction to the ARM 7 Architecture

Notes and terms of conditions. Vendor shall note the following terms and conditions/ information before they submit their quote.

AN10866 LPC1700 secondary USB bootloader

Linux Driver Devices. Why, When, Which, How?

Troubleshooting the Firewall Services Module

Enhanced Project Management for Embedded C/C++ Programming using Software Components

AN4664 Application note

Debug and Trace for Multicore SoCs How to build an efficient and effective debug and trace system for complex, multicore SoCs

Procedure: You can find the problem sheet on Drive D: of the lab PCs. Part 1: Router & Switch

UNIVERSITY OF CALIFORNIA. Los Angeles. Software for A Fault Tolerant. Microcontroller Network. A thesis submitted in partial satisfaction

ZyXEL AES-100 V2.03(AS.0) Release Notes/Manual Supplement

Interrupts and the Timer Overflow Interrupts Huang Sections What Happens When You Reset the HCS12?

Going Linux on Massive Multicore

Interrupts. 1.Maskable interrupt request can be ignored or delayed by the microprocessor and used in telephone

Comparing RTOS to Infinite Loop Designs

TDP43ME NetPS. Network Printer Server. Control Center. for Ethernet Module

SYSTEM ecos Embedded Configurable Operating System

Getting Started with Embedded System Development using MicroBlaze processor & Spartan-3A FPGAs. MicroBlaze

STLinux Software development environment

The new 32-bit MSP432 MCU platform from Texas

Hardware and Software Requirements

Programing the Microprocessor in C Microprocessor System Design and Interfacing ECE 362

KITES TECHNOLOGY COURSE MODULE (C, C++, DS)

Open Flow Controller and Switch Datasheet

ADVANCED PROCESSOR ARCHITECTURES AND MEMORY ORGANISATION Lesson-17: Memory organisation, and types of memory

Peach Fuzzer Platform

Recon Montreal

LPC2300/LPC2400 TCP/IP Overview. TCP/IP and LPC2300/LPC2400 Family October 2007

Definitions and Documents

Quick Start Guide. MRB-KW01 Development Platform Radio Utility Application Demo MODULAR REFERENCE BOARD

An introduction to nxpusblib. March 2012

Transcription:

Using the CoreSight ITM for debug and testing in RTX applications Outline This document outlines a basic scheme for detecting runtime errors during development of an RTX application and an approach to functional testing using the CoreSight Instrumentation trace. CoreSight Debug Architecture The cortex-m family of processors has a debug architecture called CoreSight. This is an on chip debug system similar to JTAG but it incorporates more advanced real time debug features. As well as being able to perform the same run control and memory read\write features as JTAG the cortex-m3 and M4 processors have up to three additional trace units. Two of these units are fitted as standard, the data watch and instrumentation trace. The third unit,the embedded trace macro cell is an optional unit which may be included when the silicon manufacturer designs the microcontroller. The data watch unit allows a low cost debug tool to view the internal SRAM and peripheral registers non intrusively while the code is running. This gives you visibility of all your key variables without having to halt the application code. The embedded trace macro cell provides instruction trace so it is possible to have a C or assembler level trace of the application code activity. The more advanced trace tools are capable of streaming 100% of the instructions executed directly to the PC hard drive so it is possible to have accurate code coverage and performance information. The CoreSight debug architecture for Cortex M3 and Cortex M4 The instrumentation trace (ITM) is slightly different from the other two trace units in that it is intrusive on the CPU ie it does use a few CPU cycles. The ITM is best thought of as a debug UART which is connected to a console window in the debugger. To use it you need to instrument your code by adding simple send and receive hooks. These hooks are part of the CMSIS standard and are automatically defined in the standard microcontroller header file. The hooks consist of three functions and one variable. static INLINE uint32_t ITM_SendChar (uint32_t ch); volatile int ITM_RxBuffer = ITM_RXBUFFER_EMPTY; static INLINE int ITM_CheckChar (void); static INLINE int ITM_ReceiveChar (void); //Send a character to the ITM //Receive buffer for the ITM //Check to see if a character has been sent //from the debugger //Read a character from the ITM

The ITM is actually a bit more complicated in that it has 32 separate channels. These are designed for future use by third party tools. We are using the public channel which is designated for debugger use. Using the instrumentation trace with RTX RTOS A typical RTX application will consist of a number of threads which communicate via various RTX methods such as main queues and event flags. As the applications complexity grows it can be hard to debug and test. For example to test one region of code it may be necessary to send several serial command packets to make one task enter a desired state to run the code that needs testing. Also if run time errors occur we may not pick up on them until the code crashes and by then it may be to late to get meaningful debug information. Thread 2 Mail queue 2 Mail queue 1 Thread 3 Event Trigger Thread 1 Simple RTOS application with Error and Test threads Thread 4 Error Thread Test Thread Error Task In an application we can introduce two additional threads an error thread and a test thread. The error thread consists of a switch statement which is triggered by the setting of its event flags. Each RTX task has sixteen error flags. Any other task can set these flags to trigger the task into activity. In the case of the error task we can use the error flags to send an error code ie a sixteen bit number. task void errorhandler (void){ uint32_t errorcode; while(1){ os_evt_wait_or(0xffff,forever); errorcode = os_evt_get(); switch(errorcode){ //wait here until error condition occurs //read error code //switch to run error code code case (THREAD2_MAILQUEUE_FULL)

ITM_SendChar('['); //send an error code to the debugger enclosed in [ ] ITM_SendChar('0'); ITM_SendChar(']'); }}} break; Basically the task waits until any of its event flags are set. It then reads the state of the error flags to get the error code. A switch statement then uses the error code to execute some recovery code, log the error to a file. During development we can also write a message to the debugger via the ITM. So in the main application code we can add statements to trap run time errors Error = os_mbx_check (MsgBoxSensor); if(error!=0){ //check the mailbox is not full //if a slot is free send the message mptr mptr->command mptr->length =_alloc_box (mpoolsensor); = rptr->template.payload[0]; = rptr->template.payloadlength; for(index=1;index< rptr->template.payloadlength;index++) mptr->payload[index-1] = rptr->template.payload[index]; os_mbx_send (MsgBoxSensor, mptr,forever); }else{ //else send an error code to the error thread os_evt_set(thread2_mailqueue_full,t_errorhandler); } In this case we check for a free message slot before sending a message. If the mail queue is full then the error task is signalled by setting a group of error flags which can be read as an error code. During debug critical runtime errors can be trapped with this method. Once the code is mature the error task becomes a central location recovery code and fault logging. Test Task One of the strengths in using an RTOS is that each of the threads is encapsulated with well defined inputs and outputs. This allows us to test the behaviour of individual threads without having to make changes to the application code ie commenting out functions, creating test harness etc. Instead we can create a test Thread. This runs at a low priority so it does not intrude on the overall performance of the application code. Like the error thread the test thread is a big switch statement but rather than waiting to be triggered by event flags in the application it is waiting for an input from the Instrumentation trace. task void testtask (void){ unsigned int command; while(forever){ while (ITM_CheckChar()!= 1) NOP(); //wait for a character to be sent from the debugger

command = ITM_ReceiveChar(); switch(command){ case ( 1 ) : //Read the ITM character //switch to the test code //inject a message into the thread2 mail queue test_func_send_thread2_message(cmd_start_motor,0x07,0x01,0x07,0,0,0,0); //send a message to thread2 break; case ( 2 ) : //halt thread1 default: os_tsk_delete(t_thread1); break; }}} In this case the test thread is waiting for a character to arrive from the debugger. The switch statement will then execute the desired test code. So for example we could halt a section of the application by deleting the task, another debug command could restart it. Then we can inject messages into the RTX mail queues or set event flags to trigger the behaviour of the different tasks. This technique is simple and quick to implement and helps to debug application code as it becomes more complex. It is also a basis for the functional testing of mature application code. Because we are using the ITM we only need t access the debug header and minimal resources are used on the microcontroller. All of the instrumented code is held in one module so it can be easily removed from the project once testing is finished. Example project An example project is avaliale for download alongside this application note. It is designed to run on the Keil MCB1768 evaluation board with a Ulink2. If you program the project into the LPC1768 flash, start the debugger and let the code run you should see the LEDs on the board flash in a symmetrical pattern.

The application code is located in main_app.c, take a few minutes to look through this to familiarise yourself with this simple application. The CMSIS core layer which includes the ITM functions is brought into the project with the microcontroller include file #include <lpc1768xx.h> The files error.c and test_functions.c provide the error handling and test functions respectively. For clarity these functions use printf to send test messages to the ITM. In a real application more light weight messaging could be used to minimise the function size and number of CPU cycles used. The file serial.c contains the low level functions used by printf. By default these use a standard UART but output can be redirected to the ITM with the #define DBG_ITM. This is located in the local options for serial.c To access the ITM from within the debugger select the view\serial windows\debug Printf Viewer This opens a console style window which allows you to send data to the test task via the ITM and view messages sent from the error task. You can also view the state of the RTX tasks by opening the Debug\OS Support\RTX Tasks and system. The event viewer also provides a task trace which is very useful for seeing the loading on the CPU and the interaction between the different tasks

To use the ITM test task make sure the debug (printf) viewer is the active window. Then the various test functions can be triggered by typing the characters 0 9 on the PC keyboard. The test task provides the following functions 1 Halt Task1 2 6 - Inject a message into the Task2 mail queue to switch the LED s 7 Inject a message with faulty parameters 8 Start Task1 9 - Stop Task2 0 Start Task2 Here if you stop Task2 it will no longer read messages from the mail queue. If Task1 is running it will continue to write into the mail queue. This will cause the queue to overflow and this will be reported by the error task. Without this kind or error trapping it is likely that you would end up on the hard fault exception vector and have no idea what had gone wrong with the program. Once the project has been fully developed the test_functions.c module can be removed and the error task can be modified to take remedial action if an error occurs. This could be logging fault codes to flash, running code to try and recover the error or worst case resetting the processor. If you have any questions or comments please contact : Trevor martin tmartin@hitex.co.uk