dcd_int_enable does not check the return value from esp_intr_alloc
Operating System
Others
Board
esp32s3 wroom1
Firmware
espressif tinyusb port, tusb_msc_storage.c
What happened ?
In tinyusb\src\portable\espressif\esp32sx\dcd_esp32sx.c, in function dcd_int_enable, the return code is not checked or returned If the esp-idf fails to allocate an interrupt, the usb device will not work but the usb task has no way of knowing See below the log output In the example the system resets, on my full system it does not reset but does not work Note the lines E (1168) intr_alloc: No free interrupt inputs for USB interrupt (flags 0xE) I (1168) TinyUSB: TinyUSB Driver installed I (1178) example_main: USB MSC initialization DONE
How to reproduce ?
Start with esp-idf example tusb_msc Change the console to the usb-cdc console you will need to replace esp_console_dev_uart_config_t with esp_console_dev_usb_cdc_config_t hw_config = ESP_CONSOLE_DEV_CDC_CONFIG_DEFAULT(); and esp_console_new_repl_uart with esp_console_new_repl_usb_cdc: ESP_ERROR_CHECK(esp_console_new_repl_usb_cdc(&hw_config, &repl_config, &repl));
Debug Log as txt file (LOG/CFG_TUSB_DEBUG=2)
ESP-ROM:esp32s3-20210327 Build:Mar 27 2021 rst:0xc (RTC_SW_CPU_RST),boot:0x29 (SPI_FAST_FLASH_BOOT) Saved PC:0x403757ec SPIWP:0xee mode:DIO, clock div:1 load:0x3fce38e0,len:0x1870 load:0x403c9700,len:0x4 load:0x403c9704,len:0xcac load:0x403cc700,len:0x2f64 entry 0x403c9918 I (125) cpu_start: Pro cpu start user code I (125) cpu_start: cpu freq: 160000000 Hz I (126) cpu_start: Application information: I (128) cpu_start: Project name: tusb_msc I (134) cpu_start: App version: 1 I (138) cpu_start: Compile time: Feb 2 2025 15:38:30 I (144) cpu_start: ELF file SHA256: 3b237ef86... I (149) cpu_start: ESP-IDF: v5.2.3-5-g97bee2dfcf-dirty I (156) cpu_start: Min chip rev: v0.0 I (161) cpu_start: Max chip rev: v0.99 I (166) cpu_start: Chip rev: v0.2 I (170) heap_init: Initializing. RAM available for dynamic allocation: I (178) heap_init: At 3FC964E8 len 00053228 (332 KiB): RAM I (184) heap_init: At 3FCE9710 len 00005724 (21 KiB): RAM I (190) heap_init: At 3FCF0000 len 00008000 (32 KiB): DRAM I (196) heap_init: At 600FE010 len 00001FD8 (7 KiB): RTCRAM I (213) spi_flash: detected chip: gd I (213) spi_flash: flash io: dio W (213) spi_flash: Detected size(16384k) larger than the size in the binary image header(4096k). Using the size in the binary image header. I (224) sleep: Configure to isolate all GPIO pins in sleep state I (230) sleep: Enable automatic switching of GPIO sleep configuration I (238) main_task: Started on CPU0 I (248) main_task: Calling app_main() I (248) example_main: Initializing storage...
Type 'help' to get the list of commands. Use UP/DOWN arrows to navigate through command history. Press TAB when typing command name to auto-complete.
Your terminal application does not support escape sequences.
Line editing and history features are disabled.
On Windows, try using Putty instead. esp32s3> I (778) example_main: Initializing SDCard I (778) gpio: GPIO[48]| InputEn: 0| OutputEn: 0| OpenDrain: 0| Pullup: 1| Pulldown: 0| Intr:0 I (788) gpio: GPIO[47]| InputEn: 0| OutputEn: 0| OpenDrain: 0| Pullup: 1| Pulldown: 0| Intr:0 I (798) gpio: GPIO[21]| InputEn: 0| OutputEn: 0| OpenDrain: 0| Pullup: 1| Pulldown: 0| Intr:0 I (808) gpio: GPIO[14]| InputEn: 0| OutputEn: 0| OpenDrain: 0| Pullup: 1| Pulldown: 0| Intr:0 I (808) gpio: GPIO[9]| InputEn: 0| OutputEn: 0| OpenDrain: 0| Pullup: 1| Pulldown: 0| Intr:0 I (818) gpio: GPIO[8]| InputEn: 0| OutputEn: 1| OpenDrain: 0| Pullup: 0| Pulldown: 0| Intr:0 I (858) gpio: GPIO[8]| InputEn: 0| OutputEn: 0| OpenDrain: 0| Pullup: 1| Pulldown: 0| Intr:0 Name: SD16G Type: SDHC/SDXC Speed: 20.00 MHz (limit: 20.00 MHz) Size: 14768MB CSD: ver=2, sector_size=512, capacity=30244864 read_bl_len=9 SSR: bus_width=4 I (868) example_main: Mount storage... I (878) example_main: Storage mounted to application: Yes I (878) example_main: ls command output:
System Volume Information
.
Screenshots
No response
I have checked existing issues, dicussion and documentation
- [x] I confirm I have checked existing issues, dicussion and documentation.
Note you must move the console init code to the beginning of the exampe so the console is opened before the msd
Hi @inbarab ,
that is right, thank you so much for such detailed description.
That is why tusb_msc example is not able to build with such configuration (#error Unsupported console type): because the USB CDC for the serial device output shares the same peripheral as (in this particular case) TinyUSB MSC device.
Anyway, the issue could be reproduced with an adding just one line: call the interrupt enable twice:
void dcd_int_enable(uint8_t rhport) {
dwc2_dcd_int_enable(rhport);
dwc2_dcd_int_enable(rhport);
}
after that, we will get the error: No free interrupt inputs for USB interrupt (flags 0xE) but everything will stll be working. Which reflects the problem that the error is just ignored.
I'll try to check the other controllers and prepare a PR with a fix for ESP chips ASAP.
Hi,
Thanks for your reply
I hope my input was useful.
Do you know if there’s a way to remove the esp32s3’s ROM usb stack once it’s started? If there is a way, maybe the usb can be switched from the rom usb stack to the tiny usb stack. I have not found a solution to this.
Cheers,
Inbar
From: Roma Jam @.> Sent: Tuesday, 4 February 2025 17:38 To: hathach/tinyusb @.> Cc: inbarab @.>; Mention @.> Subject: Re: [hathach/tinyusb] dcd_int_enable does not check the return value from esp_intr_alloc (Issue #2970)
Hi @inbarab https://github.com/inbarab ,
that is right, thank you so much for such detailed description. That is why tusb_msc example is not able to build with such configuration (#error Unsupported console type): because the USB CDC for the serial device output shares the same peripheral as (in this particular case) TinyUSB MSC device.
Anyway, the issue could be reproduced with an adding just one line: call the interrupt enable twice:
void dcd_int_enable(uint8_t rhport) { dwc2_dcd_int_enable(rhport); dwc2_dcd_int_enable(rhport); }
after that, we will get the error: No free interrupt inputs for USB interrupt (flags 0xE) but everything will stll be working. Which reflects the problem that the error is just ignored.
I'll try to check the other controllers and prepare a PR with a fix for ESP chips ASAP.
— Reply to this email directly, view it on GitHub https://github.com/hathach/tinyusb/issues/2970#issuecomment-2634342408 , or unsubscribe https://github.com/notifications/unsubscribe-auth/A46SQQW5EZLJYIT37QTYAO32ODNFHAVCNFSM6AAAAABWKNVJ52VHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDMMZUGM2DENBQHA . You are receiving this because you were mentioned. https://github.com/notifications/beacon/A46SQQR6PF35FHRXZJT33ET2ODNFHA5CNFSM6AAAAABWKNVJ52WGG33NNVSW45C7OR4XAZNMJFZXG5LFINXW23LFNZ2KUY3PNVWWK3TUL5UWJTU5ATQAQ.gif Message ID: @.*** @.***> >
@roma-jam do you want to make an PR to fix this before we make an 0.19 release ?
Hi @hathach,
yes, I briefly checked the API, and public dwc2_dcd_int_enable/dwc2_dcd_int_disable return void.
Would it be possible to consider changing it to return bool type?
@roma-jam sure, we can.
Hi @inbarab,
I double checked the issue and tried to reproduce it.
MSC example uses the USB-OTG peripheral and the same peripheral is used, when you enable the CONFIG_ESP_CONSOLE_USB_CDC option (or manually add the lines, you described earlier).
So, as this is the same peripheral, this is not possible to share it. Basically this is why this option is not available, when MSC class example is built with CONFIG_ESP_CONSOLE_USB_CDC enabled.
Could you please clarify what are you trying to achieve?
Hi @roma-jam
In this issue report, I asked that the app will be notified if the MSC failed to start (in this case, because the interrupt allocation failed). My original intention was to start with a USB console and switch to MSC in run time. This isn't possible because the built in USB stack that's used for the USB console can't be stopped, and the interrupt is not released, but that's beyond this specific report