Arduino tracing for debugging

arduino m0 samd21 debug trace

Tracing and dumping information with ArduinoTrace library when debugging Arduino code.

Code

Download code
#define ARDUINOTRACE_SERIAL SerialUSB
#include <ArduinoTrace.h>

int someValue = 42;

void setup() {
    SerialUSB.begin(9600);
    while (!SerialUSB) { }
    delay(100);
    DUMP(someValue);
}

void loop() {
    SerialUSB.print(millis());
    SerialUSB.print(": ");
    TRACE();

    blink(5);
    delay(2000);
}

void blink(int num) {
    SerialUSB.print(millis());
    SerialUSB.print(": ");
    TRACE();

    SerialUSB.print(millis());
    SerialUSB.print(": ");
    DUMP(num);

    digitalWrite(LED_BUILTIN, HIGH);
    delay(500);

    digitalWrite(LED_BUILTIN, LOW);
    delay(500);
}

Makefile

BOARD?=arduino:samd:mzero_bl
PORT := $(shell ls /dev/cu.usbmodem*)

.PHONY: default lint all flash clean

default: lint all flash clean

lint:
	cpplint --extensions=ino --filter=-legal/copyright *.ino

all:
	arduino-cli compile --fqbn $(BOARD) ./

flash:
	arduino-cli upload -p $(PORT) --fqbn $(BOARD)

clean:
	rm -r build

Serial console

Serial output from the firmware.

Arduino tracing for debugging serial console

References