feat: 修改printf重定向串口

This commit is contained in:
bmy
2024-02-07 14:20:54 +08:00
parent 04973e875c
commit 354b41dad8

View File

@@ -1,51 +1,51 @@
/********************************************************************************************************************* /*********************************************************************************************************************
* CH32V307VCT6 Opensourec Library 即CH32V307VCT6 开源库)是一个基于官方 SDK 接口的第三方开源库 * CH32V307VCT6 Opensourec Library 即CH32V307VCT6 开源库)是一个基于官方 SDK 接口的第三方开源库
* Copyright (c) 2022 SEEKFREE 逐飞科技 * Copyright (c) 2022 SEEKFREE 逐飞科技
* *
* 本文件是CH32V307VCT6 开源库的一部分 * 本文件是CH32V307VCT6 开源库的一部分
* *
* CH32V307VCT6 开源库 是免费软件 * CH32V307VCT6 开源库 是免费软件
* 您可以根据自由软件基金会发布的 GPLGNU General Public License即 GNU通用公共许可证的条款 * 您可以根据自由软件基金会发布的 GPLGNU General Public License即 GNU通用公共许可证的条款
* 即 GPL 的第3版即 GPL3.0)或(您选择的)任何后来的版本,重新发布和/或修改它 * 即 GPL 的第3版即 GPL3.0)或(您选择的)任何后来的版本,重新发布和/或修改它
* *
* 本开源库的发布是希望它能发挥作用,但并未对其作任何的保证 * 本开源库的发布是希望它能发挥作用,但并未对其作任何的保证
* 甚至没有隐含的适销性或适合特定用途的保证 * 甚至没有隐含的适销性或适合特定用途的保证
* 更多细节请参见 GPL * 更多细节请参见 GPL
* *
* 您应该在收到本开源库的同时收到一份 GPL 的副本 * 您应该在收到本开源库的同时收到一份 GPL 的副本
* 如果没有,请参阅<https://www.gnu.org/licenses/> * 如果没有,请参阅<https://www.gnu.org/licenses/>
* *
* 额外注明: * 额外注明:
* 本开源库使用 GPL3.0 开源许可证协议 以上许可申明为译文版本 * 本开源库使用 GPL3.0 开源许可证协议 以上许可申明为译文版本
* 许可申明英文版在 libraries/doc 文件夹下的 GPL3_permission_statement.txt 文件中 * 许可申明英文版在 libraries/doc 文件夹下的 GPL3_permission_statement.txt 文件中
* 许可证副本在 libraries 文件夹下 即该文件夹下的 LICENSE 文件 * 许可证副本在 libraries 文件夹下 即该文件夹下的 LICENSE 文件
* 欢迎各位使用并传播本程序 但修改内容时必须保留逐飞科技的版权声明(即本声明) * 欢迎各位使用并传播本程序 但修改内容时必须保留逐飞科技的版权声明(即本声明)
* *
* 文件名称 zf_common_debug * 文件名称 zf_common_debug
* 公司名称 成都逐飞科技有限公司 * 公司名称 成都逐飞科技有限公司
* 版本信息 查看 libraries/doc 文件夹内 version 文件 版本说明 * 版本信息 查看 libraries/doc 文件夹内 version 文件 版本说明
* 开发环境 MounRiver Studio V1.8.1 * 开发环境 MounRiver Studio V1.8.1
* 适用平台 CH32V307VCT6 * 适用平台 CH32V307VCT6
* 店铺链接 https://seekfree.taobao.com/ * 店铺链接 https://seekfree.taobao.com/
* *
* 修改记录 * 修改记录
* 日期 作者 备注 * 日期 作者 备注
* 2022-09-15 大W first version * 2022-09-15 大W first version
********************************************************************************************************************/ ********************************************************************************************************************/
#ifndef _zf_common_debug_h_ #ifndef _zf_common_debug_h_
#define _zf_common_debug_h_ #define _zf_common_debug_h_
#include "zf_common_typedef.h" #include "zf_common_typedef.h"
#define PRINTF_ENABLE (1) // 使能printf #define PRINTF_ENABLE (1) // 使能 printf
// 如果修改串口并开启了 debug UART 的中断接收 需要同步更换 debug_interrupr_handler 函数到对应的中断服务函数 // 如果修改串口并开启了 debug UART 的中断接收 需要同步更换 debug_interrupr_handler 函数到对应的中断服务函数
// 如果修改串口并开启了 debug UART 的中断接收 需要同步更换 debug_interrupr_handler 函数到对应的中断服务函数 // 如果修改串口并开启了 debug UART 的中断接收 需要同步更换 debug_interrupr_handler 函数到对应的中断服务函数
// 如果修改串口并开启了 debug UART 的中断接收 需要同步更换 debug_interrupr_handler 函数到对应的中断服务函数 // 如果修改串口并开启了 debug UART 的中断接收 需要同步更换 debug_interrupr_handler 函数到对应的中断服务函数
#define DEBUG_UART_INDEX (UART_3) // 指定 debug uart 所使用的的串口 #define DEBUG_UART_INDEX (UART_1) // 指定 debug uart 所使用的的串口
#define DEBUG_UART_BAUDRATE (115200) // 指定 debug uart 所使用的的串口波特率 #define DEBUG_UART_BAUDRATE (115200) // 指定 debug uart 所使用的的串口波特率
#define DEBUG_UART_TX_PIN (UART3_MAP0_TX_B10 ) // 指定 debug uart 所使用的的串口引脚 #define DEBUG_UART_TX_PIN (UART1_MAP0_TX_A9) // 指定 debug uart 所使用的的串口引脚
#define DEBUG_UART_RX_PIN (UART3_MAP0_RX_B11 ) // 指定 debug uart 所使用的的串口引脚 #define DEBUG_UART_RX_PIN (UART1_MAP0_RX_A10) // 指定 debug uart 所使用的的串口引脚
#define DEBUG_UART_USE_INTERRUPT (1) // 是否启用 debug uart 接收中断 #define DEBUG_UART_USE_INTERRUPT (1) // 是否启用 debug uart 接收中断
@@ -72,7 +72,6 @@
//------------------------------------------------------------------------------------------------------------------- //-------------------------------------------------------------------------------------------------------------------
#define zf_log(x, str) (debug_log_handler((x), (str), __FILE__, __LINE__)) #define zf_log(x, str) (debug_log_handler((x), (str), __FILE__, __LINE__))
typedef struct typedef struct
{ {
uint16 type_index; uint16 type_index;
@@ -83,24 +82,24 @@ typedef struct
uint8 font_x_size; uint8 font_x_size;
uint8 font_y_size; uint8 font_y_size;
void (*output_uart) (const char *str); void (*output_uart)(const char *str);
void (*output_screen) (uint16 x, uint16 y, const char *str); void (*output_screen)(uint16 x, uint16 y, const char *str);
void (*output_screen_clear) (void); void (*output_screen_clear)(void);
}debug_output_struct; } debug_output_struct;
uint32 debug_send_buffer(const uint8 *buff, uint32 len); uint32 debug_send_buffer(const uint8 *buff, uint32 len);
#if DEBUG_UART_USE_INTERRUPT // 如果启用 debug uart 接收中断 #if DEBUG_UART_USE_INTERRUPT // 如果启用 debug uart 接收中断
#define DEBUG_RING_BUFFER_LEN (64) // 定义环形缓冲区大小 默认 64byte #define DEBUG_RING_BUFFER_LEN (64) // 定义环形缓冲区大小 默认 64byte
void debug_interrupr_handler (void); void debug_interrupr_handler(void);
#endif #endif
uint32 debug_read_ring_buffer(uint8 *buff, uint32 len); uint32 debug_read_ring_buffer(uint8 *buff, uint32 len);
void debug_assert_enable (void); void debug_assert_enable(void);
void debug_assert_disable (void); void debug_assert_disable(void);
void debug_assert_handler (uint8 pass, char *file, int line); void debug_assert_handler(uint8 pass, char *file, int line);
void debug_log_handler (uint8 pass, char *str, char *file, int line); void debug_log_handler(uint8 pass, char *str, char *file, int line);
void debug_output_struct_init (debug_output_struct *info); void debug_output_struct_init(debug_output_struct *info);
void debug_output_init (debug_output_struct *info); void debug_output_init(debug_output_struct *info);
void debug_init (void); void debug_init(void);
#endif #endif