Slide 1: Advanced Debugging with MCUXpresso IDE v11.1
ADVANCED DEBUGGING WITH MCUXPRESSO IDE V11.1 AMF-SOL-T4020 MARCH 2020 PUBLIC
Slide 2: Overview and Pre-requisites
OVERVIEW AND PRE-REQUISITES 1 PUBLIC
Slide 3: Pre-requisites
Pre-requisites • Experience of programming in C • Watch the MCUXpresso tool suite overview video (<5 mins long) • Using MCUXpresso SDK selection from within MCUXpresso IDE (7 mins long): − See this video on nxp.com − Using the tutorial as a guideline, install the SDK for the board you are using 2 PU
Slide 4: The MCUXpresso Ecosystem
The MCUXpresso Ecosystem Core Technologies from NXP: • MCUXpresso IDE • MCUXpresso SDK • MCUXpresso Config Tools • MCUXpresso Secure Provisioning Tool Enabling Software Technologies: • Run time software libraries and middleware • Enable customers to focus on differentiation • From NXP and partners E
Slide 5: Evaluation to proof of concept on NXP Evaluation Boards
Evaluation to proof of concept on NXP Evaluation Boards ● Import/clone one of a large range of SDK examples ● Easy selection from with MCUXpresso IDE ● Modify pin/clock settings for your application ● Simple, push button updates into IDE project ● Or use MCUXpresso IDE New project wizard and Periphe
Slide 6: Transition to custom hardware and on to production
Transition to custom hardware and on to production ● Modify pin/clock settings for custom hardware ● Encrypt/sign application images ● Simply update then rebuild for custom board ● Setup provisioning and programming scripts ● Production ● Same visualization and control as on NXP evaluation board ● O
Slide 7: Lab Setup/Prerequisites (FRDM-K64, if available)
Lab Setup/Prerequisites (FRDM-K64, if available) • MCUXpresso IDE 11.1.x − https://www.nxp.com/mcuxpresso/ide • FRDM-K64 SDK V2.6.0 or later − http://mcuxpresso.nxp.com/ • FRDM-K64F Board with micro-USB Cable − https://www.nxp.com/freedom • FRDM-K64F Board with DAPlink/CMSIS- DAP Firmware − Bootload
Slide 8: Lab Setup/Prerequisites (LPCXpresso boards)
Lab Setup/Prerequisites (LPCXpresso boards) • Must be MCUXpresso SDK supported − LPC54xxx, LPC55xx, LPC51U68 • MCUXpresso IDE 11.1.1 − https://www.nxp.com/mcuxpresso/ide • SDK V2.7.x or later for board being used − http://mcuxpresso.nxp.com/ • Board with micro-USB Cable (e.g. …) − https://www.nxp.co
Slide 9: Advanced Debug Course Sections
Advanced Debug Course Sections Introduction/pre-requisites 1. Part 1: Basic debugging and code flashing − Creating/Cloning MCUXpresso SDK Projects in the IDE − Building, Basic Debugging − Startup, Connect, Disconnect, Attach − GUI Flash Tool 2. Part 2: Accessing data and peripherals − Global Variabl
Slide 10: Part 1: Building, Debugging and Direct Flashing
PART 1: BUILDING, DEBUGGING AND DIRECT FLASHING 9 PUBLIC
Slide 11: About this tutorial and the board you are using
About this tutorial and the board you are using • All steps in the tutorial are the same for whatever board is being used, but debug probes vary between boards − FRDM boards use micro USB to OpenSDA, as do some i.MX RT 4-digit boards − LPC54000 or LPC5500 series will have LPC-Link2 CMSIS-DAP probe −
Slide 12: MCUXpresso IDE
MCUXpresso IDE • Start the IDE with Shortcut • Select workspace • Open MCUXpresso IDE User Guide 11 PUBLIC
Slide 13: Create LED Blinky Project
Create LED Blinky Project • Prerequisite: − SDK_2.x_FRDM-K64F (or SDK for the board being used) installed in IDE • Use Quickstart Panel with “Import SDK example(s)…” − Select frdmk64f board image (or board being used) − Click “Next” − Select “demo_apps > led_blinky” − Click “Finish” 12 PUBLIC
Slide 14: Build and Debug (FRDM-K64F)
Build and Debug (FRDM-K64F) • Connect FRDM-K64F board (micro USB to OpenSDA)* − Windows may need to enumerate USB connection • Use IDE Quickstart Panel to: − Clean − Build − Debug • Debugger discovers probe − Use SHIFT to force probe re-discovery 13 PUBLIC
Slide 15: Debug Info dialog
Debug Info dialog • Image info provides a range of information on a built application • Must load image info after selecting project • Memory usage: overall memory use by region • Memory contents: detailed breakdown of all symbols by section • Call graph: shows functions called by each function, sta
Slide 16: Debugger Run Control
Debugger Run Control • Resume/Run • Suspend/Pause • Terminate/Stop • (Disconnect) • Step Into • Step Over • Step Out • Step through the code 15 PUBLIC
Slide 17: Debug Startup Breakpoint
Debug Startup Breakpoint • By default, target runs until main() • Double-Click on Debug *.launch File in Project − Opens Debug Configuration − Stop at ResetISR • Debug • Can now debug startup code 16 PUBLIC
Slide 18: Debug Toolbar in Debug View, Assembly Stepping
Debug Toolbar in Debug View, Assembly Stepping • Enable debug toolbar • Turn on instruction stepping • Perform stepping • Switch back to Source stepping 17 PUBLIC
Slide 19: Debug Quickstart Shortcuts
Debug Quickstart Shortcuts • Quick and fast way to − Debug (default) − Attach − Program − Erase • Setting is persistent between sessions 18 PUBLIC
Slide 20: Debug Quickstart Shortcuts: Attach
Debug Quickstart Shortcuts: Attach • Use ‘Attach’ to running target • Launch Configuration Icon has ‘A’ Decorator added: • Subsequent use of Debug (instead of Attach) will trigger a prompt to confirm reversion to Debug • Using Attach option will result in persistent Setting in Debug Configuration −
Slide 21: Disconnect
Disconnect • ‘Terminate’/Stop button disconnects from Target • Open Debug Configuration − Double Click on *.launch file in Project − nochange - will leave the target in its current state − stop - will leave the target in debug state i.e. halted − cont - the default, will either start the image from
Slide 22: GUI Flash Tool
GUI Flash Tool • Advanced Board flashing/programming − Program, verify, erase, check, resurrect, ... − Programming multiple boards • Select GUI Flash Tool Icon • Run Job • Messages written to Console View • Check Console View • Can also be used for Mass Erase 21 PUBLIC
Slide 23: Part 2: Accessing Data and Peripherals
PART 2: ACCESSING DATA AND PERIPHERALS 22 PUBLIC
Slide 24: About this section
About this section • Screen shots shown are from a session with FRDM-K64F • All operations also apply to any MCUXpresso SDK supported board 23 PUBLIC
Slide 25: Global Variables View Update
Global Variables View Update • Debug project • Global Variables View − Add global variables − can use Filter for easier search, press OK • Run target • Variable is automatically updated − Refresh rate defaults to every 1000ms 24 PUBLIC
Slide 26: Graphing variables
Graphing variables • Choose an example with data varying over time − Examples in this tutorial use the “bubble” application example with FRDM-K64F − Other options: emWin touch and draw example on boards with LCD panel (e.g. LPC546xx, i.MX RT1050) Any example reading on-board accelerometer or tem
Slide 27: Global variables: select symbols
Global variables: select symbols • In variables dialog, click on the eyeglasses logo to open symbol selection dialog − If you cant find the global variables dialog, type “global” in the Quick access box • Use filter to narrow down list of available globals (example from bubble application) 26 PUBLIC
Slide 28: Global variables: live value updates
Global variables: live value updates • Press green “play” symbol to start live polling of variables • With bubble application running, move the board around to see values change − Changed variables highlight yellow, variables begin plotting in Plot tab 27 PUBLIC
Slide 29: Global variables: Plotting controls
Global variables: Plotting controls Take/save snapshot (PNG format) Autoscale (zooms Measure values to full plot size) Step back / along vertical or fwd through horizontal axis Zoom in/out operations Zooms continuously while left mouse button depressed Select to pan Add/remove Left/right or Annotati
Slide 30: Global variables: Trace and statistics tabs
Global variables: Trace and statistics tabs Clicking the save icon with any of the tabs active will results in dialogs to save PNG file for plot .tsv files for Trace and Statistics 29 PUBLIC
Slide 31: Registers View
Registers View • Registers View for core registers • If view not already open: Menu Window > Show View > Other… > Debug > Registers • Pseudo Registers for Cycle Counters − cycleDelta: cycles since the last CPU stop • Measure time of code execution between two breakpoints 30 PUBLIC
Slide 32: Hard Fault – Faults view
Hard Fault – Faults view • Add code writing to read-only memory − Causes HardFault Exception • Debug and let it fault • vectpc pseudo register shows fault details 31 PUBLIC
Slide 33: Heap and Stack views
Heap and Stack views • Real-time polling of Heap usage • Visual indication (Red/Orange/Green) of usage vs limits • Heap limit set in Project properties • Stack cannot be read real time (as target would have to be stopped) 32 PUBLIC
Slide 34: Part 3: Code & Data Breakpoints
PART 3: CODE & DATA BREAKPOINTS 34 PUBLIC
Slide 35: About this section
About this section • Screen shots shown are from a session with FRDM-K64F • All operations also apply to any MCUXpresso SDK supported board 35 PUBLIC
Slide 36: Breakpoints and Breakpoints View
Breakpoints and Breakpoints View • Add Breakpoint to source view − Double-Click into ‘blue’ ribbon • Breakpoints are listed in Breakpoints view • Set/Enabled breakpoint have checkmark • Be aware of ‘Skip All Breakpoints’! 36 PUBLIC
Slide 37: Assembly Stepping and Breakpoints
Assembly Stepping and Breakpoints • Turn on Instruction Stepping • Add/Remove assembly instruction breakpoints 37 PUBLIC
Slide 38: Watchpoints
Watchpoints • Breakpoint on data read/write • Debug • Use Outline View • Toggle Watchpoint • Read/Write trigger condition • Apply and Close • Run Target stops on access • Use Breakpoint View to create/update/delete watchpoints 38 PUBLIC
Slide 39: Watchpoint Properties
Watchpoint Properties • Read/Write Access change: − Limitation of CDT: re-create watchpoint • Condition: only stops on access if condition is true • Ignore Count: counts down to zero until it stops • Actions & Filter • Note: stops target for condition evaluation! 39 PUBLIC
Slide 40: Watchpoints from Memory View
Watchpoints from Memory View • View Memory on Global Variable • In Memory View, select range • Add Watchpoint (C/C++) • Watchpoint on address range 40 PUBLIC
Slide 41: Stepping Return Value of Functions
Stepping Return Value of Functions • Problem int computeValue(int i) { − How to see the calculated return value return i*3; − Usually calculated/returned in registers } − No local variable to inspect int foo(int i) { if (computeValue(i)!=0) { • Solution return 1; − Step-Return Value in Variable view
Slide 42: Step-Return Value
Step-Return Value • Debug • Perform a Step-Return from Function which returns value 42 PUBLIC
Slide 43: Step-Return Value
Step-Return Value • After the Step-Return, return value is shown in Variables View 43 PUBLIC
Slide 44: Part 4: Instruction Trace
PART 4: INSTRUCTION TRACE 44 PUBLIC
Slide 45: About this section
About this section • Screen shots shown are from a session with FRDM-K64F (for ETM/ETB) and an LPC845 Breakout (BRK) board (for MTB) • Instruction trace availability shown on the next slide 45 PUBLIC
Slide 46: Instruction Trace – Supported Targets in MCUXpresso IDE
Instruction Trace – Supported Targets in MCUXpresso IDE • Cortex M3/M4/M7 MCUs − Target MCU must implement both an Embedded Trace Macrocell (ETM) AND an Embedded Trace Buffer (ETB). Microcontroller ✔Kinetis K, LPC18xx and LPC43xx parts Program • Cortex M0+ LPC/Kinetis MCUs execution info connector P
Slide 47: Instruction Trace
Instruction Trace • Collects details of instructions being executed • Allows complex program flow problems to be examined − Gives insight into what happening in system before a fault was encountered • <IDE Installation Path>\MCUXpresso_IDE_Instruction_Trace.pdf Code Code coverage coverage counters C
Slide 48: Instruction Trace
Instruction Trace • Debug Application − bubble demo application better than led_blinky • Instruction Trace View − If not visible, access by typing “Instruction trace in Quick Access box (top right) − Turn on ‘Record continuously’ Button • Run the Target and then Suspend/Pause • Download tracebuffer
Slide 49: Instruction Trace Triggers
Instruction Trace Triggers • Debug and Suspend • Show Instruction Trace Configuration • Refresh from target • Address of global variable − Expressions View − Add Expression − Address: &<variableName> − Copy-Paste address 49 PUBLIC
Slide 50: Instruction Trace Trigger Configuration
Instruction Trace Trigger Configuration • Trace enabled • Stall if only some free bytes in buffer • Data write on address and value written • Trigger on comparator 2 • Records some words before and after trigger • Save Configuration 50 PUBLIC
Slide 51: Part 5: FreeRTOS Task Aware Debug
PART 5: FREERTOS TASK AWARE DEBUG 51 PUBLIC
Slide 52: About this section
About this section • Screen shots shown are from a session with FRDM-K64F • All operations also apply to any MCUXpresso SDK supported board that includes FreeRTOS support 52 PUBLIC
Slide 53: FreeRTOS TAD
FreeRTOS TAD • Thread Aware Debugging − Show and switch between threads in Debug View − Views to inspect status of the RTOS • Views read RTOS data structures while target is halted • Debugger needs extra information: <IDE Installation Path>\MCUXpresso_IDE_FreeRTOS_Debug_Guide.pdf − SDK projects shou
Slide 54: Creating FreeRTOS Project
Creating FreeRTOS Project • Quickstart Panel • Import SDK example(s) • Select Board (FRDM-K64F) • rtos_example > freertos_generic • Finish to create project • Build project 54 PUBLIC
Slide 55: Debug Probe Connection
Debug Probe Connection • Configure to use All-Stop − Allows thread aware debug view − Otherwise only current thread is shown • Resume, then Pause 55 PUBLIC
Slide 56: Thread Aware Debug View
Thread Aware Debug View • Lists all FreeRTOS tasks with stacks − Switch debug context to thread − Context, registers, stack • Click on function (top) of a thread • Debug it (step out, step over) • Switch to another thread 56 PUBLIC
Slide 57: Task List
Task List • Lists FreeRTOS Tasks in the System • Menu FreeRTOS > Task List • Pause Button: do not update data when target is stopped • Save Button: Store information as .csv file 57 PUBLIC
Slide 58: Queue List
Queue List • Lists all FreeRTOS Queues • Menu FreeRTOS > Queue List • Pause Button: do not update data when target is stopped • Save Button: Store information as .csv file 58 PUBLIC
Slide 59: Queue Timer
Queue Timer • Lists all FreeRTOS Software Timer • Menu FreeRTOS > Timer List • Pause Button: do not update data when target is stopped • Save Button: Store information as .csv file 59 PUBLIC
Slide 60: Heap Usage
Heap Usage • Status of FreeRTOS Heap and Memory Allocation • Menu FreeRTOS > Queue List • Pause Button: do not update data when target is stopped • Save Button: Store information as .csv file 60 PUBLIC
Slide 61: Part 6: SWO Trace
PART 6: SWO TRACE 61 PUBLIC
Slide 62: Single Wire Output
Single Wire Output • SWO: Single Wire Output • ARM Cortex-M Hardware Feature (1 pin) • Requires that the SWO pin is routed to debug headers − Present on Tower (TWR) and LPCXpresso V2/V3 boards − Freedom (FRDM) boards do not have SWO pin available • Debug Features with SWO − SWO Console − SWO Interru
Slide 63: Enabling SWO use
Enabling SWO use • To use SWO, the SWO function must be enabled on the device, and clock set up to associated logic • MCUXpresso SDK examples usually do not have this by default, but setup via pin and clock configuration tools is typically quite simple 63 PUBLIC
Slide 64: SWO Trace Config
SWO Trace Config • Dedicated view to configure SWO • SWO Clock speed setting • (+) opens other views 64 PUBLIC
Slide 65: SWO Trace – Profile View
SWO Trace – Profile View • Displays statistical profile of application activity − Based on PC sampling, typically at ~50kHz − Non-intrusive – does not affect application • Benefits – Identify hotspots 65 PUBLIC
Slide 66: SWO Trace – Interrupt Views
SWO Trace – Interrupt Views 66 PUBLIC
Slide 67: SWO Trace – Interrupt Views
SWO Trace – Interrupt Views • Interrupts Stats − Continuous count (and other stats) of all interrupts • Benefits − Determine time spent in interrupt handlers − Optimization of interrupt handlers 67 PUBLIC
Slide 68: SWO Interrupt Stats
SWO Interrupt Stats • Capturing Interrupt Trace also populates an SWO Int Stats View • Switch to the SWO Int Stats View and compare the Stats with our measured values − Note that for linear functions the Min (time in) and Max (time in) will be the same this is not true for time spent in Main (whic
Slide 69: SWO Trace – DataWatch
SWO Trace – DataWatch • Dynamic memory accesses • Datawatch Trace • Read and write to target memory without stopping − Capture all accesses to memory location, CPU without stopping CPU • Non-intrusive • Benefits • Reads done on periodic basis (by default) − Monitor and analyse memory accesses • Unli
Slide 70: SWO Trace – ITM Printf
SWO Trace – ITM Printf • Instrumentation Trace Macrocell (ITM) block provides a mechanism for sending data from your target to the debugger via the SWO trace stream • MCUXpresso IDE allows user to redirect printf/scanf data by reimplementing low level Redlib function __sys_write / __sys_readc − Newl