You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

136 lines
5.2 KiB

  1. # Debugging FAQ
  2. This page details various common questions people have about troubleshooting their keyboards.
  3. ## Debugging :id=debugging
  4. Your keyboard will output debug information if you have `CONSOLE_ENABLE = yes` in your `rules.mk`. By default the output is very limited, but you can turn on debug mode to increase the amount of debug output. Use the `DB_TOGG` keycode in your keymap, use the [Command](feature_command.md) feature to enable debug mode, or add the following code to your keymap.
  5. ```c
  6. void keyboard_post_init_user(void) {
  7. // Customise these values to desired behaviour
  8. debug_enable=true;
  9. debug_matrix=true;
  10. //debug_keyboard=true;
  11. //debug_mouse=true;
  12. }
  13. ```
  14. ## Debugging Tools
  15. Various tools are available to debug your keyboard.
  16. ### Debugging With QMK Toolbox
  17. For compatible platforms, [QMK Toolbox](https://github.com/qmk/qmk_toolbox) can be used to display debug messages from your keyboard.
  18. ### Debugging with QMK CLI
  19. Prefer a terminal based solution? The [QMK CLI console command](cli_commands.md#qmk-console) can be used to display debug messages from your keyboard.
  20. ### Debugging With hid_listen
  21. Something stand-alone? [hid_listen](https://www.pjrc.com/teensy/hid_listen.html), provided by PJRC, can also be used to display debug messages. Prebuilt binaries for Windows,Linux,and MacOS are available.
  22. ## Sending Your Own Debug Messages :id=debug-api
  23. Sometimes it's useful to print debug messages from within your [custom code](custom_quantum_functions.md). Doing so is pretty simple. Start by including `print.h` at the top of your file:
  24. ```c
  25. #include "print.h"
  26. ```
  27. After that you can use a few different print functions:
  28. * `print("string")`: Print a simple string.
  29. * `uprintf("%s string", var)`: Print a formatted string
  30. * `dprint("string")` Print a simple string, but only when debug mode is enabled
  31. * `dprintf("%s string", var)`: Print a formatted string, but only when debug mode is enabled
  32. ## Debug Examples
  33. Below is a collection of real world debugging examples. For additional information, refer to [Debugging/Troubleshooting QMK](faq_debug.md).
  34. ### Which matrix position is this keypress?
  35. When porting, or when attempting to diagnose pcb issues, it can be useful to know if a keypress is scanned correctly. To enable logging for this scenario, add the following code to your keymaps `keymap.c`
  36. ```c
  37. bool process_record_user(uint16_t keycode, keyrecord_t *record) {
  38. // If console is enabled, it will print the matrix position and status of each key pressed
  39. #ifdef CONSOLE_ENABLE
  40. uprintf("KL: kc: 0x%04X, col: %2u, row: %2u, pressed: %u, time: %5u, int: %u, count: %u\n", keycode, record->event.key.col, record->event.key.row, record->event.pressed, record->event.time, record->tap.interrupted, record->tap.count);
  41. #endif
  42. return true;
  43. }
  44. ```
  45. Example output
  46. ```
  47. Waiting for device:.......
  48. Listening:
  49. KL: kc: 169, col: 0, row: 0, pressed: 1, time: 15505, int: 0, count: 0
  50. KL: kc: 169, col: 0, row: 0, pressed: 0, time: 15510, int: 0, count: 0
  51. KL: kc: 174, col: 1, row: 0, pressed: 1, time: 15703, int: 0, count: 0
  52. KL: kc: 174, col: 1, row: 0, pressed: 0, time: 15843, int: 0, count: 0
  53. KL: kc: 172, col: 2, row: 0, pressed: 1, time: 16303, int: 0, count: 0
  54. KL: kc: 172, col: 2, row: 0, pressed: 0, time: 16411, int: 0, count: 0
  55. ```
  56. ### How long did it take to scan for a keypress?
  57. When testing performance issues, it can be useful to know the frequency at which the switch matrix is being scanned. To enable logging for this scenario, add the following code to your keymaps `config.h`
  58. ```c
  59. #define DEBUG_MATRIX_SCAN_RATE
  60. ```
  61. Example output
  62. ```
  63. > matrix scan frequency: 315
  64. > matrix scan frequency: 313
  65. > matrix scan frequency: 316
  66. > matrix scan frequency: 316
  67. > matrix scan frequency: 316
  68. > matrix scan frequency: 316
  69. ```
  70. ## `hid_listen` Can't Recognize Device
  71. When debug console of your device is not ready you will see like this:
  72. ```
  73. Waiting for device:.........
  74. ```
  75. Once the device is plugged in then *hid_listen* finds it you will get this message:
  76. ```
  77. Waiting for new device:.........................
  78. Listening:
  79. ```
  80. If you can't get this 'Listening:' message try building with `CONSOLE_ENABLE=yes` in [Makefile]
  81. You may need privileges to access the device an OS like Linux. Try `sudo hid_listen`.
  82. On many Linux distros you can avoid having to run hid_listen as root
  83. by creating a file called `/etc/udev/rules.d/70-hid-listen.rules` with
  84. the following content:
  85. ```
  86. SUBSYSTEM=="hidraw", ATTRS{idVendor}=="abcd", ATTRS{idProduct}=="def1", TAG+="uaccess", RUN{builtin}+="uaccess"
  87. ```
  88. Replace abcd and def1 with your keyboard's vendor and product id,
  89. letters must be lowercase. The `RUN{builtin}+="uaccess"` part is only
  90. needed for older distros.
  91. ## Can't Get Message on Console
  92. Check:
  93. - *hid_listen* finds your device. See above.
  94. - Enable debug by pressing **Magic**+d. See [Magic Commands](https://github.com/tmk/tmk_keyboard#magic-commands).
  95. - Set `debug_enable=true`. See [Debugging](#debugging)
  96. - Try using `print` function instead of debug print. See **common/print.h**.
  97. - Disconnect other devices with console function. See [Issue #97](https://github.com/tmk/tmk_keyboard/issues/97).
  98. - Ensure all strings end with a newline character (`\n`). QMK Toolbox prints console output on a per-line basis.