Logging is very important for developing embedded products, especially for connection based wireless products because the use of breakpoints will probably result in dropped connections. Whereas, we can easily address problems by walking through the log. This article will introduce a simple implementation of logging on EFR32 based devices. The key point of this article is to introduce a way to classify the log into different levels, and each level of log has its own identifier.
Introduction
Let’s start with 2 design sketches, which demonstrate outputting the log via RTT and VCOM(UART).
Figure 1. Using RTT
Figure 2. Using VCOM
From the pictures, you can see the different level of logging uses different colors, this article introduces 5 levels of logging as below.
Type
Error(Highest Level)
Warning
Information
Debug
Verbose(Lowest Level)
Color
Red
Yellow
Blue
Green
White
Table 1.Log types and colors
Settings
The symbol LOG_PORT, defined in log.h, can be set to SEGGER_JLINK_VIEWER or PORT_VCOM to determine which terminal the output should be sent to.
SEGGER_JLINK_VIEWER – the log will be out from J-Link RTT.
PORT_VCOM
If VCOMis enabled, the log will be out from VCOM via USB.
If VCOMis disabled, the log will be out from the UART TX pin directly.
The definitionofLOG_LEVEL in log.h determines which level of logging should be output to the terminal. As you can see from the table 1, error has the highest level while verbose has the lowest level. For example, If the LOG_LEVELis defined as information level, then error, warning and information log will be sent to terminal, the debug and verbose log which have lower level than information will not be sent to the terminal. See figure 3, which shows the log as information level without modifying anything from figure 1.
Figure 3. Log with information level
Logging Functions
There are 5 corresponding functions to send the log, the input parameter of these five functions is the same as standard printf();.
LOGE() – Send ERROR log.
LOGW() – Send WARNING log.
LOGI() – Send INFORMATION log.
LOGD() – Send DEBUG log.
LOGV() – Send VERBOSE log.
How to migrate it to your project
Follow below steps to enable this feature in your project and customize it to meet your requirements.
Add #include “log.h” and INIT_LOG(); to the initialization area, just as the attached main.c.
Modify the project settings, add ${workspace_loc:/${ProjName}/third_party/RTT}/"${workspace_loc:/${ProjName}/log_system}" to include paths
Set the HAL_VCOM_ENABLE symbol in hal-config.h to 1 if needed.
After all the above is done, your project should be able to send the log to the terminal.
Some notes.
The main.c in the attachment is based on Bluetooth SDK v2.8.1, if you are using other version than it, it might not work if you simply replace it because the structure changes of different SDKs. In this case, you need to modify the code manually as the second half of step 2.
This log system can be used to any EFR32 devices and it should be possible to use it on EFM32 device directly or with a few changes.
Bluetooth Low Energy
Knowledge Base Articles
this is amazing! thank you
0
Hi,
Is it possible to use the RTT Viewer while putting the device in sleep mode? It appears that when I use connect to the device using RTT Viewer, the MCU stays awake permanently. I'm on a EFR32BG13P. It would be great if this debug method would be usable simultaneously with the Energy profiler (even without code correlation).
0
Hi,
Sorry for the late response, but I don't think so, at least in my daily use of the RTT, it seems the device never sleeps.
[Deprecated] KBA_BT_1206: Log System
Note: This KBA has been marked as deprecated. A more updated KBA can be found here:
Log System
Logging is very important for developing embedded products, especially for connection based wireless products because the use of breakpoints will probably result in dropped connections. Whereas, we can easily address problems by walking through the log. This article will introduce a simple implementation of logging on EFR32 based devices. The key point of this article is to introduce a way to classify the log into different levels, and each level of log has its own identifier.
Introduction
Let’s start with 2 design sketches, which demonstrate outputting the log via RTT and VCOM(UART).
Figure 1. Using RTT
Figure 2. Using VCOM
From the pictures, you can see the different level of logging uses different colors, this article introduces 5 levels of logging as below.
Table 1.Log types and colors
Settings
The symbol LOG_PORT, defined in log.h, can be set to SEGGER_JLINK_VIEWER or PORT_VCOM to determine which terminal the output should be sent to.
The definition of LOG_LEVEL in log.h determines which level of logging should be output to the terminal. As you can see from the table 1, error has the highest level while verbose has the lowest level. For example, If the LOG_LEVEL is defined as information level, then error, warning and information log will be sent to terminal, the debug and verbose log which have lower level than information will not be sent to the terminal. See figure 3, which shows the log as information level without modifying anything from figure 1.
Figure 3. Log with information level
Logging Functions
There are 5 corresponding functions to send the log, the input parameter of these five functions is the same as standard printf();.
How to migrate it to your project
Follow below steps to enable this feature in your project and customize it to meet your requirements.
After all the above is done, your project should be able to send the log to the terminal.
Some notes.
Hi,
Is it possible to use the RTT Viewer while putting the device in sleep mode? It appears that when I use connect to the device using RTT Viewer, the MCU stays awake permanently. I'm on a EFR32BG13P. It would be great if this debug method would be usable simultaneously with the Energy profiler (even without code correlation).
Hi,
Sorry for the late response, but I don't think so, at least in my daily use of the RTT, it seems the device never sleeps.
Thanks,
Kevin