Debug support

Middleware has extended debugging capabilities. These consist of different debugging levels and types of debug messages, allowing to track and catch different types of warnings, severe problems or simply output messages program flow messages (trace messages).

Module is highly configurable using library configuration methods. Application must enable some options to decide what type of messages and for which modules it would like to output messages.

With default configuration, printf is used as output function. This behavior can be changed with ESP_CF_DBG_OUT configuration.

For successful debugging, application must:

  • Enable global debugging by setting ESP_CFG_DBG to ESP_DBG_ON

  • Configure which types of messages to output

  • Configure debugging level, from all messages to severe only

  • Enable specific modules to debug, by setting its configuration value to ESP_DBG_ON

Tip

Check ESP Configuration for all modules with debug implementation.

An example code with config and latter usage:

Debug configuration setup
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
/* Modifications of esp_config.h file for configuration */

/* Enable global debug */
#define ESP_CFG_DBG                 ESP_DBG_ON

/*
 * Enable debug types. 
 * Application may use bitwise OR | to use multiple types:
 *    ESP_DBG_TYPE_TRACE | ESP_DBG_TYPE_STATE
 */
#define ESP_CFG_DBG_TYPES_ON        ESP_DBG_TYPE_TRACE

/* Enable debug on custom module */
#define MY_DBG_MODULE               ESP_DBG_ON
Debug usage within middleware
1
2
3
4
5
6
7
8
9
#include "esp/esp_debug.h"

/*
 * Print debug message to the screen
 * Trace message will be printed as it is enabled in types 
 * while state message will not be printed.
 */
ESP_DEBUGF(MY_DBG_MODULE | ESP_DBG_TYPE_TRACE, "This is trace message on my program\r\n");
ESP_DEBUGF(MY_DBG_MODULE | ESP_DBG_TYPE_STATE, "This is state message on my program\r\n");
group ESP_DEBUG

Debug support module to track library flow.

Debug levels

List of debug levels

ESP_DBG_LVL_ALL

Print all messages of all types

ESP_DBG_LVL_WARNING

Print warning and upper messages

ESP_DBG_LVL_DANGER

Print danger errors

ESP_DBG_LVL_SEVERE

Print severe problems affecting program flow

ESP_DBG_LVL_MASK

Mask for getting debug level

Debug types

List of debug types

ESP_DBG_TYPE_TRACE

Debug trace messages for program flow

ESP_DBG_TYPE_STATE

Debug state messages (such as state machines)

ESP_DBG_TYPE_ALL

All debug types

Defines

ESP_DBG_ON

Indicates debug is enabled

ESP_DBG_OFF

Indicates debug is disabled

ESP_DEBUGF(c, fmt, ...)

Print message to the debug “window” if enabled.

Parameters
  • [in] c: Condition if debug of specific type is enabled

  • [in] fmt: Formatted string for debug

  • [in] ...: Variable parameters for formatted string

ESP_DEBUGW(c, cond, fmt, ...)

Print message to the debug “window” if enabled when specific condition is met.

Parameters
  • [in] c: Condition if debug of specific type is enabled

  • [in] cond: Debug only if this condition is true

  • [in] fmt: Formatted string for debug

  • [in] ...: Variable parameters for formatted string