Skip to content

USBHID.cpp uses non safe xSemaphoreGive in ISR #11407

@ChrGri

Description

@ChrGri

Board

ESP32 S3

Device Description

ESP32 S3 dev kit

Hardware Configuration

None

Version

latest stable Release (if not listed below)

IDE Name

Arduino

Operating System

Win 11

Flash frequency

a lot

PSRAM enabled

yes

Upload speed

a lot too

Description

The USBHID.cpp code implements an tud_hid_report_complete_cb from which a non safe xSemaphoreGive is beeing called, see.

Since tud_hid_report_complete_cb is an ISR, its advisable to use xSemaphoreGiveFromISR instead, e.g.

void tud_hid_report_complete_cb(uint8_t instance, uint8_t const* report, tud_hid_report_complete_cb_len_t len) {
    BaseType_t xHigherPriorityTaskWoken = pdFALSE;
    if (tinyusb_hid_device_input_sem) {
        xSemaphoreGiveFromISR(tinyusb_hid_device_input_sem, &xHigherPriorityTaskWoken);
        if (xHigherPriorityTaskWoken) {
            portYIELD_FROM_ISR();
        }
    }
}

BR
Chris

Sketch

See above

Debug Message

Sometimes I receive TUSB:error messages. Now trying to find possible reasons. This might be one.

Other Steps to Reproduce

No response

I have checked existing issues, online documentation and the Troubleshooting Guide

  • I confirm I have checked existing issues, online documentation and Troubleshooting guide.

Activity

added
Area: LibrariesIssue is related to Library support.
bug 🐞Inconsistencies or issues which will cause a problem for users or implementers.
on May 28, 2025
added theissue type on May 28, 2025
removed
bug 🐞Inconsistencies or issues which will cause a problem for users or implementers.
on Jun 2, 2025
changed the issue type fromtoon Jun 2, 2025
SuGlider

SuGlider commented on Jun 2, 2025

@SuGlider
Collaborator

@ChrGri @lucasssvaz - This is not called from an ISR.
tud_hid_report_complete_cb() is called from a Task started within tud_task() (when USB.begin() is called)
TinyUSB uses ISR to create events in a queue. The events are processed from a FreeRTOS Task, therefore, there should be no such issue with xSemaphoreGiveFromISR

I have tracked down tud_hid_report_complete_cb() in the TinyUSB and Arduino source code.
Please let me know if you disagree and the reason for it.

ChrGri

ChrGri commented on Jun 6, 2025

@ChrGri
Author

@SuGlider Thank you very much for this investigation. If you are certain, that this is not a problem, feel free to close the issue.

BR
Christopher

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

Metadata

Metadata

Assignees

Type

Projects

No projects

Milestone

No milestone

Relationships

None yet

    Development

    No branches or pull requests

      Participants

      @ChrGri@lucasssvaz@SuGlider

      Issue actions

        USBHID.cpp uses non safe xSemaphoreGive in ISR · Issue #11407 · espressif/arduino-esp32