• Debug记录(1)


    今天下午在给nRF52832写程序时,莫名遇到了这个错误
    错误id是一个很奇怪的数。
    原代码如下:

    static void timers_init(void)
    {
        
        uint32_t timer_err_code;
        // Initialize timer module.
        APP_TIMER_INIT(APP_TIMER_PRESCALER, APP_TIMER_OP_QUEUE_SIZE, false);
    
        //创建应用定时器	  
        app_timer_create(&m_adc_sampling_timer_id,
    	                   APP_TIMER_MODE_REPEATED,
    	                   saadc_sampling_timeout_handler);
    	  APP_ERROR_CHECK(timer_err_code);
    }
    

    修改后代码如下:

    static void timers_init(void)
    {
        
        uint32_t timer_err_code;
        // Initialize timer module.
        APP_TIMER_INIT(APP_TIMER_PRESCALER, APP_TIMER_OP_QUEUE_SIZE, false);
    
        //创建应用定时器	  
        timer_err_code=app_timer_create(&m_adc_sampling_timer_id,
    	                   APP_TIMER_MODE_REPEATED,
    	                   saadc_sampling_timeout_handler);
    	  APP_ERROR_CHECK(timer_err_code);
    }
    

    经过排查发现,错误id,即变量timer_err_code没有赋值就传递给APP_ERROR_CHECK这个宏,结果导致宏调用了错误处理函数,并进一步导致了程序卡死。

    APP_ERROR_CHECK宏的作用:Macro for calling error handler function if supplied error code any other than NRF_SUCCESS
    

    注意
    1 变量声明要尽可能靠近第一次使用处,避免一次性声明一组没有马上使用的变量。
    2 函数的返回值要清楚,明了,防止使用者误用,理解错误或忽视错误返回码。

  • 相关阅读:
    SAP程序代码中RANGE表的用法注意点
    代码审计学习-1
    应用层隧道之HTTP/HTTPS和DNS
    应用层隧道技术之SSH
    横向移动-常用windows连接和相关命令
    基于MSF的路由转发
    渗透过程中的边界突破(内部分享笔记)
    网络层隧道之PowerCat
    网络层隧道之lcx和nc的使用
    网络层隧道构建之PingTunnel
  • 原文地址:https://www.cnblogs.com/Manual-Linux/p/9456036.html
Copyright © 2020-2023  润新知