3.4.4.2 Program Counter Polling

Each time the Program Counter (PC) is read out from the target, we get the exact information on the address of the code location currently being executed. The Data Visualizer can show PC values with current measurements in the same graph. This allows the user to see what is being executed by the target CPU at the various sample points of the current consumption graph. The sampled PC values will only show part of the code execution, as in most cases it is impossible to read out the PC values as fast as the target is executing instructions. The sampled values are still useful to indicate which code segment is being executed at any point in time.

A SAM L21 Xplained Pro board running a Mass Storage Class example will be used to demonstrate PC polling.

Both Target USB and Debug USB connectors of a SAM L21 Xplained Pro board is connected to a host computer. The ATSAML21 target device is running the USB Device MSC Example from ASF for SAM L21 Xplained Pro (in Atmel Studio select File→New→Example Project and search for “MSC”). The Current Measurement jumpers on the kit are set to measure MCU current and bypass I/O current.

The current graph after running a format of the mass storage device:

A disk format operation consists of both read and write operations, but from the current graph it is difficult to see what is going on when. To get more information on what is going on in the target at the various points in the current graph, the Program Counter sampling feature will be useful.

To view Program Counter samples together with current measurement data both the Power interface and the Code Profiling interface must be enabled.
Todo:
  • Enable both Power interface and Code Profiling interface in DGI Control Panel
Todo:
  • Open the Code Profiling Configuration dialog by clicking the Gear button on the Code Profiling interface
  • Select Enable Code Location
A typical current graph with Program Counter sampling enabled during a format operation is shown below.
The yellow points plotted on the graph represent polled Program Counter values. Their location on the y axis is a visual representation of their location in the code-space of the target device. The relative grouping of samples shows the execution of different functions. Patterns can easily be seen using this technique. Hovering over one of the samples shows the location of that sample in the Code location details box below the graph, as well as the value of the current sample at that point.
Double-clicking on one of the samples will open the editor and highlight the corresponding line of code.
The highlighted sample is located in a function called udi_msc_trans_block. This function transfers data from RAM to USB. From the graph it can be seen that the current spike at the marker is generated by the execution of this function as all Program Counter samples are from the same location during this spike.