-
Notifications
You must be signed in to change notification settings - Fork 0
Debug Module Usage Guide
The Debug module contains several tools for debugging your program.
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).
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 output would be:
[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
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.
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.
To initialise the debug logger, call DebugLogger_Init. Next, you will have to attach a buffer so that the debug logger 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 maintains a stack of log buffers, 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.
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.