Skip to content

USB HID Implementation for ESP32S3 has problems ! #1044

Description

@ThomasAtBBTF

I tried to run the different usb.device examples on different ESP32S3 board all with the same results.
Since version 1.26.1 and also in version 1.27.x receiving the LED information from the host works fine.
Sending keypress information to the host is working (as I confirmed with wireshark) but the report "arrives"
at the host always with only 8 bytes of "0" ! Regardless what has been send by the python code.
I recompiled the micropython image and added debug information in:

static mp_obj_t usb_device_submit_xfer(mp_obj_t self, mp_obj_t ep, mp_obj_t buffer) {
    mp_obj_usb_device_t *usbd = (mp_obj_usb_device_t *)MP_OBJ_TO_PTR(self);
    int ep_addr;
    mp_buffer_info_t buf_info = { 0 };
    bool result;

    usb_device_check_active(usbd);

    // Unmarshal arguments, raises TypeError if invalid
    ep_addr = mp_obj_get_int(ep);
    mp_get_buffer_raise(buffer, &buf_info, ep_addr & TUSB_DIR_IN_MASK ? MP_BUFFER_READ : MP_BUFFER_RW);

    uint8_t ep_num = tu_edpt_number(ep_addr);
    uint8_t ep_dir = tu_edpt_dir(ep_addr);

    if (ep_num == 0 || ep_num >= CFG_TUD_ENDPPOINT_MAX) {
        // TinyUSB usbd API doesn't range check arguments, so this check avoids
        // out of bounds array access, or submitting transfers on the control endpoint.
        //
        // This C layer doesn't otherwise keep track of which endpoints the host
        // is aware of (or not).
        mp_raise_ValueError(MP_ERROR_TEXT("ep"));
    }

    if (!usbd_edpt_claim(USBD_RHPORT, ep_addr)) {
        mp_raise_OSError(MP_EBUSY);
    }
    
    size_t len = buf_info.len;
    const byte *data = buf_info.buf;
    
    mp_printf(&mp_plat_print, "----Debug: (len=%d): ", len);
    for (size_t i = 0; i < len; i++) {
        mp_printf(&mp_plat_print, "%02x ", data[i]);
    }
    mp_printf(&mp_plat_print, "\n"); 

And also in :


bool dcd_edpt_xfer(uint8_t rhport, uint8_t ep_addr, uint8_t* buffer, uint16_t total_bytes) {
  uint8_t const epnum = tu_edpt_number(ep_addr);
  uint8_t const dir = tu_edpt_dir(ep_addr);

  
  if (ep_addr == 0x83) {
    esp_rom_printf("DCD: xfer ep=%02X len=%u : ", ep_addr, (unsigned)total_bytes);

    // Print a limited number of bytes to stay ISR-friendly
    const uint8_t *data = (const uint8_t *)buffer;
    uint16_t limit = total_bytes;
    if (limit > 32) limit = 32;   // cap output (optional)

    for (uint16_t i = 0; i < limit; i++) {
      esp_rom_printf("%02X ", data[i]);
    }
    if (limit < total_bytes) esp_rom_printf("... ");
    esp_rom_printf("\n");

  }
  DCD_ENTER_CRITICAL();


```and both logs shows that the keyboard buffer bytes are fine until these log-points.

But nonetheless  at the host side only "zeros" are arriving .

Can anyone using a ESP32S3 create a working USB HID keyboard from the sample code provided ?

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions