Programming embedded programs: software program tracing with binary protocols

[ad_1]

On this video tutorial, we clarify the final ideas of software program tracing based mostly on a binary protocol, which is way much less intrusive than utilizing printf().

Within the final episode of this collection, you realized about software program tracing and its hottest implementation with printf(). Right now’s video #46 explains the final ideas of software program tracing based mostly on a binary protocol, which is way much less intrusive and presents many extra benefits for real-time embedded software program than formatting knowledge into textual content. To focus the dialogue and supply particular examples, the video makes use of the mature QP/Spy software program tracing system [1].

Lesson 46 Software program Tracing with Binary Protocols

What’s Mistaken With printf()?

Think about a hearth truck racing to an emergency. However as an alternative of combating the blaze and rescuing the victims, the firefighter begins submitting a scenario report, which takes him an hour. (That is your CPU racing via your time-critical code and the way a millisecond “feels” to a contemporary CPU.) To make it much more ludicrous, the report shouldn’t be within the fireman’s native language. No, the report is in a international language, so the poor fireman should translate each phrase. (That is how the human-readable textual output “feels” to the CPU, for which the native format is binary.) All this appears loopy, however that is exactly what occurs within the printf() methodology. Please notice that the report itself shouldn’t be the absurd half. All of us perceive {that a} report is useful, similar to software program tracing is. Nevertheless, the way in which it’s finished with printf() is suboptimal.

A Smarter Approach

A greater resolution for a firefighter is to put on physique cameras to seize particulars with minimal distraction. Later, after the emergency, the fireman can examine the recorded footage and submit his report. And, after all, the report needs to be within the fireman’s native language in order that he gained’t waste his time on translation.

Software program Tracing in Binary Format

This analogy lays out the final construction of a extra affordable software program tracing technique. The tracing data needs to be recorded shortly right into a reminiscence buffer contained in the microcontroller within the native binary format. As demonstrated within the accompanying video, this takes solely microseconds, which is important as a result of tracing occurs within the time-critical code. However, the sluggish means of sending the tracing data to the host, which takes milliseconds, needs to be decoupled and happen within the idle thread when the CPU has nothing else to do.

The Binary Knowledge Protocol

The underlying binary knowledge protocol is probably the most important a part of a contemporary tracing system. The protocol have to be designed to simplify the information administration overhead within the goal but protect packet boundaries and detect any gaps within the knowledge and different errors. Nonetheless, it should additionally allow the information to be transmitted in arbitrary chunks, no matter could be despatched shortly within the idle thread and suits the underlying {hardware} (comparable to a UART). The video demonstrates the HDLC-like binary protocol utilized in QP/Spy, which has all these options and has confirmed itself over a few years [2].

The Host-Facet Tracing Reception

One of many fundamental benefits of the printf() method is that you need to use an ordinary serial terminal to obtain and visualize the human-readable hint output. Nevertheless, this now not works for binary knowledge, for which you want a specialised host-side utility to obtain, parse, validate, and visualize the tracing knowledge. The video demonstrates this with the QSPY host utility [3].

Finish Notes

Like a conventional debugger, a software program tracing system based mostly on a binary protocol wants symbolic data (comparable to names of objects or capabilities similar to reminiscence addresses) to visualise the information in human-readable type. Most software program tracing programs have to resolve this downside in a roundabout way. The video illustrates the method taken in QP/Spy, the place the embedded goal generates particular “dictionary” hint information. The video contrasts this with one other software program tracing system known as TRICE [4], which makes use of format strings however defers precise formatting to the host. Trice requires a preprocessing instrument (written within the Go language) to extract the format strings from the supply code. This data is subsequently used within the TRICE host utility to carry out printf-like formatting on the host machine.

[1] Quantum Leaps, QP/Spy Software program Tracing System, 2005-2024

[2] Quantum Leaps, QP/Spy Knowledge Protocol, 2005-2024

[3] Quantum Leaps, QSPY Host Utility, 2005-2024

[4] Thomas Höhenleitner, Tracing & Logging with the TRICE Library, 2022

Dr. Miro M. Samek is the creator of the open supply QP real-time embedded frameworks and the freeware QM graphical model-based design instrument. He’s additionally the founder and CEO of Quantum Leaps — the supplier of contemporary embedded software program based mostly on energetic objects and hierarchical state machines in addition to instruments for visible modeling, computerized code era, and unit testing of deeply embedded software program. Miro teaches the favored YouTube “Trendy Embedded Programs Programming” video course on which this text collection is predicated.

Associated Contents:

Proceed Studying

[ad_2]

Supply hyperlink

This “beast of a smartwatch” simply acquired a serious 35% low cost throughout Amazon’s Large Spring Sale

This FAA-approved flight planning app provides drone insurance coverage too