This example shows how to use the Simulink® Support Package for Arduino® Hardware to profile the real-time execution of generated code running as an executable on ARM® architecture-based Arduino hardware boards with XCP communication interface in External mode.
Sample times specified in the Simulink models determine the time schedule for running generated code on target hardware. With enough computing power on the hardware, the code runs in real-time according to the specified sample times. With real-time execution profiling, you can check if the generated code meets your real-time performance requirements. This support package supports the code execution profiling on the following ARM architecture-based Arduino hardware boards:
Arduino MKR Wifi 1010
Arduino MKR 1000
Arduino MKR Zero
Arduino Nano 33 BLE Sense
Arduino Nano 33 IoT
Arduino Robot Control Board
Arduino Robot Motor Board
At the end of the Simulink model code profile execution, you can:
View a report of code execution times.
Access and analyze execution time profiling data.
This example uses:
Simulink Support Package for Arduino Hardware
This task shows you how to configure an Arduino Simulink model to profile its code execution.
1. Open any Arduino Simulink model. In this example, we are using the
arduino_gettingstarted Simulink model. For more information on the
arduino_gettingstarted Simulink model, see Getting Started with Arduino Hardware example.
2. On the Modeling tab of the Simulink Toolstrip, click Model Settings.
3. On the Hardware Implementation tab, select the ARM architecture-based Arudino board from the Hardware board drop-down menu.
4. Go to Advanced Parameters and select Use Embedded Coder features.
5. Go to Code Generation > Verification on the left pane. If this option does not appear on the left pane, click Apply > OK on the Configuration Parameters dialog box and close it. Open the dialog box and continue with the steps mentioned below.
6. Select Measure task execution time to profile execution time for each rate in the Simulink model. The Workspace variable,
executionProfile, holds the profiling data in the workspace.
Metrics only for Save options.
8. Click Apply and OK.
9. On the Simulation tab of the Simulink Toolstrip, set the Stop time to
10. On the Hardware tab of the Simulink model, in the Mode section, select Run on board and then click Monitor & Tune to build, deploy, and run your model as an executable on the ARM Arduino board. At the start of execution, a window appears and shows that the executable is running on the ARM Arduino board. The code runs for
5 seconds and then stops.
11. Enter this code to obtain the profiling report for the session that you just ran. This report shows each task has a different expected turnaround and execution time.
This report provides the following details:
1. A detailed summary
2. Information about profiled code sections, which includes time measurements for:
entry_point_fn_initialize function, for example,
The entry point function, for example,
entry_point_fn_terminate function, for example,
3. Average and maximum Arduino CPU core utilization.
4. Definition of metrics.
The report has these sections:
1. Section: Name of function from which code is generated.
2. Maximum Execution Time in ns: Longest time between start and end of code section.
3. Average Execution Time in ns: Average time between start and end of code section.
4. Calls: Number of calls to the code section.
5. MATLAB icon: Icon that you click to display the profiled code section.
Profile other Simulink models from the Simulink Support Package for Arduino Hardware. Observe the time taken for implementing steps in the Simulink model that helps to improve its efficiency.