Outputting Debug Logs
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). 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\platform\boards\board_SK.h for details) of the corresponding module according to the output port configured, and register corresponding Send and Flush APIs. See bsp_log_init() for details. The APIs are provided as follows when UART is configured as the output port.
void bsp_log_init(void)
{
#if (APP_LOG_ENABLE == 1)
#if (APP_LOG_PORT == 0)
bsp_uart_init();
#elif (APP_LOG_PORT == 1)
SEGGER_RTT_ConfigUpBuffer(0, NULL, NULL, 0, SEGGER_RTT_MODE_BLOCK_IF_FIFO_FULL);
#endif
#if (APP_LOG_PORT <= 2)
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;
#if (APP_LOG_PORT == 0)
app_log_init(&log_init, bsp_uart_send, bsp_uart_flush);
#elif (APP_LOG_PORT == 1)
app_log_init(&log_init, bsp_segger_rtt_send, NULL);
#elif (APP_LOG_PORT == 2)
app_log_init(&log_init, bsp_itm_send, NULL);
#endif
app_assert_init();
#endif
#endif
}
- 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). 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.
You also need to configure in J-Link RTT Viewer, as shown in Figure 31.
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 30 and is placed at 0x00805000, then 0x00805000 can be entered in the Address field.
If you choose GCC for compilation, modifications shown in Figure 30 are not required. The address to be entered for RTT Control Block in J-Link RTT Viewer should be the address of _SEGGER_RTT in the .map file generated by the compilation project.