DBG
Introduction
Debug pins (DBG) are specialized GPIO pins that provide a low-level serial interface for debugging, system monitoring, and recovery operations on the Mecha Comet. These pins enable direct communication with the system's bootloader and operating system, facilitating effective diagnostics and troubleshooting.
Purpose of Debug Pins
- Low-Level System Logging: DBG pins provide access to critical system information, including boot messages, kernel logs, and system status, aiding in diagnosing boot failures and runtime issues.
- Bootloader Interaction: They allow direct interaction with the U-Boot bootloader, enabling firmware debugging, boot parameter modification, and firmware flashing.
- System Recovery: DBG pins can be used for emergency recovery operations, such as reflashing firmware or loading alternative bootloaders when standard boot methods fail.
- Headless Debugging: They enable remote debugging and system monitoring without requiring a graphical interface, crucial for embedded and headless environments.
Mecha Comet Debug Pin Mapping
On the Mecha Comet device, the debug pins are mapped as follows:
Signal | Pin | Function |
---|---|---|
DBG TX | GPIOX | UART Transmit |
DBG RX | GPIOY | UART Receive |
Accessing the Debug Interface
- Hardware Connection
- Use a USB-to-serial adapter (e.g., FTDI, CP2102) to connect the DBG TX and RX pins to Mecha comet device.
- Connect:
- DBG TX → USB-Serial RX
- DBG RX → USB-Serial TX
- GND → GND
- Set the baud rate (typically 115200 baud) for communication.
- Software Setup
- On Linux, use
screen
orminicom
:$ screen /dev/ttyUSB0 115200
- On Windows, use PuTTY or Tera Term.
- On Linux, use
Debug Pin Usage in Mecha Comet
Debug Pin Usage on Mecha Comet
- Serial Console Access: DBG pins provide access to the U-Boot bootloader and Linux kernel logs.
- U-Boot Interaction: Interrupt the boot process by pressing a key during startup to enter U-Boot mode, allowing for firmware flashing and boot parameter modification.
- Kernel Debugging: Use
dmesg
to view real-time kernel logs and debug boot failures.
Example Code for Debugging
- Python
- C
Python Example
import serial
ser = serial.Serial('/dev/ttyS0', 115200)
ser.write(b'Hello, Debug!\n')
ser.close()
To Run the Python Script on the Mecha Comet:
- Save the script as
debug_example.py
. - Make sure you have
pyserial
installed:
$ pip install pyserial
- Run the script:
$ python3 debug_example.py
- Ensure you have the necessary permissions to access Debug pins. You may need to run the script with
sudo
.
C Example (UART Communication)
#include <stdio.h>
#include <fcntl.h>
#include <termios.h>
#include <unistd.h>
int main() {
int fd = open("/dev/ttyS0", O_RDWR | O_NOCTTY);
struct termios tty;
tcgetattr(fd, &tty);
cfsetispeed(&tty, B115200);
cfsetospeed(&tty, B115200);
tcsetattr(fd, TCSANOW, &tty);
write(fd, "Hello, Debug!", 13);
close(fd);
return 0;
}
To Compile and Run the C Program on the Mecha Comet:
- Save the code as
debug_example.c
. - Compile the code:
$ gcc -o debug_example debug_example.c
- Run the program:
$ ./debug_example
- Ensure you have the necessary permissions to access Debug pins. You may need to run the program with
sudo
. - Check the serial console for output.
Rust Example
use std::fs::OpenOptions;
use std::io::Write;
fn main() {
let mut serial = OpenOptions::new().write(true).open("/dev/ttyS0").unwrap();
serial.write_all(b"Hello, Debug!\n").unwrap();
}
To Run the Rust Program on the Mecha Comet:
- Save the code as
debug_example.rs
. - Make sure you have Rust installed:
$ curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
- Compile the code:
$ rustc debug_example.rs
Use Cases
- Real-Time System Health Monitoring: DBG pins enable continuous logging of critical system events, providing valuable insights into system health and performance. This facilitates early detection of potential issues, aiding in proactive maintenance and troubleshooting.
- Remote Headless System Debugging and Management: DBG pins provide a reliable serial console for remote access to headless systems, eliminating the need for physical access. This allows for efficient debugging, configuration, and management of systems deployed in remote or inaccessible locations.
- Emergency Firmware Recovery and System Restoration: In critical situations where standard boot methods fail due to firmware corruption or system instability, DBG pins offer a reliable pathway for restoring or reflashing firmware via UART. This ensures system resilience and minimizes downtime.