CN / EN
Doc Feedback
Thanks for your interest, welcome to contact us.
Thanks for your feedback

Output Debug Logs

The GR551x SDK supports outputting debug logs of applications from hardware ports in a customized output mode. Hardware ports include UART, J-Link RTT, and ARM Instrumentation Trace Macrocell (ARM ITM). The GR551x SDK provides an APP LOG module to facilitate log output. To use the APP LOG module, users need to enable APP_LOG_ENABLE in custom_config.h, and configure APP_LOG_PORT based on the needed output port.

Module Initialization

After configuration, you need to set log parameter by calling app_log_init() during peripheral initialization and to initialize the APP LOG module by registering log output APIs and Flush APIs. The APP LOG module supports using the printf() (a C standard library function) and APP LOG APIs to output debug logs. If you use APP LOG APIs, you can optimize logs by setting log level, log format, filter type, or other parameters; if you use printf(), the LOG parameter can be set to NULL.

Call the initialization function (see SDK_Folder\components\libraries\bsp\bsp.h for details) of the corresponding module according to the output port configured, and register corresponding Send and Flush APIs. See user_log_debug_init() for details. The APIs are provided as follows when UART is configured as the output port.

static void user_log_debug_init(void)
{
    app_log_init_t log_init;

    log_init.filter.level = APP_LOG_LVL_DEBUG;
    log_init.fmt_set[APP_LOG_LVL_ERROR] = APP_LOG_FMT_ALL & (~APP_LOG_FMT_TAG);
    log_init.fmt_set[APP_LOG_LVL_WARNING] = APP_LOG_FMT_LVL;
    log_init.fmt_set[APP_LOG_LVL_INFO] = APP_LOG_FMT_LVL;
    log_init.fmt_set[APP_LOG_LVL_DEBUG] = APP_LOG_FMT_LVL;

    app_log_init(&log_init, bsp_uart_send, bsp_uart_flush);

#if APP_LOG_STORE_ENABLE
    app_log_store_info_t store_info;
    app_log_store_op_t   op_func;

    store_info.nv_tag   = APP_LOG_NVDS_TAG;
    store_info.db_addr  = APP_LOG_DB_START_ADDR;
    store_info.db_size  = APP_LOG_DB_SIZE;
    store_info.blk_size = APP_LOG_ERASE_BLK_SIZE;

    op_func.flash_init  = hal_flash_init;
    op_func.flash_erase = hal_flash_erase;
    op_func.flash_write = hal_flash_write;
    op_func.flash_read  = hal_flash_read;
    op_func.time_get    = NULL;

    app_log_store_init(&store_info, &op_func);
#endif

}
Note:
  • The input parameters of app_log_init() include the log initialization parameter, log output API, and Flush API (registration not required).
  • GR551x SDK provides an APP LOG STORE module, which supports storing the debugging logs in flash and outputting the logs from flash. To use the APP LOG STORE module, users need to enable APP_LOG_STORE_ENABLE in custom_config.h. This module is configured in the ble_app_rscs project (in SDK_Folder\projects\ble\ble_peripheral\ble_app_rscs), which can be used as a reference for users to use the APP LOG STORE module.
  • Application logs output by using printf() cannot be stored by the APP LOG STORE module.

When the debugging logs are output through UART, the implemented log output API and Flush API are bsp_uart_send and bsp_uart_flush, respectively. bsp_uart_send implements app_uart asynchronous output API (app_uart_transmit_async) and hal_uart synchronous output API (hal_uart_transmit). Users can choose a proper log output port according to specific applications. As a uart_flush API, bsp_uart_flush is used to output the to-be-sent data cached in the memory in interrupt mode. Contents in both bsp_uart_send and bsp_uart_flush can be overwritten by users.

When the debugging logs are output through J-Link RTT or ARM ITM, the implemented log output APIs are bsp_segger_rtt_send() and bsp_itm_send(). No Flush API is implemented when either J-Link RTT or ARM ITM is configured as the output port.

Application

After completing initialization of the APP LOG module, you can use any of the following four APIs to output debug logs:

  • APP_LOG_ERROR()
  • APP_LOG_WARNING()
  • APP_LOG_INFO()
  • APP_LOG_DEBUG()

In interrupt output mode, call app_log_flush() function to output all the debug logs cached, to ensure that all debug logs are output before the SoC is reset or the system enters the Sleep Mode.

To output logs through J-Link RTT, it is recommended to modify SEGGER_RTT.c as follows.

Figure 31 To create an RTT Control Block and place it at 0x00805000

You also need to configure in J-Link RTT Viewer, as shown in Figure 32.

Figure 32 To configure J-Link RTT Viewer

The address of RTT Control Block is specified in Address, the value of which can be obtained by inquiring the address of the _SEGGER_RTT structure in the .map file (generated during project compilation). If an RTT Control Block has been created as recommended in Figure 31 and is placed at 0x00805000, then 0x00805000 can be entered in the Address field.

Figure 33 To obtain the RTT Control Block address

Scan to follow

Open WeChat, use "Scan" to follow.