This blog is to describe some hints if you are using the nRF Connect SDK for development.

Cover

  • How to enable the Debugger and set the breakpoint through Segger Embedded Studio
  • How to enable the Logger and print out the log through RTT terminal instead of UART
  • How to use the menuconfig to enable the specify configuration

How to enable the Debug option inside the KConfig

https://docs.zephyrproject.org/latest/reference/kconfig/CONFIG_DEBUG_OPTIMIZATIONS.html

CONFIG_LOG=y
CONFIG_LOG_DEFAULT_LEVEL=4
CONFIG_DEBUG_OPTIMIZATIONS=y
CONFIG_LOG_PRINTK=y

How to enable the LOGGER and print out the log through RTT

https://docs.zephyrproject.org/latest/reference/kconfig/CONFIG_USE_SEGGER_RTT.html

CONFIG_LOG=y
CONFIG_LOG_DEFAULT_LEVEL=4
CONFIG_DEBUG_OPTIMIZATIONS=y
CONFIG_LOG_PRINTK=y

# Segger RTT
CONFIG_USE_SEGGER_RTT=y
CONFIG_RTT_CONSOLE=y
CONFIG_UART_CONSOLE=n
CONFIG_LOG_BACKEND_RTT=y
CONFIG_LOG_BACKEND_UART=n

CONFIG_ASSERT=y
CONFIG_STACK_SENTINEL=y
CONFIG_LOG_PROCESS_THREAD=y

https://docs.zephyrproject.org/latest/reference/logging/index.html

Logger can be controlled using API defined in include/logging/log_ctrl.h. Logger must be initialized before it can be used. Optionally, user can provide function which returns timestamp value. If not provided, k_cycle_get_32 is used for timestamping. log_process() function is used to trigger processing of one log message (if pending). Function returns true if there is more messages pending.

Following snippet shows how logger can be processed in simple forever loop.

#include <logging/log_ctrl.h>

void main(void)
{
     log_init();
     
     LOG_INF("Example is started!");

     while (1) {
             if (log_process(false) == false) {
                     /* sleep */
             }
     }
}

How to check KConfig (configuration) on the project

Open the .config (inside the build\zephyr\)

Inside the .config, all the configuration are listed.