MCUXpresso IDE Instruction Trace
MCUXpresso IDE Instruction Trace
Trace Guide
Rev. 11.5.0 — 11 January, 2022   User guide
NXP Semiconductors                                                                      MCUXpresso IDE Instruction Trace Guide
11 January, 2022
MCUXpresso IDE Instruction Trace Guide - All information provided in this document is subject to legal disclaimers © 2022 NXP Semiconductors. All rights reserved.
MCUXpresso IDE Instruction Trace Guide - All information provided in this document is subject to legal disclaimers © 2022 NXP Semiconductors. All rights reserved.
MCUXpresso IDE Instruction Trace Guide - All information provided in this document is subject to legal disclaimers © 2022 NXP Semiconductors. All rights reserved.
1. Trace Overview
                               There are two different kinds of tracing technologies available directly within MCUXpresso IDE.
                               • Instruction Trace - capturing an instruction stream within onboard RAM of the MCU. This
                                 data can then be retrieved, decoded, and displayed within the IDE.
                                 • Available with any supported debug probe.
                               • SWO Trace - capturing events occurring on a running MCU in real time
                                 • Available with any supported debug probe.
                               The Trace functionality available depends on the features supported by your target MCU and
                               the features supported by your debug probe.
                               The rest of this guide looks at Instruction Trace. For information regarding SWO Trace, see the
                               SWO Trace guide.
                                             Compatibility
                                             Introduced in MCUXpresso IDE version 10.2.0 : Instruction Trace functionality can
                                             now be used with all supported debug solutions. Previous versions of MCUXpresso
                                             IDE only supported instruction trace for LinkServer (including CMSIS-DAP) debug
                                             connections.
                               The MCUXpresso IDE exposes the powerful Embedded Trace Macrocell (ETM) on Cortex M3
                               and M4 to focus the generated trace stored in the ETB. Trace can be focused on specific areas
                               of code, or triggered by complex events, for example. On the Cortex M0+, the MTB provides
                               simple Instruction Trace using shared SRAM.
                               •   Getting Started [3] - Tutorials to help you learn how to use Instruction Trace
                               •   Concepts [7] - The technical background of instruction tracing
                               •   Reference [15] - Details of the interface and operation of Instruction Trace
                               •   Troubleshooting [23] - solutions to common challenges you may face
                               • ETB is supported on a range of Cortex-M3, M4 and M7 MCU parts from NXP including:
                                 • LPC18xx / LPC43xx
                                 • Many Kinetis K series parts, including MK64F
MCUXpresso IDE Instruction Trace Guide - All information provided in this document is subject to legal disclaimers © 2022 NXP Semiconductors. All rights reserved.
                               Note that Instruction Trace is not supported with LPC17xx MCUs (which do not implement an
                               ETB) or LPC13xx/LPC15xx MCUs (which do not implement ETM or ETB).
MCUXpresso IDE Instruction Trace Guide - All information provided in this document is subject to legal disclaimers © 2022 NXP Semiconductors. All rights reserved.
2. Getting Started
                               The following tutorials guide you through the process of using Instruction Trace.
                                             Note:
                                             This configuration is not required for Instruction Trace on Cortex-M3, Cortex-M4
                                             and Cortex-M33 MCU parts.
                               MCUXpresso IDE’s new project wizard will automatically include a file called mtb.c for parts that
                               support MTB trace. This file places an array called __mtb_buffer__ into memory at the required
                               alignment. The MTB will then be configured to use this space as its buffer, allowing it to record
                               execution trace without overwriting user code or data. The array __mtb_buffer__ should not be
                               used within your code, since the MTB will overwrite any data entered into it.
                               •   __MTB_DISABLE   - If this symbol is defined, then the buffer array for the MTB will not be created.
                               •   __MTB_BUFFER_SIZE- a symbol specifying the size of the buffer array for the MTB. This must be
                                   a power of 2 in size, and fit into the available RAM. The MTB buffer will also be aligned to its
                                   ‘size’ boundary and be placed at the start of a RAM bank (which should ensure minimal or
                                   zero padding due to alignment).
                               •   __MTB_RAM_BANK - allows MTB Buffer to be placed into a specific RAM bank. When this is not
                                   defined, the “default” (first if there are several) RAM bank is used.
                               If you have a project for an MTB supported part that does not already contain the mtb.c file, you
                               simply need to copy the mtb.c file from an existing project, or create a new project and copy the
                               file from there.
                                             Warning
                                             Enabling the MTB manually without properly configuring the target’s memory usage
                                             will result in unpredictable behavior. The MTB can overwrite user code or data, which
                                             is likely to result in a hard fault.
                                             Note:
                                             Instruction Trace depends on optional components in the target. These components
                                             may or may not be available on the LPC device you are working with. See the
                                             Instruction Trace Overview [1] for more information.
                               First, you will debug code on your target. You can import an example project or use one of your
                               own.
MCUXpresso IDE Instruction Trace Guide - All information provided in this document is subject to legal disclaimers © 2022 NXP Semiconductors. All rights reserved.
                               If you are using a Cortex-M0+ part with an MTB you must first configure the memory usage of
                               your code to avoid conflicts. See Configuring the Cortex-M0+ for Instruction Trace [3] to
                               learn how to do this.
Step 1: Start the target and show the Instruction Trace View
                               The trace buffer should now be configured as a circular buffer, and your target should be running
                               your code. Once the trace buffer is filled up, older trace data is overwritten by the newer trace
                               data. Configuring the trace buffer as a circular buffer ensures that the most recently executed
                               code is always stored in the buffer.
                               If the Record Trace Continuously button                                     was grayed out, or you encountered an error,
                               check out the troubleshooting guide [23].
                               There may be a short delay as the trace is downloaded from the target and decompressed.
                               Once the trace has been decompressed, it is displayed as a list of executed instructions in the
                               Instruction Trace View.
                               In this step we explore the captured trace by stepping through it in the instruction View and linking
                               the currently selected instruction to the source code that generated it, as well as seeing it in
                               context in the disassembly View.
                               As a row becomes selected, the source code corresponding to the instruction in that row should
                               be highlighted in the source code editor. The disassembly View should also update with the
                               current instruction selected. There can be a slight lag in the disassembly View as the instructions
                               are downloaded from the target and disassembled.
                               In this step we turn on the profile View. In the source code editor the instructions that were traced
                               will be highlighted. This highlighting can be useful for seeing code coverage. In the disassembly
                               View each instruction is labeled with the number of times each it was executed.
MCUXpresso IDE Instruction Trace Guide - All information provided in this document is subject to legal disclaimers © 2022 NXP Semiconductors. All rights reserved.
                               This tracing could be useful for figuring out why a variable is being set to a garbage value.
                               Suppose we have a variable that is mysteriously being set to 0xff when we expect it to always
                               be between 0x0 and 0xA for example.
                               Note – For Cortex-M0+ based systems, this functionality requires additional hardware to be
                               implemented alongside the MTB. Some parts such as the LPC8xx and LPC11U6x families do
                               not provide this.
                               To trace the instructions that resulted in the write of the unexpected value we are going to
                               have trace continuously enabled with the ETB acting as a circular buffer. Next we will set up a
                               trigger [11] to stop trace being written to the ETB after the value 0xff gets written to the variable
                               we are interested in. The trigger event requires two DWT comparators. One of the comparators
                               watches for any write to the address of the variable and the other watches for the value 0xff being
                               written to any address. The position of the trigger in the trace is set to capture a small amount of
                               data after the trigger and then to stop putting data into the ETB.
Step 1: Start the target and show the Instruction Trace Config View
                               1. Display the Disassembly View by clicking       Window -> Show View -> Disassembly
                               2. Enter the variable name into the location search box and hit enter.
                               3. Copy the address of the variable to clipboard.
                                           Note:
                                           We are assuming that the variable is a global variable.
                               In this step we configure trace to be generated unconditionally in the Instruction Trace Config
                               View.
                               To make sure that no packets get lost if the ETM becomes overwhelmed we enable stalling.
                               Setting the stall level to 14 bytes mean that the processor will stall when there are only 14 bytes
                               left in the formatting buffer. This setting ensures that we do not miss any data, however, it comes
                               at the cost of pausing the CPU when the ETM cannot keep up with it. See stalling [9] in the
                               Concepts section for more information.
MCUXpresso IDE Instruction Trace Guide - All information provided in this document is subject to legal disclaimers © 2022 NXP Semiconductors. All rights reserved.
                               In the first watchpoint comparator choose data write in the comparator drop-down box and
                               then enter the address of the variable that you obtained earlier. This event resource will be true
                               whenever there is a write to that address, regardless of the value written.
                               Select Data Value Write from the drop-down, note that data comparators are not implemented
                               in all watch point comparators. Enter the value we want to match, 0xff, in the text box. Next we
                               link the data comparator to the comparator we configured in step 5 by selecting 1 in both the
                               link 1 and link 2 fields. Select the Data size to word.
                               The event resource Comparator 2 will now be true when Comparator 1 is true and the word
                               0x000000ff is written.
                               In the Trigger condition section select the One Input tab. Set the resource to be Watchpoint
                               Comparator 2 and ensure that the Invert resource option is not checked. These setting ensure
                               that a trigger is asserted when the Watchpoint Comparator 2 is true — i.e. when 0xff is written
                               to our focal variable.
                               Slide the Trigger position slider over to the right, so that only 56 words are written to the buffer
                               after the trigger fires. This setting will provide some context for the trigger and allows up to 4040
                               words of trace to be stored from before the trigger, which will help us see how the target ended
                               up writing 0xff to our variable.
                               Now press the green check button          to apply the configuration to the ETM and ETB. Resume
                               the target after the configuration has been applied. Once the target resumes, the buffer will start
                               filling with instructions. Once the buffer is filled the newest instructions will overwrite the oldest.
                               When the value 0xff is written to the focal variable, the trigger counter will start to count down
                               on every word written to the buffer. Once the trigger counter reaches zero, no further trace will
                               be recorded, preserving earlier trace.
                               After some time view the captured trace by pausing the target and downloading the content of
                               the buffer:
MCUXpresso IDE Instruction Trace Guide - All information provided in this document is subject to legal disclaimers © 2022 NXP Semiconductors. All rights reserved.
3. Concepts
                  3.1 Micro Trace Buffer (MTB)
                               The CoreSight Micro Trace Buffer for the M0+ (MTB) provides simple execution trace capabilities
                               to the Cortex-M0+ processor. It is an optional component which may or may not be provided in
                               a particular MCU. See Supported Targets [1]
                               The MTB captures Instruction Trace by detecting non-sequentially executed instructions and
                               recording where the program counter (PC) originated and where it branched to. Given the code
                               image and this information about non-sequential instructions, the Instruction Trace component
                               of MCUXpresso IDE Trace is able to reconstruct the executed code.
                               The huge number of instructions executed per second on a target generate large volumes of
                               trace data. Since the MTB only has access to a relatively small amount of memory, it gets filled
                               very quickly. To obtain useful trace a developer can configure the MTB to only focus on a small
                               area of code, to act as a circular buffer or download the content of the buffer when it fills up.
                               Additionally, all three of these techniques may be combined.
The following sections contain detailed information about the MTB’s operation and use.
                                              Warning
                                              The MTB does not have its own dedicated memory. The memory map used by the
                                              target must be configured so that some RAM is reserved for the MTB. The MTB must
                                              then be configured to use that reserved space as described in the Configuring the
                                              Cortex-M0+ for Instruction Trace [3] in the Getting Started section.
                               The MTB can also be enabled and disabled by two external signals TSTART and                                               TSTOP.      On the
                               LPC8xx parts, these are driven by the “External trace buffer command” register:
Note that if TSTART and TSTOP are asserted at the same time TSTART takes priority.
MCUXpresso IDE Instruction Trace Guide - All information provided in this document is subject to legal disclaimers © 2022 NXP Semiconductors. All rights reserved.
                               code and the length of Instruction Trace that the MTB is able to capture before getting overwritten
                               or needing to be drained.
                               Since the MTB uses the same SRAM used by global variables, the heap and stack, care must be
                               taken to ensure that the target is configured so that the MTB’s memory and the memory used by
                               your code do not overlap. For more information see Configuring the Cortex-M0+ for Instruction
                               Trace [3] in the Getting Started Guide.
                               There is a significant performance cost associated with using auto-resume since the time taken
                               to pause the target, download the buffer content and resume it again is much greater than the
                               time the MTB takes to fill the buffer.
                               The data is not decompressed during the auto-resume cycles and so it is still necessary to press
                               Download trace buffer                in the Instruction Trace toolbar to view the captured trace.
                                              Tip:
                                              To suspend the target once auto-resume is set press the Cancel button in the
                                              downloading trace progress dialog box. If the downloading trace progress dialog
                                              box is not displayed long enough to click Cancel use the Stop auto-resume button
                                                  in the Instruction Trace View toolbar. This disables auto-resume so that the
                                              target will remain halted the next time the MTB suspends it.
                               The trace recorded by the MTB is compressed. The code image is required to decompress
                               the trace. This image must be identical to the image running on the target when the trace was
                               captured. It is possible to download and decompress a trace from a previous session if the same
                               code image is running on the target. However, if the trace buffer contains old trace data, and a
                               different code image is downloaded to the target, downloading the buffer may result in invalid
                               trace being displayed.
MCUXpresso IDE Instruction Trace Guide - All information provided in this document is subject to legal disclaimers © 2022 NXP Semiconductors. All rights reserved.
This section describes some of the key components and features of the ETM.
               3.2.1 Stalling
                               The ETM uses as relatively small FIFO buffer to store formatted packets, which are then copied
                               to the ETB. This FIFO buffer can overflow when the rate of packets being written into it exceed
                               the rate at which they can be copied out to the ETB.
                               If stalling is supported on the target the ETM can be set to stall the processor when an FIFO
                               overflow is imminent. The stall level sets the threshold number of free bytes in the FIFO at which
                               the processor should be stalled. The stall does not take effect instantly and so the level should
                               be set such that there is space for further packets to be added to the buffer after the stall level
                               is reached. Overflows can still occur even with stalling enabled.
                               The maximum value is the total number of bytes in the FIFO buffer. Setting the stall level to this
                               will stall the processor whenever anything is entered into the FIFO. For example if a stall level
                               of 14 bytes was chosen, the processor would be instructed to stall any time there were fewer
                               than 14 bytes left in the in the buffer. If the target had a 24 byte FIFO buffer, this level would
                               allow a 10 byte safety buffer for packets generated between the stall level being detected and
                               the processor actually stalling.
                               Stalling is enabled from the Instruction Trace Config View [20]. Check the Stall processor
                               box and select a stall level with the slider.
                               Events can be specified in the Instruction Trace Config View [20]. For details on how to
                               build these events see ETM event configuration [21] .
                               Different sets of event resources are implemented by different silicon vendors. The following
                               event resources are supported by MCUXpresso IDE Trace:
MCUXpresso IDE Instruction Trace Guide - All information provided in this document is subject to legal disclaimers © 2022 NXP Semiconductors. All rights reserved.
                               continues counting down. The reload value can be set in the ETM Instruction Trace Config
                               View.
                               When a start comparator becomes true, the start / stop block asserts its output to high and stays
                               high until a stop comparator becomes true. The start / stop block logic is reset to low when the
                               ETM is reset.
                               Note that checking both start and stop for the same comparator will be treated as just checking
                               start.
                               The ETB and ETM are optional components in the Cortex-M3, Cortex-M4 and Cortex-M33
                               targets. Their implementation is vendor specific. When they are implemented the vendors may
                               implement different subsets of the ETM’s and ETB’s features. Instruction Trace will automatically
                               detect which features are implemented for your target; however, note that not all of the features
                               listed in this guide may be available on your target.
                               The ETM compresses the sequence of executed instruction into packets. The ETB is an on
                               chip buffer that stores these packets. This tool downloads the stored packets from the ETB and
                               decompresses them back into a stream of instructions.
                               This feature is useful for finding out how your target reached a specific state. It allows you to
                               visualize the flow of instructions stored in the buffer for example.
                               There are multiple ways to use the ETB. The simplest is continuous recording, where the ETB
                               is treated as a circular buffer, overwriting the oldest information when it is full. There are also
                               more advanced options that allow the trace to be focused on code that is of interest to make the
MCUXpresso IDE Instruction Trace Guide - All information provided in this document is subject to legal disclaimers © 2022 NXP Semiconductors. All rights reserved.
                               most of the ETB’s memory. This focusing is achieved by stopping tracing after some trigger or
                               by excluding regions of code. These modes of operation are described in this document.
               3.3.1 Triggers
                               The trigger mechanism of using Instruction Trace works by constantly recording trace to the ETB
                               until some fixed period after a specified event. This method allows the program flow up to, around
                               or after some event to be investigated.
                               There are two components that need to be configured to use triggers. These are the trigger
                               condition and the trigger counter. The trigger condition is an event (a Boolean combination of
                               event resources). When the trigger condition event becomes true, the trigger counter counts
                               down every time a word is written to the ETB. When the trigger counter reaches zero no further
                               packets are written to the ETB.
                               To use the ETB in this way the Trace Enable event is set to be always on (hard wired). The ETB
                               is constantly being filled, overflowing and looping round, overwriting old data. The trigger counter
                               is set using the trigger position slider. The counter’s value is set to the words after trigger value.
                               You can think of the position of the slider as being the position of the trigger in the resulting trace
                               that will be captured by the ETB.
                               There are three main ways of using the trigger: trace after – when that the data from the trigger
                               onwards is the interesting information; trace about — the data either side of the trigger is of
                               interest; and trace before — data before the trigger is the key information.
Trace after
                               When the slider is at the far left, the words before trigger will be zero and the words after
                               trigger will be equal to the number of words which can be stored in the ETB. This corresponds
                               to the situation where the region of interest occurs after the trigger condition. Once the ETB
                               receives the trigger packet the trigger counter, which was equal to words after trigger will count
                               down with every subsequent word written to the ETB, until it reaches zero. The trigger packet will
                               be early in the trace and the instruction trace will include all instructions from when the trigger
                               event occurred, until the ETB buffer filled up.
                               Note that in order to facilitate decoding of the trace the ETM periodically emits synchronization
                               information. On some systems the frequency that these are generated can be set. Otherwise, by
                               default, they are generated every 0x400 cycles. It is therefore necessary to make sure that you
                               allow some trace data to be collected before your specific area of interest when using the trigger
                               mechanism so that this synchronization information is included.
Trace around
                               As the trigger position slider is moved to the right, the words after trigger value decreases. This
                               means that the data will stop getting written to the ETB sooner. Since the Trace Enable event
                               was set to true, there will be older packets, from before the trigger event, still stored in the ETB.
                               The resulting instruction trace will include some instruction from before the trigger and some from
                               after the trigger. Use the slider to balance the amount of trace before and after the trigger.
Trace before
                               With the trigger position slider towards the far right, the instruction trace will focus on the trace
                               before the trigger event. Note that only trace captured after the instruction trace has been
                               configured will be captured. For example pausing the target and setting a trigger condition for the
                               next instruction, with the trace position set to the far right would not be able to include instruction
                               trace from before the trace was configured, but rather it would stop after words after trigger
                               number of words was written to the ETB, leaving most of the ETB unused.
                               Note that setting the trigger position all the way to the right, such that words after trigger is zero
                               will disable the trigger mechanism.
MCUXpresso IDE Instruction Trace Guide - All information provided in this document is subject to legal disclaimers © 2022 NXP Semiconductors. All rights reserved.
               3.3.2 Timestamps
                               When the timestamps check-box is selected and implemented, a time stamp packet will be put
                               into the packet stream. The interval between packets may be configurable if the target allows it,
                               or may be generated at a fixed rate.
                               If supported, there is a Timestamp event. Timestamps are generated when the event fires.
                               A counter resource could be used to periodically enter timestamps into the trace stream for
                               example.
                                           Note:
                                           ARM recommends against using the always true condition as it is likely to insert a
                                           large number of packets into the trace stream and make the FIFO buffer overflow.
Note that a time of zero in the time stamp indicates that time stamping is not fully supported
                                           Note
                                           There may be a lag of several instructions between the trigger condition being met
                                           and the target being suspended
                               The ETM provides the option to output packets for all branch instructions — both indirect and
                               direct. Checking this option will output a branch packet for every branch encountered. These
                               branch packets enable the reconstruction of the program flow without requiring access to the
                               memory image of the code being executed.
                               This option is not usually required as the Instruction Trace tool is able to reconstruct the program
                               flow using just the indirect branches and the memory image of the executed code. This option
                               dramatically increases the number of packets that are output and can result in FIFO overflows,
                               resulting in data loss or reduced performance if stalling [9] is enabled. It can also make
                               synchronization harder (e.g. in triggered traces) as you can end up with fewer I-Sync packets
                               in the ETB.
                                           Warning:
                                           Instruction Trace and SWO Data Watch Trace cannot be used simultaneously as
                                           they both require use of the DWT unit.
MCUXpresso IDE Instruction Trace Guide - All information provided in this document is subject to legal disclaimers © 2022 NXP Semiconductors. All rights reserved.
                               the PC to match in the match value field. Use the Disassembly View to find the address of the
                               instruction that you are interested in. When the PC is equal to the entered match value, the
                               watchpoint comparator will be true; otherwise it is false.
                               Setting a mask enables a range of addresses to be matched by a single comparator. Set the
                               Mask size to be the number of low order bytes to be masked. The range generated by the mask
                               is displayed next to the Mask size box. The comparator event resource will be true whenever
                               the PC is within the range defined by the mask.
                                           Note:
                                           Instruction addresses must be half-word aligned
                                           Warning
                                           Instruction address comparators should not be applied to match a                                             NOP    or an        IT
                                           instruction, as the result is unpredictable.
                               Data access address Comparators are event resources that watch for reads or writes to specific
                               addresses in memory. As with the instruction comparator, the address is entered as the match
                               value. There are three different data access comparators:
                               • Data R/W — true when a value is read from or written to the matched address
                               • Data Read — only true if a value is read from the matched address.
                               • Data Write — only true if a value is written to the matched address.
                               Like instruction address comparators, data access address comparators can operate on a range
                               of addresses.
                                           Note:
                                           These comparators do not consider the value being written or read — they only
                                           consider the address that is being read from or written to.
                               • Data Value R/W — true when a value is read or written that is equal to the Match Value
                               • Data Value Read — only true if a value is read that is equal to the Match Value
                               • Data Value Write — only true if a value is written that is equal to the Match Value
                               The size of the value to be match must be configured as either a word, half word or byte in
                               the Data size drop-down. Only the lowest order bits up to the request size will be matched. For
                               example, if the Data size is set to byte, only the lowest order byte of the match value will be
                               used in the comparisons.
                               Typically, you might want to match only a specific value written to a specific variable. Data value
                               comparators provide this facility by linking to up to two data access address comparators:
MCUXpresso IDE Instruction Trace Guide - All information provided in this document is subject to legal disclaimers © 2022 NXP Semiconductors. All rights reserved.
                                           Tip:
                                           When there are only two DWT comparators the option to link the two comparators
                                           is given as a check-box.
                               To use this feature, choose Cycle Counter from the comparator drop-down and enter the match
                               value into the Match Value field.
MCUXpresso IDE Instruction Trace Guide - All information provided in this document is subject to legal disclaimers © 2022 NXP Semiconductors. All rights reserved.
4. Reference
                  4.1 Instruction Trace View
                               From the Instruction Trace View you can configure trace for your target, and download and
                               view the captured trace. Open the Instruction Trace View by clicking Window -> Show View
                               -> Instruction Trace.
                               For trace generated by the ETM, the color of the text in the instruction list provides information
                               about the traced instruction. Grayed-out text indicates that the instruction did not pass it condition.
                               A red background indicates a break in the trace due an ETM FIFO buffer overflow. Instructions
                               may be missing between red highlighted instruction and the proceeding entry in the trace View.
                               If the Stall option is available it can be used to help ensure this does not occur in subsequent
                               traces.
                               A break in the trace may occur due to trace becoming disabled and then renabled (for example
                               to exclude the tracing of a delay function). Breaks in the trace are indicated by a line drawn
                               across the row.
                               A green background highlights the trigger packet that is generated after the trigger condition is
                               met. Press the trigger button to jump to this instruction in the instruction list.
MCUXpresso IDE Instruction Trace Guide - All information provided in this document is subject to legal disclaimers © 2022 NXP Semiconductors. All rights reserved.
                               The Record trace continuously           button configures the trace buffer as a circular buffer. Once
                               the trace buffer is filled up, older trace data is overwritten by newer trace data.
                               This mode of operation ensures that when the target is paused, the buffer will contain the most
                               recently executed instructions.
                               Note: The target must be connected, with your code downloaded and execution suspended,
                               before you can configure trace.
                               Press the Show Instruction Trace config View button       to display the Instruction Trace config
                               View. This View will provide you with access to all of the trace buffer’s configuration settings.
                               The Instruction Trace config View’s contents depend on the features supported by your target.
                               See the following sections for more information on your target.
                               Note: The target must be connected, with your code downloaded and execution suspended,
                               before you can configure trace.
                               Press the Download trace buffer       button to download the content of the trace buffer from the
                               target. The data will be downloaded and decompressed. The list of executed instructions will be
                               entered into the Instruction View table.
Notes
                               The Link to source      toggle button enables the linking of the currently-selected instruction in
                               the Instruction Trace View to the corresponding line of source code in the source code viewer.
                               The line of source code that generated the selected instruction will be highlighted in the source
                               code viewer.
MCUXpresso IDE Instruction Trace Guide - All information provided in this document is subject to legal disclaimers © 2022 NXP Semiconductors. All rights reserved.
                                           Tip:
                                           You can use the the cursor keys within the Instruction Trace View to scroll through
                                           the executed instructions.
                               The Link to disassembly       toggle button enables the linking of the currently selected instruction
                               in the Instruction Trace View to the corresponding instruction in the disassembly viewer. The
                               selected instruction will be highlighted in the disassembly viewer.
                               Note: The target must be suspended to allow the disassembly View to display the code on the
                               target.
                                           Tip:
                                           You can use the the cursor keys within the Instruction Trace View to scroll through
                                           the executed instructions.
                               The Toggle profile        button enables and disables the display of profile information
                               corresponding to the currently downloaded instruction trace.
                               When the display of profile information is enabled, a column appears in the disassembly View
                               that shows the count of each executed instruction that was captured in the trace buffer.
                               Lines of source code whose instructions were recorded in the trace buffer are highlighted in the
                               source View.
                                           Tip:
                                           You can customize the display of the highlighting by editing the Profile info in
                                           source View item in the preferences panel under       General -> Editors -> Text
                                           Editors -> Annotations
                               The Save trace      button saves the content of the Instruction Trace View to a csv file. These
                               files can be large and may take a few seconds to save.
                               Trace downloaded from an ETB (the embedded trace buffer on the Cortex M3 and M4) may
                               contain a trigger packet. If the trace stream contain such a packet, the jump to trigger                                             button
                               will show it in the Instruction Trace View.
                               When using the MTB auto-resume feature [8], the user may not have time to press the suspend
                               button or the Cancel button in the download trace progress dialog box as the target is being
                               rapidly suspended and restarted. Pressing the Stop auto-resume button    will turn off the auto-
                               resume feature, so that the target will suspend the next time the MTB reaches its watermark
                               level without resuming.
MCUXpresso IDE Instruction Trace Guide - All information provided in this document is subject to legal disclaimers © 2022 NXP Semiconductors. All rights reserved.
                               You can choose the columns shown in the instruction list using the select columns action                                                                 .
                               The available columns are listed below.
Rearrange the column ordering in the table by dragging the header of the columns.
  Column                                   Description
  Inst No                                  The index of the instruction in the trace
  Time                                     The timestamp associated with an instruction
  PC                                       The address of the instruction
  Disassembly                              The disassembled instruction
  C                                        The condition code for the instruction. E for instructions that passed their condition and
                                           were executed, N for instructions which were not executed.
  opCode                                   The op code for the instruction.
  Arguments                                The arguments for the op code
  Offset                                   Offset of the instruction within the function
  Function                                 The C function name which the instruction belongs to
  Filename                                 The C source file that the instruction is associated with
  Line no                                  The line number in the C source file that the instruction is associated with
Changes made to the MTB configuration are only applied when the Apply button is pressed.
MCUXpresso IDE Instruction Trace Guide - All information provided in this document is subject to legal disclaimers © 2022 NXP Semiconductors. All rights reserved.
Figure 4.2. Instruction Trace Config View for MTB Instruction Trace
               4.2.2 Enabling
                               The three check-boxes in the top section of the View control whether the MTB is enabled or not.
                               The first check-box Enable MTB can be used to directly enable or disable the MTB. The second
                               two check-boxes control whether or not the MTB is affected by start and stop signals TSTART
                               and TSTOP which can be triggered by software using the target’s external trace buffer command
                               register EXTTRACECMD.
               4.2.3 Buffer
                               The buffer section of the MTB configuration View displays information about where in memory
                               the MTB data is stored. It displays the size of the buffer and provides instructions on how to
                               change or remove the buffer.
                               See MTB memory configuration [7] for more information and Configuring the Cortex-M0+ for
                               Instruction Trace [3] for an example.
               4.2.4 Watermark
                               The watermark section of the MTB advanced configuration View allows you to configure an action
                               to be performed when the buffer fills to a certain level. The slider configures the watermark level
                               at which the action is triggered. The address next to the slider indicates the absolute address
                               of the watermark.
MCUXpresso IDE Instruction Trace Guide - All information provided in this document is subject to legal disclaimers © 2022 NXP Semiconductors. All rights reserved.
                               Selecting Halt target on match suspends the target when the buffer fills to the specified
                               watermark level. When the target is halted the content of the buffer is automatically drained and
                               stored. The buffer is reset so that it can be refilled once the target is resumed. The trace is not
                               decompressed or displayed in the Instruction Trace View until the Download buffer button is
                               pressed. This behavior allows multiple trace runs to be concatenated.
                               Selecting Auto resume allows the target to be automatically restarted once the buffer has been
                               downloaded. It only has an effect if Halt target on match is also selected. This auto-resume
                               feature allow the trace capture not to be limited to the size of the MTB’s buffer allowing code
                               coverage to measured. The frequent interruptions have a large impact on target performance.
                                           Note
                                           You can suspend an auto-resuming target by pressing the cancel button in the
                                           buffer download progress dialog box. If the MTB buffer is sufficiently small, then
                                           the progress dialog box may not be displayed long enough for the user to select
                                           cancel. In that case you should press the Stop auto-resume button       . Both of
                                           these methods will turn off the auto-resume feature and the target will suspend
                                           without restarting the next time the watermark matches.
                               Selecting stop trace collection on match allows the MTB to stop recording trace once it has
                               been filled once, without interrupting the execution of the target. This feature could be useful
                               when used in conjunction with a DWT comparator that starts trace on a certain condition.
                               The state of the target is read each time the refresh button    in the Instruction Trace Config
                               View. For example the, the Enable MTB box will show whether or not the MTB is currently
                               enabled. This information can be useful for confirming that TSTART and TSTOP signals are affecting
                               the MTB as expected when using the target’s external trace buffer command register EXTTRACECMD.
                               Pressing the Apply button        will update the MTB’s configuration — even if no settings are
                               changed by the user. This action will have the effect of clearing the content of the MTB’s buffer.
                               That is, if the MTB contains trace that has not been downloaded and then the user applies the
                               configuration, the content of the buffer will be lost.
                               Changes made to the MTB configuration are only applied when the Apply button                                                is pressed.
                               A star appended to a section title indicates that it contains unapplied changes.
                                           Note:
                                           For Cortex-M33 targets the Trace Config View is not yet availabe. Only continous
                                           recording can be used.
MCUXpresso IDE Instruction Trace Guide - All information provided in this document is subject to legal disclaimers © 2022 NXP Semiconductors. All rights reserved.
                               • The simplest option is a binary enabled/disabled choice. This is accessed by selecting the
                                 Simple tab. Select enable for the Event to always be true or disable for the event to always
                                 be false. See Figure 4.4.
                               • To use a single event resource select the One Input tab. An event resource can be chosen
                                 from the drop-down and the event will be true when the event resource is true. Checking the
                                 Invert resource box will cause the Event to be true when the event resource is false, and
                                 visa-versa. See Figure 4.5.
                               • To combine two event resources select the Two Inputs tab. The events can be chosen from
                                 the drop-downs and the logical combination operation selected. As with the One Input tab the
                                 resources can be inverted. See Figure 4.6.
The configuration on the visible tab is used when the Apply button is clicked.
MCUXpresso IDE Instruction Trace Guide - All information provided in this document is subject to legal disclaimers © 2022 NXP Semiconductors. All rights reserved.
MCUXpresso IDE Instruction Trace Guide - All information provided in this document is subject to legal disclaimers © 2022 NXP Semiconductors. All rights reserved.
5. Troubleshooting
                               This section of the help provides solutions to common problems that you may encounter while
                               using Instruction Trace.
5.1 General
You can also double check that your target is in Supported Targets [1]
5.2 MTB
5.4 ETB
               5.4.1 Trigger Packet Missing from Trace Even Though Trigger Occurred
                               It may be that the trigger packet was lost due to FIFO overflow and was not written to the ETB.
                               To make sure that it actually was triggered, look at the trigger counter (the number of words to
                               write after the trigger condition). The trigger counter only decrements after the trigger has been
                               activated. If it has not decremented, check your trigger condition.
                               If the trigger counter has decremented and you see no packet, try enabling stalling if it is
                               implemented.
                               There are a limited number of these hardware debug comparators implemented on a part, for
                               example the DWT unit of a Corex-M3 would typically have four. A specific comparator can
                               only be used by one component at a time. To use a comparator for a particular component,
                               either watchpoint, data watch or Instruction Trace, it must be requested from the IDE. If all
                               of the comparators are currently in use the request will be denied. Comparators need to be
                               explicitly released by the component that has successfully requested it to be available to another
                               component. Different comparators may be used by different components at the same time.
MCUXpresso IDE Instruction Trace Guide - All information provided in this document is subject to legal disclaimers © 2022 NXP Semiconductors. All rights reserved.
                               Comparators for watchpoints are requested automatically when the debugger resumes execution
                               of the target. If there are insufficient comparators available the error message in the figure
                               Figure 5.1 below will be shown.
The comparators for watchpoints are released when the target suspend execution
                               A comparator is requested when a check is marked next to an item in the SWO Data Watch
                               View. The tool selects the first free comparator to use. If no comparators are available you will
                               be alerted with the error message in figure Figure 5.2.
                               When an item is unchecked in the SWO Data Watch View its comparator is released and will
                               become available to other components.
See SWO Trace View for more information about using SWO Data Watch Trace.
MCUXpresso IDE Instruction Trace Guide - All information provided in this document is subject to legal disclaimers © 2022 NXP Semiconductors. All rights reserved.
                               To use a comparator select the Request button corresponding to the comparator to use in the
                               Watchpoint comparators section (see figure Figure 5.3). If that specific comparator is already
                               in use you will see an error message (see figure Figure 5.4). Once it has been successfully
                               requested it can be configured and the Request button is replaced with a Release button.
                               Press the Release button to stop using the comparator for Instruction Trace and allow other
                               components to use it.
MCUXpresso IDE Instruction Trace Guide - All information provided in this document is subject to legal disclaimers © 2022 NXP Semiconductors. All rights reserved.
Error message shown when the user tries to request a comparators that is already in use.
MCUXpresso IDE Instruction Trace Guide - All information provided in this document is subject to legal disclaimers © 2022 NXP Semiconductors. All rights reserved.
6. Legal information
                               Information in this document is provided solely to enable system and software implementers to
                               use NXP products. There are no express or implied copyright licenses granted hereunder to
                               design or fabricate any integrated circuits or integrated circuits based on the information in this
                               document.
                               NXP makes no warranty, representation, or guarantee regarding the suitability of its products for
                               any particular purpose, nor does NXP assume any liability arising out of the application or use of
                               any product or circuit, and specifically disclaims any and all liability, including without limitation
                               consequential or incidental damages. “Typical” parameters that may be provided in NXP data
                               sheets and/or specifications can and do vary in different applications, and actual performance
                               may vary over time. All operating parameters, including “Typicals”, must be validated for
                               each customer application by customer’s technical experts. NXP does not convey any license
                               under its patent rights nor the rights of others. NXP sells products pursuant to standard terms
                               and conditions of sale, which can be found at the following address: https://www.nxp.com/
                               SalesTermsandCondition.
                               While NXP has implemented advanced security features, all products may be subject to
                               unidentified vulnerabilities. Customers are responsible for the design and operation of their
                               applications and products to reduce the effect of these vulnerabilities on customer’s applications
                               and products, and NXP accepts no liability for any vulnerability that is discovered. Customers
                               should implement appropriate design and operating safeguards to minimize the risks associated
                               with their applications and products.
                               NXP, the NXP logo, Freescale, the Freescale logo, Kinetis and Tower are trademarks of NXP
                               B.V.
                               Arm, Cortex, Thumb, TrustZone, Mbed, Keil, CoreSight are registered trademarks of Arm Limited
                               (or its subsidiaries) in the US and/or elsewhere. Microsoft, Azure ThreadX are trademarks of the
                               Microsoft group of companies. FreeRTOS™ and FreeRTOS.org™ are trade marks of Amazon
                               Web Services, Inc. SEGGER Embedded Studio is a trademark of SEGGER Microcontroller
                               GmbH. J-Link is a trademark of SEGGER MICROCONTROLLER GMBH & CO. KG IAR
                               trademark is owned by IAR Systems AB. Java and all Java-based trademarks are trademarks
                               of Oracle Corporation in the United States, other countries, or both. Linux is the registered
                               trademark of Linus Torvalds in the U.S. and other countries. UNIX is a registered trademark
                               of The Open Group in the United States and other countries. Eclipse, CDT are trademarks of
                               Eclipse Foundation, Inc.
MCUXpresso IDE Instruction Trace Guide - All information provided in this document is subject to legal disclaimers © 2022 NXP Semiconductors. All rights reserved.