Skip to content

Debugging

Debug is mainly made with serial communication, using FTDI to UART or native USB when available. See Serial Ports to check compatibilities with different microcontrollers.

VS Code includes a terminal with capabilities to work with serial communications. The procedure is easy:

  1. Upload the firmware
  2. Open the terminal to see debug output (push PlatformIO terminal button on bottom bar)
  3. Upload another firmware, PlatformIO will take care of closing the previous open serial
  4. After new code upload the terminal will be open again automatically

Also there are other terminal applications available like the popular Putty, Termite in windows and Minicom/Picocom in linux/mac, but PlatformIO can't manage this terminals to open/close automatically when you are uploading code.

Serial Debug Configuration

By default the debug is enabled with the configuration of rhio-pinmap. These macros are used on the background. You can add this macros to your conf-user.h to overwrite with your own configuration.

// File conf-user.h
#define USE_SERIAL false
#define USE_SERIAL_SOFTWARE false
#define SERIAL_DEBUG -1
#define SERIAL_DEBUG_BAUDS 115200
#define SERIAL_DEBUG_RX 0  //
#define SERIAL_DEBUG_TX 0
#define SERIAL_DEBUG_WAIT false

Note

All properties are described in Serial Conf

This options may be different for each microcontroller, again, please take a look at Serial Ports and these examples.

// Serial Debug in ESP32
#define USE_SERIAL true
#define USE_SERIAL_SOFTWARE false
#define SERIAL_DEBUG Serial
#define SERIAL_DEBUG_BAUDS 115200
#define SERIAL_DEBUG_RX 0  //
#define SERIAL_DEBUG_TX 0
#define SERIAL_DEBUG_WAIT false

// Serial Debug in SAMD21
#define USE_SERIAL true
#define USE_SERIAL_SOFTWARE false
#define SERIAL_DEBUG SerialUSB
#define SERIAL_DEBUG_BAUDS 115200
#define SERIAL_DEBUG_RX 0  //
#define SERIAL_DEBUG_TX 0
#define SERIAL_DEBUG_WAIT true  // On Native USB wait for serial enabled

// Software Serial Debug in Duino Uno (requires external FTDI to USB)
#define USE_SERIAL true
#define USE_SERIAL_SOFTWARE true
#define SERIAL_DEBUG SERIAL_SOFTWARE
#define SERIAL_DEBUG_BAUDS 115200
#define SERIAL_DEBUG_RX SDA  // Use I2C port as Software Serial.
#define SERIAL_DEBUG_TX SCL  // Other pins may be used, as IO0-7, 1Wire, Spi...
#define SERIAL_DEBUG_WAIT false

The most important part may be the macro SERIAL_DEBUG that contains an Arduino Hardware Serial object or -1 to disable it.

Configure platformio.ini

To open a terminal console, PlatformIO needs to know which is the serial port to listen to.

Configure platformio.ini:

[user]
upload_port = COMx or /dev/ttyXXX
monitor_port = COMx or /dev/ttyXXX
monitor_speed = 115200

Connect the microcontroller to the computer, a new COM port should be created, see Device Manager on Windows to find COMx (where x is a random number). In Linux/Mac look at directory /dev, a file with name ttyUSBx or ttyACMx is the COM port. Update upload_port and monitor_port with the name of your serial port.

Debug Level

Debug messages are grouped by type:

  • error
  • warning
  • info
  • verbose

The macro DEBUG_LEVEL (conf-user.h) contains a number with the level of debug.

// debug levels:
//    1 = error
//    2 = 1 + warning
//    3 = 2 + info
//    4 = 3 + verbose
//    0 = off

// Show only error messages
#define DEBUG_LEVEL 1

// Show error + warning
#define DEBUG_LEVEL 2

// Show error + warning + info
#define DEBUG_LEVEL 3

// Show error + warning + info + verbose (more info)
#define DEBUG_LEVEL 4

// Disable all (do not show messages)
#define DEBUG_LEVEL 0

Debug messages starts with a letter indicating what kind of message are:

  • [E] = error
  • [W] = warning
  • [I] = info
  • [V] = verbose

Test Output

This is a typical debug when the application starts:

------------------------------------
RHOMB.IOT - The Modular IoT Firmware
       version 0.1.0

[I] 0 setup MAIN interruption on pin: 0
[I] 0 INIT ESP32 SPIFFS Memory
[I] 0 Rolling Log File
[I] 0 INIT Timer
[I] 0 Use default config - Version: 1
[I] 0 [info] Previus config loaded
[I] 0 SET Opmode: 1
[I] 0 SET new device ID: 4245060915
[I] 0 INIT device
[I] 0 SET OPMODE NORMAL
[I] 1 SET Opmode: 1
[I] 2 Enable WiFi
[I] 2 home: 1111aaaa
[I] 2 Trying to connect WiFi...: 255
[I] 3 Wifi Connected
[I] 3 SET Opmode: 4

Comments