SlideShare a Scribd company logo
1 of 30
Download to read offline
Advanced debugging on ARM Cortex
devices like STM32, Kinetis, LPC, etc.
Agenda
• Advanced debugging
• How to analyze a crashed system
• System analysis with SVW real-time event- and data tracing
• Recording execution history with ETM instruction tracing
• How to debug a dual-core system
• Debugging RTOS-based applications
• Alternative approach: Avoid introducing bugs
• Coding standards
• Code complexity management
• Peer reviews
How to analyze a crashed
ARM Cortex system
Understanding system crashes caused by ARM Cortex hard fault
exceptions, for example due to division by zero, pointer errors, illegal
addresses, illegal instructions or other problems.
Cortex-M hard fault categories
• Bus faults
• Access to invalid memory regions
• Byte access to “word only” registers
• Memory management faults
• Access that violate the MPU setup
• Execute code from non-executable memory regions
• Usage faults
• Undefined instructions
• Unaligned memory access
• Divide by zero
• Accidentally switch to ARM mode (if CPU is thumb only!)
• Hard faults
• Caused by bus, memory management and usage faults if their
respective handler is not enabled
1. Enable interrupt handlers
• Bus, memory management and usage
faults needs to be enabled.
• Otherwise they are escalated into a
hard fault.
• Enabled in the System Handler
Control and State Register
2. Fault reason display
Memory management fault status
register
Bus fault status register
Usage fault status register
For example, division by
zero is flagged in this bit
3. Analyzing hard fault location
• Halt in fault handler
• Find fault type in SFR-Viewer
• Locate stacked PC using SP +24
• Locate the code
SP+24
The Cortex-M hard fault analyzer
A tool automated solution
– The Atollic TrueSTUDIO debugger can show where and why the CPU crashed automatically
– No need to manually perform the steps described on previous pages
– MUCH more convenient than the manual approach
System analyzis and real/time
event and data tracing
Understand how Serial Wire Viewer (SWV/SWO/ITM) can be used to
analyze system behavior
Serial wire viewer real-time tracing
• Not always feasible to stop the CPU to examine the state of the
application (using breakpoints) due to timing issues (e.g. motor control).
• Tracing is about getting information out of the chip without halting the
CPU.
• Application and timing logic will be preserved but still possible to examine
what is happening.
• SWV provides low-cost but yet powerful event and data tracing in ARM
Cortex processors.
• SWV is part of the ARM CoreSight debugger architecture, and uses the 1-
pin SWO pin to transfer data from CPU to debugger. ITM also uses the
SWO pin for S/W trace.
Debugger capabilities enabled by
SWV/SWO/ITM
• Event trace (log and timeline graph)
• Exception trace (log and timeline graph)
• Data trace and memory access history (log and timeline graph)
• Interrupt statistics graph
• Statistical profiling graph
• Execution time measurement
• printf() output re-directed into debugger console
printf() redirection using ITM
• Re-direct printf() output to the IDE
• printf() redirection implemented with a simple
C macro using ITM interface on JTAG cable
• 32 available ITM ports (consoles/channels)
• Different software routines can print to
different ports. For example:
• Application prints to channel 0
• RTOS prints to channel 1
• TCP/IP stack prints to channel 2
• Benefits:
• No need for USB / RS232 or external display
• Up to 32 independent output channels
• ITM can also be used for other tasks, i.e.
generic software instrumented trace
printf() redirection using ITM
1. Redirect low level output stub used by
printf (syscalls.c in TrueSTUDIO) to ITM
channel 0 (CMSIS standardized macro)
4. The text printed to the ITM channel 0 is
intercepted by the debugger and printed
in the SWV Console View
2. Enable ITM port 0 in the SWV
configuration GUI
3. Generate some printf output
Measure exec time of code blocks
• Measure the execution time of code blocks by sending time-stamped
bytes over the ITM-channel
– Requires target instrumentation
– Implemented with simple C macro
– Sending 1 byte over ITM = 1 CPU cycle
– Time measured by comparing time stamps
in ITM trace log
• Benefits:
– Measure execution time of code
blocks not equal to one C-function
• Parts of a function
• Parts of a system
with many functions
Speed optimization with statistical
profiling
• Non-intrusive PC sampling during system
execution
• See how much execution time is spent in
each function
• Based on periodic sampling so not 100%
accurate, but becomes more and more
reliable as execution time increase.
• Benefits:
• Analyze where most execution time is
spent
• Prioritize optimization efforts
• Done without speed penalty (maintains
full real-time behavior since no
instrumentation).
Exception & Interrupt tracing
See how interrupts occur in real-time in
your application
• What exception source/peripheral?
• What interrupt handler?
• Time spent in interrupt?
• Any interrupt nesting?
• When do interrupts occur?
Understand interrupt handler performance
• How much execution time is
spent in each interrupt handler?
• Shortest/Average/Longest
runtime?
Real-time data monitoring
• Real-time watch of mem./vars. while target is running
at full speed
• See memory/variable value in real-time
• See the complete memory access history
• Double-click on a memory access -> open
code line that made specific memory access
• Real-time data graph
makes it easy to
understand variable
values
• Zoom in / out
• Take screenshots
• Toggle between cycles/time
• Broken patterns found easily
Record execution flow using
ETM/ETB instruction tracing
Inspect recorded data to understand what the CPU was doing before a bug
leads to a crash
(Not available in all Cortex devices)
ETM trace (record data)
• Instruction tracing collects an enormous amount of data (1s exec time on
Cortex-M4 is ~100MB binary packed, or 5-10GB human readable).
• Trace Triggers are used to start/stop tracing in order to reduce the massive
amount of data collected
• Event triggered start/stop (on PC or memory access)
• “Breakpoint” triggered start/stop
ETM trace (analyse data)
Show the recorded execution history on different abstraction
(“zoom”) levels:
• Function trace
• C trace
• Mixed C/Asm trace
• Asm trace
How to debug dual-core
processors
(using a Freescale Vybrid Cortex A5/M4
as an example)
Special dual-core considerations
• Symmetric dual-core
• Cores of identical type (for example two ARM Cortex A9’s)
• Often used for load balancing of tasks/threads using an O/S. In
such case debugger must have O/S specific dual-core features.
• More often used in “mobile devices” (smartphones/tablets)
• Asymmetric dual-core
• Cores of different type (for example one A5 + one M4)
• The cores run largely independently, even using different
(or no) O/S.
• More often used in “traditional embedded systems”
• “New problems”
• Debugging two cores from the same debugger GUI at the same time
• In Eclipse-based IDE’s:
• A mouse-click swaps between A5 or M4 context.
• Views can be “pinned” to stay visible in “wrong” context
• One JTAG-probe in daisy-chaining mode is sufficient to debug both
cores simultaneously
• Core synchronisation and communication – shared memory, serial
interfaces etc
How to debug a dual-core system
• In Eclipse-based IDE’s:
• A mouse-click in the call stack (Debug view) will swap CPU
context
• Debugger views from a CPU context can be pinned (stay in
visible in other CPU’s context) – e.g. to compare
SFR/memory data
• For Freescale Vybrid:
• First boot the A5 and
let it enable the M4
• Then boot the M4
• Once booth are
booted, they execute
independently but
share memory and
peripherals
Debug RTOS-based applications
Kernel aware debugging
• An RTOS have internal object states you need to study during
debugging
• Tasks, semaphores, mailboxes, timers, etc.
• You need to peek into the RTOS and see how kernel objects
changes when debugging the system
• Your debugger needs to have RTOS views for the kernel objects
in your RTOS
An alternative approach:
Avoid introducing bugs
in the first place
Reduce bugs by writing better code
Check code for MISRA-C compliance
Reduce the number of bugs by following a best-practice
coding standard developed by industry experts.
Measure and manage code complexity
Measure cyclomatic value of code complexity, and refactor (simplify)
complex functions.
Benefits:
• Complexity level –> Where to rewrite & refactor?
• Low complexity –> Low probability of errors
• Low complexity –> Low cost for maintenance
• Low complexity –> Easy to test
Reduce bugs with peer reviews
Source code reviews
Colleagues study each other’s code, trying to find problems and
suggest improvements.
Typically a 3-phase process:
• Individual review phase – study the code
• Team discussion phase – code review meeting
• Individual rework phase – fix problems assigned to me
Learn more on ARM Cortex
development and debugging!
ARM development and debugging white paper
More white papers on ARM cortex development
Learn more on ARM Cortex development tools
www.atollic.com
Click to read more:
More information:
www.atollic.com
EUROPE & WORLDWIDE
Atollic AB
Science Park
Gjuterigatan 7
SE-553 18 Jönköping
Sweden
+46 36 19 60 50
info@atollic.com
USA & AMERICAS
Atollic Inc
241 Boston Post Road West
1st Floor
Marlborough
Massachusetts 01752
+1 (973) 784-0047
sales.usa@atollic.com
2013.09.23.

More Related Content

What's hot

Pipelining of Processors
Pipelining of ProcessorsPipelining of Processors
Pipelining of ProcessorsGaditek
 
Basics of micro controllers for biginners
Basics of  micro controllers for biginnersBasics of  micro controllers for biginners
Basics of micro controllers for biginnersGerwin Makanyanga
 
Basic MIPS implementation
Basic MIPS implementationBasic MIPS implementation
Basic MIPS implementationkavitha2009
 
Instruction set and instruction execution cycle
Instruction set and instruction execution cycleInstruction set and instruction execution cycle
Instruction set and instruction execution cycleMkaur01
 
Pipelinig hazardous
Pipelinig hazardousPipelinig hazardous
Pipelinig hazardousjasscheema
 
The survey on real time operating systems (1)
The survey on real time operating systems (1)The survey on real time operating systems (1)
The survey on real time operating systems (1)manojkumarsmks
 
Instruction Execution Cycle
Instruction Execution CycleInstruction Execution Cycle
Instruction Execution Cycleutsav_shah
 
Pipelining , structural hazards
Pipelining , structural hazardsPipelining , structural hazards
Pipelining , structural hazardsMunaam Munawar
 
Rtos princples adn case study
Rtos princples adn case studyRtos princples adn case study
Rtos princples adn case studyvanamali_vanu
 
ARM Processor architecture
ARM Processor  architectureARM Processor  architecture
ARM Processor architecturerajkciitr
 
Processor structure and funtions
Processor structure and funtionsProcessor structure and funtions
Processor structure and funtionsMuhammad Ishaq
 

What's hot (20)

Pipelining of Processors
Pipelining of ProcessorsPipelining of Processors
Pipelining of Processors
 
Os introduction
Os introductionOs introduction
Os introduction
 
Os introduction
Os introductionOs introduction
Os introduction
 
Cpu & its execution of instruction
Cpu & its execution of instructionCpu & its execution of instruction
Cpu & its execution of instruction
 
Pipelining & All Hazards Solution
Pipelining  & All Hazards SolutionPipelining  & All Hazards Solution
Pipelining & All Hazards Solution
 
Basics of micro controllers for biginners
Basics of  micro controllers for biginnersBasics of  micro controllers for biginners
Basics of micro controllers for biginners
 
Basic MIPS implementation
Basic MIPS implementationBasic MIPS implementation
Basic MIPS implementation
 
Control unit
Control  unitControl  unit
Control unit
 
Instruction set and instruction execution cycle
Instruction set and instruction execution cycleInstruction set and instruction execution cycle
Instruction set and instruction execution cycle
 
Program execution
Program executionProgram execution
Program execution
 
Pipelinig hazardous
Pipelinig hazardousPipelinig hazardous
Pipelinig hazardous
 
Program control
Program controlProgram control
Program control
 
The survey on real time operating systems (1)
The survey on real time operating systems (1)The survey on real time operating systems (1)
The survey on real time operating systems (1)
 
Instruction Execution Cycle
Instruction Execution CycleInstruction Execution Cycle
Instruction Execution Cycle
 
Lec 2
Lec 2Lec 2
Lec 2
 
16 control unit
16 control unit16 control unit
16 control unit
 
Pipelining , structural hazards
Pipelining , structural hazardsPipelining , structural hazards
Pipelining , structural hazards
 
Rtos princples adn case study
Rtos princples adn case studyRtos princples adn case study
Rtos princples adn case study
 
ARM Processor architecture
ARM Processor  architectureARM Processor  architecture
ARM Processor architecture
 
Processor structure and funtions
Processor structure and funtionsProcessor structure and funtions
Processor structure and funtions
 

Similar to Advanced debugging on ARM Cortex devices such as STM32, Kinetis, LPC, etc.

Introduction to embedded System.pptx
Introduction to embedded System.pptxIntroduction to embedded System.pptx
Introduction to embedded System.pptxPratik Gohel
 
How to Measure RTOS Performance
How to Measure RTOS Performance How to Measure RTOS Performance
How to Measure RTOS Performance mentoresd
 
Mces MOD 1.pptx
Mces MOD 1.pptxMces MOD 1.pptx
Mces MOD 1.pptxRadhaC10
 
MK Sistem Operasi.pdf
MK Sistem Operasi.pdfMK Sistem Operasi.pdf
MK Sistem Operasi.pdfwisard1
 
Report in SAD
Report in SADReport in SAD
Report in SADjesseledm
 
Embedded systems 101 final
Embedded systems 101 finalEmbedded systems 101 final
Embedded systems 101 finalKhalid Elmeadawy
 
CSW2017Richard Johnson_harnessing intel processor trace on windows for vulner...
CSW2017Richard Johnson_harnessing intel processor trace on windows for vulner...CSW2017Richard Johnson_harnessing intel processor trace on windows for vulner...
CSW2017Richard Johnson_harnessing intel processor trace on windows for vulner...CanSecWest
 
Unit 1 processormemoryorganisation
Unit 1 processormemoryorganisationUnit 1 processormemoryorganisation
Unit 1 processormemoryorganisationKarunamoorthy B
 
Unit 2 processor&memory-organisation
Unit 2 processor&memory-organisationUnit 2 processor&memory-organisation
Unit 2 processor&memory-organisationPavithra S
 
Asia 14-garcia-illera-dude-wtf-in-my-can
Asia 14-garcia-illera-dude-wtf-in-my-canAsia 14-garcia-illera-dude-wtf-in-my-can
Asia 14-garcia-illera-dude-wtf-in-my-caninjenerzntu
 
Embedded systems introduction
Embedded systems introductionEmbedded systems introduction
Embedded systems introductionmohamed drahem
 
MODULE IV embedded (1).pptx
MODULE IV embedded (1).pptxMODULE IV embedded (1).pptx
MODULE IV embedded (1).pptxSajinvs4
 
Introduction to microcontrollers
Introduction to microcontrollersIntroduction to microcontrollers
Introduction to microcontrollersEdwardOmondi4
 
MODULE 1 MES.pptx
MODULE 1 MES.pptxMODULE 1 MES.pptx
MODULE 1 MES.pptxManvanthBC
 
ARM Introduction 1.ppthhhhhhhhhhhhhuuuuuuu
ARM Introduction 1.ppthhhhhhhhhhhhhuuuuuuuARM Introduction 1.ppthhhhhhhhhhhhhuuuuuuu
ARM Introduction 1.ppthhhhhhhhhhhhhuuuuuuuvenur239
 

Similar to Advanced debugging on ARM Cortex devices such as STM32, Kinetis, LPC, etc. (20)

Introduction to embedded System.pptx
Introduction to embedded System.pptxIntroduction to embedded System.pptx
Introduction to embedded System.pptx
 
How to Measure RTOS Performance
How to Measure RTOS Performance How to Measure RTOS Performance
How to Measure RTOS Performance
 
Mces MOD 1.pptx
Mces MOD 1.pptxMces MOD 1.pptx
Mces MOD 1.pptx
 
MK Sistem Operasi.pdf
MK Sistem Operasi.pdfMK Sistem Operasi.pdf
MK Sistem Operasi.pdf
 
PILOT Session for Embedded Systems
PILOT Session for Embedded Systems PILOT Session for Embedded Systems
PILOT Session for Embedded Systems
 
Cache profiling on ARM Linux
Cache profiling on ARM LinuxCache profiling on ARM Linux
Cache profiling on ARM Linux
 
Report in SAD
Report in SADReport in SAD
Report in SAD
 
Embedded systems 101 final
Embedded systems 101 finalEmbedded systems 101 final
Embedded systems 101 final
 
CSW2017Richard Johnson_harnessing intel processor trace on windows for vulner...
CSW2017Richard Johnson_harnessing intel processor trace on windows for vulner...CSW2017Richard Johnson_harnessing intel processor trace on windows for vulner...
CSW2017Richard Johnson_harnessing intel processor trace on windows for vulner...
 
12429908.ppt
12429908.ppt12429908.ppt
12429908.ppt
 
Unit 1 processormemoryorganisation
Unit 1 processormemoryorganisationUnit 1 processormemoryorganisation
Unit 1 processormemoryorganisation
 
Unit 2 processor&memory-organisation
Unit 2 processor&memory-organisationUnit 2 processor&memory-organisation
Unit 2 processor&memory-organisation
 
Asia 14-garcia-illera-dude-wtf-in-my-can
Asia 14-garcia-illera-dude-wtf-in-my-canAsia 14-garcia-illera-dude-wtf-in-my-can
Asia 14-garcia-illera-dude-wtf-in-my-can
 
Mod 3.pptx
Mod 3.pptxMod 3.pptx
Mod 3.pptx
 
Cs intro-ca
Cs intro-caCs intro-ca
Cs intro-ca
 
Embedded systems introduction
Embedded systems introductionEmbedded systems introduction
Embedded systems introduction
 
MODULE IV embedded (1).pptx
MODULE IV embedded (1).pptxMODULE IV embedded (1).pptx
MODULE IV embedded (1).pptx
 
Introduction to microcontrollers
Introduction to microcontrollersIntroduction to microcontrollers
Introduction to microcontrollers
 
MODULE 1 MES.pptx
MODULE 1 MES.pptxMODULE 1 MES.pptx
MODULE 1 MES.pptx
 
ARM Introduction 1.ppthhhhhhhhhhhhhuuuuuuu
ARM Introduction 1.ppthhhhhhhhhhhhhuuuuuuuARM Introduction 1.ppthhhhhhhhhhhhhuuuuuuu
ARM Introduction 1.ppthhhhhhhhhhhhhuuuuuuu
 

Recently uploaded

Building Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
Building Real-Time Data Pipelines: Stream & Batch Processing workshop SlideBuilding Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
Building Real-Time Data Pipelines: Stream & Batch Processing workshop SlideChristina Lin
 
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptx
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptxKnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptx
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptxTier1 app
 
XpertSolvers: Your Partner in Building Innovative Software Solutions
XpertSolvers: Your Partner in Building Innovative Software SolutionsXpertSolvers: Your Partner in Building Innovative Software Solutions
XpertSolvers: Your Partner in Building Innovative Software SolutionsMehedi Hasan Shohan
 
Cloud Management Software Platforms: OpenStack
Cloud Management Software Platforms: OpenStackCloud Management Software Platforms: OpenStack
Cloud Management Software Platforms: OpenStackVICTOR MAESTRE RAMIREZ
 
Advancing Engineering with AI through the Next Generation of Strategic Projec...
Advancing Engineering with AI through the Next Generation of Strategic Projec...Advancing Engineering with AI through the Next Generation of Strategic Projec...
Advancing Engineering with AI through the Next Generation of Strategic Projec...OnePlan Solutions
 
Call Girls in Naraina Delhi 💯Call Us 🔝8264348440🔝
Call Girls in Naraina Delhi 💯Call Us 🔝8264348440🔝Call Girls in Naraina Delhi 💯Call Us 🔝8264348440🔝
Call Girls in Naraina Delhi 💯Call Us 🔝8264348440🔝soniya singh
 
What is Binary Language? Computer Number Systems
What is Binary Language?  Computer Number SystemsWhat is Binary Language?  Computer Number Systems
What is Binary Language? Computer Number SystemsJheuzeDellosa
 
Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time ApplicationsUnveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time ApplicationsAlberto González Trastoy
 
Engage Usergroup 2024 - The Good The Bad_The Ugly
Engage Usergroup 2024 - The Good The Bad_The UglyEngage Usergroup 2024 - The Good The Bad_The Ugly
Engage Usergroup 2024 - The Good The Bad_The UglyFrank van der Linden
 
Hand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptxHand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptxbodapatigopi8531
 
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed DataAlluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed DataAlluxio, Inc.
 
5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdf5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdfWave PLM
 
cybersecurity notes for mca students for learning
cybersecurity notes for mca students for learningcybersecurity notes for mca students for learning
cybersecurity notes for mca students for learningVitsRangannavar
 
What is Fashion PLM and Why Do You Need It
What is Fashion PLM and Why Do You Need ItWhat is Fashion PLM and Why Do You Need It
What is Fashion PLM and Why Do You Need ItWave PLM
 
Unit 1.1 Excite Part 1, class 9, cbse...
Unit 1.1 Excite Part 1, class 9, cbse...Unit 1.1 Excite Part 1, class 9, cbse...
Unit 1.1 Excite Part 1, class 9, cbse...aditisharan08
 
Optimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTVOptimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTVshikhaohhpro
 
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...soniya singh
 
EY_Graph Database Powered Sustainability
EY_Graph Database Powered SustainabilityEY_Graph Database Powered Sustainability
EY_Graph Database Powered SustainabilityNeo4j
 
chapter--4-software-project-planning.ppt
chapter--4-software-project-planning.pptchapter--4-software-project-planning.ppt
chapter--4-software-project-planning.pptkotipi9215
 
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASEBATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASEOrtus Solutions, Corp
 

Recently uploaded (20)

Building Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
Building Real-Time Data Pipelines: Stream & Batch Processing workshop SlideBuilding Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
Building Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
 
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptx
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptxKnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptx
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptx
 
XpertSolvers: Your Partner in Building Innovative Software Solutions
XpertSolvers: Your Partner in Building Innovative Software SolutionsXpertSolvers: Your Partner in Building Innovative Software Solutions
XpertSolvers: Your Partner in Building Innovative Software Solutions
 
Cloud Management Software Platforms: OpenStack
Cloud Management Software Platforms: OpenStackCloud Management Software Platforms: OpenStack
Cloud Management Software Platforms: OpenStack
 
Advancing Engineering with AI through the Next Generation of Strategic Projec...
Advancing Engineering with AI through the Next Generation of Strategic Projec...Advancing Engineering with AI through the Next Generation of Strategic Projec...
Advancing Engineering with AI through the Next Generation of Strategic Projec...
 
Call Girls in Naraina Delhi 💯Call Us 🔝8264348440🔝
Call Girls in Naraina Delhi 💯Call Us 🔝8264348440🔝Call Girls in Naraina Delhi 💯Call Us 🔝8264348440🔝
Call Girls in Naraina Delhi 💯Call Us 🔝8264348440🔝
 
What is Binary Language? Computer Number Systems
What is Binary Language?  Computer Number SystemsWhat is Binary Language?  Computer Number Systems
What is Binary Language? Computer Number Systems
 
Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time ApplicationsUnveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
 
Engage Usergroup 2024 - The Good The Bad_The Ugly
Engage Usergroup 2024 - The Good The Bad_The UglyEngage Usergroup 2024 - The Good The Bad_The Ugly
Engage Usergroup 2024 - The Good The Bad_The Ugly
 
Hand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptxHand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptx
 
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed DataAlluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
 
5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdf5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdf
 
cybersecurity notes for mca students for learning
cybersecurity notes for mca students for learningcybersecurity notes for mca students for learning
cybersecurity notes for mca students for learning
 
What is Fashion PLM and Why Do You Need It
What is Fashion PLM and Why Do You Need ItWhat is Fashion PLM and Why Do You Need It
What is Fashion PLM and Why Do You Need It
 
Unit 1.1 Excite Part 1, class 9, cbse...
Unit 1.1 Excite Part 1, class 9, cbse...Unit 1.1 Excite Part 1, class 9, cbse...
Unit 1.1 Excite Part 1, class 9, cbse...
 
Optimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTVOptimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTV
 
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
 
EY_Graph Database Powered Sustainability
EY_Graph Database Powered SustainabilityEY_Graph Database Powered Sustainability
EY_Graph Database Powered Sustainability
 
chapter--4-software-project-planning.ppt
chapter--4-software-project-planning.pptchapter--4-software-project-planning.ppt
chapter--4-software-project-planning.ppt
 
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASEBATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
 

Advanced debugging on ARM Cortex devices such as STM32, Kinetis, LPC, etc.

  • 1. Advanced debugging on ARM Cortex devices like STM32, Kinetis, LPC, etc.
  • 2. Agenda • Advanced debugging • How to analyze a crashed system • System analysis with SVW real-time event- and data tracing • Recording execution history with ETM instruction tracing • How to debug a dual-core system • Debugging RTOS-based applications • Alternative approach: Avoid introducing bugs • Coding standards • Code complexity management • Peer reviews
  • 3. How to analyze a crashed ARM Cortex system Understanding system crashes caused by ARM Cortex hard fault exceptions, for example due to division by zero, pointer errors, illegal addresses, illegal instructions or other problems.
  • 4. Cortex-M hard fault categories • Bus faults • Access to invalid memory regions • Byte access to “word only” registers • Memory management faults • Access that violate the MPU setup • Execute code from non-executable memory regions • Usage faults • Undefined instructions • Unaligned memory access • Divide by zero • Accidentally switch to ARM mode (if CPU is thumb only!) • Hard faults • Caused by bus, memory management and usage faults if their respective handler is not enabled
  • 5. 1. Enable interrupt handlers • Bus, memory management and usage faults needs to be enabled. • Otherwise they are escalated into a hard fault. • Enabled in the System Handler Control and State Register
  • 6. 2. Fault reason display Memory management fault status register Bus fault status register Usage fault status register For example, division by zero is flagged in this bit
  • 7. 3. Analyzing hard fault location • Halt in fault handler • Find fault type in SFR-Viewer • Locate stacked PC using SP +24 • Locate the code SP+24
  • 8. The Cortex-M hard fault analyzer A tool automated solution – The Atollic TrueSTUDIO debugger can show where and why the CPU crashed automatically – No need to manually perform the steps described on previous pages – MUCH more convenient than the manual approach
  • 9. System analyzis and real/time event and data tracing Understand how Serial Wire Viewer (SWV/SWO/ITM) can be used to analyze system behavior
  • 10. Serial wire viewer real-time tracing • Not always feasible to stop the CPU to examine the state of the application (using breakpoints) due to timing issues (e.g. motor control). • Tracing is about getting information out of the chip without halting the CPU. • Application and timing logic will be preserved but still possible to examine what is happening. • SWV provides low-cost but yet powerful event and data tracing in ARM Cortex processors. • SWV is part of the ARM CoreSight debugger architecture, and uses the 1- pin SWO pin to transfer data from CPU to debugger. ITM also uses the SWO pin for S/W trace.
  • 11. Debugger capabilities enabled by SWV/SWO/ITM • Event trace (log and timeline graph) • Exception trace (log and timeline graph) • Data trace and memory access history (log and timeline graph) • Interrupt statistics graph • Statistical profiling graph • Execution time measurement • printf() output re-directed into debugger console
  • 12. printf() redirection using ITM • Re-direct printf() output to the IDE • printf() redirection implemented with a simple C macro using ITM interface on JTAG cable • 32 available ITM ports (consoles/channels) • Different software routines can print to different ports. For example: • Application prints to channel 0 • RTOS prints to channel 1 • TCP/IP stack prints to channel 2 • Benefits: • No need for USB / RS232 or external display • Up to 32 independent output channels • ITM can also be used for other tasks, i.e. generic software instrumented trace
  • 13. printf() redirection using ITM 1. Redirect low level output stub used by printf (syscalls.c in TrueSTUDIO) to ITM channel 0 (CMSIS standardized macro) 4. The text printed to the ITM channel 0 is intercepted by the debugger and printed in the SWV Console View 2. Enable ITM port 0 in the SWV configuration GUI 3. Generate some printf output
  • 14. Measure exec time of code blocks • Measure the execution time of code blocks by sending time-stamped bytes over the ITM-channel – Requires target instrumentation – Implemented with simple C macro – Sending 1 byte over ITM = 1 CPU cycle – Time measured by comparing time stamps in ITM trace log • Benefits: – Measure execution time of code blocks not equal to one C-function • Parts of a function • Parts of a system with many functions
  • 15. Speed optimization with statistical profiling • Non-intrusive PC sampling during system execution • See how much execution time is spent in each function • Based on periodic sampling so not 100% accurate, but becomes more and more reliable as execution time increase. • Benefits: • Analyze where most execution time is spent • Prioritize optimization efforts • Done without speed penalty (maintains full real-time behavior since no instrumentation).
  • 16. Exception & Interrupt tracing See how interrupts occur in real-time in your application • What exception source/peripheral? • What interrupt handler? • Time spent in interrupt? • Any interrupt nesting? • When do interrupts occur? Understand interrupt handler performance • How much execution time is spent in each interrupt handler? • Shortest/Average/Longest runtime?
  • 17. Real-time data monitoring • Real-time watch of mem./vars. while target is running at full speed • See memory/variable value in real-time • See the complete memory access history • Double-click on a memory access -> open code line that made specific memory access • Real-time data graph makes it easy to understand variable values • Zoom in / out • Take screenshots • Toggle between cycles/time • Broken patterns found easily
  • 18. Record execution flow using ETM/ETB instruction tracing Inspect recorded data to understand what the CPU was doing before a bug leads to a crash (Not available in all Cortex devices)
  • 19. ETM trace (record data) • Instruction tracing collects an enormous amount of data (1s exec time on Cortex-M4 is ~100MB binary packed, or 5-10GB human readable). • Trace Triggers are used to start/stop tracing in order to reduce the massive amount of data collected • Event triggered start/stop (on PC or memory access) • “Breakpoint” triggered start/stop
  • 20. ETM trace (analyse data) Show the recorded execution history on different abstraction (“zoom”) levels: • Function trace • C trace • Mixed C/Asm trace • Asm trace
  • 21. How to debug dual-core processors (using a Freescale Vybrid Cortex A5/M4 as an example)
  • 22. Special dual-core considerations • Symmetric dual-core • Cores of identical type (for example two ARM Cortex A9’s) • Often used for load balancing of tasks/threads using an O/S. In such case debugger must have O/S specific dual-core features. • More often used in “mobile devices” (smartphones/tablets) • Asymmetric dual-core • Cores of different type (for example one A5 + one M4) • The cores run largely independently, even using different (or no) O/S. • More often used in “traditional embedded systems” • “New problems” • Debugging two cores from the same debugger GUI at the same time • In Eclipse-based IDE’s: • A mouse-click swaps between A5 or M4 context. • Views can be “pinned” to stay visible in “wrong” context • One JTAG-probe in daisy-chaining mode is sufficient to debug both cores simultaneously • Core synchronisation and communication – shared memory, serial interfaces etc
  • 23. How to debug a dual-core system • In Eclipse-based IDE’s: • A mouse-click in the call stack (Debug view) will swap CPU context • Debugger views from a CPU context can be pinned (stay in visible in other CPU’s context) – e.g. to compare SFR/memory data • For Freescale Vybrid: • First boot the A5 and let it enable the M4 • Then boot the M4 • Once booth are booted, they execute independently but share memory and peripherals
  • 25. Kernel aware debugging • An RTOS have internal object states you need to study during debugging • Tasks, semaphores, mailboxes, timers, etc. • You need to peek into the RTOS and see how kernel objects changes when debugging the system • Your debugger needs to have RTOS views for the kernel objects in your RTOS
  • 26. An alternative approach: Avoid introducing bugs in the first place
  • 27. Reduce bugs by writing better code Check code for MISRA-C compliance Reduce the number of bugs by following a best-practice coding standard developed by industry experts. Measure and manage code complexity Measure cyclomatic value of code complexity, and refactor (simplify) complex functions. Benefits: • Complexity level –> Where to rewrite & refactor? • Low complexity –> Low probability of errors • Low complexity –> Low cost for maintenance • Low complexity –> Easy to test
  • 28. Reduce bugs with peer reviews Source code reviews Colleagues study each other’s code, trying to find problems and suggest improvements. Typically a 3-phase process: • Individual review phase – study the code • Team discussion phase – code review meeting • Individual rework phase – fix problems assigned to me
  • 29. Learn more on ARM Cortex development and debugging! ARM development and debugging white paper More white papers on ARM cortex development Learn more on ARM Cortex development tools www.atollic.com Click to read more:
  • 30. More information: www.atollic.com EUROPE & WORLDWIDE Atollic AB Science Park Gjuterigatan 7 SE-553 18 Jönköping Sweden +46 36 19 60 50 info@atollic.com USA & AMERICAS Atollic Inc 241 Boston Post Road West 1st Floor Marlborough Massachusetts 01752 +1 (973) 784-0047 sales.usa@atollic.com 2013.09.23.