Skip to content

usb_write fails to write to endpoint buffer in old device stack #104535

@temportalflux

Description

@temportalflux

Describe the bug

I'm using a nice!nano aurora sweep keyboard, and using ZMK to compile the firmware for it. I'm trying to send some custom HID data from my firmware to the USB device interface on my computer, so I can write a custom software to listen to that data and update state. This data will describe the physical switches on my keyboard and the layers which are active, instead of trying to infer which switches are pressed from standard keyboard scancodes.

To achieve this, I'm using zmk-raw-hid to send some data via zephyr call hid_int_ep_write. ZMK is currently constrained to the old device stack (not device_next). I've traced the stack via github repos + search.

zmk_raw_hid calls hid_int_ep_write in send_report
-> hid_int_ep_write
-> usb_device.c usb_write

my custom module code:

struct raw_board_event {
    uint8_t event_type;
    uint8_t value;
    uint8_t state;
};

struct raw_board_event board_event;
board_event.event_type = 0;
board_event.value = ev->position;
board_event.state = ev->state;

struct raw_hid_sent_event hid_event;
hid_event.length = sizeof(board_event);
hid_event.data = (uint8_t*)&board_event;
raise_raw_hid_sent_event(hid_event);

the output (as described below) repeatedly tries to write to the endpoint buffer, and fails. Its unclear to me why its failing, the error message simply returns with an error code of 11, which seems to be driven by the error defined for EAGAIN. Its unclear why its failing to write to the endpoint buffer, or what can be done to fix that behavior.

Various CDC_ACM config flags have been tried, including CONFIG_USB_CDC_ACM=y, CONFIG_USBD_CDC_ACM=y, and CONFIG_USBD_CDC_ACM_CLASS=y.

Regression

  • This is a regression.

Steps to reproduce

No response

Relevant log output

[00:01:38.998,748] <inf> zmk: USB - Sending Raw HID report of length 12
[00:01:38.998,779] <dbg> zmk: send_report: USB - Sending Raw HID report
                              00 be 05 00 0a 00 00 00  00 00 00 00 00 00 00 00 |........ ........
                              00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00 |........ ........
[00:01:38.998,809] <wrn> usb_device: Failed to write endpoint buffer 0x84
[00:01:38.998,809] <wrn> usb_device: Failed to write endpoint buffer 0x84
[00:01:38.998,840] <wrn> usb_device: Failed to write endpoint buffer 0x84
[00:01:38.998,840] <wrn> usb_device: Failed to write endpoint buffer 0x84
[00:01:38.998,870] <wrn> usb_device: Failed to write endpoint buffer 0x84
[00:01:38.998,901] <wrn> usb_device: Failed to write endpoint buffer 0x84
[00:01:38.998,901] <wrn> usb_device: Failed to write endpoint buffer 0x84
[00:01:38.998,931] <wrn> usb_device: Failed to write endpoint buffer 0x84
[00:01:38.998,962] <wrn> usb_device: Failed to write endpoint buffer 0x84
[00:01:38.998,962] <wrn> usb_device: Failed to write endpoint buffer 0x84
[00:01:38.998,992] <wrn> usb_device: Failed to write endpoint buffer 0x84
[00:01:38.998,992] <err> zmk: Failed to send report: -11
[00:01:38.999,023] <wrn> zmk: Not sending, no active address for current profile
[00:01:38.999,023] <err> zmk: Not connected to active profile

Impact

Functional Limitation – Some features not working as expected, but system usable.

Environment

  • OS: Linux 18.0.0 x86_64 (X64) (zorin on wayland)
  • Toolchain: ZMK, nice!nano controller, aurora sweep shield

Additional Context

ZMK folks have communicated that ZMK will be unable to upgrade to zephyr's new device stack for a little while yet (until sometime after v0.4 release). So upgrading to the new device stack is not available to me in the immediate future.
I'd love assistance understanding this bug and if there is any way to debug or fix this to a reasonable degree. Zephyr support via discord has expressed strong advice to not bother debugging the old stack, but thats not a reasonable option for me at this time.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugThe issue is a bug, or the PR is fixing a bug

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions