Microcontrollers, Basics Fundamentals of Digital Debugging 19 January 2012 Jonathan A. Titus
Digital Debugging Any discussion of debugging invariable mixes hardware and software. But do not let debug sessions degenerate into battles between hardware and software people.
Digital Debugging Prevent defects from the beginning Create a best-practices document and programming style Use Deming’s error-prevention steps Develop tests and perform unit tests as you go Write code that tests for limits and errors
Digital Debugging Use W Edwards Deming’s error-prevention “loop” Identify a defect Find the defect’s root cause Locate where the defect occurred Implement preventive practices Monitor the process to verify effectiveness
Digital Debugging Use a Pareto chart to classify and identify defects:
Digital Debugging References 1. "Automated Defect Prevention:Best Practices in Software Management," by Dorota Huizinga and Adam Kolawa, Wiley Interscience, 2007. ISBN: 978-0-470- 04212-0.
Digital Debugging References 2. "Test-Driven Development for Embedded C," James W. Grenning, The Pragmatic Programmers, 2011. ISBN: 978- 1-93435-662-3.
Digital Debugging Write code that tests for limits and errors...
Digital Debugging Avoid problems: Carefully define specifications for a project: What happens when someone types an incorrect value, say, $000 at an ATM machine? What happens when someone continues to key-in incorrect PINs? Can you handle a printer-out-of-paper condition? What happens when a communication comes through with an incorrect CRC value? How do you handle a divide-by-zero error?
Simple Hardware Debug Tools An LED and a pushbutton: simple debug friends: Basic on-off test or debug indicator Flash patterns Start-stop code Not a recommended debugging technique! Pushbutton connected to pin for P1.3.
Debugger or Emulator? Debug/programming pods: Direct connection with programming tools Program MCU flash memory Debugging capabilities (vary by MCU) Require 3 to 5 signals Provide a USB or serial connection to host PC JTAG signals, but not IEEE-1149 compliant Often built into dev-kit boards (USB)
Debug & Programming Pods
Debugging “Messages” Helpful to see your own debug information Avoid C printf statements -- high code price Microchip PICKits can operate as a UART IAR Embedded Workbench has text window Some dev-kit boards have virtual serial port for simple text communications with host PC. Jon’s debug “secret weapon”
A Debug Secret Weapon... An inexpensive receipt printer for <$100
A Debug Secret Weapon... Standard logic levels for serial input to printer Only one pin needed (plus ground) No drivers or debug module needed Small amount of code needed for UART Use bit bashing instead of UART, if necessary Immediate record of debug messages and data Good for field testing Inexpensive--many on ebay (serial, NOT USB!) Jon’s: Ithaca Series 80PLUS
What do Good Debug Tools Do? Trace execution of code Watch variables and registers Set breakpoints Step through and over code Quickly make changes to code via IDE and test again They have limits in real-time situations
Presentation of Debug Information
ARM Debugging... Wow!
ARM Reference "The Definitive Guide to the ARM Cortex-M3," by Joseph Yiu, Newnes, 2007. ISBN: 978-0-7506-8534-4.
Debugging Hardware Logic Analyzer Oscilloscope Protocol Analyzer Power-Analysis Hardware and Software
Logic Analyzers I
Logic Analyzers II
Logic Analyzers III
Logic Analyzers IV
Oscilloscopes I
Oscilloscopes II
Protocol Analyzers
Power Analysis I
Power Analysis II
Debug Challenges I Interrupts Direct-Memory Access
Debug Challenges II It’s not always YOUR fault! Check for revised docs, errata sheets, forum comments, app notes... MCU sleep mode did not behave as expected. PWM output did not behave as expected. Shared USB and serial pins! Not documented.
Hed Text Bullets If Needed
Hed Text Bullets If Needed