zmk_mf68/docs/docs/development/usb-logging.md

83 lines
2.7 KiB
Markdown
Raw Normal View History

2020-07-08 01:58:12 +10:00
---
title: USB Logging
---
2020-08-30 08:05:43 +10:00
import Tabs from '@theme/Tabs';
import TabItem from '@theme/TabItem';
2020-07-08 01:58:12 +10:00
## Overview
If you are developing ZMK on a device that does not have a built in UART for debugging and log/console output,
Zephyr can be configured to create a USB CDC ACM device and the direct all `printk`, console output, and log
messages to that device instead.
:::warning Battery Life Impact
Enabling logging increases the power usage of your keyboard, and can have a non-trivial impact to your time on battery.
It is recommended to only enable logging when needed, and not leaving it on by default.
:::
2020-07-08 01:58:12 +10:00
## Kconfig
The `CONFIG_ZMK_USB_LOGGING` KConfig value needs to be set, either by copy and pasting into the `app/prj.conf` file, or by running
`west build -t menuconfig` and manually enabling the setting in that UI at `ZMK -> Advanced -> USB Logging`.
2020-07-08 01:58:12 +10:00
2020-11-02 09:21:40 +11:00
:::note
If you are debugging your own keyboard in your [user config repository](user-setup.md), use
2020-11-02 09:21:40 +11:00
`config/boards/shields/<your_keyboard>/<your_keyboard>.conf` instead of `app/prj.conf`. In Github
2020-11-04 00:11:56 +11:00
Actions, you can search the `Kconfig file` build log to verify the options above have been enabled
2020-11-02 09:21:40 +11:00
for you successfully.
:::
2020-07-08 01:58:12 +10:00
```
# Turn on logging, and set ZMK logging to debug output
CONFIG_ZMK_USB_LOGGING=y
2020-07-08 01:58:12 +10:00
```
## Viewing Logs
2020-08-30 08:05:43 +10:00
After flashing the updated ZMK image, the board should expose a USB CDC ACM device that you can connect to and view the logs.
2020-07-08 01:58:12 +10:00
2020-08-30 08:05:43 +10:00
<Tabs
defaultValue="linux"
values={[
{label: 'Linux', value: 'linux'},
{label: 'Windows', value: 'win'},
2020-11-02 08:22:34 +11:00
{label: 'MacOS', value: 'macos'}
2020-08-30 08:05:43 +10:00
]}>
<TabItem value="linux">
2020-07-08 01:58:12 +10:00
2020-08-30 08:05:43 +10:00
On Linux, this should be a device like `/dev/ttyACM0` and you can connect with `minicom` or `tio` as usual, e.g.:
2020-07-08 01:58:12 +10:00
```
sudo tio /dev/ttyACM0
```
2020-08-30 08:05:43 +10:00
</TabItem>
<TabItem value="win">
2020-08-30 08:05:43 +10:00
2020-08-30 12:22:43 +10:00
On Windows, you can use [PuTTY](https://www.putty.org/). Once installed, use Device Manager to figure out which COM port your controller is communicating on (listed under 'Ports (COM & LPT)') and specify that as the 'Serial line' in PuTTY.
![Controller COM port](../assets/usb-logging/com.jpg)
2020-08-30 12:22:43 +10:00
![PuTTY settings](../assets/usb-logging/putty.jpg)
2020-08-30 12:22:43 +10:00
If you already have the Ardunio IDE installed you can also use its built-in Serial Monitor.
2020-08-30 08:05:43 +10:00
2020-11-02 08:22:34 +11:00
</TabItem>
<TabItem value="macos">
2020-11-04 00:11:56 +11:00
On MacOS, the device name is something like `/dev/tty.usbmodemXXXXX` where `XXXXX` is some numerical ID.
2020-11-02 08:22:34 +11:00
You can connect to the device with [tio](https://tio.github.io/) (can be installed via [Homebrew](https://formulae.brew.sh/formula/tio)):
```
sudo tio /dev/tty.usbmodem14401
```
2020-11-04 00:11:56 +11:00
You should see tio printing `Disconnected` or `Connected` when you disconnect or reconnect the USB cable.
2020-08-30 08:05:43 +10:00
</TabItem>
</Tabs>
2020-07-08 01:58:12 +10:00
From there, you should see the various log messages from ZMK and Zephyr, depending on which systems you have set to what log levels.