Implement UART debugging by reusing DEBUG_PRINT when ITW not active
This commit is contained in:
+23
-3
@@ -21,6 +21,8 @@
|
||||
/* USER CODE BEGIN Includes */
|
||||
#include "canlog.h"
|
||||
#include "cansend.h"
|
||||
#include <stdio.h>
|
||||
#include <stdarg.h>
|
||||
/* USER CODE END Includes */
|
||||
|
||||
/* Private typedef -----------------------------------------------------------*/
|
||||
@@ -64,7 +66,6 @@ osMessageQueueId_t xUARTQueue;
|
||||
|
||||
osSemaphoreId_t xUARTDMASemaphore;
|
||||
osThreadId_t xUartTask;
|
||||
|
||||
/* USER CODE END PV */
|
||||
|
||||
/* Private function prototypes -----------------------------------------------*/
|
||||
@@ -75,14 +76,33 @@ static void MX_CAN1_Init(void);
|
||||
static void MX_CAN2_Init(void);
|
||||
static void MX_SDIO_SD_Init(void);
|
||||
static void MX_USART1_UART_Init(void);
|
||||
/* USER CODE END PFP */
|
||||
|
||||
/* USER CODE BEGIN PFP */
|
||||
/* USER CODE BEGIN PF */
|
||||
int _write(int file, char *ptr, int len)
|
||||
{
|
||||
for (int i = 0; i < len; i++) ITM_SendChar((*ptr++));
|
||||
return len;
|
||||
}
|
||||
/* USER CODE END PFP */
|
||||
|
||||
#ifndef DEBUG_ITM
|
||||
void uart_debug_print(const char *fmt, ...)
|
||||
{
|
||||
char buf[128];
|
||||
va_list args;
|
||||
|
||||
va_start(args, fmt);
|
||||
int len = vsnprintf(buf, sizeof(buf), fmt, args);
|
||||
va_end(args);
|
||||
|
||||
if (len > 0)
|
||||
{
|
||||
while (HAL_UART_GetState(&huart1) & HAL_UART_STATE_BUSY_TX);
|
||||
HAL_UART_Transmit(&huart1, (uint8_t*)buf, len, 100);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
/* USER CODE END PF */
|
||||
|
||||
/* Private user code ---------------------------------------------------------*/
|
||||
/* USER CODE BEGIN 0 */
|
||||
|
||||
Reference in New Issue
Block a user