Browse Source

增加printx,方便后续调试

xuy 3 years ago
parent
commit
4cad00e05a
2 changed files with 32 additions and 3 deletions
  1. 2 2
      Core/Inc/main.h
  2. 30 1
      Core/Src/main.c

+ 2 - 2
Core/Inc/main.h

@@ -35,9 +35,9 @@ extern "C" {
 
 //#define DEBUG
 #ifdef DEBUG
-	#define WatchDogOn   0   //是否打开看门狗 
+	#define WatchDogOn   0   //关闭看门狗 
 #else
-	#define WatchDogOn   1   //是否打开看门狗
+	#define WatchDogOn   1   //打开看门狗
 #endif
 //0----关闭看门狗SP706   1----打开看门狗SP706--------------必须配置的参数1/3
 //#define WatchDogOn   1   //是否打开看门狗 

+ 30 - 1
Core/Src/main.c

@@ -150,6 +150,8 @@ DMA_HandleTypeDef hdma_usart1_tx;
 DMA_HandleTypeDef hdma_usart2_rx;
 DMA_HandleTypeDef hdma_usart3_rx;
 
+uint8_t bufMain[128];
+
 /* Definitions for defaultTask */
 osThreadId_t defaultTaskHandle;
 const osThreadAttr_t defaultTask_attributes = {
@@ -519,6 +521,34 @@ void Callback010(void *argument);
 void Cang_Init(void);
 
 static void MX_NVIC_Init(void);
+
+// for debug,将信息输出到指定的uart总线上
+static void DumpMsg(uint8_t *msg)
+{
+	HAL_GPIO_WritePin(GPIOA,con03_uart2_kongzhiqi_Pin,GPIO_PIN_RESET);
+	delay_sys_us(80);
+	HAL_UART_Transmit_IT(&huart2,msg,strlen(msg));		
+	while (huart2.gState == HAL_UART_STATE_BUSY_TX)
+	{
+		osDelay(1);
+	}
+	delay_sys_us(80);
+	HAL_GPIO_WritePin(GPIOA,con03_uart2_kongzhiqi_Pin,GPIO_PIN_SET);
+}
+
+#include <stdarg.h>
+void printx(const char *log,...)
+{
+	osMutexAcquire(myMutex01Handle, portMAX_DELAY);
+    va_list ap;
+    va_start(ap,log);
+    vsnprintf(bufMain,sizeof(bufMain),log,ap);
+    va_end(ap);
+
+    DumpMsg(bufMain);
+	osMutexRelease(myMutex01Handle);
+}
+
 /* USER CODE BEGIN PFP */
 void Flash_ReadBytes(uint16_t* sorBuf,uint32_t FlashAddr,uint16_t len)
 {
@@ -823,7 +853,6 @@ void Cang_Init(void)
   * @brief  The application entry point.
   * @retval int
   */
-	uint8_t bufMain[128];
 int main(void)
 {
   /* USER CODE BEGIN 1 */