Skip to content

Debug Module Usage Guide

Kolosso edited this page Nov 6, 2024 · 14 revisions

The Debug module contains several tools for debugging your program.

Print Macros

Overview

There are three print macros included:

  • PRINT_INFO: for printing general debug information.
  • PRINT_ERROR: for printing errors.
  • PRINT_WARN: for printing warnings.

These macros do a few nice things for you:

  • They format your messages in a nice way.
  • They include extra information for errors and warnings.
  • They can be disabled so your program is stripped of all print statements (good for optimizing).

Each line that is printed will also include a subject, which indicates the origin of the message. You define the subject name at the top of each file that uses one of the print macros using the syntax: #define PRINT_SUBJECT "Subject Name Here". Note that PRINT_INFO, PRINT_ERROR, and PRINT_WARN all require a subject to compile.

Example

Here's an example program using the print macros:

#include "tuk/tuk.h"

// define the name of the file/module.
#define PRINT_SUBJECT "Main"

int main()
{
  /* HAL init... */
  
  PRINT_INFO("This is a test");
  PRINT_WARN("This is a warning. There's about to be an error!");
  PRINT_ERROR("Ahhh, your board is on fire!");

  int my_integer = 15;
  PRINT_INFO("my_integer = %d", &my_integer);

  return 0;
}

The resulting output is:

[Main] This is a test
[Main] WARNING: This is a warning. There's about to be an error! ('../Core/Src/main.c':103)
[Main] ERROR: Ahhh, your board is on fire! ('../Core/Src/main.c':104)
[Main] my_integer = 15

Setup

In order to see your program's output, you will need to do some setup in STM32CubeIDE. This article includes step-by-step instructions on how to do that.

Debug Logger

❗ This section needs expansion. It's missing an explanation of how to use the Debug Logger in your program. That will be written at a later date.

Overview

The debug logger is a useful tool for storing diagnostic information so it can later be transmitted to CDH. This data would only be used by ground station operators to debug certain problems with the system.

Basic Usage

To initialise the debug logger, call DebugLogger_Init. In order to use it, you will have to attach a buffer so that it has a place to put data. To do this, create a LogBuffer and pass it to DebugLogger_Push_Buffer. The passed buffer will become the active log. Any calls to DebugLogger_Put will append to that buffer.

When you're done logging to your buffer, call DebugLogger_Pop_Buffer. This will detach it from the logger.

Note that pushing and popping are stack operations. The debug logger can support several attached logs at once, which means you can effectively designate scopes of your program to specific buffers. This is needed in ISRs to prevent corruption of the active buffer.

⚠️ Warning: Remember that a single log buffer only stores up to 4 bytes of data. If the buffer overflows, DebugLogger_Put will return false and the data will not be recorded. For this reason, you should store data judiciously.

Clone this wiki locally