Skip to main content

Debugging and Logging

A device application has no console. Its logging calls land in a 512-byte log window at the end of the output buffer, and the host reads that window over the SD interface. This page shows the device half in brief, and then the recipe that reads the log from inside your own host application.

Log from the device application

Add C0Logger.c to your build and print through the logger API.

#include "C0Logger.h"

print_lstr("computing\n");
tiny_printf("sampleCount = %d\n", (int) sampleCount);

The Hardware Abstraction Layer page of each module documents the library, the build switch that turns every call into a no-op, and the full function table. See Debug Logging (C0-microSD) and Debug Logging (C0-microSD+).

Embed the log reader in your host application

The C0_debug_logger.py script is the standalone way to read the log, but it occupies a terminal and clears the screen on every poll. The neater approach inside a host application is the C0Logger class that underlies the script itself. It wraps the same interface object your application already holds, polls the log window on a background thread, and writes each snapshot wherever you point it.

from signaloid_utilities.debug_logger import C0Logger

with C0Logger(compute_module, polling_rate=0.5, no_clear=True, no_header=True) as logger:
logger.start()
output = compute_module.calculate_command(1, poll_sleep_time=0.001, verbose=False)
logger.stop()

start() launches the reader thread, stop() joins it, and the with block stops the thread even when the round trip raises. Log lines from the device application appear interleaved with your application's own output while the computation runs.

The constructor options shape the output.

OptionDefaultPurpose
polling_rate1Seconds between polls of the log window.
output_filesys.stdoutA stream, or a file path to append snapshots to.
no_clearFalseSkip clearing the console before each snapshot. Set it when interleaving with application output.
no_headerFalseSkip the timestamp header above each snapshot.
no_header_stylingFalseKeep the header but drop its box drawing.
print_hexFalsePrint a hex dump of the window instead of decoded text.

Two variants of the same recipe cover the remaining cases.

  • Log to a file. Pass output_file="device.log" and drop no_clear and no_header, so timestamped snapshots accumulate in the file while the console stays clean.
  • A dedicated reader process. Call logger.start_blocking() instead of start() to run the loop in the foreground, which suits a small companion script or a separate process that does nothing but follow the log.

Each poll is a block read on the same SD bus that carries your data transfers, so keep polling_rate moderate while the host moves large buffers.

The log window holds the most recent 512 bytes, so a device application that prints faster than the polling rate overwrites older records between snapshots.

Next steps