NRF52832 study notes (13) - RTT print debug log

I. Background

Log output information to facilitate debugging observes the running state, and the commonly used serial printf similar functions. But in nrf5x serial chip is only one state, if you have used the serial port, by providing a way to display when the Log does not take up the serial port, which is the RTT Viewer output of the simulator JLink.

Second, the print function to initialize

In the main function, the first step is to initiate a print log function log_init(), the function is actually trigger either a serial printer can also be triggered RTT print.

/**@brief Application main function.
 */
int main(void)
{
    bool erase_bonds;

    // Initialize.
    log_init();
    timers_init();
    buttons_leds_init(&erase_bonds);
    power_management_init();
    ble_stack_init();
    gap_params_init();
    gatt_init();
    services_init();
    advertising_init();
    conn_params_init();

    // Start execution.
    NRF_LOG_INFO("Blink example started.")advertising_start();

    // Enter main loop.
    for (;;)
    {
        idle_state_handle();
    }
}

Three, SDK Configuration

Click sdk_config.h file

select Configuration Wizard

3.1 Configuring a serial printer

nRF_Log in Check UART option

to switch back to Text Editor interface, you can find the NRF_LOG_BACKEND_UART_ENABLE already set to 1, the serial port is enabled.

In nrf_log_default_backends.c file, when we enabled NRF_LOG_BACKEND_UART_ENABLE, corresponding to modify the file to the serial port initialization

in nrf_log_backend_uart.c file

here initialize serial port parameters, in accordance with the config.h conducted contents of the documents, while the tube configured with only a foot print output pin.

Note: If you are in the configuration file has the NRF_LOG_BACKEND_UART_ENABLE set to 1, this is not the time to configure the serial port initialization again.

3.2 Configuration RTT Print

nRF_Log in check RTT option

切换回 Text Editor 界面,可以发现已经把 NRF_LOG_BACKEND_RTT_ENABLE 设置为 1,也就是使能了 RTT。

nrf_log_default_backends.c 文件中,当我们使能了 NRF_LOG_BACKEND_RTT_ENABLE 后,对应会修改文件中对 RTT 初始化

四、开始打印日志

4.1 串口打印

打开串口调试助手,波特率设置为 115200

4.2 RTT打印

找到你的 SEGGER 的安装位置,找到驱动版本下的 JLinkRTTViewer.exe

打开后弹出选择界面。这个功能我们必须接上 JLink,设置参数如下,使用 USB 端口输出,目标设备选择 nRF52832_xxAA

五、API调用

5.1 打印普通信息

函数名:
NRF_LOG_INFO
用法:

NRF_LOG_INFO("Template example started."); 

5.2 打印浮点数

函数名:
NRF_LOG_FLOAT
用法:

/**
 * @brief Macro to be used in a formatted string to a pass float number to the log.
 *
 * Use this macro in a formatted string instead of the %f specifier together with
 * @ref NRF_LOG_FLOAT macro.
 * Example: NRF_LOG_INFO("My float number" NRF_LOG_FLOAT_MARKER "\r\n", NRF_LOG_FLOAT(f)))
 */
#define NRF_LOG_FLOAT_MARKER "%s%d.%02d"

/**
 * @brief Macro for dissecting a float number into two numbers (integer and residuum).
 */
#define NRF_LOG_FLOAT(val) (uint32_t)(((val) < 0 && (val) > -1.0) ? "-" : ""),   \
                           (int32_t)(val),                                       \
                           (int32_t)((((val) > 0) ? (val) - (int32_t)(val)       \
                                                : (int32_t)(val) - (val))*100)

• 由 Leung 写于 2020 年 2 月 25 日

• 参考:青风电子社区

发布了91 篇原创文章 · 获赞 136 · 访问量 7万+

Guess you like

Origin blog.csdn.net/qq_36347513/article/details/104500464