Debug Interfaces: JTAG, SWD, and Serial Logging
What You'll Learn
- 1Configure JTAG and SWD connections
- 2Use breakpoints, watchpoints, and memory inspection
- 3Design a useful serial logging system
- 4Reproduce field faults with limited diagnostics
Debugging embedded targets requires a channel into silicon and a story about what happened before failure. JTAG provides a boundary scan chain with multiple wires, while SWD achieves debug with two pins for space constrained parts. Beyond live debugging, structured serial logging and memory dumps carry evidence out of the field where no probe is attached. Good teams plan debug access and log formats before hardware is frozen, because pads omitted at layout time cannot be recovered later.
JTAG, SWD, and Probe Setup
JTAG shifts data through a chain of test access ports using clock, data in, data out, and mode select lines, which also supports boundary scan for board tests. SWD replaces it with bidirectional data and clock, offering equivalent debug on two pins with lower routing cost.
Probe choice affects flash programming speed, trace capability, and voltage support. Shared pins, level shifters, and connector pinouts must be defined in the schematic so every board can be programmed and debugged without improvised adapters.
Breakpoints, Watchpoints, and Trace
Flash breakpoints are limited in number on most parts, so hardware watchpoints on addresses catch data corruption precisely when a variable changes unexpectedly. Memory inspection during a hard fault reveals register and stack state at the crash.
Instruction trace records executed addresses with a trace port or integrated buffer, giving an ordered view leading up to failure. When trace bandwidth is unavailable, a persistent last known good state ring in RAM approximates it.
Serial Logging and Field Evidence
Logging levels, module tags, and timestamps turn raw prints into a usable narrative. Rate limits and guarded formatting keep a logging call from disturbing the timing it is meant to observe, and buffered output avoids blocking in critical sections.
For field returns, enable a crash record with reset reason, fault registers, software version, and a small ring of recent events in retained memory. Parsing tools then reconstruct the sequence of events from a device that can never be attached to a probe.
Debug Access Options
| Interface | Pins | Best Use |
|---|---|---|
| JTAG | Four or five plus ground | Boundary scan and full trace |
| SWD | Two | Pin constrained production debug |
| Serial console | One or two | Runtime logging and commands |
| Memory dump | Any transport | Post mortem field analysis |
| Trace port | Several plus clock | Instruction level history |
Real-World Examples
- Watchpoint on corruption â A data watchpoint halts exactly when a control flag is overwritten by a stray pointer.
- Hard fault register capture â Stacked registers and fault status are copied to retained memory before a controlled reset.
- Tagged runtime log â Module tags and levels let a noisy feature be silenced without recompiling the whole image.
- Production flashing fixture â A bed of nails fixture programs and tests units over SWD in seconds per board.
đĄKeep Debug Pads on the Schematic
Common Mistakes
Logging inside tight timing loops
Fix: Formatting and transmit interrupts distort the timing being measured.
Leaving debug access disabled
Fix: Locked chips cannot be recovered after a bad flash; keep an authenticated recovery path.
Relying on printf alone
Fix: Prints without structure or timestamps rarely reconstruct a complex failure sequence.
Key Takeaways
- JTAG and SWD provide inspection, control, and programming access.
- Watchpoints and trace capture events that breakpoints miss.
- Structured, rate limited logging preserves timing while explaining behavior.
- Retained crash records carry evidence from the field.
Frequently Asked Questions
What is the difference between JTAG and SWD?
JTAG uses a shift register chain over multiple pins; SWD uses a two wire protocol with equivalent debug features.
Why do my breakpoints not work in flash?
Many parts support only a small number of hardware breakpoints on flash; use software breakpoints for extra locations.
How do I debug without a probe in the field?
Write crash records and event rings to retained memory and read them back through the product interface.
Interview Questions
Q1: How would you diagnose an intermittent reset?
Capture reset reason registers, supply monitoring, and a retained event log, then correlate with a scope on power and reset lines.
Q2: What makes embedded logs useful?
Timestamps, levels, module tags, bounded formatting cost, and consistent event identifiers that tools can parse.
Extended Learning: Beyond the Basics
Key Concepts Summary
This lesson covers fundamental concepts that serve as building blocks for more advanced topics. Master these basics before moving to intermediate and advanced material.
Prerequisite Knowledge
Before studying this topic in depth, ensure you understand:
- Basic definitions and terminology
- Core formulas and their derivations
- Common applications in real-world scenarios
- Typical pitfalls and misconceptions
Step-by-Step Walkthrough
Let us work through a complete example to solidify understanding:
Step 1: Identify the problem type. Determine which category this problem falls into and which approach is most appropriate.
Step 2: Apply the relevant formula. Substitute known values into the appropriate equation, paying attention to units and constraints.
Step 3: Simplify and solve. Work through the algebra step by step, checking each intermediate result.
Step 4: Verify the answer. Check that the solution satisfies the original conditions and makes logical sense.
Common Mistakes to Avoid
- Misidentifying the problem type â Always start by categorizing the problem
- Incorrect formula application â Verify the formula applies to your specific case
- Unit errors â Always check units are consistent throughout
- Sign errors â Pay careful attention to positive and negative values
- Rounding too early â Keep full precision until the final answer
- Forgetting constraints â Check that solutions satisfy all given conditions
Real-World Applications
Understanding this concept is essential for:
- Advanced problem solving in examinations
- Building intuition for more complex topics
- Developing analytical thinking skills
- Applying mathematical reasoning to practical situations
Practice Exercises
- Basic: Solve 5 problems of increasing difficulty using the core concept.
- Intermediate: Apply the concept to word problems with multiple steps.
- Advanced: Combine this concept with 2-3 other topics in a comprehensive problem.
- Challenge: Create your own problem that requires this concept plus additional knowledge.
Interview and Exam Tips
- Common question patterns: Identify which exam or interview formats test this topic
- Time management: Practice completing problems within time constraints
- Common traps: Know the typical mistakes examiners set as distractors
- Verification strategy: Develop a quick method to check your answer
Related Topics
- Previous Topic â Build on the foundation laid here
- Next Topic â See how this concept extends to more advanced material
- Practice Problems â Additional exercises with solutions
- Video Explanation â Visual walkthrough of key concepts
Quick Reference Card
| Concept | Formula/Rule | Key Insight | Common Use |
|---|---|---|---|
| Core Definition | See main text | Understand the intuition | Foundation for all applications |
| Key Formula | See main text | Memorize the derivation | Direct problem solving |
| Special Case | See main text | Recognize when it applies | Simplifies complex problems |
| Edge Case | See main text | Know the limitations | Avoids errors |
Further Reading
For students who want to go deeper:
- Standard textbooks on the subject
- Research papers applying this concept
- Online courses with video explanations
- Practice problem collections with detailed solutions