This is for fellow students going through, youtube descriptions cant ahve angular brackets, so just type in the 3 #includes in the .c file
All this is shamelessly taken from a uni course of mine, and resued here :_)
myDebugger.h
/*
* myDebugger.h
*
* Created on: Jun 17, 2024
* Author: zero
*/
#ifndef INC_MYDEBUGGER_H_
#define INC_MYDEBUGGER_H_
void debug_printf(const char *fmt, ...);
#endif /* INC_MYDEBUGGER_H_ */
myDebugger.c
/*
* myDebugger.c
* This is a debugging library for functions that we can use when debugging :)
*
* Created on: Jun 17, 2024
* Author: zero
*/
// Includes
// RU-vid does not allow angular brakcets, so you will have to type #include for stdio.h, stdint.h, and stdarg.h
#include "myDebugger.h"
#include "stm32f3xx_hal.h"
// Code
//debug_printf sends a max of 256 characters to the ITM SWO t
//It uses a _variable length argument_, same as normal printf and does stuff :)
//Indeed, just call this function as if it was printf
void debug_printf(const char *fmt, ...) {
char buffer[256];
va_list args;
va_start(args, fmt);
vsnprintf(buffer, sizeof(buffer), fmt, args);
va_end(args);
uint16_t i = 0;
while(buffer[i] != '\0') {
ITM_SendChar(buffer[i]);
i++;
}
}
26 сен 2024