From 0f9485c633e842aa25a8aefede18d06dab98b7a6 Mon Sep 17 00:00:00 2001 From: greedyhao Date: Thu, 10 Dec 2020 22:07:49 +0800 Subject: [PATCH] [bluetrum] fix hal_printf --- bsp/bluetrum/ab32vg1-ab-prougen/board/board.c | 40 ++++++++++++++++--- .../ab32vg1_hal/include/ab32vg1_hal.h | 2 +- 2 files changed, 35 insertions(+), 7 deletions(-) diff --git a/bsp/bluetrum/ab32vg1-ab-prougen/board/board.c b/bsp/bluetrum/ab32vg1-ab-prougen/board/board.c index 69c1078599..a3b24816af 100644 --- a/bsp/bluetrum/ab32vg1-ab-prougen/board/board.c +++ b/bsp/bluetrum/ab32vg1-ab-prougen/board/board.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2006-2020, Bluetrum Development Team + * Copyright (c) 2006-2020, RT-Thread Development Team * * SPDX-License-Identifier: Apache-2.0 * @@ -19,12 +19,40 @@ void cpu_irq_comm(void); void set_cpu_irq_comm(void (*irq_hook)(void)); extern uint32_t __aram_start, __eram_end; -void hal_printf(const char *format, ...) +void hal_printf(const char *fmt, ...) { - va_list param; - va_start(param, format); - rt_kprintf(format, param); - va_end(param); + rt_device_t console = rt_console_get_device(); + + va_list args; + rt_size_t length; + static char rt_log_buf[RT_CONSOLEBUF_SIZE]; + + va_start(args, fmt); + /* the return value of vsnprintf is the number of bytes that would be + * written to buffer had if the size of the buffer been sufficiently + * large excluding the terminating null byte. If the output string + * would be larger than the rt_log_buf, we have to adjust the output + * length. */ + length = rt_vsnprintf(rt_log_buf, sizeof(rt_log_buf) - 1, fmt, args); + if (length > RT_CONSOLEBUF_SIZE - 1) + length = RT_CONSOLEBUF_SIZE - 1; +#ifdef RT_USING_DEVICE + if (console == RT_NULL) + { + rt_hw_console_output(rt_log_buf); + } + else + { + rt_uint16_t old_flag = console->open_flag; + + console->open_flag |= RT_DEVICE_FLAG_STREAM; + rt_device_write(console, 0, rt_log_buf, length); + console->open_flag = old_flag; + } +#else + rt_hw_console_output(rt_log_buf); +#endif + va_end(args); } void timer0_isr(int vector, void *param) diff --git a/bsp/bluetrum/libraries/hal_libraries/ab32vg1_hal/include/ab32vg1_hal.h b/bsp/bluetrum/libraries/hal_libraries/ab32vg1_hal/include/ab32vg1_hal.h index a3bbab46fc..a215fdee55 100644 --- a/bsp/bluetrum/libraries/hal_libraries/ab32vg1_hal/include/ab32vg1_hal.h +++ b/bsp/bluetrum/libraries/hal_libraries/ab32vg1_hal/include/ab32vg1_hal.h @@ -13,6 +13,6 @@ void hal_set_tick_hook(void (*hook)(uint32_t ticks)); void hal_set_ticks(uint32_t ticks); void hal_mdelay(uint32_t nms); void hal_udelay(uint16_t nus); -void hal_printf(const char *format, ...); +void hal_printf(const char *fmt, ...); #endif