Skip to content

Calling hcd_init multiple times causes a hard_assert #1628

@jmark1m

Description

@jmark1m

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 #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

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions