tinyusb icon indicating copy to clipboard operation
tinyusb copied to clipboard

Calling hcd_init multiple times causes a hard_assert

Open jmark1m opened this issue 3 years ago • 0 comments

Operating System

Others

Board

RP2040 / Pico

Firmware

Pico-SDK 1.4.0

What happened ?

I am using TinyUSB as a HOST in a noisy environment and sometimes I need to reset the USB bus. To do this I call "hcd_init(0)" as part of the reset process.

Previously in TinyUSB version 0.13.0, this wasn't an issue and it allowed me to do this without crashing.

After this was added in TinyUSB 0.14.0, rp2040: use shared IRQ handlers, so user can also hook the USB IRQ by @kilograham in https://github.com/hathach/tinyusb/pull/1519

it crashes on a hard_assert because of the call to "irq_add_shared_handler()" which was previously "irq_set_exclusive_handler()".

I believe the reason it is crashing is that it is exceeding PICO_MAX_SHARED_IRQ_HANDLERS.

Perhaps irq_remove_handler() should be called first?

How to reproduce ?

I added something like this to my code to confirm it crashed,

for(uint8_t x = 0; x < 20; x++ ) { printf("calling hcd_init %d\r\n", x); vTaskDelay(100); hcd_init(0);
}

Debug Log as txt file

calling hcd_init 1 calling hcd_init 2 calling hcd_init 3 assertion "irq_hander_chain_free_slot_head >= 0" failed: file "/home/markj/pico/pico-sdk/src/rp2_common/hardware_irq/irq.c", line 205, funcr

Screenshots

No response

I have checked existing issues, dicussion and documentation

  • [X] I confirm I have checked existing issues, dicussion and documentation.

jmark1m avatar Sep 07 '22 19:09 jmark1m