1 /** 2 ****************************************************************************** 3 * @file dbg_trace.h 4 * @author MCD Application Team 5 * @brief Header for dbg_trace.c 6 ****************************************************************************** 7 * @attention 8 * 9 * Copyright (c) 2018-2021 STMicroelectronics. 10 * All rights reserved. 11 * 12 * This software is licensed under terms that can be found in the LICENSE file 13 * in the root directory of this software component. 14 * If no LICENSE file comes with this software, it is provided AS-IS. 15 * 16 ****************************************************************************** 17 */ 18 19 20 /* Define to prevent recursive inclusion -------------------------------------*/ 21 #ifndef __DBG_TRACE_H 22 #define __DBG_TRACE_H 23 24 #ifdef __cplusplus 25 extern "C" 26 { 27 #endif 28 29 /* Exported types ------------------------------------------------------------*/ 30 /* External variables --------------------------------------------------------*/ 31 /* Exported macros -----------------------------------------------------------*/ 32 #if ( ( CFG_DEBUG_TRACE_FULL != 0 ) || ( CFG_DEBUG_TRACE_LIGHT != 0 ) ) 33 #define PRINT_LOG_BUFF_DBG(...) DbgTraceBuffer(__VA_ARGS__) 34 #if ( CFG_DEBUG_TRACE_FULL != 0 ) 35 #define PRINT_MESG_DBG(...) do{printf("\r\n [%s][%s][%d] ", DbgTraceGetFileName(__FILE__),__FUNCTION__,__LINE__);printf(__VA_ARGS__);}while(0); 36 #else 37 #define PRINT_MESG_DBG printf 38 #endif 39 #else 40 #define PRINT_LOG_BUFF_DBG(...) 41 #define PRINT_MESG_DBG(...) 42 #endif 43 44 #define PRINT_NO_MESG(...) 45 46 /* Exported functions ------------------------------------------------------- */ 47 48 /** 49 * @brief Request the user to initialize the peripheral to output traces 50 * 51 * @param None 52 * @retval None 53 */ 54 extern void DbgOutputInit( void ); 55 56 /** 57 * @brief Request the user to sent the traces on the output peripheral 58 * 59 * @param p_data: Address of the buffer to be sent 60 * @param size: Size of the data to be sent 61 * @param cb: Function to be called when the data has been sent 62 * @retval None 63 */ 64 extern void DbgOutputTraces( uint8_t *p_data, uint16_t size, void (*cb)(void) ); 65 66 /** 67 * @brief DbgTraceInit Initialize Logging feature. 68 * 69 * @param: None 70 * @retval: None 71 */ 72 void DbgTraceInit( void ); 73 74 /**********************************************************************************************************************/ 75 /** This function outputs into the log the buffer (in hex) and the provided format string and arguments. 76 *********************************************************************************************************************** 77 * 78 * @param pBuffer Buffer to be output into the logs. 79 * @param u32Length Length of the buffer, in bytes. 80 * @param strFormat The format string in printf() style. 81 * @param ... Arguments of the format string. 82 * 83 **********************************************************************************************************************/ 84 void DbgTraceBuffer( const void *pBuffer , uint32_t u32Length , const char *strFormat , ... ); 85 86 const char *DbgTraceGetFileName( const char *fullpath ); 87 88 /** 89 * @brief Override the standard lib function to redirect printf to USART. 90 * @param handle output handle (STDIO, STDERR...) 91 * @param buf buffer to write 92 * @param bufsize buffer size 93 * @retval Number of elements written 94 */ 95 size_t DbgTraceWrite(int handle, const unsigned char * buf, size_t bufSize); 96 97 #ifdef __cplusplus 98 } 99 #endif 100 101 #endif /*__DBG_TRACE_H */ 102 103