zephyrproject-rtos / zephyr

Primary Git Repository for the Zephyr Project. Zephyr is a new generation, scalable, optimized, secure RTOS for multiple hardware architectures.
https://docs.zephyrproject.org
Apache License 2.0
11k stars 6.69k forks source link

STM32 USB UDC driver uses mutex from interrupt #82408

Closed NielsVeul closed 21 hours ago

NielsVeul commented 1 day ago

Describe the bug

The STM32 USB UDC driver uses a mutex from an interrupt. The interrupt callback HAL_PCD_SetupStageCallback leads to the function udc_ep_buf_alloc, which uses the mutex with api->lock().

To Reproduce

To reproduce the issue, build sample/subsys/usb/cdc_acm, with the usbd next configuration and asserts enabled.

Expected behavior

An assert will trigger, because a mutex is used inside an interrupt.

Impact

The USB next stack is not useable with the STM32 MCU, since an assert will trigger

Logs and console output

ASSERTION FAIL [!arch_is_in_isr()] @ WEST_TOPDIR/zephyr/kernel/mutex.c:111 mutexes cannot be used inside ISRs [00:00:06.177,000] os: r0/a1: 0x00000004 r1/a2: 0x0000006f r2/a3: 0x00000005 [00:00:06.177,000] os: r3/a4: 0x00000004 r12/ip: 0x00001821 r14/lr: 0x0800a2db [00:00:06.177,000] os: xpsr: 0x01000059 [00:00:06.177,000] os: Faulting instruction address (r15/pc): 0x0800d94c [00:00:06.177,000] os: >>> ZEPHYR FATAL ERROR 4: Kernel panic on CPU 0 [00:00:06.177,000] os: Fault during interrupt handling

[00:00:06.177,000] os: Current thread: 0x20000c78 (unknown) [00:00:06.257,000] os: Halting system

Environment (please complete the following information):

Additional context

github-actions[bot] commented 1 day ago

Hi @NielsVeul! We appreciate you submitting your first issue for our open-source project. 🌟

Even though I'm a bot, I can assure you that the whole community is genuinely grateful for your time and effort. πŸ€–πŸ’™

henrikbrixandersen commented 21 hours ago

Duplicate of https://github.com/zephyrproject-rtos/zephyr/issues/61464