Beware that this post is related to an SDK in maintenance mode
More Info: Consider nRF Connect SDK for new designs
This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

How to send logging via cli over UART

Dear support team,

I would like to simultaneously use logging and CLI via UART in an application running on the NRF52810 with Softdevice S112.

In my application, I need to use UART (and not on RTT).

In my "main.c", I am calling

  • Log_Init(): Mainly calling NRF_LOG_INIT(NULL)
    I don't call the macro "NRF_LOG_DEFAULT_BACKENDS_INIT()" (according to Link)
  • CLI_Init(): Calling nrf_cli_init(...)
  • CLI_Start(): Calling nrf_cli_start(&m_cli_uart);

CLI and CLI via UART are defined by these macros:

NRF_CLI_UART_DEF(m_cli_uart_transport, 0, 64, 16);
NRF_CLI_DEF(m_cli_uart,
            "my-app:~$ ",
            &m_cli_uart_transport.transport,
            '\r',
            CLI_APP_LOG_QUEUE_SIZE);

Logging is always done with the NRF_LOG_INFO() macro.

At current, I only receive those logs

  • which are invoked in "main" and
  • which are followed by a NRF_LOG_FLUSH(). ("Followed" means that at least one NRF_LOG_FLUSH() is needed before entering the infinite task loop to see the log output.)

I would also like to do some logging in subroutines, but NRF_LOG_FLUSH() can only be called in "main" or in an assert handler (see https://devzone.nordicsemi.com/f/nordic-q-a/50683/nrf_log_flush-issue).

What am I doing  wrong?

Here are my potentially relevant CLI and LOG settings in sdk_config.h:

#define NRF_MPU_LIB_CLI_CMDS 0
#define NRF_BALLOC_CLI_CMDS 1
#define NRF_CLI_ENABLED 1
#define NRF_CLI_ARGC_MAX 12
#define NRF_CLI_BUILD_IN_CMDS_ENABLED 1
#define NRF_CLI_CMD_BUFF_SIZE 256
#define NRF_CLI_ECHO_STATUS 1
#define NRF_CLI_WILDCARD_ENABLED 0
#define NRF_CLI_METAKEYS_ENABLED 0
#define NRF_CLI_PRINTF_BUFF_SIZE 23
#define NRF_CLI_HISTORY_ENABLED 1
#define NRF_CLI_HISTORY_ELEMENT_SIZE 32
#define NRF_CLI_HISTORY_ELEMENT_COUNT 8
#define NRF_CLI_VT100_COLORS_ENABLED 0
#define NRF_CLI_STATISTICS_ENABLED 0
#define NRF_CLI_LOG_BACKEND 1
#define NRF_CLI_USES_TASK_MANAGER_ENABLED 0
#define NRF_CLI_UART_ENABLED 1
#define NRF_QUEUE_CLI_CMDS 0
#define TASK_MANAGER_CLI_CMDS 0
#define NRF_LOG_CLI_CMDS 1
#define NRF_CLI_BLE_UART_CONFIG_LOG_ENABLED 0
#define NRF_CLI_BLE_UART_CONFIG_LOG_LEVEL 3
#define NRF_CLI_BLE_UART_CONFIG_INFO_COLOR 0
#define NRF_CLI_BLE_UART_CONFIG_DEBUG_COLOR 0
#define NRF_CLI_LIBUARTE_CONFIG_LOG_ENABLED 0
#define NRF_CLI_LIBUARTE_CONFIG_LOG_LEVEL 3
#define NRF_CLI_LIBUARTE_CONFIG_INFO_COLOR 0
#define NRF_CLI_LIBUARTE_CONFIG_DEBUG_COLOR 0
#define NRF_CLI_UART_CONFIG_LOG_ENABLED 1
#define NRF_CLI_UART_CONFIG_LOG_LEVEL 3
#define NRF_CLI_UART_CONFIG_INFO_COLOR 0
#define NRF_CLI_UART_CONFIG_DEBUG_COLOR 0

#define NRF_CLI_LOG_BACKEND 1
#define NRF_LOG_CLI_CMDS 1
#define NRF_CLI_BLE_UART_CONFIG_LOG_ENABLED 0
#define NRF_CLI_BLE_UART_CONFIG_LOG_LEVEL 3
#define NRF_CLI_LIBUARTE_CONFIG_LOG_ENABLED 0
#define NRF_CLI_LIBUARTE_CONFIG_LOG_LEVEL 3
#define NRF_CLI_UART_CONFIG_LOG_ENABLED 1
#define NRF_CLI_UART_CONFIG_LOG_LEVEL 3

Do you need any further information?

Parents
  • Hi Amanda,
    thank you!

    I was finally able to receive the complete log output by combining NRF_LOG_PROCESS() and CLI_Process().
    Is this the intended way to do it?

    while (m_uart_active)
        {
          if (!NRF_LOG_PROCESS())
          {
            CLI_Process();
            idle_state_handle();
          }
        }

    So I found a working solution. Thank you, feel free to close this issue.

Reply
  • Hi Amanda,
    thank you!

    I was finally able to receive the complete log output by combining NRF_LOG_PROCESS() and CLI_Process().
    Is this the intended way to do it?

    while (m_uart_active)
        {
          if (!NRF_LOG_PROCESS())
          {
            CLI_Process();
            idle_state_handle();
          }
        }

    So I found a working solution. Thank you, feel free to close this issue.

Children
No Data
Related