From 3ddda900487f55bec506562fffd9f38e419a3ecd Mon Sep 17 00:00:00 2001 From: chen <15335560115@163.com> Date: 星期六, 12 七月 2025 16:34:10 +0800 Subject: [PATCH] 成功调好485串口接和收逻辑,usb串口用于查看log输出和上位机配置,需要注意在打印彻底完成后进行切换 --- keil/include/drivers/mk_trace.c | 35 ++++++++++++++++++++--------------- 1 files changed, 20 insertions(+), 15 deletions(-) diff --git a/keil/include/drivers/mk_trace.c b/keil/include/drivers/mk_trace.c index 689fde4..9a42237 100644 --- a/keil/include/drivers/mk_trace.c +++ b/keil/include/drivers/mk_trace.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2019-2023 Beijing Hanwei Innovation Technology Ltd. Co. and + * Copyright (c) 2019-2025 Beijing Hanwei Innovation Technology Ltd. Co. and * its subsidiaries and affiliates (collectly called MKSEMI). * * All rights reserved. @@ -50,7 +50,7 @@ #if TRACE_EN #ifndef BACKTRACE_EN -#define BACKTRACE_EN (0) +#define BACKTRACE_EN (1) #endif #ifndef TRACE_BUF_SIZE @@ -202,10 +202,12 @@ (TRACE_LVL_CONFIG_1 >> (4 * (TRACE_MODULE_SE - 8))) & 0xf, // SCP03 (TRACE_LVL_CONFIG_1 >> (4 * (TRACE_MODULE_SCP03 - 8))) & 0xf, + // Aliro + (TRACE_LVL_CONFIG_1 >> (4 * (TRACE_MODULE_ALIRO - 8))) & 0xf, }; -const static char *module_name[TRACE_MODULE_NUM] = {"[MAC]", "[PHY]", "[DRV]", "[APP]", "[UWB]", "[UCI]", "[TEST]", - "[BOOT]", "[OS]", "[FIRA]", "[CCC]", "[SE]", "[SCP03]"}; +const static char *module_name[TRACE_MODULE_NUM] = {"[MAC]", "[PHY]", "[DRV]", "[APP]", "[UWB]", "[UCI]", "[TEST]", + "[BOOT]", "[OS]", "[FIRA]", "[CCC]", "[SE]", "[SCP03]", "[ALIRO]"}; const static char *level_tag[TRACE_LEVEL_NUM] = { "[ERROR]", @@ -328,6 +330,9 @@ int trace_close(void) { int ret = 0; + // flush the trace buffer before close + trace_flush(); + trace_handle.enabled = 0; if ((trace_handle.port == TRACE_PORT_UART0) || (trace_handle.port == TRACE_PORT_UART1)) { @@ -1060,7 +1065,6 @@ } #endif - int trace_printf(uint16_t module, uint8_t level, const char *fmt, ...) { if (trace_handle.enabled == 0) @@ -1088,7 +1092,7 @@ // uint32_t lock = int_lock(); if ((module & TRACE_NO_TIMESTAMP) == 0) { - mk_snprintf(&buf[pre_len], sizeof(buf) - pre_len, "%10u | ", sys_tick_us()); + mk_snprintf(&buf[pre_len], sizeof(buf) - pre_len, "%10u | ", rtc_us()); pre_len = strlen(buf); } if ((module & TRACE_NO_MODULE_NAME) == 0) @@ -1442,18 +1446,12 @@ } while (1); } -#if defined(__ARMCC_VERSION) && (__ARMCC_VERSION >= 6010050) -#pragma clang diagnostic push -#pragma clang diagnostic ignored "-Wuninitialized" -#endif - -#if BACKTRACE_EN void trace_flush(void) { if ((trace_handle.port == TRACE_PORT_UART0) || (trace_handle.port == TRACE_PORT_UART1)) { enum UART_DEV_T trace_uart = (trace_handle.port == TRACE_PORT_UART0) ? UART_ID0 : UART_ID1; - while (uart_tx_in_progress(trace_uart)) + while (uart_tx_fifo_is_empty(trace_uart) == false) { } } @@ -1489,6 +1487,13 @@ trace_handle.sending = false; int_unlock(lock); } + +#if defined(__ARMCC_VERSION) && (__ARMCC_VERSION >= 6010050) +#pragma clang diagnostic push +#pragma clang diagnostic ignored "-Wuninitialized" +#endif + +#if BACKTRACE_EN static const char trace_new_line[] = TRACE_NEW_LINE; @@ -1527,7 +1532,7 @@ trace_output_blocking(separate_line, sizeof(separate_line) - 1); // Timestamp - len += mk_snprintf(&trace_handle.tx_buf[len], sizeof(trace_handle.tx_buf) - (uint32_t)len, "%10d | " TRACE_NEW_LINE, sys_tick_us()); + len += mk_snprintf(&trace_handle.tx_buf[len], sizeof(trace_handle.tx_buf) - (uint32_t)len, "%10d | " TRACE_NEW_LINE, rtc_us()); // Title and PC len += mk_snprintf(&trace_handle.tx_buf[len], sizeof(trace_handle.tx_buf) - (uint32_t)len, TRACE_NEW_LINE "### ASSERT @ 0x%08X ###" TRACE_NEW_LINE, @@ -1624,7 +1629,7 @@ uint32_t *stack; // Timestamp - len += mk_snprintf(&trace_handle.tx_buf[len], sizeof(trace_handle.tx_buf) - (uint32_t)len, "%10d | " TRACE_NEW_LINE, sys_tick_us()); + len += mk_snprintf(&trace_handle.tx_buf[len], sizeof(trace_handle.tx_buf) - (uint32_t)len, "%10d | " TRACE_NEW_LINE, rtc_us()); // Title len += mk_snprintf(&trace_handle.tx_buf[len], sizeof(trace_handle.tx_buf) - (uint32_t)len, -- Gitblit v1.9.3