1 Star 0 Fork 15

shancan/单片机调试助手-windows

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
贡献代码
同步代码
取消
提示: 由于 Git 不支持空文件夾,创建文件夹后会生成空的 .keep 文件
Loading...
README
LGPL-3.0

单片机调试助手-windows

1. 介绍

单片机调试助手,集串口/蓝牙/TCP/UDP调试、IAP升级、波形助手、图像助手等功能一体

2. 安装教程

  1. 点击右上方克隆/下载,下载ZIP包
  2. 解压ZIP包,双击单片机调试助手.exe即可直接运行

3. 软件特性

串口配置为1位起始位、8位数据位、1位停止位。

单片机IAP升级。

详见在线升级调试程序(一) (jswyll.com/iap/)

支持使用扇区描述文件升级扇区大小不一的单片机,格式为json,Blocks表示FLASH块数组,Base是各个Block的基地址,Sectors是扇区数组,Size是扇区大小,Number是该大小的扇区个数。示例,TC264的FLASH扇区如下

地址范围 大小 名称(缩写) 描述
0x6000_0000 - 0x6000_dfff 120KB CPU1 Data Scratch-Pad SRAM (CPU1.DSPR) 高速暂存SRAM
0x8000_0000 - 0x800f_ffff 1MB Program Flash 0 (PF0) 程序FLASH0
0x8010_0000 - 0x8027_ffff 1.5MB Program Flash 1 (PF1) 程序FLASH1

对于PF0和PF1,扇区结构如下:
Sector Structure of PFx of PMU0

其中,偏移地址(Offset Address)是相对PF0或PF1的首地址而言的。则扇区描述文件编写为:

{
    "Blocks": 
    [
        {
            "Base": "0x80000000",
            "Sectors": 
            [
                {
                    "Size": "16KB",
                    "Number": 8
                }, 
                {
                    "Size": "32KB",
                    "Number": 8
                }, 
                {
                    "Size": "64KB",
                    "Number": 4
                }, 
                {
                    "Size": "128KB",
                    "Number": 3
                }
            ]
        }, 
        {
            "Base": "0x80100000",
            "Sectors": 
            [
                {
                    "Size": "16KB",
                    "Number": 8
                }, 
                {
                    "Size": "32KB",
                    "Number": 8
                }, 
                {
                    "Size": "64KB",
                    "Number": 4
                }, 
                {
                    "Size": "128KB",
                    "Number": 3
                }, 
                {
                    "Size": "256KB",
                    "Number": 2
                }
            ]
        }
    ]
}
  • 有新版本时软件自动更新

  • 在接收区文本框连续单击三次可清空接收框内容

  • 在发送区输入\r\n可以转义成回车换行

  • 发送快捷键:Alt+N,N为0~9,对应各个发送按钮

  • 可设置异常拔出串口后在10秒内尝试重新打开

  • 记忆应用配置(设置、文本框、选择框内容)

  • 暗色界面主题

彩色打印 - 解析ANSI颜色字符

本软件支持ANSI转义序列:ANSI escape code - Wikipedia标准的重置(0)、黑色(30)、红色(31)、绿色(32)、黄色(33)和蓝色(34)转义序列。由于软件主题为亮色时,白色背景下的黄色前景字体不显眼,故以金色前景色显示。

典型例子:乐鑫科技ESP_LOG、RT_Thread 日志组件(RT-Thread API参考手册: 日志组件)。

效果图

image-20211111184033127

RT-Thread打印

在"rt_config.h"中打开彩色宏定义

#define RT_DEBUG
#define RT_DEBUG_COLOR

在.c源文件中可打印

#define DBG_TAG "main"
#define DBG_LVL DBG_LOG
#include <rtdbg.h>

int CO2;

int main(void)
{
    // ...
    LOG_D("init ok.");
    // ...
    LOG_I("read CO2 value: %d", CO2);
    // ...
    LOG_W("location info is noneffective.");
    // ...
    LOG_E("read O2 failed!");
        
    while (1)
    {
        // ...
    }
}

其中,打印类型如下表:

打印类型 说明 使用颜色打印时的颜色
LOG_E 错误 红色
LOG_W 警告 黄色
LOG_I 信息 绿色
LOG_D 调试 默认颜色

各打印类型函数的用法与printf函数一样。

DBG_TAG是打印标签,每个源文件可以不一样,通常取为文件名,便于显示打印信息时知道打印来源。

打印等级DBG_LVL可取为:DBG_ERRORDBG_WARNINGDBG_INFODBG_LOG,打印等级依次增大,即该源文件文件打印的类型越多:

DBG_LVL 打印的类型
DBG_ERROR 只打印LOG_E
DBG_WARNING 打印LOG_ELOG_W
DBG_INFO 打印LOG_ELOG_WLOG_I
DBG_LOG 打印LOG_ELOG_WLOG_ILOG_D

可以在调试时把打印等级设为DBG_LOG来显示更多的信息;在正式版时设为DBG_INFO或更高的等级以减少程序大小。

注意: #include <rtdbg.h>应在宏定义DBG_TAGDBG_LVL之后。

非RT-Thread中打印

不使用RT-Thread时,可以模仿RT-Thread的打印方式:

  1. 新建一个"rtdbg.h"文件,保存在所在工程中,内容复制自RT-Thread的"rtdbg.h",并增加如下第37~40行的代码

    /*
     * Copyright (c) 2006-2018, RT-Thread Development Team
     *
     * SPDX-License-Identifier: Apache-2.0
     *
     * Change Logs:
     * Date           Author       Notes
     * 2016-11-12     Bernard      The first version
     * 2018-05-25     armink       Add simple API, such as LOG_D, LOG_E
     */
    
    /*
     * The macro definitions for debug
     *
     * These macros are defined in static. If you want to use debug macro, you can
     * use as following code:
     *
     * In your C/C++ file, enable/disable DEBUG_ENABLE macro, and then include this
     * header file.
     *
     * #define DBG_TAG           "MOD_TAG"
     * #define DBG_LVL           DBG_INFO
     * #include <rtdbg.h>          // must after of DBG_LVL, DBG_TAG or other options
     *
     * Then in your C/C++ file, you can use LOG_X macro to print out logs:
     * LOG_D("this is a debug log!");
     * LOG_E("this is a error log!");
     */
    
    #ifndef RT_DBG_H__
    #define RT_DBG_H__
    
    #ifdef __cplusplus
    extern "C" {
    #endif
        
    #include <stdio.h>
    #define RT_DEBUG
    #define RT_DEBUG_COLOR
    #define rt_kprintf printf
    
    /* the debug log will force enable when RT_DEBUG macro is defined */
    #if defined(RT_DEBUG) && !defined(DBG_ENABLE)
    #define DBG_ENABLE
    #endif
    
    /* it will force output color log when RT_DEBUG_COLOR macro is defined */
    #if defined(RT_DEBUG_COLOR) && !defined(DBG_COLOR)
    #define DBG_COLOR
    #endif
    
    #if defined(RT_USING_ULOG)
    /* using ulog compatible with rtdbg  */
    #include <ulog.h>
    #else
    
    /* DEBUG level */
    #define DBG_ERROR           0
    #define DBG_WARNING         1
    #define DBG_INFO            2
    #define DBG_LOG             3
    
    #ifdef DBG_TAG
    #ifndef DBG_SECTION_NAME
    #define DBG_SECTION_NAME    DBG_TAG
    #endif
    #else
    /* compatible with old version */
    #ifndef DBG_SECTION_NAME
    #define DBG_SECTION_NAME    "DBG"
    #endif
    #endif /* DBG_TAG */
    
    #ifdef DBG_ENABLE
    
    #ifdef DBG_LVL
    #ifndef DBG_LEVEL
    #define DBG_LEVEL         DBG_LVL
    #endif
    #else
    /* compatible with old version */
    #ifndef DBG_LEVEL
    #define DBG_LEVEL         DBG_WARNING
    #endif
    #endif /* DBG_LVL */
    
    /*
     * The color for terminal (foreground)
     * BLACK    30
     * RED      31
     * GREEN    32
     * YELLOW   33
     * BLUE     34
     * PURPLE   35
     * CYAN     36
     * WHITE    37
     */
    #ifdef DBG_COLOR
    #define _DBG_COLOR(n)        rt_kprintf("\033["#n"m")
    #define _DBG_LOG_HDR(lvl_name, color_n)                    \
        rt_kprintf("\033["#color_n"m[" lvl_name "/" DBG_SECTION_NAME "] ")
    #define _DBG_LOG_X_END                                     \
        rt_kprintf("\033[0m\n")
    #else
    #define _DBG_COLOR(n)
    #define _DBG_LOG_HDR(lvl_name, color_n)                    \
        rt_kprintf("[" lvl_name "/" DBG_SECTION_NAME "] ")
    #define _DBG_LOG_X_END                                     \
        rt_kprintf("\n")
    #endif /* DBG_COLOR */
    
    /*
     * static debug routine
     * NOTE: This is a NOT RECOMMENDED API. Please using LOG_X API.
     *       It will be DISCARDED later. Because it will take up more resources.
     */
    #define dbg_log(level, fmt, ...)                            \
        if ((level) <= DBG_LEVEL)                               \
        {                                                       \
            switch(level)                                       \
            {                                                   \
                case DBG_ERROR:   _DBG_LOG_HDR("E", 31); break; \
                case DBG_WARNING: _DBG_LOG_HDR("W", 33); break; \
                case DBG_INFO:    _DBG_LOG_HDR("I", 32); break; \
                case DBG_LOG:     _DBG_LOG_HDR("D", 0); break;  \
                default: break;                                 \
            }                                                   \
            rt_kprintf(fmt, ##__VA_ARGS__);                     \
            _DBG_COLOR(0);                                      \
        }
    
    #define dbg_here                                            \
        if ((DBG_LEVEL) <= DBG_LOG){                            \
            rt_kprintf(DBG_SECTION_NAME " Here %s:%d\n",        \
                __FUNCTION__, __LINE__);                        \
        }
    
    #define dbg_log_line(lvl, color_n, fmt, ...)                \
        do                                                      \
        {                                                       \
            _DBG_LOG_HDR(lvl, color_n);                         \
            rt_kprintf(fmt, ##__VA_ARGS__);                     \
            _DBG_LOG_X_END;                                     \
        }                                                       \
        while (0)
    
    #define dbg_raw(...)         rt_kprintf(__VA_ARGS__);
    
    #else
    #define dbg_log(level, fmt, ...)
    #define dbg_here
    #define dbg_enter
    #define dbg_exit
    #define dbg_log_line(lvl, color_n, fmt, ...)
    #define dbg_raw(...)
    #endif /* DBG_ENABLE */
    
    #if (DBG_LEVEL >= DBG_LOG)
    #define LOG_D(fmt, ...)      dbg_log_line("D", 0, fmt, ##__VA_ARGS__)
    #else
    #define LOG_D(...)
    #endif
    
    #if (DBG_LEVEL >= DBG_INFO)
    #define LOG_I(fmt, ...)      dbg_log_line("I", 32, fmt, ##__VA_ARGS__)
    #else
    #define LOG_I(...)
    #endif
    
    #if (DBG_LEVEL >= DBG_WARNING)
    #define LOG_W(fmt, ...)      dbg_log_line("W", 33, fmt, ##__VA_ARGS__)
    #else
    #define LOG_W(...)
    #endif
    
    #if (DBG_LEVEL >= DBG_ERROR)
    #define LOG_E(fmt, ...)      dbg_log_line("E", 31, fmt, ##__VA_ARGS__)
    #else
    #define LOG_E(...)
    #endif
    
    #define LOG_RAW(...)         dbg_raw(__VA_ARGS__)
    
    #endif /* defined(RT_USING_ULOG) && define(DBG_ENABLE) */
    
    #ifdef __cplusplus
    }
    #endif
    
    #endif /* RT_DBG_H__ */
    
    

    注释第39行#define RT_DEBUG_COLOR可关闭颜色打印。

  2. 在.c源文件中使用,使用方法和在RT-Thread中一样

注意: 由于Keil C51的不支持C99以上的语法标准,不支持可变宏定义,以上方法无法在Keil C51中使用。

虚拟波形助手:

效果图:

  • 单击可移动红色游标到该位置
  • 鼠标指针移到曲线上可显示该点数值
  • 双击暂停接收波形(关闭端口),再次双击继续接收(打开端口)
  • 在图表区域鼠标滚轮可缩放

测试条件:51单片机STC8G,波特率115200bps

使用方法

菜单栏 - 扩展 - 波形助手打开该功能,软件在收到指定协议的数据后将自动解析为波形。

当前协议:单片机发送数据格式:“0:波形1数值,1:波形2数值,2:波形3数值...\r\n”。其中“\r\n”代表回车并换行,每发送一行代表一次各个波形的Y值,冒号和逗号均为英文半角符,数值可为整数或小数,冒号前的0、1、2、3等表示数据对应于哪个波形。示例:0:-0.912962,1:0.408004\r\n

测试代码,发送正弦、余弦函数值:

#include <math.h>
#include <stdio.h>
void main()
{
    float t = 0;
  	// 初始化...
      
    while(1)
  	{
        printf("0:%f,1:%f\r\n", sin(t), cos(t));
        t += 0.1;
        delay_ms(10);
    }
}

上述代码中printf函数已被重定向输出到串口,故可以直接用printf打印。

如果printf未重定向输出到串口,可以用先用sprintf函数先将字符串输出到数组,然后再调用串口函数发送字符串,效果是等同的:

#include <math.h>
#include <stdio.h>
#includde <string.h>
  
void main()
{
    float t = 0;
    char txt[64];
  	// 初始化...
      
    while(1)
  	{
        sprintf(txt, "0:%f,1:%f\r\n", sin(t), cos(t));
        uart_putstr(UART_1, txt, strlen(txt));
        t += 0.1;
        delay_ms(10);
    }
  }

例如,智能车调试PID时,可以:

#include <stdio.h>

extern int aim_speed, real_speed;
extern float speed_P, speed_I, speed_D;

int main(void)
{
    // 初始化...
    while(1)
    {
        printf("0:%d,1:%d,2:%.3f,3%.3f,4:%.3f", aim_speed, real_speed, speed_P, speed_I, speed_D)
        delay_ms(100);
    }
}

效果如下:

image-20211106184531877

4. 更新日志

  • 2022.01.12 增加两个多条发送行;修复全屏时遮住状态栏(Bug: 多显示屏)
  • 2021.09.22 特性: IAP支持扇区大小不一的MCU(使用扇区描述文件)
  • 2021.09.26 修复Keil编译一次触发两次升级问题
  • 2022.03.30 修复某些情况下启动时自动打开端口的为空;支持使用bin文件和flash描述文件进行升级

5. 问题反馈

提交issue:https://gitee.com/jswyll_com/mcu_assistant/issues

作者邮箱:2439423861@qq.com

GNU LESSER GENERAL PUBLIC LICENSE Version 3, 29 June 2007 Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/> Everyone is permitted to copy and distribute verbatim copies of this license document, but changing it is not allowed. This version of the GNU Lesser General Public License incorporates the terms and conditions of version 3 of the GNU General Public License, supplemented by the additional permissions listed below. 0. Additional Definitions. As used herein, "this License" refers to version 3 of the GNU Lesser General Public License, and the "GNU GPL" refers to version 3 of the GNU General Public License. "The Library" refers to a covered work governed by this License, other than an Application or a Combined Work as defined below. An "Application" is any work that makes use of an interface provided by the Library, but which is not otherwise based on the Library. Defining a subclass of a class defined by the Library is deemed a mode of using an interface provided by the Library. A "Combined Work" is a work produced by combining or linking an Application with the Library. The particular version of the Library with which the Combined Work was made is also called the "Linked Version". The "Minimal Corresponding Source" for a Combined Work means the Corresponding Source for the Combined Work, excluding any source code for portions of the Combined Work that, considered in isolation, are based on the Application, and not on the Linked Version. The "Corresponding Application Code" for a Combined Work means the object code and/or source code for the Application, including any data and utility programs needed for reproducing the Combined Work from the Application, but excluding the System Libraries of the Combined Work. 1. Exception to Section 3 of the GNU GPL. You may convey a covered work under sections 3 and 4 of this License without being bound by section 3 of the GNU GPL. 2. Conveying Modified Versions. If you modify a copy of the Library, and, in your modifications, a facility refers to a function or data to be supplied by an Application that uses the facility (other than as an argument passed when the facility is invoked), then you may convey a copy of the modified version: a) under this License, provided that you make a good faith effort to ensure that, in the event an Application does not supply the function or data, the facility still operates, and performs whatever part of its purpose remains meaningful, or b) under the GNU GPL, with none of the additional permissions of this License applicable to that copy. 3. Object Code Incorporating Material from Library Header Files. The object code form of an Application may incorporate material from a header file that is part of the Library. You may convey such object code under terms of your choice, provided that, if the incorporated material is not limited to numerical parameters, data structure layouts and accessors, or small macros, inline functions and templates (ten or fewer lines in length), you do both of the following: a) Give prominent notice with each copy of the object code that the Library is used in it and that the Library and its use are covered by this License. b) Accompany the object code with a copy of the GNU GPL and this license document. 4. Combined Works. You may convey a Combined Work under terms of your choice that, taken together, effectively do not restrict modification of the portions of the Library contained in the Combined Work and reverse engineering for debugging such modifications, if you also do each of the following: a) Give prominent notice with each copy of the Combined Work that the Library is used in it and that the Library and its use are covered by this License. b) Accompany the Combined Work with a copy of the GNU GPL and this license document. c) For a Combined Work that displays copyright notices during execution, include the copyright notice for the Library among these notices, as well as a reference directing the user to the copies of the GNU GPL and this license document. d) Do one of the following: 0) Convey the Minimal Corresponding Source under the terms of this License, and the Corresponding Application Code in a form suitable for, and under terms that permit, the user to recombine or relink the Application with a modified version of the Linked Version to produce a modified Combined Work, in the manner specified by section 6 of the GNU GPL for conveying Corresponding Source. 1) Use a suitable shared library mechanism for linking with the Library. A suitable mechanism is one that (a) uses at run time a copy of the Library already present on the user's computer system, and (b) will operate properly with a modified version of the Library that is interface-compatible with the Linked Version. e) Provide Installation Information, but only if you would otherwise be required to provide such information under section 6 of the GNU GPL, and only to the extent that such information is necessary to install and execute a modified version of the Combined Work produced by recombining or relinking the Application with a modified version of the Linked Version. (If you use option 4d0, the Installation Information must accompany the Minimal Corresponding Source and Corresponding Application Code. If you use option 4d1, you must provide the Installation Information in the manner specified by section 6 of the GNU GPL for conveying Corresponding Source.) 5. Combined Libraries. You may place library facilities that are a work based on the Library side by side in a single library together with other library facilities that are not Applications and are not covered by this License, and convey such a combined library under terms of your choice, if you do both of the following: a) Accompany the combined library with a copy of the same work based on the Library, uncombined with any other library facilities, conveyed under the terms of this License. b) Give prominent notice with the combined library that part of it is a work based on the Library, and explaining where to find the accompanying uncombined form of the same work. 6. Revised Versions of the GNU Lesser General Public License. The Free Software Foundation may publish revised and/or new versions of the GNU Lesser General Public License from time to time. Such new versions will be similar in spirit to the present version, but may differ in detail to address new problems or concerns. Each version is given a distinguishing version number. If the Library as you received it specifies that a certain numbered version of the GNU Lesser General Public License "or any later version" applies to it, you have the option of following the terms and conditions either of that published version or of any later version published by the Free Software Foundation. If the Library as you received it does not specify a version number of the GNU Lesser General Public License, you may choose any version of the GNU Lesser General Public License ever published by the Free Software Foundation. If the Library as you received it specifies that a proxy can decide whether future versions of the GNU Lesser General Public License shall apply, that proxy's public statement of acceptance of any version is permanent authorization for you to choose that version for the Library.

简介

单片机调试助手,集串口/蓝牙/TCP/UDP调试、IAP升级、波形助手、图像助手等功能一体 展开 收起
README
LGPL-3.0
取消

发行版

暂无发行版

贡献者

全部

近期动态

不能加载更多了
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
C#
1
https://gitee.com/huang-shancan/mcu_assistant.git
git@gitee.com:huang-shancan/mcu_assistant.git
huang-shancan
mcu_assistant
单片机调试助手-windows
master

搜索帮助