您当前的位置: 首页 >  嵌入式

仙剑情缘

暂无认证

  • 3浏览

    0关注

    333博文

    0收益

  • 0浏览

    0点赞

    0打赏

    0留言

私信
关注
热门博文

基于嵌入式ARM环境下运行的lvgl系统Debug打印配置

仙剑情缘 发布时间:2020-03-24 00:37:40 ,浏览量:3

  • 在lv_conf.h中定义LV_USE_DEBUG为1
    #define LV_USE_DEBUG        1
  • 在lv_conf.h中定义LV_USE_LOG为1
    #define LV_USE_LOG      1
  • 配置打印等级

如果要打印所有的级别,将LV_LOG_LEVEL设成LV_LOG_LEVEL_TRACE,以下是警告及错误级别的信息会打印

配置打印接口,如果使用printf方式打印,将LV_LOG_PRINTF设为1,现使用RTT打印,配置如下
* 1: Print the log with 'printf';
 * 0: user need to register a callback with `lv_log_register_print_cb`*/
#  define LV_LOG_PRINTF   0
五个等级的打印都是调用函数lv_log_add函数,函数实现如下
/**
 * Add a log
 * @param level the level of log. (From `lv_log_level_t` enum)
 * @param file name of the file when the log added
 * @param line line number in the source code where the log added
 * @param dsc description of the log
 */
void lv_log_add(lv_log_level_t level, const char * file, int line, const char * dsc)
{
    if(level >= _LV_LOG_LEVEL_NUM) return; /*Invalid level*/

    if(level >= LV_LOG_LEVEL) {

#if LV_LOG_PRINTF
        static const char * lvl_prefix[] = {"Trace", "Info", "Warn", "Error"};
        printf("%s: %s \t(%s #%d)\n", lvl_prefix[level], dsc, file, line);
#else
        if(custom_print_cb) custom_print_cb(level, file, line, dsc);
#endif
    }
}
LV_LOG_PRINTF为0时,调用了函数指针custom_print_cb
if(custom_print_cb) custom_print_cb(level, file, line, dsc);
那么这个函数指针需要指向用户注册的打印接口函数,使用lv_log_register_print_cb函数来注册,函数实现 如下
/**
 * Register custom print/write function to call when a log is added.
 * It can format its "File path", "Line number" and "Description" as required
 * and send the formatted log message to a consol or serial port.
 * @param print_cb a function pointer to print a log
 */
void lv_log_register_print_cb(lv_log_print_g_cb_t print_cb)
{
    custom_print_cb = print_cb;
}
 准备RTT打印相关文件配置,具体可参考https://blog.csdn.net/mygod2008ok/article/details/102926458
  • 注册自己的打印函数 
    lv_log_register_print_cb(my_printf);
函数指针类型原型如下
typedef void (*lv_log_print_g_cb_t)(lv_log_level_t level, const char *, uint32_t, const char *);
自己的打印函数

void my_printf(lv_log_level_t level, const char *file, uint32_t line, const char *dsc)
{
	NRF_LOG_INFO("level:%d,file:%s,line:%d,dsc:%s",level,file,line,dsc);
}
测试验证,故意将用户数据传入NULL,等下在lv定时器回调操作空指针,引发的一个打印测试
    /*Create a line meter*/

    lv_obj_t* lmeter;

    lmeter = lv_lmeter_create(lv_scr_act(), NULL);

    lv_lmeter_set_range(lmeter, 0, 60);

    lv_lmeter_set_value(lmeter, 10);

    lv_lmeter_set_scale(lmeter, 360, 15);

 
   
    lv_lmeter_set_style(lmeter, LV_LMETER_STYLE_MAIN,&style_lmeter);

    lv_obj_set_size(lmeter, 80, 80);

    lv_obj_align(lmeter, slider, LV_ALIGN_OUT_BOTTOM_MID, 0, 20);

   

    lv_task_t* t = lv_task_create(line_meter_task, 200, LV_TASK_PRIO_MID, NULL);

    lv_task_ready(t);
回调引用空指针引发异常
void line_meter_task(lv_task_t* t)
{

    static uint8_t progress;

    lv_obj_t* lmeter = t->user_data;

    progress += 10;

    if (progress == 60)
    {

        progress = 0;

    }

    lv_lmeter_set_value(lmeter, progress);
}
 烧录并运行,打开RTT Viewer

打印的等级定义如下

/*Possible log level. For compatibility declare it independently from `LV_USE_LOG`*/

#define LV_LOG_LEVEL_TRACE 0 /**< A lot of logs to give detailed information*/
#define LV_LOG_LEVEL_INFO 1  /**< Log important events*/
#define LV_LOG_LEVEL_WARN 2  /**< Log if something unwanted happened but didn't caused problem*/
#define LV_LOG_LEVEL_ERROR 3 /**< Only critical issue, when the system may fail*/
#define LV_LOG_LEVEL_NONE 4 /**< Do not log anything*/
#define _LV_LOG_LEVEL_NUM 5 /**< Number of log levels */
找到出错文件lv_debug.c的167行    在这打个断点调试,然后运行出函数,定位到出错点  继续找到void line_meter_task(lv_task_t* t)函数   找到void line_meter_task(lv_task_t* t)函数注册的地方  

 

 

 

 

关注
打赏
1658017818
查看更多评论
立即登录/注册

微信扫码登录

0.1713s