/* 常用STM32调试打印命令源程序*/
/* putchar */ #ifdef __GNUC__ /* With GCC/RAISONANCE, small printf (option LD Linker->Libraries->Small printf set to 'Yes') calls __io_putchar() */ #define PUTCHAR_PROTOTYPE int __io_putchar(int ch) #else #define PUTCHAR_PROTOTYPE int fputc(int ch, FILE *f) #endif /* __GNUC__ */
/*1. STM32串口调试 STM32UartImpl.c*/
--------------------------------
#include <./Interface/UartIntf.h> #include <STM32Impl.h> #include <string.h> #include <Debug.h> static UART_HandleTypeDef* puartdebug = NULL; void Stm32SendString(const char* str) { if(puartdebug == NULL)return; HAL_UART_Transmit(puartdebug,(uint8_t*)str,strlen(str),1000); } VATAPI_RESULT UartOpenDebugPort(void* puart,fpSendString* fpsend) { puartdebug = (UART_HandleTypeDef*)puart; *fpsend = Stm32SendString; return SUCCESS; }
/* 2. 调用DBGSTR() /SYSHANG()来调试STM32 Debug.C */ -----------------------------------------------------------------------
#ifndef _DEBUG_ #define _DEBUG_ #include <string.h> #include <stdio.h> #include <stdarg.h> #include <string.h> typedef void (*fpSendString)(const char* str); void DebugInitPort(fpSendString fpstr); void DebugPrintf(const char* fmt,...); void DebugSystemHang(const char* fmt,...); #define __FILENAME__ (strrchr(__FILE__, '/') ? strrchr(__FILE__, '/') + 1 : (strrchr(__FILE__, '\\') ? strrchr(__FILE__, '\\') + 1 : __FILE__)) #define DBGSTR(format, args...) DebugPrintf("[%s:%d] "format"\r\n",__FILENAME__, __LINE__, ##args) #define SYSHANG(format, args...) DebugSystemHang("[%s:%d] Hang : "format"\r\n",__FILENAME__, __LINE__, ##args)
static fpSendString fpsend = NULL; static char bufoutput[128]; void DebugInitPort(fpSendString fpstr) { fpsend = fpstr; } void DebugPrintf(const char* fmt,...) { va_list args; if(fpsend == NULL)return; va_start(args,fmt); vsprintf(bufoutput, fmt, args); va_end(args); fpsend(&bufoutput[0]); } void DebugSystemHang(const char* fmt,...) { va_list args; if(fpsend == NULL)return; va_start(args,fmt); vsprintf(bufoutput, fmt, args); va_end(args); fpsend(&bufoutput[0]); while(1); } #endif
--------------------------- ---------------------------------- --------------------------
#include <VATDebug.h> #include <stdio.h> #include <stdarg.h> #include <string.h>
