-
Notifications
You must be signed in to change notification settings - Fork 3
Debugging CLI
A command line interface is available for debugging purposes. It is accessible over USB or a UART and can be used for testing and to get information about the avionics' state.
The command line interface can be configured to be accessible via USB or via any of the four UART interfaces on the MCU board. Each of the configuration headers has a Console section which controls what interface the command line will be available on.
In order to make the debugging command line available over a USB serial interface, in your variant configuration header file you must enable a USB CDC interface and configure the console to use that interface. The required sections of the variant configuration file look something like this:
// USB
#define ENABLE_USB
#define ENABLE_USB_CDC_PORT_0
// Console
#define ENABLE_CONSOLE
#define CONSOLE_CDC_PORT 0After compiling and uploading with the correct configuration the MCU board should appear as a serial interface when connected to a computer over USB.
The best way to use the USB serial interface on macOS or Linux is with GNU Screen. The MCU board will appear as a tty devices in /dev. On Linux it will probably be something like /dev/ttyACM0, on macOS it will appear as something of the form /dev/tty.usbmodem#####. Once you have found the name of the serial interface, you can open it with screen by running the following command (replace DEVICE_NAME with the name of the serial interface):
screen DEVICE_NAMEOn Linux, it may be necessary to add your user to the dialout group in order to have the necessary permissions to access serial devices.
On Windows, you can use putty to access the command line interface. You can get putty from www.putty.org.
To find out which COM port the MCU board shows up as, open Device Manager and then connect the MCU board. Look for a new item to show up under the Ports (COM & LPT) section, as shown in the image below.
Once you have identified the port, you can connect to it with Putty by choosing Serial as the connection type within Putty and entering the COM port name in the Serial Line field. The speed and other serial settings to not matter.
To make the CLI available via one of the UARTs on the MCU board, the console section of the variant configuration header section should look something like this:
// Console
#define ENABLE_CONSOLE
#define CONSOLE_UART uart3_gAny of the 4 UARTS can be used. Make sure that the UART is enabled and configured with an appropriate baud rate and that the UART is not being used for anything else.
New commands can be added to the debugging interface in debug-commands.c. Every command needs three things:
- A function to be run when the command is called
- A macro for the name of the command
- A macro with a help string for the command
Command functions are provided arguments and a console descriptor which they can use to print. The arguments provided to the function are space delimited. The first argument is always the command name.
Here is an example of a command that echos its arguments:
#define DEBUG_ECHO_NAME "echo"
#define DEBUG_ECHO_HELP "Echos it's arguments.\nUsage: echo <string>"
static void debug_echo (uint8_t argc, char **argv, struct console_desc_t *console)
{
for (uint8_t i = 1; i < argc, i++) {
console_send_str(console, argv[i]);
console_send_str(console, " ");
}
console_send_str(console, "\n");
}The command must also be added to the list of debugging commands, which is at the end of debug-commands.c. The entry for our echo command would look like this:
{.func = debug_echo, .name = DEBUG_ECHO_NAME, .help_string = DEBUG_ECHO_HELP}