How to develop smaller, faster, smarter code using IAR Embedded Workbench
Agenda
• Optimizations• Code quality• Advanced debugging and Trace
Optimizations
IoT design considerations
• Small• Cheap• Time to market• Performance and power efficiency
What options do we have?
Size vs Speed
• Room for more features• Use a cheaper device• Use a device with less
memory
• Better response time• Faster execution
• Saving power • Enhance battery time
Power
Structuring the application
To be efficient: • Isolate device-dependent code• Use tuned code where needed• Optimize the rest for size
Optimize speedOptimize size
Hardware
Device Driver Files
Generic Program
Files
Tuned Program
Files
1. Project2. File group3. File4. Function
#pragma optimize=speedvoid matrix_mul_matrix(MATDAT *A, MATDAT *B){...
}
Different levels of optimizations
Speed, size or both?
OptimizationCommon sub-expressions Speed ↑ Size →Loop unrolling Speed ↑ Size ↑Function inlining Speed ↑ Size ?Code motion Speed ↑ Size →Dead code elimination Speed → Size ↓Static clustering Speed ↑ Size ↓Instruction scheduling Speed ↑ Size →
Effect
Advanced debugging and Trace
Breakpoints
• Toggle breakpoints on any C or assembly line• Define complex breakpoint conditions.
– Run until the next time the condition is met. – Run until number of times the condition occurs.
Other breakpoints
• Data breakpointsHalt the target at access of a specific memory location/range set in memory window, optional with a certain pattern match (dependent on driver)
• Log breakpoints
• Trace start/stop breakpointsTriggered by ETM trace data
• Immediate breakpointsSimulator only, association with C-SPY macros
Debugging via SWD/SWO
ITM eventsInterrupt loggingData logging Power logging
Power debugging
Work fast, sleep a lot!• Optimizations• Efficient code
Detailed power logsPower breakpoints
Function-level power profiling
• Integrated measuring of power consumption correlated to the source code
• Tune the application to minimize power-consuming use of hardware resources
• Enabled by I-jet or other hardware with power debugging support
Additional debug features• Stack analysis
• Attach to running target– Connect to the target anytime without resetting the application
RTOS Awareness PluginGet instant information from your RTOS!
• Debugger awareness for integrated RTOSes and other software components, such as TCP/IP stacks
• Project templates and quick access to RTOS-specific help
• RTOS-specific syntax highlighting enabled for use by plugins
Integrated software solutions
Trace
• Follow the program flow
• Learn where the application has been and how you got there
• Go back in time and evaluate execution backwards
Why use trace?
Time
Bug occurs Break
Without trace
Without trace: Usually only a little information availableWith trace: Go back in time and evaluate the behavior
With trace Trace information~103.. ~106 instructions
Instruction Trace
Each executed instruction is recorded, usually by sending info to dedicated pins on the device• Requires special HW, a trace probe, to recieve the data• Large amounts of data and limited memory...
ETM (Embedded Trace Macrocell)
ETM
Instructiontrace
Trace port
Navigating trace data
Millions and millions
• ETM trace generates copious quantities of data– Hard to find the right section of code
• Navigation tools in the trace window are available– Combined with previously mentioned
techniques, helps you quickly isolate bugs
Trace filtering and navigation
Navigate forwards or backwards on…… loops… functions… interrupts… statement boundaries
Code coverage• Verify whether all parts have been executed• Using trace data• Possible to require that all code is really tested, i.e.
executed in a test session
Integrated profiling tools
Function profiling • Based on simulator,
sampled trace or full trace• Execution time per function• Select time interval
Stack analysis• Calculates maximum stack usage• Helps find the optimal stack size• Checks stack integrity at runtime to
detect overflow
Debugging multicore processors
• Visibility of all cores• Start and stop cores simultaneously or individually• Step one core while others are running or stopped• Multicore breakpoints, e.g.
• BP on 1 core stops execution on all cores• BP on core A with condition on core B
• Multicore Trace• Very challenging for Heterogeneous MCPs with e.g. different trace capabilities
• Cortex-A9 has PTM (Program Trace)• Cortex-M3 or Cortex-A5/A8 has ETM • Some have even data trace
IAR Embedded Workbench SMP Support
• One project and debugger instance for all cores• Cores can be stopped/run individually or together
IAR Embedded Workbench AMP Support
Master (Cortex-A) Slave (Cortex-M4)
Start/stop core0/core1 Start/stop all cores
Migrate to our tools
Reasons to migrate to IAR Embedded Workbench Best in class code optimization Access to first-class technical support Code analysis tools Safety certified build tools State-of-the-art debugger
Works with externally built ELF files Even better with IAR Systems built executables
Migrate to IAR build tools
• Linker supports AEABI compliant ELF object files
• Support for 17 GCC attributes• Syntax: __attribute__ ((attribute-list))
Take advantage of the IAR project converter
Project converter
• Included in IAR Embedded Workbench• Project converters for:
– TI Code Composer Studio for Arm + MSP430– Keil uVision5 for Arm– Renesas HEW and e2Studio for RX– ST Atollic
Optimization goals have varied over time but modern tools offer several options
Modern debugging tools offer tons of possibilities to evaluate the code
Full control of your appliciaton on a Multi-core platform is essential
Smart Trace capabilities will help you to quickly identify the million dollar bug
Improve yout products and development processes with IAR Systems
Summary
Thank you for your attention!
www.iar.com