2021-07-22 00:40:40 +02:00
|
|
|
# Debugging
|
|
|
|
|
2019-03-28 14:47:10 +01:00
|
|
|
This document describes some of the Klipper debugging tools.
|
2016-05-25 17:37:40 +02:00
|
|
|
|
2021-07-22 00:40:40 +02:00
|
|
|
## Translating gcode files to micro-controller commands
|
2016-09-11 02:49:25 +02:00
|
|
|
|
|
|
|
The Klippy host code can run in a batch mode to produce the low-level
|
2017-04-27 21:14:11 +02:00
|
|
|
micro-controller commands associated with a gcode file. Inspecting
|
|
|
|
these low-level commands is useful when trying to understand the
|
2016-09-11 02:49:25 +02:00
|
|
|
actions of the low-level hardware. It can also be useful to compare
|
2017-04-27 21:14:11 +02:00
|
|
|
the difference in micro-controller commands after a code change.
|
2016-09-11 02:49:25 +02:00
|
|
|
|
|
|
|
To run Klippy in this batch mode, there is a one time step necessary
|
2017-04-27 21:14:11 +02:00
|
|
|
to generate the micro-controller "data dictionary". This is done by
|
|
|
|
compiling the micro-controller code to obtain the **out/klipper.dict**
|
|
|
|
file:
|
2016-09-11 02:49:25 +02:00
|
|
|
|
|
|
|
```
|
|
|
|
make menuconfig
|
|
|
|
make
|
|
|
|
```
|
|
|
|
|
|
|
|
Once the above is done it is possible to run Klipper in batch mode
|
|
|
|
(see [installation](Installation.md) for the steps necessary to build
|
|
|
|
the python virtual environment and a printer.cfg file):
|
|
|
|
|
|
|
|
```
|
|
|
|
~/klippy-env/bin/python ./klippy/klippy.py ~/printer.cfg -i test.gcode -o test.serial -v -d out/klipper.dict
|
|
|
|
```
|
|
|
|
|
|
|
|
The above will produce a file **test.serial** with the binary serial
|
|
|
|
output. This output can be translated to readable text with:
|
|
|
|
|
|
|
|
```
|
|
|
|
~/klippy-env/bin/python ./klippy/parsedump.py out/klipper.dict test.serial > test.txt
|
|
|
|
```
|
|
|
|
|
|
|
|
The resulting file **test.txt** contains a human readable list of
|
2017-04-27 21:14:11 +02:00
|
|
|
micro-controller commands.
|
2016-09-11 02:49:25 +02:00
|
|
|
|
|
|
|
The batch mode disables certain response / request commands in order
|
|
|
|
to function. As a result, there will be some differences between
|
2017-04-27 21:14:11 +02:00
|
|
|
actual commands and the above output. The generated data is useful for
|
|
|
|
testing and inspection; it is not useful for sending to a real
|
|
|
|
micro-controller.
|
2016-09-11 02:49:25 +02:00
|
|
|
|
2021-07-22 00:40:40 +02:00
|
|
|
## Testing with simulavr
|
2016-05-25 17:37:40 +02:00
|
|
|
|
|
|
|
The [simulavr](http://www.nongnu.org/simulavr/) tool enables one to
|
|
|
|
simulate an Atmel ATmega micro-controller. This section describes how
|
|
|
|
one can run test gcode files through simulavr. It is recommended to
|
|
|
|
run this on a desktop class machine (not a Raspberry Pi) as it does
|
|
|
|
require significant cpu to run efficiently.
|
|
|
|
|
|
|
|
To use simulavr, download the simulavr package and compile with python
|
|
|
|
support:
|
|
|
|
|
|
|
|
```
|
|
|
|
git clone git://git.savannah.nongnu.org/simulavr.git
|
|
|
|
cd simulavr
|
|
|
|
./bootstrap
|
|
|
|
./configure --enable-python
|
|
|
|
make
|
|
|
|
```
|
|
|
|
|
|
|
|
Note that the build system may need to have some packages (such as
|
|
|
|
swig) installed in order to build the python module. Make sure the
|
|
|
|
file **src/python/_pysimulavr.so** is present after the above
|
|
|
|
compilation.
|
|
|
|
|
|
|
|
To compile Klipper for use in simulavr, run:
|
|
|
|
|
|
|
|
```
|
|
|
|
cd /patch/to/klipper
|
|
|
|
make menuconfig
|
|
|
|
```
|
|
|
|
|
2017-05-28 17:04:59 +02:00
|
|
|
and compile the micro-controller software for an AVR atmega644p, set
|
|
|
|
the MCU frequency to 20Mhz, and select SIMULAVR software emulation
|
|
|
|
support. Then one can compile Klipper (run `make`) and then start the
|
|
|
|
simulation with:
|
2016-05-25 17:37:40 +02:00
|
|
|
|
|
|
|
```
|
2016-06-11 01:51:04 +02:00
|
|
|
PYTHONPATH=/path/to/simulavr/src/python/ ./scripts/avrsim.py -m atmega644 -s 20000000 -b 250000 out/klipper.elf
|
2016-05-25 17:37:40 +02:00
|
|
|
```
|
|
|
|
|
|
|
|
Then, with simulavr running in another window, one can run the
|
|
|
|
following to read gcode from a file (eg, "test.gcode"), process it
|
2017-04-11 18:49:12 +02:00
|
|
|
with Klippy, and send it to Klipper running in simulavr (see
|
|
|
|
[installation](Installation.md) for the steps necessary to build the
|
|
|
|
python virtual environment):
|
2016-05-25 17:37:40 +02:00
|
|
|
|
|
|
|
```
|
2019-11-25 02:15:57 +01:00
|
|
|
~/klippy-env/bin/python ./klippy/klippy.py config/generic-simulavr.cfg -i test.gcode -v
|
2016-05-25 17:37:40 +02:00
|
|
|
```
|
|
|
|
|
2021-07-22 00:40:40 +02:00
|
|
|
### Using simulavr with gtkwave
|
|
|
|
|
2016-05-25 17:37:40 +02:00
|
|
|
|
|
|
|
One useful feature of simulavr is its ability to create signal wave
|
|
|
|
generation files with the exact timing of events. To do this, follow
|
|
|
|
the directions above, but run avrsim.py with a command-line like the
|
|
|
|
following:
|
|
|
|
|
|
|
|
```
|
2016-06-11 01:51:04 +02:00
|
|
|
PYTHONPATH=/path/to/simulavr/src/python/ ./scripts/avrsim.py -m atmega644 -s 20000000 -b 250000 out/klipper.elf -t PORTA.PORT,PORTC.PORT
|
2016-05-25 17:37:40 +02:00
|
|
|
```
|
|
|
|
|
|
|
|
The above would create a file **avrsim.vcd** with information on each
|
|
|
|
change to the GPIOs on PORTA and PORTB. This could then be viewed
|
|
|
|
using gtkwave with:
|
|
|
|
|
|
|
|
```
|
|
|
|
gtkwave avrsim.vcd
|
|
|
|
```
|
|
|
|
|
2021-07-22 00:40:40 +02:00
|
|
|
## Manually sending commands to the micro-controller
|
|
|
|
|
2016-05-25 17:37:40 +02:00
|
|
|
|
2018-01-11 19:46:20 +01:00
|
|
|
Normally, the host klippy.py process would be used to translate gcode
|
|
|
|
commands to Klipper micro-controller commands. However, it's also
|
|
|
|
possible to manually send these MCU commands (functions marked with
|
|
|
|
the DECL_COMMAND() macro in the Klipper source code). To do so, run:
|
2016-05-25 17:37:40 +02:00
|
|
|
|
|
|
|
```
|
2021-02-07 20:20:47 +01:00
|
|
|
~/klippy-env/bin/python ./klippy/console.py /tmp/pseudoserial
|
2016-05-25 17:37:40 +02:00
|
|
|
```
|
2017-04-11 19:41:11 +02:00
|
|
|
|
2018-01-11 19:46:20 +01:00
|
|
|
See the "HELP" command within the tool for more information on its
|
|
|
|
functionality.
|
|
|
|
|
2021-02-07 20:20:47 +01:00
|
|
|
Some command-line options are available. For more information run:
|
|
|
|
`~/klippy-env/bin/python ./klippy/console.py --help`
|
|
|
|
|
2021-07-22 00:40:40 +02:00
|
|
|
## Generating load graphs
|
2017-04-11 19:41:11 +02:00
|
|
|
|
|
|
|
The Klippy log file (/tmp/klippy.log) stores statistics on bandwidth,
|
|
|
|
micro-controller load, and host buffer load. It can be useful to graph
|
|
|
|
these statistics after a print.
|
|
|
|
|
|
|
|
To generate a graph, a one time step is necessary to install the
|
|
|
|
"matplotlib" package:
|
|
|
|
|
|
|
|
```
|
|
|
|
sudo apt-get update
|
|
|
|
sudo apt-get install python-matplotlib
|
|
|
|
```
|
|
|
|
|
|
|
|
Then graphs can be produced with:
|
|
|
|
|
|
|
|
```
|
2019-06-19 20:12:56 +02:00
|
|
|
~/klipper/scripts/graphstats.py /tmp/klippy.log -o loadgraph.png
|
2017-04-11 19:41:11 +02:00
|
|
|
```
|
|
|
|
|
|
|
|
One can then view the resulting **loadgraph.png** file.
|
2018-01-11 19:46:20 +01:00
|
|
|
|
2019-04-02 04:24:45 +02:00
|
|
|
Different graphs can be produced. For more information run:
|
|
|
|
`~/klipper/scripts/graphstats.py --help`
|
|
|
|
|
2021-07-22 00:40:40 +02:00
|
|
|
## Extracting information from the klippy.log file
|
2018-01-11 19:46:20 +01:00
|
|
|
|
|
|
|
The Klippy log file (/tmp/klippy.log) also contains debugging
|
|
|
|
information. There is a logextract.py script that may be useful when
|
|
|
|
analyzing a micro-controller shutdown or similar problem. It is
|
|
|
|
typically run with something like:
|
|
|
|
|
|
|
|
```
|
|
|
|
mkdir work_directory
|
|
|
|
cd work_directory
|
|
|
|
cp /tmp/klippy.log .
|
|
|
|
~/klipper/scripts/logextract.py ./klippy.log
|
|
|
|
```
|
|
|
|
|
|
|
|
The script will extract the printer config file and will extract MCU
|
|
|
|
shutdown information. The information dumps from an MCU shutdown (if
|
|
|
|
present) will be reordered by timestamp to assist in diagnosing cause
|
|
|
|
and effect scenarios.
|
2019-06-23 23:58:27 +02:00
|
|
|
|
2021-07-22 00:40:40 +02:00
|
|
|
## Running the regression tests
|
2019-06-23 23:58:27 +02:00
|
|
|
|
2020-09-26 04:13:56 +02:00
|
|
|
The main Klipper GitHub repository uses "github actions" to run a
|
|
|
|
series of regression tests. It can be useful to run some of these
|
|
|
|
tests locally.
|
2019-06-23 23:58:27 +02:00
|
|
|
|
|
|
|
The source code "whitespace check" can be run with:
|
|
|
|
```
|
|
|
|
./scripts/check_whitespace.sh
|
|
|
|
```
|
|
|
|
|
|
|
|
The Klippy regression test suite requires "data dictionaries" from
|
|
|
|
many platforms. The easiest way to obtain them is to
|
|
|
|
[download them from github](https://github.com/KevinOConnor/klipper/issues/1438).
|
|
|
|
Once the data dictionaries are downloaded, use the following to run
|
|
|
|
the regression suite:
|
|
|
|
```
|
|
|
|
tar xfz klipper-dict-20??????.tar.gz
|
|
|
|
~/klippy-env/bin/python ~/klipper/scripts/test_klippy.py -d dict/ ~/klipper/test/klippy/*.test
|
|
|
|
```
|