#tinyusb
1 messages ยท Page 8 of 1
thank you for your PR and patient, I was off for TET (Lunar New Year). I think we may just cast TOTAL_DRIVER_COUNT to uint8_t instead. To ensure TOTAL_DRIVER_COUNT is less than 255, we can do an TU_ASSERT() in tud_init() so that we only run the check once.
#define TOTAL_DRIVER_COUNT ((uint8_t) (_app_driver_count + BUILTIN_DRIVER_COUNT))
@wiredopposite The fixes you mention probably helped with plug and unplug when the device is connected to the host directly. When the device is connected through a hub, the first transfer to the hub after a failed IN or OUT transfer to a device disconnected from the hub fails. At around line 297, I printed the return value from usb_in_transaction().
if (ep->ep_num & EP_IN) {
int ok = usb_in_transaction(pp, ep);
if (ok != 0) {
print...
[hathach/tinyusb] New branch created: fix-stringop-overread-warning
Describe the PR
Fix static checker by gcc 14 warning metnioned in https://github.com/hathach/tinyusb/discussions/2958#discussioncomment-11952362
thanks for your PR, I also have this board. I will try to troubleshoot it later. Just merge master to get ci passed.
tusb_config.h must be provided by application not the stack itself
Well done, I was just about to start a PR to fix this
no, since I don't have the boards. But it should similar to existing other mcx mcu, PR is welcome
check out examples/device/dynamic_configuration, this can be done by dynamically change the configuration descriptor, and tud_disconect() is needed to force host to re-enumerate (and VID/PID maybe required to prevent host caching config/driver)
superb !! Thank you very much for your PR. I aadded the full table for DIGITIZER 0x0D from HID v1.6. It is good to merge
+1 for this feature.
You can just use the external application driver linked above (usb_midi_host), it works great. There's no need for this to be part of tinyusb.
@jfedor2 thats what we are currently doing. But there are huge performance problems with that if you do more advanced stuff via USB Host. So i would it say it depends. Generally there is room for improvement and better integration of the MIDI Host feature with TinyUSB.
In the past I have used Adafruit_TinyUSB_Arduino.
Will this host controller driver be available there?
If not, what frame/lib do you recommend for using tinyusb with Arduino for ESP32-S3?
I am specifically interested in USB MIDI Host.
Thanks!
I took a look and couldn't reproduce the issue with audio_4_channel_mic example where sample rate is fixed and marked as read only in descriptor.
When sample rate is read only Windows won't call set sample rate but get sample rate is always called.
Describe the PR
Add CMake presets for easier build.
Now examples can be built in one line, such as cmake --workflow --preset stm32c071nucleo or cmake --build --preset stm32c071nucleo -t audio_4_channel_mic-jlink for flashing.
Additional context
IAR now has a dropdown preset menu for quick board switching.
I observe that if I roll back the Pico-PIO-USB library to version 0.5.3, this problem goes away. I am closing this issue in this library.
@hathach Hi, is there an ETA about when this can get merged? Or do you need any help understanding or testing the code?
@nevvkid Can you please describe where the performance problems from application drivers come from, and what advanced stuff you are doing that suffers when you use application drivers?
As far as I understand it, the USB host code accesses external driver functions using function pointers; same as built-in drivers. External application driver function pointers are stored in an array; built-in driver function pointers are stored in a different array. To get a pointer to the function pointers...
Hi @marchingband,
Question: are you using the CDC as a CLI or just for output?
Thanks
Inbar
@inbarab i was using it for input and output, not for a CLI but for a serial interface for a web app actually.
I ended up abandoning this approach and have both CDC and MSC at the same time.
I was running into this issue as well. Thank you for providing this info as it's helped me to achieve a workaround for now ^^
Operating System
Windows 11
Board
RP2040 (Any Board)
Firmware
N/A
What happened ?
When CFG_TUD_HID_EP_BUFSIZE is set to 64, and a host (Such as Windows) sends a 64 byte packet as an OUTPUT report to the HID endpoint, the data is never received.
How to reproduce ?
As described
Debug Log as txt file (LOG/CFG_TUSB_DEBUG=2)
N/A
Screenshots
No response
I have checked existing issues, dicussion and documentation
- [x] I confirm I have checked existi...
So it turns out that now when doing an HID report that includes the report ID, the report size must be exclusive from the report ID. With previous versions, even when I included report ID (and sending a 64 byte packet), I'd have to say 64 bytes and not 63.
For Arduino, it depends on arduino-esp32 core, it may start up initizliaing usb stack as device mode in which case tusb stack need to be teardown/re-initialized to host mode (api may not available yet). Sum up, To use Adafruit_TinyUSB you need to make sure
- CFG_TUH_ENABLED = 1
- usb is initialized
@hathach wow that is incredible news thank you!
I would love to see some Arduino examples sketches.
Is there an issue at Arduino-ESP32 I can follow to know when your updates get compiled into core?
merged despite IAR issue, it is probably something with the license server. Skip/fix later.
@hathach Hi, is there an ETA about when this can get merged? Or do you need any help understanding or testing the code?
Sorry, I am just back from Lunar New Year, still catching up. All is good, I only need time to review all pending PRs. Thank you for your patient.
When I try to use the tiny usb cdc-acm for input and output (in my case, the esp-idf cli), the I get a task watch dog on the repl task (see stack dump below)
Any ideas what I'm doing wrong?
I took the esp-idf example of tusb console and added the esp-idf console, I can upload the changes I made
PS C:\dev\ESP\tusb_console> xtensa-esp32s3-elf-addr2line -pfiaC -e build/tusb_console.elf 0x42014FAF:0x3FC93CB0 0x420153CC:0x3FC93CD0 0x403770E9:0x3FC93D00 0x400559DD:0x3FC9CC50 0x4037D00E:0x3FC9CC60...
@inbarab This isn't a good place to get support for this error, it's almost certainly unrelated to the driver. You could post your code on Reddit or some beginner friendly forum.
[hathach/tinyusb] New comment on pull request #2923: Fix issues found using default CodeQL settings.
thank you for your PR and patient, I was off for TET (Lunar New Year).
Welcome back, and I hope your time off was all that you hoped!
I think we may just cast TOTAL_DRIVER_COUNT to uint8_t instead. To ensure TOTAL_DRIVER_COUNT is less than 255, we can do an TU_ASSERT() in tud_init() so that we only run the check once.
#define TOTAL_DRIVER_COUNT ((uint8_t) (_app_driver_count + BUILTIN_DRIVER_COUNT))
Could you help me understand the proposed assertion, whi...
@hathach Should we rename
dcd_edpt_iso_alloc()anddcd_edpt_iso_activate()to cover all endpoint types ?
I think we can skip/postpone this for now since it it not common. Revise later if needed.
[hathach/tinyusb] New branch created: fix-2923-alt
Describe the PR
make sure TOTAL_DRIVER_COUNT is not overflow 8-bit, alternative to #2923
[hathach/tinyusb] New comment on pull request #2923: Fix issues found using default CodeQL settings.
I made the change proposal for the idea here https://github.com/hathach/tinyusb/pull/2987 . We check/assert when app driver count is intialized and give up if total driver count overflows 8-bit. The rest should function as it is.
look good thank you. In the future, I would hope we could merge this driver to chipidea fullspeed making it easier to maintain driver.
@hathach wow that is incredible news thank you! I would love to see some Arduino examples sketches. Is there an issue at Arduino-ESP32 I can follow to know when your updates get compiled into core?
I haven't paid attention to arduino-esp32 lately, but It is moving fast. My CI HIL pool actually test esp32-p4 host function each PR https://github.com/hathach/tinyusb/blob/master/test/hil/tinyusb.json#L10 same dwc2 as s3 (with different usbip configuration). You ca...
This is brilliant !! Thank you, this can help to make building with ci easier. Thought the gen_presets.py need to be updated to genertae correct path to presets that in collective examples
path to BoardPresets.json is not correct (2 ../ less)
path to BoardPresets.json is not correct (one ../ less)
Describe the PR
update IAR LMS CLOUD to fix IAR build issue
Describe the PR
update make to use FreeRTOSConfig in family instead of examples, cleanup and remove board_mcu.h
I don't see any motive for this.
Thank you very much of your PR. It has been a quite and I really appreciate your effort and patient. I have been wanting to review/merge this but keep getting pulled by other works and kind of forgot sometimes. Adding an new host driver is significant works, and reviewing it may take a bit longer. Though I have sync it up with master, also fix some out of sync naming/signature/make changes. I run the example and it works well (great work).
We will need to migrate the endpoint to use the n...
I made more changes to update the driver to use the new endpoint stream API (similar to cdc host). I have only tested with midi_rx example, didn't test with tx at all. I will try to look up what the string doing with midi and continue to make more update, I think we should also need to make some driver API changes as well. Hopefully we could wrap this up and merge this soon enough.
look good thank you. In the future, I would hope we could merge this driver to chipidea fullspeed making it easier to maintain driver.
You're welcome. But merging the driver with the general purpose ChipIdea FS driver could be difficult because the 16-bit PICs have a unique BDT layout. The 8-bit PICs could have a third BDT layout.
Thank you so much for allocating some of your limited time to this. Us MIDI people really appreciate it!!
Is #2814 relevant (and maybe #2776) could they be accounted for in this merge?
look good thank you. In the future, I would hope we could merge this driver to chipidea fullspeed making it easier to maintain driver.
You're welcome. But merging the driver with the general purpose ChipIdea FS driver could be difficult because the 16-bit PICs have a unique BDT layout. The 8-bit PICs could have a third BDT layout.
That is what I hope if we could manage to solve these technical differences, we solve some of them with other usbip. However, I haven't actually run t...
Is #2814 relevant (and maybe #2776) could they be accounted for in this merge?
That PR solve another issue, and isn't part of this.
look great, thank you
@hathach Set CFG_MIDI_HOST_DEVSTRINGS to 1 to process the virtual cable names of the attached device for MIDI IN and MIDI OUT from the MIDI configuration descriptors and the string descriptors during enumeration and to enable the API for applications to read the strings. For example, on my Arturia KeyLab Essential 88 keyboard, virtual cable 0 is labeled "MIDI" and virtual cable 1 is labeled "DAW" for both MIDI IN and MIDI OUT.
@hathach I recommend that you reference the usb_midi_host project when merging this pull request. I have been maintaining it for quite a while and have fixed a number of issues since this pull request was submitted.
@hathach Set
CFG_MIDI_HOST_DEVSTRINGSto 1 to process the virtual cable names of the attached device for MIDI IN and MIDI OUT from the MIDI configuration descriptors and the string descriptors during enumeration and to enable the API for applications to read the strings. For example, on my Arturia KeyLab Essential 88 keyboard, virtual cable 0 is labeled "MIDI" and virtual cable 1 is labeled "DAW" for both MIDI IN and MIDI OUT.
Thank you for explanation
@hathach I recommend that yo...
PS: I made more changes to the API and its signature and feeling good for now. I will check the string thing later, need to switch to other works for now. So the string is mostly for displaying the label ? Besides that does it has any behavior or setting impact ?
@hathach Yes, CFG_MIDI_HOST_DEVSTRINGS is for displaying labels for virtual cables. Enabling the setting requires slightly more RAM and code space. Enabling it slows enumeration slightly because the driver needs to parse the Jack Descriptors. The setting does not change run-time behavior after enumeration. Applications with no UI do not need it.
Many MIDI devices do not implement Jack Descriptor strings. Some implement them, but do it poorly. An example RP2040 device that uses Jack Descr...
Default is still high speed, but setting
SPEED=high|full work as expected.
make BOARD=same70_xplained SPEED=full
Tested with examples/device/cdc_msc
lsusb -v
...
TinyUSB Device:
Product ID: 0x4003
Vendor ID: 0xcafe
Version: 1.00
Serial Number: 0123456789ABCDEF
Speed: Up to 12 Mb/s <------ full speed here
Manufacturer: TinyUSB
Location ID: 0x03142130 / 12
Current Available (mA): 500
Current Required (mA): 100...
That is a little beyond my skills, but I have opened an issue with core, asking for example Arduino code.
Thank you very much for your help :)
https://github.com/espressif/arduino-esp32/issues/10978
Operating System
MacOS
Board
ESP32-s3 devkit
Firmware
Any firmware using ESP32-s3 usb device, I worked on usb audio.
What happened ?
Look like there is a bug in calculation of available FIFO RAM for esp32-s3 (and also for P4 as I can see).
In file dwc2_esp32.h we can find this definition:
static const dwc2_controller_t _dwc2_controller[] = {
{ .reg_base = DWC2_FS_REG_BASE, .irqnum = ETS_USB_INTR_SOURCE, .ep_count = 7, .ep_in_count = 5, .ep_fifo_size = 1024 }
};
...
I understand that the topic has already been examined, and that the usage of a common DWC2 driver seems the best to limit effort, but in file dcd_esp32sx.c it's clear that things are different:
- first there is the following:
// FIFO size in bytes
#define EP_FIFO_SIZE 1024
so it's clear that 1024 is in bytes
- then this map:
// "USB Data FIFOs" section in reference manual
// Peripheral FIFO architecture
//
// --------------- 320 or 1024 ( 1280 or 4096 bytes )
// | IN F...
if we consider to have only 256 words and not 1024 for buffers on the esp32s3 the usb is very limited.
No, ESP32-S3 has only 256 word or 1024 bytes for USB FIFO, the value 4096 is for STM32 who has a bigger FIFO.
From reference manual:
OK, thank you , I had seen this ... and it's incoerent with the image in the technical reference ...
Moreover I was examing the fork of Tinyusb by expressif ...
https://github.com/espressif/tinyusb/blob/82a7a644ccbe5a38c725517ca3baf0703f90b2fb/src/portable/espressif/esp32sx/dcd_esp32sx.c
I don't have access to more detailed info, but trying to understand the code and reasoning on everything I believe...
Describe the PR
improving the structure and readability of the code, as well as enhancing the handling of USB hub status and control transfers.
@rppicomidi https://github.com/hathach/tinyusb/pull/2994 improve hub driver with pio-usb, there is still more to push. Let me know if that helps with your issue
Operating System
Linux
Board
Fruit Jam
Firmware
CircuitPython using enhance-hub branch.
What happened ?
An assert is hit. Code would crash without it due to a null pointer.
How to reproduce ?
Plug in more HID devices than TinyUSB is configured for. It tries to open all of the HID interfaces found. If it tries to open more than it's been configured for, then it hits an assert. Instead, it should fail to open the device using the HID driver but still make it availab...
@rppicomidi thank you for your explanation, if string is only used for displaying label. I think we can just add an optional callback that have all these information when parsing descriptor instead of storing them in the interface. If application need these, they should store it.
Any chance we could get this reviewed and merged in?
[hathach/tinyusb] New comment on pull request #2923: Fix issues found using default CodeQL settings.
It's been a couple months since I worked on this. If I understand your PR, you are trying to explicitly keep that macro to type uint8_t, and chose to use TU_ASSERT() to cause the firmware to hang at runtime if this is exceeded.
If this reduces the CodeQL warnings, then I'm OK with your alternate method, and you can close this PR.
this is always on my radar but still haven't manage time to review this.
Quick glance, looks like
src/common/tusb_debug.huses printf and snprintf;- hw/mcu/sony/cxd56 has some fseek calls but it also includes
stdioitself so not an issue NULLis also defined in stddef which is included anyway
running include-what-you-use after removing the stdio.h include might provide more clues.
[hathach/tinyusb] New comment on pull request #2923: Fix issues found using default CodeQL settings.
It's been a couple months since I worked on this. If I understand your PR, you are trying to explicitly keep that macro to type
uint8_t, and chose to useTU_ASSERT()to cause the firmware to hang at runtime if this is exceeded.If this reduces the CodeQL warnings, then I'm OK with your alternate method, and you can close this PR.
thanks, I am always working on something and got pending PR. the _app_driver_count is only assigned when initialization with tud_init() and the sum...
Thank you very much everyone for putting time and effort for this PR. Especially @atoktoto and @rppicomidi for getting most of the work done. I am sorry for being super late, I have to constant switching works and haven't worked much with rp2040 until now.
Though since there is lots of changes since this PR is created, I have update and also make lots of changes, notably:
- lost of API rename and signature changes to match other class driver consistency e.g num_rx_cables --> rx_cable_cou...
Applying this patch fixed the issue on my RP2040 with audio.
re-added code only seems to change wMaxPacketSize to the value larger than the one specified in endpoint descriptor which is out of specs. Can you
- provide the wMaxPacketSize of your endpoint descriptor along with your expected bitrate. Then
- try to increase the value in your endpoint descriptor to higher (maybe round up to 64) to see it would work then.
@hathach I am just back from travel. I may need a few days to get you feedback. Sorry for the delay.
@hathach If I pull master branch, it does not build. The file family.c fails on `#include "board.h" board.h:no such file or directory. Commit 9d2fd6c4acd334a25592487ba7d10b46ccecfedf still builds fine. Did some change not get pushed?
@hathach If I pull master branch, it does not build. The file
family.cfails on#include "board.h"board.h:no such file or directory. Commit 9d2fd6c still builds fine. Did some change not get pushed?
which BOARD you are building with, and your specific make/cmake commaand. I make some changes to the rp2040 bsp in the PR as well.
@hathach I am just back from travel. I may need a few days to get you feedback. Sorry for the delay.
no problems, please take your time.
Operating System
Linux
Board
Fruit Jam
Firmware
CircuitPython with PICO PIO USB Host
What happened ?
Device fails to enumerate.
How to reproduce ?
Enumerate a thrustmaster joystick full speed device connected through a ch334 hub. Also seen with an 8bitdo controller.
When setting the device address the device correctly sees the pack and acks. However if the host doesn't read the ack correctly, the transfer fails and is retried. It perpetually fails because the d...
The midi_rx example does not build. I tried the build with VS Code using the Raspberry Pi pico-examples project and pico-sdk 2.1.1. The reasons the build failed are likely out of scope for this pull request. I am writing them here because I do not know where else to file them.
It does not build for two reasons:
- The pico-sdk file
src/rp2_common/tinyusb/CMakeLists.txtsetsBOARDtopico-sdk, which does not work with the latest TinyUSB code. Even the develop branch of the `pico...
@rppicomidi how to do build the example, I normally just go to tinyusb/exmaples/ and cmake there. I surely can try to make it backward compatible.
Describe the PR
soc/usb_pins.h header will be deprecated in IDF v6.0. It is not needed nor used in current tinyusb
Additional context
Operating System
Linux
Board
Raspberry Pi Pico
Firmware
What happened ?
I tried to use the pico-examples project in the VS Code IDE. The project does not build. Refer to pull request #1627.
How to reproduce ?
- Start with tinyusb code after commit 1cfc88d
- Clone the pico-examples project
- Install Microso...
@hathach Refer to issue #3004 for reproduce steps. Yes, putting an empty board.h file in the pico-sdk directory seems to allow it to build.
I don't use vscode, can you provide equivalent cmake command to test with.
I am using the VS Code IDE. See issue #3004
@hathach Refer to issue #3004 for reproduce steps. Yes, putting an empty
board.hfile in thepico-sdkdirectory seems to allow it to build.
I don't use vscode, but if this fix the compile issue, let just do it. I guess I miss this board config
[hathach/tinyusb] New branch created: fix-rp2-picosdk-board
Describe the PR
fix #3004
I am sorry to argue. I do not love VS Code IDE either. However, the Raspberry Pi documentation instructs most of their users to use VS Code. The average Raspberry Pi Pico C/C++ application developer pool will encounter this issue as I described it. It is good to try Raspberry Pi Pico example code using VS Code. Same reason I try the Arduino IDE, too.
But from the command line, to build the device_info example:
export PICO_SDK_PATH=[your path to the pico-sdk]
export PICO_BOARD=pico
export...
Also need to fix 3 CMakeList.txt files. I added command line steps to reproduce to #3004.
ah thanks, seems like it is more than board.h in pico-sdk. I may make more changes as well, let me reproduce and try to fix it
Isn't the counterpart to tud_disconnect() simply tud_connect()? Adding _usbd_rhport = RHPORT_INVALID; to tud_disconnect() would break this pair of functions.
If you want to tud_init() after tud_disconnect(), shouldn't you call tud_deinit()?
Hi,
full tusb_teardown() implementation could be found in this PR: https://github.com/hathach/tinyusb/pull/2904
Oh hey look! Someone else is trying to do the same thing I am, but on the upstream library!
https://github.com/adafruit/Adafruit_TinyUSB_Arduino/issues/491
I've submitted a similar PR against Adafruit_TinyUSB_Arduino.
Oh hey look! Someone else is trying to do the same thing I am, but on the upstream library!
https://github.com/adafruit/Adafruit_TinyUSB_Arduino/issues/491
I've submitted a similar PR against Adafruit_TinyUSB_Arduino.
[hathach/tinyusb] New branch created: fix-8bitdo-enum
Describe the PR
- fix(hcd_rp2040) assert/panic endpoint already active: when a device reset while having on-going control transfer
- featuer(host) always get language id, manufacturer, product and serial string. Which is required by some device such as 8bitdo
- add tuh_descriptor_get_string_langid() API
@tannewt please try to see if this works with your 8bitdo gamepad
this may be fixed by https://github.com/hathach/tinyusb/pull/3007, @RobertDaleSmith if you have time to try it out.
Since you are working on usbh, I found at least on NUCLEO-H7S3L8 speed detection is more stable by putting tusb_time_delay_ms_api(ENUM_DEBOUNCING_DELAY_MS); at the start of enum_new_device().
I should note that this patch has saved the day on a big project, as it is the difference between working and not working for me as well.
It seems that the hw_endpoint_init() call is what is missing from the main repo. Adding it back as follows seems to work for me as well.
// New API: Configure and enable an ISO endpoint according to descriptor
bool dcd_edpt_iso_activate(uint8_t rhport, tusb_desc_endpoint_t const * ep_desc) {
(void) rhport;
const uint8_t ep_addr = ep_desc-...
Since you are working on usbh, I found at least on NUCLEO-H7S3L8 speed detection is more stable by putting
tusb_time_delay_ms_api(ENUM_DEBOUNCING_DELAY_MS);at the start ofenum_new_device().
hmm that is weird, delay before port_reset() shouldn't make a difference since port got reset anyway, and the delay afterwards is rather generous ~450ms. Thank you for the hint, I will check this out next time I test with h7rs.
would it work if you increase the wMaxPacketSize to 448 in device descriptor ?
Using the dcd_edpt_iso_activate() from current main repo, setting ep size to 448 did not change anything. No playback.
Using the snippet above with the hw_endpoint_reset_transfer() call, ep size to 448, WORKS!
Using LOG=2 output, the massive load of output messages breaks the audio playback, here is the LOG=1 output with your new snippet:
ep_desc->wMaxPacketSize: 448
ep_desc->wMaxPacketSize: 4
USB Streaming
USB Mount
Clock set current freq: 48000
ep_desc->wMaxPacketSize: 448...
In midi_host.c, lines 173-176
if (xferred_bytes) {
tu_edpt_stream_read_xfer_complete(&p_midi_host->ep_stream.rx, xferred_bytes);
tuh_midi_rx_cb(idx, xferred_bytes);
}
Many MIDI devices, especially from Korg, will always respond to an IN transfer request from the host with 64 bytes of data. If they have no data to send, they will send back all 64-bytes of zero instead of NAK. If they have only a single message to send, they will send back the first 4 bytes ...
A question about the example program: Why does it not also demonstrate MIDI TX? For example, see https://github.com/rppicomidi/usb_midi_host/blob/main/examples/C-code/usb_midi_host_example/usb_midi_host_example.c
The example will either light up the transport LEDs on MIDI controller devices that support play and record transport buttons, or it will play musical notes on sound generating MIDI devices. If the issue is you have no commercial MIDI hardware to test this, perhaps just hooking it...
There are some MIDI devices, especially guitar pedals, that are designed for high speed USB 2.0 instead of full speed. They also do not provide an alternate descriptor when the host is full speed. As a result, their bulk endpoint descriptor max transfer sizes are always 512 bytes. That is too large for chips like the RP2040 that only support full speed USB. The code in the usb_midi_host application driver limits the endpoint sizes to the maximum that the hardware supports before opening the...
tuh_midi_stream_write() should handle running status to make converting serial streams with running status encoded easier. This feature was added to the usb_midi_host application driver by pull request. See https://github.com/rppicomidi/usb_midi_host/blob/82a5c8e04bb16d638beafbb594c8f241279c6764/usb_midi_host.c#L616
Many MIDI devices, especially from Korg, will always respond to an IN transfer request from the host with 64 bytes of data. If they have no data to send, they will send back all 64-bytes of zero instead of NAK. If they have only a single message to send, they will send back the first 4 bytes encoded as a MIDI message packet and the remaining 60 bytes all zero. And so on.
Ah sorry, I didn't pay attention to this, I just did a quick check to see if all zeroes is a valid packet to make sure...
@rppicomidi which changes you need to make to the CMakeLists.txt. I have tried but it seems to compile the pico-examples just fine with current master (already added board.h to bsp/rp2040/pico_sdk)
cmake -DBOARD='raspberry_pi_pico' -DFAMILY='rp2040' ..
Using PICO_SDK_PATH from environment ('/home/hathach/code/pico/pico-sdk')
PICO_SDK_PATH is /home/hathach/code/pico/pico-sdk
Initializing PICO_BOARD from environment ('pico')
Initializing PICO_PLATFORM from environment ('rp2040')
Target bo...
thank you for the detail, I got what is really missing from my testing. I only test with the configuraation wherre it is either streaming or off entirely. Wehereaas you switch to very low bitrate 4 <-> 384 back and forth. Look like the issue happen when switching and the iso transfer is not complete yet (therefore you got the warning previously). Let me revise this, and I think we can update and get this merge.
If I remember correctly dwc2 does speed detection at the end of reset. If DEBOUNCING_DELAY_MS is placed after the end of reset then it won't help speed detection since it's already done.
New issue: exemple hid_mouse_log_filter mouse not scrolling up and down. https://github.com/adafruit/Adafruit_TinyUSB_Arduino/issues/501
@FearLabsAudio based on your feedback, I have updated the PR to abort pending PR if it is active. Would you mind to test again simply with your normal packet size = 392 to see if it still works.
@HiFiPhile it is weird, there is ENUM_RESET_DELAY_MS which is 50ms per USB specs, it should be enough for dwc2 to detect the link speed, the ENUM_DEBOUNCING_DELAY_MS is mostly waiting for device to bootup/clock init before we start talking to it iirc. I will check again later.
hcd_port_reset(_dev0.rhport);
// Since we are in middle of rhport reset, frame number is not available yet.
// need to depend on tusb_time_millis_api()
tusb_time_delay_ms_api(ENUM_RESE...
Great, audio should be functional on RP2404/2350 again!
I did move the ep size back to 392 and it works fine. I am using the macro in tusb_config.txt:
TUD_AUDIO_EP_SIZE(CFG_TUD_AUDIO_FUNC_1_MAX_SAMPLE_RATE, CFG_TUD_AUDIO_FUNC_1_N_BYTES_PER_SAMPLE_RX, CFG_TUD_AUDIO_FUNC_1_N_CHANNELS_RX)
Which in my case evaluates to 392
it is weird, there is ENUM_RESET_DELAY_MS which is 50ms per USB specs,
I think some devices need extra time to power on (DP is pulled high but not ready to communicate), in which case ENUM_RESET_DELAY_MS is not enough. Speed detection is done once hcd_port_reset_end(_dev0.rhport); is called but the device is not ready yet. Then we wait for ENUM_DEBOUNCING_DELAY_MS but since the detection is already done it's not very useful.
thank you for your feedback. @pschatzmann would you mind checking this to see if PR's update work for your setup. Once confirmed we can finally merge this :)
@gemarcano The last commit https://github.com/hathach/tinyusb/commit/ca0d53e80eb6d2a5a39630f523bf890954bbc87b Is working well for me.
@rppicomidi I made more changes to addres 2 of your reviewed issues
- all zero response: it is special case, I think we can just simply check if all rx bytes are zeroes instead of doing it in 4 bytes which is quicker. I guess there is no device that has zero packet between meanningful packets in the same response ?
- force bulk 512 -> 64 bytes is done in tu_edpt_validate() which will help other drivers using bulk/stream ep API as well.
Other issues can be resolved in follow-up PR, pleas...
Operating System
Windows 10
Board
MSP-EXP432E401Y
Firmware
examples/device/audio_test - master branch (commit 6bba41045a4224abb68256dcf2fce893da47a743)
What happened ?
I was tweaking the audio_test example to play back a raw PCM audio file and noticed that the sound seemed noisy. I went back and tried playing the audio from the unmodified audio_test example and it sounded noisy as well. I'm running this test on Windows so I wasn't able to get plot_audio_samples.py worki...
plot_audio_samples.py support Windows, you may need install dependencies and modify device = 'Microphone (MicNode) MME'.
When you did the recording you left logging on or off ?
[hathach/tinyusb] New branch created: fix-dwc2-host-conflict-max3421e
fix(dwc2) host driver conflict with max3421e, opt out hcd_dwc2 when max3421 is enabled
My issue was the script wouldn't get passed import sounddevice as sd. I'm not sure where I saw it but there is a software library (not just a python one) that I need to install on my Windows PC. The link for it pointed to a page that no longer had a reference to sounddevice for Windows.
No logging was used for my test or screenshot. I just use "make BOARD=msp_exp432e401y" to build the binary without modifying any sources.
I misunderstood what the assert does without a debugger. I looked and it returns false. So, it won't crash.
Related area
Host API
Hardware specification
RP2 PIO usb host code
Is your feature request related to a problem?
In CircuitPython we open endpoints before we use them. We only track what we use for a small period of time while the VM is running. If a second VM run opens an endpoint it will call open a second time. On PIO USB host code, this causes a second allocation for the open endpoint and basically leaks the memory of the first. Eventually the endpoint opening will fail b...
So debugging this a bit more. I wanted to repeatedly send a buffer with very recognizable pattern. So I filled test_buffer_audio array with 0x0000,0x1111,0x2222.....0x7777 and then repeat.
I'm seeing this from Audacity
and I'm seeing this in the raw USB data packets.
So it looks like data is being mangled som...
Thank you for your PR, the issue is caused when switching interface when endpoint is transferring data. https://github.com/hathach/tinyusb/pull/2937#discussion_r1981261121 I have updated this PR to abort pending transfer if active and reset and start clean. I will merge this now since I am in the middle of updating TinyUSB Arduino https://github.com/adafruit/Adafruit_TinyUSB_Arduino/pull/498 . Should it still be an issue with you, feel free to open issue/pr
closed due to lack of response
Operating System
Windows 11
Board
rp2040 with usb host
Firmware
exemple hid_mouse_log_filter mouse not scrolling up and down. not picking up mouse scroll up and down and move it up.tested from oldest to newest mouses.
What happened ?
exemple hid_mouse_log_filter mouse not scrolling up and down. not picking up mouse scroll up and down and move it up.tested from oldest to newest mouses.
How to reproduce ?
exemple hid_mouse_log_filter mouse not scrolling up and down....
While there is a define for the port, the clock enable is hardcoded for GPIOA, so setting a different port than GPIOA doesn't work. This fixes it by adding a define for enabling the port clock.
It also adds a define for the pin mode, because not all boards have the LED connected in a way that open drain works with it.
Describe the PR
A clear and concise description of what this PR solve.
Additional context
If applicable, add any other context about the PR and/or screenshots...
Describe the PR
This MR changes the following (listed in commit order):
- Turn
docs/contributing/code_of_conduct.rstanddocs/info/contributors.rstinto proper files (previously were symbolic links) - Fixed code formatting in
.rstfiles- Ensure all references to symbols (functions/variables etc) are displayed as inline literals (wrapped with double back ticks)
- Ensure that all code blocks have language specific syntax highlighting (if highlighting for that language i...
Ok. I think the issue is with the musb dcd layer. For some reason writing 32 bit values to the fifo is causing this corruption issue. Only doing 16 bit or 8 bit writes to the fifo appears to work and leads to the packets received on the PC matching what is expected.
Here are the changes I made.
The packets I receive now matches exactly what I expect.

[shell]$ make board=stm32l412nucleo SPEED=full all
make: *** tinyusb/hw/bs...
Please remove all from make
Please remove
allfrommake
The problem remains
Nice analyze, but the reason is something else.
Even if 32bit values are stored unaligned in FIFO, doing reg->u32 = *(uint32_t const *)addr; will first load the value into CPU register with a LDR instruction, since Cortex-M4 support unaligned memory access it should be ok, then the value is written into USB fifo.
You can test tu_unaligned_read32() for 32bit read loop https://github.com/hathach/tinyusb/blob/334ac8072650e3b18278042c2c2b402db73c7359/src/portable/synopsys/dwc2/dwc2_common...
Ops, BOARD should be in upper case, also since stm32l412 is FS only so need to add SPEED: make BOARD=stm32l412nucleo all
Your correct. Since none of my workarounds were working I did feel like something else was going on. Using the above function you mentioned didn't resolve the issue.
Looking at the FIFO register in the MSP432E TRM it seems like for a single packet mixing 32 bit, 16 bit and 8 bit writes are not allowed.
Taking a look at another device with the same Mentor IP it seems like they purely stick with 8 bit w...
For a single packet read and write operations must pick either 32-bit, 16-bit or 8-bit read or write operations. Mixing and matching can cause corruption of data.
This becomes a bigger issue when using TinyUSB fifo that has to deal with wrapping since read/write operations may be split between multiple transfers of different sizes.
Therefore, create a function that will determine which operation can be used for transfer the entire buffer of data. Then read and write operations can use a...
So although 96 bytes need to be written its possible that only 34 bytes are written initially and then 62 bytes are written. So I can see within 1 packet this mix match causing a problem.
Just read the DS, me too I think it should be the issue.
In fact (3) is already implemented by audio class (the only one who use fifo based transfer) as half of MCUs doesn't support fifo based transfer.
You can test with define TUD_AUDIO_PREFER_RING_BUFFER=0
We can either fix or remove fifo support...
Still seems to be an issue. I have installed the Pico-PIO-USB project using the script.
~/projects/pico/pico-sdk$ git status
HEAD detached at 2.1.0
Changes not staged for commit:
(use "git add <file>..." to update what will be committed)
(use "git restore <file>..." to discard changes in working directory)
(commit or discard the untracked or modified content in submodules)
modified: lib/btstack (new commits)
modified: lib/tinyusb (new commits, untracked content)
no changes a...
I will attempt to integrate this driver with some of my applications after you merge it. Any issues I encounter will result in smaller pull requests that should be simpler to review and manage.
I will attempt to integrate this driver with some of my applications after you merge it. Any issues I encounter will result in smaller pull requests that should be simpler to review and manage.
Thank you very much for the effort and patient so far. Feel free to submit more follow-up PRs, I will try to review them as soon as I could.
[hathach/tinyusb] New branch created: fix-pico-examples-build
fix(rp2040) set RTOS as cmake cache to fix pico-example build
thank you, I am able to reproduce the issue, this should be fixed by #3019
minor fix on calculation of desc_end in vendord_open( ) for descriptor prasing
Describe the PR
fix desc_end calculation
In vendor device class, function vendord_open()
Additional context
In vendor_device.c, original code
https://github.com/hathach/tinyusb/blob/master/src/class/vendor/vendor_device.c
const uint8_t* p_desc = tu_desc_next(desc_itf);
const uint8_t* desc_end = p_desc + max_len;
desc_end is calaulated by p_desc + max_len which is `u_d...
Still nothing about this topic?
I don't have time and experience with ffb to write this example. PR is welcome
i dont understand why hathach keep updating tinyusb but not Adafruit_TinyUSB_Arduino.
I assume the arduino library is only updated on releases of tinyusb
you could ask them to in an issue if you like
Thank you for the fix, but the logic can be better.
For example non-fifo based 11 bytes transfer can be 5*16b loops + 1*8b loop.
- even length -> 32b + 16b transfers
- odd length -> 16b + 8b transfers
Operating System
Others
Board
iMXRT1052EVB
Firmware
Currently high speed is disabled for iMXRT family CPUs USB host, as mentioned in the comment:
https://github.com/hathach/tinyusb/blob/master/src/portable/chipidea/ci_hs/hcd_ci_hs.c#L99
When will it be fixed?
What happened ?
When the host in high speed:
- Have issue when plug/unplug devices.
- Does not detect disconnection
How to reproduce ?
- Override full speed mode by commenting out statement
https://githu...
Please don't repost known issue
Sorry, where is the socalled known issue?
Describe the PR
Add Media Transfer Protocol (MTP) device class support
Additional context
Feature request reference: https://github.com/hathach/tinyusb/issues/1079
The implementation has been tested and found functional at prototype level. We provide an example tested on STM32F3. It makes use of blulk and interrupt EPs only, so it should be supported by most platforms.
The class supports a single session only, but it allows multiple objects and nested associations (i.e. fil...
Operating System
Others
Board
ESP32-S3
Firmware
Probably the most relevant example is uac2_headset.
What happened ?
After the 0.18.0 release, certain platforms such as iOS fail to record the microphone because the endpoint stalls. This was root caused to missing 4 byte alignment on ctrl_buf_1. It seems that this changed in #2865 but it is unclear why it was changed, probably a mistake.
How to reproduce ?
Record microphone in a USB audio class 2.0 example. The orig...
Hi, with a first look I think the issue should be elsewhere, since with DWC2 IP (used by ESP32) there isn't an alignment requirement for control transfer buffer. Also data buffer aligment is only needed when DMA is enabled.
Meanwhile ctrl_buf_1 should be aligned for some NXP MCUs
Operating System
Linux
Board
raspberry pi pico
Firmware
examples/host/midi_rx except modified tusb_config.h to add the line
#define CFG_TUH_MIDI_STREAM_API 0
What happened ?
Build failed.
pico-sdk/lib/tinyusb/src/class/midi/midi_host.c:156:24: error: 'midih_interface_t' has no member named 'stream_read'
[build] 156 | tu_memclr(&p_midi->stream_read, sizeof(p_midi->stream_read));
pico-sdk/lib/tinyusb/src/class/midi/midi_host.c:157:53: error: 'midih_...
Describe the PR
Fix issue #3028
Additional context
See Issue #3028
Unused static variable
Static variable mtp_object_properties_supported is never read.
Comparison result is always the same
Comparison is always false because xferred_bytes >= 64.
No trivial switch statements
This switch statement should either handle more cases, or be rewritten as an if statement.
Long switch case
Switch has at least one case that is too long: MTP_PHASE_DATA_IN (36 lines).
Congrats!
I started working on my own MTP driver about a week ago and just got the first few things working now before I found your PR. Nowhere near done yet but here's my branch in case it helps anybody: https://github.com/WerWolv/tinyusb/tree/sicd
Operating System
Linux
Board
rp2040
Firmware
https://github.com/Cpasjuste/uGamePad
What happened ?
Hi,
In my (rp2040/rp2350) project, i did update tinyusb to be up to date. But since then, i have a device which is not working anymore in host mode. This is the "Neo Geo Mini USB-C Gamepad".
The problem comes from the addition of the "newly added" enumerations in [usbh.c](https://github.com/hathach/tinyusb/blob/5333d042f9384ec1cc0663a2708c0ca7cb5cdc32/src/host/usbh.c#L1...
Related area
The midi_host driver addresses the attached device by index. Device string get functions need the device address.
Hardware specification
Is hardware independent. I am testing on Raspbery Pi Pico
Is your feature request related to a problem?
I want to be able to fetch Manufacturer, Product and other device strings without blocking the code. The host API that supports that requires the device address. The mount callback returns the device address within the callbac...
we can implement tuh_cdc_itf_get_info(uint8_t idx, tuh_itf_info_t* info); similar to https://github.com/hathach/tinyusb/blob/master/src/class/cdc/cdc_host.c#L287
Tried the uac2_headset example in pico2040 with linux, and the device is not showing up and this the output from dmesg. Any help would be appreciated
[ +0.093643] usb 3-2.2: USB disconnect, device number 10
[ +0.434362] usb 3-2.2: new full-speed USB device number 11 using xhci_hcd
[ +0.109792] usb 3-2.2: New USB device found, idVendor=cafe, idProduct=4010, bcdDevice= 1.00
[ +0.000004] usb 3-2.2: New USB device strings: Mfr=1, Product=2, SerialNumber=3
[ +0.000003] usb 3-2.2: Produ...
OK. Pull request coming shortly.
Describe the PR
See #3031
Additional context
See #3031
Operating System
Linux
Board
pico
Firmware
examples/host/midi_rx
What happened ?
Each virtual cable in a USB MIDI device consumes at least one internal jack and one external jack. Although devices with more than a total of 8 virtual cables are not common, they do exist. For example plugging a MOTU MIDI Express 128 would cause https://github.com/hathach/tinyusb/blob/5333d042f9384ec1cc0663a2708c0ca7cb5cdc32/src/class/midi/midi_host.c#...
@WerWolv thank you for sharing!
I am giving some context here, asย it might be beneficial for review.ย I had a short look at your code, the implementation is not that far from the one we're suggesting. Since you already have a hands-on experience on how the MTP class works, it would be great if you could take a look at our code too (feel free to add comments or propose corrections) and maybe perform a test on a physical device (since now, we tested it on STM32F3 and on a custom PSoC5LP port, o...
[hathach/tinyusb] New branch created: ctrl_fix
Describe the PR
Title.
Additional context
@hathach Please sync mcux-sdk to 2.15 which moved the delay to between AHBCLKCTRLSET and USBPHY->CTRL_CLR.
Merged the latest changes in master branch.
Current problems (and I need help):
- The communication to LowSpeed device via external HUB sometimes fails. (ex: cannot get the device descriptor, tuh_mount_cb() not called)
- Plugging to the Root Port doesn't cause the problem with same device.
- In my test, USB keyboards are often causing this problem.
- Plugging the external HUB sometimes causes the resetting MCU.
thank you. I will update mcux sdk later, since I am in the middle of other paid works.
Thank you for the update and patient, sorry, I am stil busy with other works. Will check this out as soon as I could.
UAC ctrl buffer alignment fixed in #3034.
Operating System
Linux
Board
Firmware
.
What happened ?
Seems like cmake on my system was installed by Visual Studio, and default generator was Visual Studio 17. As a person not really familiar with cmake it took some time to understand it and fix it with env variables. Maybe it make sense to enforce needed generator to avoid this problem?
How to reproduce ?
.
Debug Log as txt file (LOG/CFG_TUSB_DEBUG=2)
.
Screenshots
No response
I have checke...
You can use CMake Presets: cmake --preset lpcxpresso55s69, cmake --build --preset lpcxpresso55s69
Maybe it make sense to enforce needed generator to avoid this problem?
It's impossible with CMakeLists.txt
Operating System
MacOS
Board
STM32F411 Blackpill
Firmware
examples/host/midi_rx
What happened ?
I can't seem to get tuh_umount_cb/tuh_midi_umount_cb to be called when the device is unmounted, even if I use the stock example.
How to reproduce ?
Just build any example, I use examples/host/midi_rx and upload it to blackpill. Plug in and unplug device.
Debug Log as txt file (LOG/CFG_TUSB_DEBUG=2)
[debug.txt](https://github.com/user-attachments/files/1927...
@verylowfreq I'm glad you're working on this! If you need someone for tests, hit me up, I have a nanoCH32V203 which I can do tests with.
Operating System
Linux
Board
pico
Firmware
I am trying to build a project that uses this library.
yet it constantly fails.
I do not have the dcd_pio_usb.c and hcd_pio_usb.c files. I am missing the pio_usb directory (inside ~/pico/pico-sdk/lib/tinyusb/src/portable/raspberrypi there is only an rp2040 folder).
I tried to manually create the folder and put the files in manually, from this repo, however, the build still fails.
I am suspecting I have an older version of ...
[hathach/tinyusb] New branch created: update-pio-usb
Describe the PR
change pio-usb to upstream
How it is intended to do when building from make?
How it is intended to be done when building from make? (As I can see, make calls cmake)
I will update the readme later, it basically, you can pick either make/ninja as generator
cmake -Bbuild_dir BOARD=adafruit_feather_nrf52840
cmake -Bbuild --build
thanks for the issue, it should be fixed now, I change to use an wip pio-usb fork previously.
can you rebase master to fix ci
So instead of
make BOARD=raspberry_pi_pico FAMILY=rp2040 CMAKE_DEFSYM='-G "Unix Makefiles" ' all
should I use
cmake -Bbuild_dir BOARD=raspberry_pi_pico FAMILY=rp2040 cmake -Bbuild_dir --build
(Not at home rn, I can test command above in 9 hours)
Thank you so much! Do I have to do something different now? Or just remove the folder and redo the git submodule update --init --recursive as before?
I rebased and pushed. The code builds on my system. The diff shows only my changes. What is broken?
Thank you for the effort, but I tried exactly the same thing:
cd ~/pico/pico-sdk/lib
rm -rf tinyusb
git submodule update --init --recursive
And i get exactly the same results. Do i have to do something differently?
Sorry for the trouble.
Describe the PR
A clear and concise description of what this PR solve.
Additional context
If applicable, add any other context about the PR and/or screenshots here.
Related area
IOS apple support
Hardware specification
rp2040
Is your feature request related to a problem?
No this will allow the embedded devices to connect to IOS device and open a whole new avenue of innocative IOT project that work with apple ecosystem
Describe the solution you'd like
A usb host example to communicate with usbmuxd library to interact with IOS devices
I have checked existing issues, dicussion and documentation
- [x] I confirm I have checked exi...
Operating System
Linux
Board
RP2040
Firmware
N/A
What happened ?
There's a discrepancy in how TinyUSB and PICO_SDK check if stdio to UART is enabled.
From https://github.com/raspberrypi/pico-sdk/blob/master/src/rp2_common/pico_stdlib/stdlib.c
void setup_default_uart(void) {
#if LIB_PICO_STDIO_UART
stdio_uart_init();
#elif defined(PICO_DEFAULT_UART_BAUD_RATE) && defined(PICO_DEFAULT_UART_TX_PIN) && defined(PICO_DEFAULT_UART_RX_PIN)
...
#endif
while TinyUSB...
tinyusb use python script instead of sumodule to manage dependencies, try run this in tinyusb/
python tools/get_deps.py rp2040
I rebased and pushed. The code builds on my system. The diff shows only my changes. What is broken?
previously pio-usb is pointed to my wip fork, but that is merged upstream and the branch is deleted. Seem like your PR still have issue with conversion warnings. Please try to fix that.
Hello everyone, and thank you all for the effort of speeding up USB host on the Raspberry Pi Pico! Unfortunalely, after testing the proposed re-implementation of the RP2xxx HCD, I've found a couple of bugs and potentional issues that would be nice to have fixed:
- This code assumes that there can be only one USB hub attached (see https://github.com/rppicomidi/tinyusb/blob/f981f5c9fdd8ea227650f145af43829d836c1534/src/portable/raspberrypi/rp2040/hcd_rp2040.c#L113), while in fact the number of ...
Thank you. I found out how to view the detailed build logs and finally saw the error.
Thanks for the answer. Sorry for annoying you again, but I do not have such a file inside /tinyusb/
~/pico/pico-sdk/lib/tinyusb/tools$ ls -la
total 52
drwxrwxr-x 4 user1 user1 4096 ฮฮฑฯ 18 21:20 .
drwxrwxr-x 10 user1 user1 4096 ฮฮฑฯ 18 21:20 ..
-rw-rw-r-- 1 user1 user1 4415 ฮฮฑฯ 18 21:20 build_board.py
-rw-rw-r-- 1 user1 user1 3586 ฮฮฑฯ 18 21:20 build_esp32sx.py
-rw-rw-r-- 1 user1 user1 5456 ฮฮฑฯ 18 21:20 build_family.py
-rw-rw-r-- 1 user1 user1 2321 ฮฮฑฯ 18 21:20 iar_gen.py
-rw-r...
your pico-sdk and tinyusb is too old, please update both and try again
please move this up, right after the bInterfaceNumber
Those are standard request, I dont see why it could cause the issue, can you get and post the debug log and the device info using pc such as lsusb -v here
HiFiPhile means this issue is known by maintainer and we just don't have time and motivation to address it atm. Regarding the question "When will this be fixed ?" the answer is always "when someone makes an PR"
Once again, thank you for the comment.
Sorry if I am being a noob, but since I do not have recent experience in this (it's been some time since I played with the pico), and I am afraid of messing things up, what is the reccomended way to update the sdk and the tinyusb library?
I have been trying to update the tinyusb, but I guess this doesn't work since the sdk is old. Does tinyusb come with the sdk?
Is there a guy somewhere?
check out the rpi pico guide for step by step detail
just bump it to 32, the structure is use temporarily and does not occupies longterm memory at all.
Hi,
Yes I agree, this is strange. The device is a proprietary thing thought, maybe it's not "compliant".
I would need to buy a usb-c to usb-a someday (wanted to do that since a while), so for I now I will try to take a closer look on the pico in the next days and report back.
Thanks !
With Pull Request #3032, this issue is fixed as far as I am concerned.
Describe the PR
See issue #3033
Additional context
See issue #3033
can you put an bracket for if() { }
I also notice at line 594 the statement is out of place, it is either part of default of get the wrong indent, would you mind double checkinging it. Thank you
https://github.com/hathach/tinyusb/blob/4b46493cb4f8699c95e01783eee5cf90ca7810e2/src/class/midi/midi_host.c#L592-L594
@hathach Good catch on line 594! Yes, that statement is out of place. Will fix it.
@wbcbz7 Thank you for taking the time to review this in detail.
This code assumes that there can be only one USB hub attached
Yes, that is because multiple hub support is a relatively new feature. I will address that.
During my tests of simultaneous USB Mass Storage and HID devices, it turns out control transfers can get sometimes corrupted by current EPx transfer control structures, and vice versa
Can you post evidence of that happening? For example, a USB sniffer trace, ...
Can you post evidence of that happening? For example, a USB sniffer trace, a log, or a file diff? It will help me root cause the issues you are seeing.
I'll try to hook an logic analyzer and dump a trace at weekends, so far you can try to reproduce a bug this way:
- Clone a
host_cdc_msc_hidexample from Pico-SDK, then add a simple routine tomsc_app.cwhich will repeatedly read or write data from the mass storage device (i.e. from [this gist](https://gist.github.com/wbcbz7/95ce4c1aa03...
@wbcbz7 Thank you for the additional information. I will try your experiment.
By design, the HCD first tries pending Control transfers, then pending Interrupt transfers, and only if there is any time left in the frame does it try pending Bulk transfers. If you are seeing large bulk transfers slowing down HID interrupt polling rate, then there is a problem. Control transfers that NAK for a long time could potentially slow down the polling interval because RP2040 auto-retry cannot be disable...
@wbcbz7 I have addressed the hub issue and have done a git merge with the latest TinyUSB and pushed it up. I am trying your test code now and find no evidence of issues yet. I am using a powered 4-port hub, a USB mouse plus 2 USB flash drives. Is there a particular block size or blocks per transfer number that causes issues in your testing? Is it possible that the merged code you created introduced some other issue?
@rppicomidi, I've just libked the test application with your latest commit, and while it seems to bie slightly more stable, it still appears to occasionally hang during bulk transfers if control transfers are executed concurrently. I've tried usb-sniffer-lite to capture USB frame data but even with an external trigger it seems to not have enough buffer memory to capture the exact moment of hang, so I had to revert back to my logic analyzer. Attached there are two PulseView sessions with bulk ...
Operating System
Windows 11
Board
M5stack cardputer with espressif esp32-s3
Firmware
FREETOS
What happened ?
I am trying to use cardputer with esp3-s3 microcontroller in USB host mode.
The 1st hurdle is that for ESP32-S3 code for USB PHY initialization is missing in tinyusb. This can be circumvented by using a function from the espressif usb component (usb_new_phy).
After calling usb_new_phy the call to tusb_init will succeed.
tusb_init is followed by tuh_task.
We wait ...
Is it usable for the voard in its current state?
Is it usable for the board in its current state?
If you use it in device mode yes.
Unfortunately I need Host mode:(
ST's usb stub makes me suffer.
As I can say, there are problems with the board itself. Even examples code sometimes doesn't work, because of the device's USB controller state. I think it breaks some state inside itself, that's why it happens. Only powering it off for ~10 seconds helps. I don't know why is that, but it's true. I can prove it on my board.
`static usb_phy_handle_t phy_hdl;
/**
- @brief Main entry point for the ESP-IDF application.
- Initializes TinyUSB in host mode and continuously polls for USB events.
- When the device descriptor is received, it is printed to the console.
*/
extern "C" void app_main(void)
{
// Configure USB PHY
usb_phy_config_t phy_conf = {
.controller = USB_PHY_CTRL_OTG,
.target = USB_PHY_TARGET_INT,
.otg_mode = USB_OTG_MODE_HOST,
.otg_speed = USB_PHY_SPEED_UND...
@HiFiPhile .. thank you for pointing me to this. If I had known earlier, it would have saved me 2 days of debugging. I took the usb_init code that you pointed me to. It does the same stuff that I figured out myself the hard way.. but the code looks a lot nicer now.
Unfortunately it does not resolve the crash problem with CFG_TUH_DWC2_SLAVE_ENABLE.
I managed to create the debug log with log level 3 now. However, I had to "manually" terminate the logfile in the channel_xfer_start function as o...
OK.. don't spent cycles on this. I will try to generate a core dump.
I can reproduce this phenomenon on STM32H7S3L8.
The cause is some devices behaves badly on control request, like ACK to setup packet but NACK to data packet. Since every retry 2 interrupts are fired it will stuck hard.
A random USB Key:
@hathach we may need to limit NACK storm.
@torsts can you test the stock example exmaples/host/device_info or cdc_msc_hid_freertos to see if that woks. I personally don't have issue with esp32 mcu.
@HiFiPhile I will check this later, we can limit NAKs per frame for each endpoint e.g 3 times
@hathach I will try the examples you are referring to. In addition I will try to increase the stack size. Eventually the stack is more preassured with CFG_TUH_DWC2_SLAVE_ENABLE and the chances for an overflow are bigger.
Stacksize does not seem to play a role here. I noticed something else. We dont seem to be able to get out of an interrupt signalling state. I did some debugging around hcd_int_handler. We hit GINTSTS_CONIDSTSCHNG, then GINTSTS_HPRTINT and then > 30 x GINTSTS_NPTX_FIFO_EMPTY without ever receiving something. This is strange.. IIRC the 1st packet has 8 bytes max.. so even when sending each byte individually, we should have received something in the meantime. Will have a closer look to handle_tx...
I tried exmaples/host/device_info. Had to rewrite the code a bit as I dont have a board with LED. I am facing the same behavior. I will keep debugging with my original project.
Looking deeper.. the OS does not crash. It gets reset with reason ESP_RST_INT_WDT.
Here is the weird thing, we call into handle_txfifo_empty but inside we never call dfifo_write_packet. So the packet does not go onto the wire.
Eventually I am missing some FIFO setup code.
if ((xact_bytes > (txsts_bm->fifo_available << 2)) || (txsts_bm->req_queue_available == 0)) {
This is why we "fail":
txsts_bm->fifo_available == 0 and txsts_bm->req_queue_available == 0;
I tried exmaples/host/device_info. Had to rewrite the code a bit as I dont have a board with LED. I am facing the same behavior. I will keep debugging with my original project.
- you can skip the led, just define a dummy pin. That will make sure we test on the same software (I also prefer to test with stock example as well).
- Also please provide the LOG=2 output
- Does the issue occurs with other device or only with 1 specific ? what is the device specific make/model and its configurat d...
BOARD_ConfigMPU() is mcu-specific, this work with rt1170 but I have issue with rt1060 and other smaller variant such as 1015. I will comment this for now (in the next push/pr). we can generate and move these into its own board later when having time. :)
Unfortunately I just have 1 device and it is not a developer board. This means: no LEDs, just one USB connector. When USB is used by code, I am loosing the builtin JTAG capability as there is some "hardwiring" to the USB port. I had to add code, that redirects printf to a file that will be stored on a microSD card. In addition I had to close the file before freeRTOS reboots.. otherwise it will have 0 content. I logged with LOG level 3. Here is what I get when using the FIFO (before reset):
U...
Unfortunately I just have 1 device and it is not a developer board.
The question is about the devices tested when esp32 is acting as host, like keyboard, usb key, etc.
I think the problem is that imx family is too generic, minxing too many architectures.
yeah, I think mcxepersso pinconfig can generate mpu code (not sure), will do that later on. trying to add imxrt1064 to test both device and ehci mode and need to disable this to get it work.
I tried 3 different devices and could do more.. the device arrival is recognized but as soon as I want to fetch the 1st descriptor, the bytes from "Get Descriptor" dont go into the fifo.. hence never leave the esp32
I have the same thing on S3 with device_info example and default config (CFG_TUH_DWC2_SLAVE_ENABLE=1).
With CFG_TUH_DWC2_DMA_ENABLE=1 all works.
Seems that something changed after adding the DMA support.
Was it working in single mode before adding the DMA?
@torsts Could you try to comment these lines and try again please?
diff --git a/src/portable/synopsys/dwc2/hcd_dwc2.c b/src/portable/synopsys/dwc2/hcd_dwc2.c
index b13479b02..723d1169b 100644
--- a/src/portable/synopsys/dwc2/hcd_dwc2.c
+++ b/src/portable/synopsys/dwc2/hcd_dwc2.c
@@ -814,9 +814,9 @@ static bool handle_txfifo_empty(dwc2_regs_t* dwc2, bool is_periodic) {
// skip if there is not enough space in FIFO and RequestQueue.
// Packet's last word written to FIFO...
I have the same thing on S3 with
device_infoexample and default config (CFG_TUH_DWC2_SLAVE_ENABLE=1).With
CFG_TUH_DWC2_DMA_ENABLE=1all works.Seems that something changed after adding the DMA support.
Was it working in single mode before adding the DMA?
I forgot, I think hcd dwc2 are mostly tested on P4. Slave and DMA are added pretty much same time. I will try to pul out a S3 to test with and maybe added that to the hil pool as well. Btw, does the issue occurs with...
Dont have an S2. ;) .. I commented out the lines as requested.. The behavior changes. No watchdog reset anymore. However, I still dont seem to receive the descriptor (at least on the top application level). One thing I can already confirm, with this change I get further and receive a GINTSTS_HCINT -> handle_channel_irq. This is where my current debug centers.
As a sidenote, espressif itself uses the dma in host mode. Will eventually try to force slave mode on them in case I figure out a coup...
Dont have an S2. ;) .. I commented out the lines as requested.. The behavior changes. No watchdog reset anymore. However, I still dont seem to receive the descriptor (at least on the top application level). One thing I can already confirm, with this change I get further and receive a GINTSTS_HCINT -> handle_channel_irq. This is where my current debug centers. ... and afterwards we get GINTSTS_RXFLVL as well.
As a sidenote, espressif itself uses the dma in host mode. Will eventually try...
@torsts
Could you replace the printf with the esp_rom_printf, by adding the lines in tusb_config.h:
`
#define CFG_TUSB_DEBUG_PRINTF esp_rom_printf
`
and then share the log?
@roma-jam I dont have a developer board.. so just the one (1) builtin USB. From my understanding, jtag and serial print gets lost as soon as I switch the controller into host mode. How exactly would I retrieve the log from esp_rom_printf ?
I in a state where "something (process_enumeration) worked once"... but not stable. Now it feels like a race condition.
I am working on getting a LOG but I likely have to pick a different approach than esp_rom_printf.
@torsts
Ah, I didn't get that you use the custom board.
How exactly would I retrieve the log from esp_rom_printf ?
This macros redefine the printf implementation and (in case printf is being called from ISR) prevent the exception. But this is not our case, I also read that you already redirected it to the SD card.
In case, you commented out the lines, what is the last line in the log?
Before it was
Get 8 byte of Device Descriptor
[0:0] Get Descriptor: 80 06 00 01 00 00 08 00
```...
@roma-jam .. ok.. took a bit .. here the last lines of the log
/--
...
Device configured
Parsing Configuration descriptor (wTotalLength = 32)
Device mounted, address: 1
[0:1] Get Descriptor: 80 06 00 01 00 00 12 00
on EP 00 with 8 bytes: OK
on EP 80 with 18 bytes: OK
[0:1] Control data:
0000: 12 01 10 02 00 00 00 40 1C 1B 0E 1A 00 01 02 03 |.......@........|
0010: 01 01 |..|
on EP 00 with 0 bytes: OK
--- Device Descriptor for device 1 ---
...
@hathach , @roma-jam , @HiFiPhile .. I am ready to close this bug report from my side as the original problem seem to be resolved with the removal of the lines. What is your opinion on this?
@torsts I don't think that my suggestion could be a solution, as I just offer that to disable the usage of txsts_bm pointer, which uses gnptxsts as a source for fifo_available value, as this register is not relevant when dedicated FIFO is used.
But this is not a solution so far as we need another mechanism to handle the available FIFO.
I am able to reproduce the issue with S3 and host slave mode while it works with dma mode. As discussioned, it is probably an forever blocking while() in the driver. Will try to troubleshoot this next time I got to work with hcd dwc2.
TinyUSB Device Info Example
[0:] USBH Device Attach
I (346) main_task: Returned from app_main()
Guru Meditation Error: Core 0 panic'ed (Interrupt wdt timeout on CPU0).
Core 0 register dump:
PC : 0x4200c069 PS : 0x00060034 A0 : 0x8200c...
Related area
CH32V307 is supported by tinyusb, is it possible to support CH32V303 and CH32V305?
Hardware specification
CH32V303
Is your feature request related to a problem?
I've tried to run CH32V307 porting on CH32V303. But it doesn't work.
Describe the solution you'd like
Support CH32V303 and CH32V305.
I have checked existing issues, dicussion and documentation
- [x] I confirm I have checked existing issues, dicussion and documentation.
Took me almost the day.. but looks like I finally figured it out. We seem to face an architectural problem that the compiler is hiding from us. Below you will find some code that I wrote do to demonstrate the issue. I had to do the system_abort as I cannot debug my custom board without a coredump.
`// Define a volatile pointer to the register
volatile uint32_t *reg_ptr = (volatile uint32_t *)0x6008002C;
// Read the register value
uint32_t reg_value = 0;
value2_4 = txsts_bm->fifo_available;
...
Hello,
I'm trying to port to the STM32H747XIH using the STM32H747-DISCO board, using only HS host for CDC, MSC and HID, for three days, and no matter what I do, I always get stuck at:
while (dwc2->grstctl & GRSTCTL_CSRST) {}
- I have already tried an empty project, just simple porting.
- Then, I adapted the STM32H743 example.
- Added HAL_PWREx_EnableVddUSB during initialization.
- Added @static void reset_core(dwc2_regs_t* dwc2):
while (!(dwc2->grstctl & GRSTCTL_AHBIDL)) { }
Can anyb...
Nice found, it looks like something similar to #2940, in that case it's a armcloang's bug. I'm not familiar with the ABI of xtensa core.
@HiFiPhile . yes, pretty similiar.. and I agree to the MACRO strategy as I have seen something like this before. Unfortunately I am a reverse engineer and not a coder.. otherwise I would go and shoot for a fix myself.
Describe the PR
A clear and concise description of what this PR solve.
Additional context
If applicable, add any other context about the PR and/or screenshots here.
Apologies, meant this PR for my forked repo.
Operating System
Others
Board
STM32H747I-DISCO
Firmware
examples/host/cdc_msc_hid
What happened ?
I am trying to use STM32H747I-DISCO as Host to plug USB HUB
In this hub I will conect a CDC, HID and MSC.
I solved many problems, but this last one I need help.
The USB3320 CPEN pin controls VBUS and I cant turn this pin on.
How to reproduce ?
Just run the STM32Cube project
https://github.com/eng-software/TestTinyUSB.git
Debug Log as txt file (LOG/CFG_TUSB_DEB...
No problem, I have made the same mistake as well
ESP-IDF also met this issue: https://github.com/espressif/esp-idf/blob/a45d713b03fd96d8805d1cc116f02a4415b360c7/components/hal/platform_port/include/hal/misc.h#L34
To be able to use this macro GCC's statement expression and typeof extensions are needed, armclang and IAR EWARM(not affected) support it.
Hi @roundby
Great work, do you try it with littlefs?
Operating System
Others
Board
RP2040 Custom board
Firmware
/*
- The MIT License (MIT)
- Copyright (c) 2019 Ha Thach (tinyusb.org)
- Permission is hereby granted, free of charge, to any person obtaining a copy
- of this software and associated documentation files (the "Software"), to deal
- in the Software without restriction, including without limitation the rights
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- copies of the Softwar...
This commit breaks USB High Speed on my Renesas Vision Board RA8D1 chip. I was applying patches one by one from a working High Speed
version (however with a bug that sometimes drops a single byte on reception). When reached this commit, all sorts of bad things start to appear. like failed asserts and when replacing with the new /portable/renesas/rusb2/dcd_rusb2.c still worse.
I am going to take a finer grained approach (since this is a huge commit) to detect what is wrong with it. But w...
Now its working.
- I fixed my hardware startup
- Removed the option
Sugestion:
USB disconnection is not working verywell, so I suggest the change above:
static void handle_hprt_irq(uint8_t rhport, bool in_isr) {
dwc2_regs_t* dwc2 = DWC2_REG(rhport);
uint32_t hprt = dwc2->hprt & ~HPRT_W1_MASK;
const dwc2_hprt_t hprt_bm = dwc2->hprt_bm;
if (dwc2->hprt & HPRT_CONN_DETECT) {
// Port Connect Detect
hprt |= HPRT_CONN_DETECT;
if (hprt_bm.conn_status) {
hcd_event_d...
Related area
driver
Hardware specification
rp2040
Is your feature request related to a problem?
When I was using the example about the mouse, I found that it seemed there was no use of the absolute position of the mouse, but all were using the relative position.
Describe the solution you'd like
I hope to add relevant functions or provide other solutions to enable the use of absolute positions.
I have checked existing issues, dicussion and documentation
- [x] I con...
Sorry, it seems that I have figured out the definition of absolute position. I'll go and verify it.
[hathach/tinyusb] New branch created: update-endpoint-open
- fix(hcd) hcd_edpt_open() return true if endpoint is already opened.
- also update the device_info example
Describe the PR
The SOF flag was not cleared in the hcd_int_handler() ISR or handle_sof_irq() function inside of it.
This caused recurring and infinite IRQs in some cases (e.g. when connecting a HUB).
Additional context
See discussion here: https://github.com/hathach/tinyusb/discussions/3062
Thank you , indeed it looks better !
Thank you for the PR, I think you missed APB1 and APB2.
CI failed with:
In file included from /home/circleci/project/hw/bsp/ch32v20x/family.c:21:
/home/circleci/project/hw/bsp/ch32v20x/family.c: In function 'board_init':
/home/circleci/project/hw/bsp/ch32v20x/boards/nanoch32v203/board.h:16:47: error: 'RCC_APB1Periph_GPIOA' undeclared (first use in this function); did you mean 'RCC_APB2Periph_GPIOA'?
16 | #define LED_CLOCK_EN() RCC_APB1PeriphClockCmd(RCC_APB1Periph_GPIOA, EN...
@hathach I made some improvements and it's mostly working with device_info example.
I found a nice graph to illustrate the reset sequence. Chirp K for HS detection happens within 7ms of the start of reset, to make speed detection reliable the debouncing delay need to be placed before reset.
I captured ...
You are right, I'm sorry I didn't notice it. I only tested it on my own board that has the LED on port C, which is APB2. I'll fix it immediately.
Describe the PR
On boards using the Synopsys DWC2 USB IP core, there were no disconnection events when a USB device was unplugged.
This PR enabled the GINTSTS_DISCINT flag, to get an interrupt on disconnection + handles it by calling hcd_event_device_remove().
Additional context
Tested on an STM32F7, but behavior should be identical on any device using the dwc2
Operating System
Windows 11
Board
rp2040
Firmware
Based on https://github.com/hathach/tinyusb/tree/86ad6e56c1700e85f1c5678607a762cfe3aa2f47/examples/device/hid_multiple_interface modificatory
What happened ?
I was unable to grab any functional implementation data using usblyzer and Wireshark
How to reproduce ...
Describe the PR
Fix gcc-riscv issue about volatile bitfields are incorrectly accessed using an access width not appropriate to the type of its container.
Tested on espressif_s3_devkitm with device_info and cdc_msc_freertos examples.
For the host I've tested an usb key and an FTDI usb-uart.
Device 1: ID 0403:6001 SN FT1ZK9MQ
Device Descriptor:
bLength 18
bDescriptorType 1
bcdUSB 0200
bDeviceClass 0
bDeviceSubClass ...
Hi, I ended up with the same thing in #2960
I also removed hcd_event_device_remove(rhport, in_isr); from handle_hprt_irq() to prevent double remove event in some cases.
Aha, nice!
Do you want me to remove hcd_event_device_remove in handle_hprt_irq as well, and merge this PR first?
It doesn't matter to me, whichever you can get merged first :)
Do you want me to remove hcd_event_device_remove in handle_hprt_irq as well
Yes please, just double checked ST's HAL code.
and merge this PR first ?
@hathach is busy atm, since dwc2 is widely used it's better wait for Espressif @roma-jam for a double check.
Personally I tested with ESP32-S3-DevKitM and NUCLEO-H7S3L8.
Out of topic: Have you experienced any bouncing issue doing quickly connection/disconnection like in #2960 ?
Hi,
Has anyone tried porting the TinyUSB host stack to Zephyr, or can someone provide some pointers on how to get started with porting TinyUSB host stack support in Zephyr?"
Hi,
Has anyone tried porting the TinyUSB host stack to Zephyr, or can someone provide some pointers on how to get started with porting TinyUSB host stack support in Zephyr?"
There are some commits about zephyr support, but it's still not supported fully. Look at osal_zephyr.h file and corresponding portable files.
Hi @OrhanYigitDurmaz ,
Thank you for the responce, could you please point me where the osal_zephyr.h available.
@HiFiPhile
- I've updated the PR. I have also removed
hcd_event_device_remove(rhport, in_isr);fromhandle_hprt_irq()now - About the "bouncing": if I manually connect/disconnect very quickly, the USB port crashes indeed.
It crashes inusbh.cin functionprocess_enumeration()in caseENUM_ADDR0_DEVICE_DESC:TU_ASSERT(tuh_descriptor_get_device(addr0, _usbh_epbuf.ctrl, 8, process_enumeration, ENUM_SET_ADDR),);
thank you, I am thinking, maybe we just remove the struct/bitfield in the register typedef i.e leaving only uint32_t. bitfield struct can be use with local variale only. Will try that when I got sometime,
I am thinking, maybe we just remove the struct/bitfield in the register typedef i.e leaving only uint32_t. bitfield struct can be use with local variable only
Yes we can do let this. Adding a macro makes the thing complicate and losing the interest of bitfields.
I am thinking, maybe we just remove the struct/bitfield in the register typedef i.e leaving only uint32_t. bitfield struct can be use with local variable only
Yes we can do let this. Adding a macro makes the thing complicate and losing the interest of bitfields.
sure, I will do this later if you are busy. I need to fix an racing issue with pio-usb when overclocking rp2350 to 264mhz first :)
We would really like if something along these lines could be landed
We would really like if something along these lines could be landed
Fixed by #2967
I'm using this in a work project. I'd love to see something around these lines landed.
This is a very practical feature, and I also hope that it can be implemented as soon as possible.
Operating System
Linux
Board
STM32F7
Firmware
tinyUSB master, USB host on STM32F7 w/ DWC USB IP Core
What happened ?
When connecting a HS device with an interrupt endpoint with bInterval = 1 (1 microframe, 125us), it is being polled only at 2 microframe interval (250us), in case of a NAK.
How to reproduce ?
Connected a device with bInterval = 1 on it's interrupt endpoint
Debug Log as txt file (LOG/CFG_TUSB_DEBUG=2)
Debug log not relevant, I think.
The i...
What I am seeing is this alternating interval of:
- the channel IRQ finding a NAK (+HALTED), then deferring issuing a new IN token to the SOF handler. (every 250us)
- then 1 microframe later: the SOF IRQ re-scheduling the IN token, (so also every 250us, but with 125us offset to the channel IRQ)
It seems to me that the channel IRQ handler should immediately re-issue a new IN token (submit URB) after rec...
I've found a potential solution by calling edpt_xfer_kickoff() from the channel_xfer_in_retry() handler, for hcint & HCINT_HALTED.
This is essentially the same thing as the SOF handler would do, but then right after receiving the NACK, instead of wasting a microframe waiting for the next SOF to come along.
Any comments on what The Right Way to do this, is?
I've updated the refactor.
Describe the PR
When connecting a HS device with an interrupt endpoint with bInterval = 1 (1 microframe, 125us), it was being polled only at 2 microframe interval (250us), in case of a NAK. This is because the retry was deferred to the next SOF, basically wasting a full microframe.
The fix is to re-send the IN token as soon as we get the NAK, in base bInterval = 1. In other cases, we still rely on the existing polling interval calculations in the SOF IRQ handler.
Addition...
Operating System
Linux
Board
Fruit Jam
Firmware
CircuitPython using TinyUSB commit: 60e6d53d1
What happened ?
An assertion occurred when TinyUSB ran out of device numbers.
How to reproduce ?
Plug in the LS mouse from the Adafruit shop: https://www.adafruit.com/product/2025 into the Fruit Jam.
For some reason, the onboard hub detects brief USB device disconnects. It emits the port connection change each time it does. By the time the status is read the connection s...
seems like an deboucing issue, I will look at this, and order the mouse for testing if needed
Describe the PR
HFIR register for SOF timing was programmed with an off-by-one value (it needs a -1 applied).
-
This probably comes from a historical error in the Synopsys databook. They corrected it in version 3.30a, according to this comment on a mailinglist: https://lists.infradead.org/pipermail/linux-rpi-kernel/2016-February/003290.html
-
Also, the official Linux kernel dwc2 driver (maintained by Synopsys) contains the values with
-1offset, as can be seen in the `dwc2_calc_f...
Me too I was looking at enumerate handling without hub. Currently there are 2 issues related to blocked debouncing wait:
_usbh_qfilled up- xfer complete event of previous enumeration attempt arrive at next enumeration
I'm testing by break down the delay into smaller chunk, so far it's more reliable:
https://github.com/HiFiPhile/tinyusb/commit/22ea6ee67a4f545409b9290ef57c51e3d02d797a
Describe the PR
DWC2 host can generate a lot of HPRTINT interrupt when a device is attached, due to electrical contact bounce.
All of these events were being forwarded to the TinyUSB host stack as new HCD_EVENT_DEVICE_ATTACH events, causing many issues:
- rapid succession of ATTACH and REMOVE events, occurring in the middle of device enumeration
- queue exhaustion because more events were generated than could be swallowed by the
tuh_task() - many other weird combinations of cod...
I need to do some tests to understand better periodic transfer... With 1st look it seems not only bInterval = 1 but all bInterval have an extra SOF period.
Thank you !
Hum that's interesting, on databook 4.20a the - 1 is still missing.
Huh! I don't have access to their databook(s), unfortunately. So I just copied the mentioned versions from the mailing list thread!
Describe the PR
Fix xfer complete event of previous enumeration mess with next enumeration.
[1:1] Get Descriptor: 80 06 03 03 09 04 00 01
on EP 00 with 8 bytes: OK
on EP 80 with 40 bytes: OK
[1:1] Control data:
0000: 28 03 4D 00 61 00 73 00 73 00 20 00 53 00 74 00 |(.M.a.s.s. .S.t.|
0010: 6F 00 72 00 61 00 67 00 65 00 20 00 44 00 65 00 |o.r.a.g.e. .D.e.|
0020: 76 00 69 00 63 00 65 00 |v.i.c.e.|
[1:0:0] USBH DEVICE REMOVED
[1:0:0] unplu...
Describe the PR
Seems the resume is missing.
Before:
After:
Indeed doing the debouncing at DCD layer is much simpler.
I was testing break down the 450ms debouncing delay into smaller chunks in order to let the event queue processed in time.
22ea6ee67a4f545409b9290ef57c51e3d02d797a
_dev0.enumerating = 0 is trying to stop ongoing control transfer once the device is unplugged, then normally _ctrl_xfer will end up in idle state. However in some cases control transfer state get stuck.
I think a good fix is instead of _dev0.enumerating = 0 ...
This adds tud_cdc_reset_cb(), which can be implemented to receive notifications when the CDC driver is reset.
Additional context
My application use a writer thread that goes to sleep when the the TX fifo is full, and is woken up by the tud_cdc_tx_complete_cb() callback. However, if there is a usb reset, then it gets hung since any pending writes are discarded. It would be useful to have a callback so that the writer thread can also wake up when there has been a usb reset.
You should use tud_mount_cb()
Long switch case
Switch has at least one case that is too long: MSC_STAGE_CMD (99 lines).
Switch has at least one case that is too long: MSC_STAGE_DATA (40 lines).
Switch has at least one case that is too long: MSC_STAGE_STATUS_SENT (35 lines).
Describe the PR
This fixes TUSB_VERSION_STRING to actually report the version
Additional context
Before: TUSB_VERSION_STRING expands to "TUSB_VERSION_MAJOR.TUSB_VERSION_MINOR.TUSB_VERSION_REVISION"
After: TUSB_VERSION_STRING expands to: "0.18.0"
Just did some tests and confirmed my guess, all intervals are polled one frame longer.
Please try https://github.com/HiFiPhile/tinyusb/tree/retry
Since hcd_dwc2 and usbh changes are generic I've excluded them from this PR, will address them separetely.
Describe the PR
- if a previous enumeration failed _ctrl_xfer status could stuck, it needs to be cleared before next attempt.
- after _dev0.enumerating is reset in hcd_event_handler(), if an attach event arrived before _ctrl_xfer clean up in remove event, a racing condition will happen.
Hi, thanks for your response. I also looked into using tud_mount_cb(), but it seemed like there are some cases that that doesn't cover. For example, if I do a reset in Linux using something like:
int fd = open("/dev/bus/usb/001/005", USBDEVFS_RESET);
ioctl(fd, USBDEVFS_RESET, 0);
close(fd);
Then the CDC class driver gets reset, but I don't get a notification from either tud_cdc_tx_complete_cb() or tud_mount_cb(). Do you have any other suggestions?
Any reason why you are doing USB reset ? A part from some buggy WiFi chips whos get stuck there is no benefit.
You are wrong in open permission, should be fd = open(filename, O_WRONLY);
If the host does suspend/resume you need also tud_resume_cb/tud_suspend_cb
While I can see the issue described here, it seems to me this is not the proper fix, but rather a workaround - with it's own side-effects.
Why wasn't this xfer cleared? And what if is currently ongoing?
There seem to be some race conditions between handling some stuff in the interrupt handler, and deferring some stuff to the tuh_task(). This is probably the root of (some of) these problems...
You are wrong in open permission, should be fd = open(filename, O_WRONLY);
You're right, I copy pasted it incorrectly into my comment.
Any reason why you are doing USB reset ? A part from some buggy WiFi chips whos get stuck there is no benefit.
I've been trying to debug an issue where my embedded device gets stuck a weird state, and I'm 80% sure it is because the host is doing a usb reset at some point (I've been using the C code above to try to reproduce it). What I'm seeing i...
@HiFiPhile thanks, that makes sense!
However, if I try your branch, I get a data toggle error. (Cannot just issue a channel_xfer_start(dwc2, ch_id); on the tests I did on my side)
However, I have integrated your idea into this PR and update it. Can you check?
Where is the 450ms value coming from, btw? It seems quite high, IIRC USB standard recommends a 100ms debouncing time.
For the _dev0.enumerating = 0, I just noticed your PR: https://github.com/hathach/tinyusb/pull/3080 and that seems solid to me!
After a USB reset the host will do the whole enumeration process, when the device is ready (set configuration request ok) tud_mount_cb() is called, I've also verified it on Arch Linux kernel 6.13 with USBDEVFS_RESET . While the reset itself doesn't guarantee anything.
On Linux tud_cdc_line_state_cb() is pretty reliable, if I remember correctly DTR is set to ON automatically when the device is opened.
it seems to me this is not the proper fix, but rather a workaround - with its own side-effects.
Could you detail more, what you mean sie-effects ?
However, if I try your branch, I get a data toggle error
I didn't met it in my side, what's the error message ? channel_send_in_token() doesn't work when DMA is enabled, need some investigation.
Where is the 450ms value coming from, btw? It seems quite high, IIRC USB standard recommends a 100ms debouncing time.
I think we can reduce it and place tusb_time_delay_ms_api(ENUM_DEBOUNCING_DELAY_MS); beforehcd_port_reset(_dev0.rhport); Actually Windows use 100ms delay.
Describe the PR
- usbh enumeration for string descriptor (langid, manufacturer product, serila): always get the first 2 bytes to determine the length first. otherwise, some device may have buffer overflow.
- fix neopixel for s3 devkitc
perfect, thank you. I couldn't done it any better. I change dwc2_ep/channel_count() to inline function to avoid forcing gnu standard. The rest is mostly clean up
I get a HCINT_DATATOGGLE_ERR when using channel_xfer_start(), since it updates edpt->next_pid, which it shouldn't for a retry.
Can we merge this? Is there any more action required from my side?
@hathach @HiFiPhile
I have also rebased on master, and should have properly merged the bitfields change.
Can we merge this? Is there any more action required from my side?
@hathach @HiFiPhile
I want to apologize, because I was really sure that my previous testing showed that tud_mount_cb() was not being called durring USBDEVFS_RESET. However, I tested it again tonight, and confirmed that tud_mount_cb() is indeed being called after reset, just as you said. I'm not sure what happened the first time (maybe I accidentally implemented tud_unmount_cb() instead?).
To close this out, I ended up using tud_cdc_line_state_cb() and tud_mount_cb(), which I think robustly cover...
It's reliable in my end, @hathach do you need more test ?
I get a
HCINT_DATATOGGLE_ERRwhen usingchannel_xfer_start(), since it updatesedpt->next_pid, which it shouldn't for a retry.
Ah that's make sense
Operating System
Linux
Board
ch32v203c_r0_1v0
Firmware
examples/host/device_info
What happened ?
I'm writing USB host support for the CH32V203, and have identified ep_desc structures passed in to hcd_edpt_open() randomly being modified by observing ep_desc->wMaxPacketSize changing to nonsensical values due to the structure being allocated on the stack inside usbh_edpt_control_open():
static bool usbh_edpt_control_open(uint8_t dev_addr, uint8_t max_packet_si...
Hi, it is by design, hcd driver need to maintain EP and transfer status internally since different HCDs behaves differently.
You can look at dwc2 example which has _hcd_data stuct.
Thank you for the clarification. Iโll add some comments to the HCD template about this to make it clearer for other new contributors, and send a PR soon.ย Unrelated, the CH32V203 HCD driver Iโm writing is coming along nicely now, getting past assigning the device ID and starting enumeration!--ย jpmOn 16 Apr 2025, at 18:21, HiFiPhile @.***> wrote:๏ปฟ
Hi, it is by design, hcd driver need to maintain EP and transfer status internally since different HCDs behaves differently.
You can look a...
Add a comment in hcd_edpt_open() to make new contributors aware that ep_desc is allocated from the stack when called from usbh_edpt_control_open(), so if any values from ep_desc are required (eg ep_desc->wMaxPacketSize) they must be copied.
See also #3083
Thank you for the note, I think it's more clear with something like HCD must maintain endpoint and transfer status locally (not a native English speaker)
Describe the PR
- Add ci s3 host testing using TS3USB30
- de-duplicate flash board_test for board with multiple flags_on
Describe the PR
- Ci add picow native host controller test
- also refactor ci setup toolchain
thank you for your PR. I also clean up and remove the halted_sof_schedule flags (obsolete code). since channel_xfer_in_retry() is only called when halted. Please check if the changes make sense to you
my bad, I think we cannot simply clear data here. We should mark endpoint for removal then disable channel first, within the halted interrupt check the flag and clear the endpoint.
Ah yes we should close the channel properly, especially when a hub is used.
Describe the PR
A small fix following #3072.
When we enable SOF interrupt the 1st time it could be already pending but uncleared, in hcd_int_handler gintsts = dwc2->gintsts & gintmsk, since gintmsk is unset yet gintsts is also unset, in result SOF flag is not cleared.
Cause SOF fire immediately and retry interval shorter.
we don't need to use channel_xfer_start() since all meta data is setup, also it will toggle PID (causing data toggle error). Just enabled channel with channel->hcchar |= HCCHAR_CHENA; is good enough.
thank you for your PR. PING is indeed missing, I have
- rename to next_do_ping for clearer meaning
- I found that in case of transfer complete with NYET, we didn't do ping e.g msc out 31 bytes command
- simply use
channel->hcchar |= HCCHAR_CHENA;to continue transfer with existing meta data. Note channel.hctsiz.do_ping is cleared by host controller when interrupt trigger (in my testing with stm32f769), but we clear it anyway since dwc2 has too many variants :)
I've changed it use channel_disable(), I think there is no need to wait until the channel is disabled ?
Thank you, I think it's good on h7rs.
Yeah it's safer to check if sof is already enabled, I think it can only happen if CPU usage is very high which makes latency in processing.
@hathach I've tested on h7rs and esp32-s3, both works well.
Fixes: #2632
This makes the web serial website code available and it adds lots of new features that make serial debugging fun!
If you find any bugs or want some changes just tell me.
I tried to keep it as simple as possible while still providing useful features.
thank you for your PR. It is great idea, I think we will move the attach_debouncing flag and event igonored to usbh later, that would aplly the fix for all the hcd (later). Let just get this merged first.
I also update the usbh to prevent control stage locked up when device is unplugged while usbh trying to make the transfer.
Thank you for the great interactions on this project and thanks for merging the PR(s) so fast!
should include _dev0.enumerating == 1 since other value has obsolete (for new device) after enumerated successfully. The isr blindly set the flag, but we need to check since we do more than that here. Also hcd_device_close(_dev0.rhport, 0) instead of using hub_addr
they must be copied, there is no requirement that is long-term memory, even with normal enumeration which usbh control memory is used temporarily for holding device configuration. But they can be wiped out and reused for other control transfer.
I haven't tested, is hcd_device_close(_dev0.rhport, 0) works with device under a hub ?
It should, the 2nd argument is the device addres that is removed. Otherwise, it will try to remove the hub that attached the rhport.
I think there is a loophole with early return. If set address is done _dev0.enumerating is still true but _usbh_devices also needs to be cleaned.
ah you are right, putting enumerating in dev0 is confusing. Let me revise and fix this.
[hathach/tinyusb] Issue opened: #3092 Support of several instances of TinyUSB stack (device or host)
Related area
port support
Hardware specification
all hardware with several ports
Is your feature request related to a problem?
Unable to init stack on two ports simultaneously.
Relates to:
Describe the solution you'd like
Possibility to run TinyUSB (device) stack on several peripherals (ports) simultaneously.
In the code that would be like:
tusb_rhport_init_t dev_init = {
.role = TUSB_R...
made an improvement from just a flag enumerating to actual enumerating_daddr to make it easier to clean up when device unplugged while enumerating not completed yet. @HiFiPhile please let me know if this make sense to you. after this merged, I will make the https://github.com/hathach/tinyusb/pull/3075 ignoring attach/detach on the same rhport/hub/port while debouncing to usbh to make it generic for all host controller. This seems to work rathe well.
It works pretty well in my side, tried some quick action and no assert happened :)
[hathach/tinyusb] New branch created: refactor-usbh-bus-info
Describe the PR
rename hcd_devtree_info_t to tuh_bus_info_t, hcd_devtree_get_info to hcd_bus_info_get
streamline bus info to usbh_devies, also replace dev0 (renamed to dev0_bus)
Related area
New port support
Hardware specification
CH32 variant with USBFS, eg CH32V203C8T6 as used on the currently supported board ch32v203c_r0_1v0
Is your feature request related to a problem?
CH32 supports USB Host mode in the USBFS peripheral, but TinyUSB does not support it (yet)
Describe the solution you'd like
I have started writing support for the CH32 USBFS host mode, and it's now at the point where the USB host will enumerate some devices using the host/dev...
Have you seen PR 2793? Chances are high because it is neither an issue, a discussion or part of the documentation.
Describe the PR
Possibly a copy-paste error ? -mcpu= flag should be cortex-m0 on gcc, like with the other compilers
I have not seen this one, thank you! I guess keep this bug open until it's merged, so it's a bit more visible that this support exists in the wild?
[hathach/tinyusb] New branch created: usbh-improve-hub
Describe the PR
- refactor hub driver and move port reset on connection change to usbh.
- hub: add hub_port_get_status_local(), ignore resp in hub_port_get_status(pot != 0)
- usbh properly deboucning with hub/rootport accordingly to usb specs, also add 10ms of reset recovery
This pull request introduces several updates to improve USB host functionality, enhance clarity in the codebase, and...
That sounds like a good idea! I would love to see more people getting involved with the CH32 family because of its unique feature of having two USB ports which makes it ideal for dual-role projects.
Operating System
Windows 11
Board
esp32-s3
Firmware
void usb_start(void){
ESP_LOGI(TAG, "USB Composite initialization");
const tinyusb_config_t tusb_cfg = {
.device_descriptor = NULL,
.string_descriptor = NULL,
.string_descriptor_count = 0,
.external_phy = false,
.configuration_descriptor = NULL,
};
ESP_ERROR_CHECK(tinyusb_driver_install(&tusb_cfg));
tinyusb_config_cdcacm_t acm_cfg = {
.usb_dev = TINYUSB...
To clarify, without the chokes on the USB cable, turning on the inverter immediately interrupts the USB communication.
With 2 chokes on the cable, the connection is stable for a random amount of time. Sometimes all day, sometimes a few minutes.
With no EMI generating loads switched on, the connection is stable indefinitely.
Operating System
Linux
Board
custom STM32F746 -> USB3300 -> USB2507 -> USB2507 board
Firmware
Relevant code
#define TUSB_STACK_SIZE (4096) * (CFG_TUSB_DEBUG ? 2 : 1)
static osThreadId_t usbd_task_handle;
static const osThreadAttr_t usbd_task_attributes = {
.name = "usbd_task",
.stack_size = TUSB_STACK_SIZE,
.priority = (osPriority_t)osPriorityAboveNormal7,
};
static osThreadId_t usbh_task_handle;
static const osThreadAttr_t usbh_task_attributes = {
...
I was preparing to do work on the nxp/mcx bsps and noticed some of the dependices could not be fetch on a fresh clone:
This is a patch to make sure we fetch the commit for a dep, they checkout head before doing any checks. I added some prints for when a new folder / repo is initialized.
Everything worked ok on my test cases (mcx, lpc55 and lpc43) once this fix was in place.
C:\ELI\tinyusb_dev\tinyusb-dev\tools> .\get_deps.py mcx
cloning lib/FreeRTOS-Kernel with https://github.c...
I would like MTP to be implemented into tinyusb too :)
Operating System
Linux
Board
Affects Local Development and the CI
Firmware
Happens with b5d4d0f6237ecaf78b2548e5c4a08810e0957066 but I think this has more to do with the dependency repos and how "HEAD" is handled.
What happened ?
I was preparing to do work on the nxp/mcx bsps to add more boards and noticed some of the dependencies could not be fetched on a fresh clone
I have a patch here:
https://github.com/hathach/tinyusb/pull/3100
That enables builds to work a...
I will be porting tinyuf2 to MCXA156 and N947 and need this work in place.
This is the 1st step before bringing in support for other MCX devices.
We had previous patched https://github.com/hathach/mcux-sdk.git' for MCX support as it was not pulically available
I updated get_deps to point to the mcux-sdk version 2.16.10 from NXP. I repointed the entry in the get_deps script to use NXP MCU repo. The existing current code couldn't build as the MCUXpresso SDK was old.
- For now, I p...
I second the request for MTP device class. It turned out to very useful for Teensy based data acquisition systems.
thank you for the fix. @ehughes the current mcu sdk is pointed to my fork, which is used when upstream does not include mcx-n mcu. Since you are working on the port, maybe take the time to make the sdk upstream again (if mcx is now supported).
i would give a Plus too.
Hi @roundby Great work, do you try it with littlefs?
littlefs must work for us, to be useful.
Thanks for this great work!
Hi @roundby Great work, do you try it with littlefs?
i guess it will be hard with littlefs.
easier to make 1 FAT Partition, and copy the stuff over to littlefs later.
Describe the PR
usbh skip attach/remove event on the same roothub port while in debouncing delay. For hub since we don't poll the interrupt endpoint before debouncing, it should be good enough
remove the old logic detecting duplicated attach event, which should be filtered by the new debouncing.
remove dwc2 debouncing logic (which is now is done at usbh layer)
@hathach
FYI: This is the PR for the NXP MCX work. It points to the upstream repo (and I added another board). It is the 1st step before added more mcx support
Also, the codespell keeps failing on the github ci. There is a driver in the upstream nxp repo with some spelling mistakes. Since the ci does a clone of that repo I am not sure how to bypass it. The .codespellrc say to ignore the hw.mcu folder but it doesn't look like the ci system is following it.
Lastly, there i...
I can try to get host stack running on multiple controllers (same usbip) easily. For device, it needs quite a bit of works, and it is kind of neat and not popular feature. I am not sure Icould mannge the time to do it myself, however PR is welcome.
@hathach
FYI: This is the PR for the NXP MCX work. It points to the upstream repo (and I added another board). It is the 1st step before addin more mcx support
The codespell keeps failing on the github ci. There is a driver in the upstream nxp repo with some spelling mistakes. Since the ci does a clone of that repo I am not sure how to bypass it. The .codespellrc say to ignore the hw/mcu folder but it doesn't look like the ci system is following it.
codespell faailed with b...
I've changed it use
channel_disable(), I think there is no need to wait until the channel is disabled ?
I am on vacation, will try to check this out afterwards (next week or so).
Operating System
Windows 10
Board
STM32F427VIT6 demo board
Firmware
tinyusb_min_struct.zip
we pulled the code from your master branch on Apr 4, 2025.
What happened ?
Tested plaftform:
STM32F427VIT6๏ผUSB-FS(PA11/PA12), FS Mode, Host
HUB IC: CH334P
Mouse: Logitech G502(set to 1000hz and 500hz)
issue 1:
tested board: STM32F427VIT6 -> CH334P(USB HUB) -> HID MOUSE(1000hz)
What happened:
po...
@hathach Is there anything needed to merge this PR? looks like CI is good
@hathach is in vacation, I think he will return in about one week:)
Related area
I would like to have tinyUSB support USB Host on ESP32-P4
Hardware specification
ESP32-P4
Is your feature request related to a problem?
ESP-IDF provide is own usb host stack but it only support HS with no STT support for FS or LS device connected on HUB.
It would be benefical if tinyusb support esp32p4 as tinyusb support LS FS and HS device on hub.
Describe the solution you'd like
Add host support for the P4, and ideally an example.
I have checked e...
@hathach coming back to this, can I interpret your comment to mean that tusb does not presently support highspeed operation over ULPI with dwc2?
TinyUSB does not provide any locking means to protect the DCD variables. This can lead to race conditions when the user is trying to submit a transfer while the device is being disconnected. This can cause the device to be in an inconsistent state, leading to a crash or undefined behavior.
This commit adds a spin-lock to protect the DCD variables during device disconnect.
- Reported in https://github.com/espressif/esp-idf/issues/9691
- Also reported in https://github.com/espressif/esp...
Flyby comment: This has been sitting for over a year. Would an additional reviewer help? Is there some test suite it needs to pass? Would someone updating it to $head help? What would it take to get unstuck? (I have extensive serial tty and USB experience, albeit not with this code. I may be uninvolved in the project, but I can back up running my mouth as a bystander. :-)
Operating System
Linux
Board
Raspberry Pi Pico RP2040
Firmware
examples/device/audio_test
What happened ?
I can't get any of the audio examples to work on Raspberry Pi Pico RP2040 platform connected to the Linux (Debian 12) host. I expected the board LED to start blinking and the audio device to appear after connecting the board to the host. However, the board hangs almost immediately after connection, the LED randomly remains on or off, new audio device does not appear...
It also hangs immediately after connecting to the Windows 11 host. Although when I tested the same examples on the same board two or three months ago, everything worked
Would an additional reviewer help? Is there some test suite it needs to pass? Would someone updating it to $head help? What would it take to get unstuck? (I have extensive serial tty and USB experience, albeit not with this code. I may be uninvolved in the project, but I can back up running my mouth as a bystander. :-)
More reviewers will definitely help especially for large PR like this one. @hathach spends most time for Adafruit, I've some free time after work but I'm much less famili...
[hathach/tinyusb] New branch created: ci_vbus
Describe the PR
Some devices don't have the VBUS pin connected, OTGSC_VBUS_CHARGE need to be set to let USB work.
This is bulky because it does a lot of busy work in addition to the actual work.
I'm not a reviewer of this project, but I have domain knowledge. I picked through the bits and bobs of the code itself and it seems fine to me.
TYPE_COUNT is never used. Is it better to have a TYPE_UNKNOWN = 0 at the top for use before the board is successfully probed?
Are you concerned that divisor might be zero or that it might be non-integer?
I think you can do a static_assert using either typeid() or typeof() for the latter. The former is probably more important, even if it's an assert.
Minor: B-D are never used and A is used in only one place.
Maybe just make that a CHANNEL_OFFSET? (Maybe it's tradition; I'm reviewing in relative isolation.)
FWIW, I picked through it last night. (GitHub kept crashing while reviewing it, including during my review submission, which I've just retriggered.) The actual changes are pretty small and are surely non-contentious.
This PR looks large because it takes the sin of changing C comments to C++, reformatting, moving code (the main contributor to the size of this being so large as to blow up github's web review), and actual development all in one PR. After I realized that, I quit fussing abo...
It turned out that Pico SDK 2.1.1 is pulling TinyUSB release 0.18.0 with it, in which the problem exists. I updated TinyUSB to the current version from the master branch and everything seems to work again.
would you mind telling which MCU that requires this fix as well
no, it means you have to define max speed to high manually if adding ULPI phy.
would you mind telling which MCU that requires this fix as well
It's LPC4322 on J-Link probe (I'm doing some hacking ;)), USB0_VBUS pin need to be connected to 5V to work.
still happend with sigma mouse + fruit jam, doing more tests to fix.
Operating System
Linux
Board
STM32WB55
Firmware
Master branch with following examples:
examples/device/uac2_headset
examples/device/audio_test
examples/device/uac2_speaker_fb
What happened ?
Recently I tried to run audio examples on my dev board STM32WB55 and figured out that host is unable to enumerate the device properly. I checked previous versions of the library and figure out that on tag 0.16.0 for audio_test example problem don't exist so I went through changes i...
Describe the PR
fix #3073 occured with https://www.adafruit.com/product/2025. The mouse is sensible with physical connection. It got reset easily even though SE0 is not hold long enough and generate a few attach event (without detach event). The device itself actually got reset and need to go through the whole enumeration. The solution is forcing removal of the device with the same bus info (rhport, hub addr, hub port) before SET_ADDR.
Also include other chores and hub clean up as well
Describe the PR
This PR add support for vendor-spicific command messages to the usbtmc_device
Additional context
Bevore messages with MsgID = REQUEST_VENDOR_SPECIFIC_IN and VENDOR_SPECIFIC_OUT where ignored. Now the vendor_specific messages are handled similar to normal ones, except that the MsgId is set to REQUEST_DEV_DEP_MSG_IN for the response of vendor-specific commands
ci IAR failed due to capacity limit. Cancel and re-run ci does not help. It may take several hours to recover, will just ignore that for this PR.
try again with master, it may be fixed now.
@tannewt @ladyada I found out that our store sigmachip mouse seems to have an internal timeout. If it does not received HID related request not sure which one (probably get hid report or set protocol/idle), it will reset it self, the reset cause SE0 but seems like not long enough for hub to regconize as disconnect event and then try to enumerate itself.
Not saying that all out of bounds vulnerabilities are removed from TinyUSB, but the 4 explicitly mentioned in this issue are resolved at this point.
hidd_control_xfer_cb
The min value of the HID buffer size and the request size reduce the vulnerability to just the contents of the HID buffer:
https://github.com/hathach/tinyusb/blob/542e5b4550a01d034b78308d77c408ed89427513/src/class/hid/hid_device.c#L301-L323
Similar fix:
https://github.com/hathach/tinyusb/blob/542e5b45...
I had looked at other DFU's at the time, as my company had a nonstandard DFU tool as well that had custom extensions.
From what I saw, DFU 1.1a is quite popular, given how popular ST is as a platform, but DFU 1.1a, is more like DFU 2.0, as it is not compatible with DFU 1.1 devices. The main problematic part is the overloading of DFU_DNLOAD and DFU_UPLOAD. Additionally, many of their custom commands are for specific bootloaders, and thus they have many different versions.
It just so happen...
thank you @scully-jmccarthy for double check this, I guess we can close this now
I apologize for never getting back to you on https://github.com/hathach/tinyusb/pull/913. I looked through the DFU rework and it looks great. It's much cleaner than the brute force "by the spec" implementation I had originally contributed.
no problems, we are all busy
Can you please elaborate a bit more please ?
For most of people USB is a bit complicated, and most people on esp32.com argue that tinyusb do not support host mode on the P4. (all idf exemples with tinyusb are for usb device only, the host examples are made with the espressif host stack ( which is limited, and do not support LS ans FS device on a FS HUB)).
There seems to be a discrepancy between the TinyUSB documentation and the advice provided on the ESP32 forum. I saw on the main page o...
Hi @RoxerRN ,
all idf exemples with tinyusb are for usb device only
In esp-idf we use the tinyUSB for device examples only, as we don't have our own device stack. But that doesn't mean, that tinyUSB doesn't support host stack.
host examples are made with the espressif host stack ( which is limited, and do not support LS ans FS device on a FS HUB)
Currently, the limitation for Full-speed USB peripheral was solved (https://github.com/espressif/esp-idf/issues/15683) and now there is a ...
Operating System
Linux
Board
rp2040
Firmware
webusb_serial example in picosdk_v2.1.0 compiled with LOG=2
Developement setup: ubuntu24.04 host computer, Windows10 guest in virtualbox.
What happened ?
Enumeration fails when usb device is assigned to virtualbox guest.
How to reproduce ?
Once the device get connected to the host computer it enumerates as normal device accessible from host applications. Now assigning the device to virtualbox guest system the enumeratio...
Please update to master manually, picosdk is too old. 53989a9
Related area
vendor device, documentation
Hardware specification
not specific hardware
Is your feature request related to a problem?
Tinyusb is a great library. However I am wondering if there could be better documentation on the structure? Especially I am confused about the way it is written when trying to implement custom vendor devices. What is the proper way to use endpoint vs endpoint streams? It seems I can use usbd_edpt_xfer, but I do not want to break anything. It see...
Hi @roma-jam Thank you very much for your answers,
So, with tinyUSB host stack you are able to attach the Low- or Full-speed devices to USB High-speed peripheral on P4.
I definitely want to give it a try, my board is built this way. I managed to compile TinyUSB with the P4 but I cannot manage to compile family.c because #include "bsp/board_api.h" #include "board.h" are not found. I use idf-esp to compile so I think i cannot use family.cmake and so one.
Do you know the proper way to com...
can we use the osal_mutex instead, there is an osal API for that ?
sure thing, please make an PR if you oculd, we can review and merge it. Don't worry too much about the setting we can just invent CFG_TUD_DFU_FUSE_xyz or something. The implementaiton is more important, the rest we can go through via review/comment
This fixes 2 issues with the parsing of descriptors inside vendord_open().
-
The code was calcing 'desc_end' as being after the actual end of descriptors due to doing:
desc_end = tu_desc_next(desc_itf) + max_leninstead ofdesc_end = desc_itf + max_len. -
The code did not handle an interface that finished with non-endpoint descriptors. The code should skip over all descriptors that are part of the interface, but it only skips over endpoint descriptors. So if there are othe...
Hi,
The code was calcing 'desc_end' as being after the actual end of descriptors due to doing: desc_end = tu_desc_next(desc_itf) + max_len instead of desc_end = desc_itf + max_len.
That's not true. const uint8_t* desc_end = (uint8_t const*)desc_itf + max_len; fixed by https://github.com/hathach/tinyusb/pull/3118
Hi,
The code was calcing 'desc_end' as being after the actual end of descriptors due to doing: desc_end = tu_desc_next(desc_itf) + max_len instead of desc_end = desc_itf + max_len.
That's not true, const uint8_t* desc_end = (uint8_t const*)desc_itf + max_len;, actually fiex by #3020
Hi,
The code was calcing 'desc_end' as being after the actual end of descriptors due to doing: desc_end = tu_desc_next(desc_itf) + max_len instead of desc_end = desc_itf + max_len.
That's not true,
const uint8_t* desc_end = (uint8_t const*)desc_itf + max_len;, actually fiex by #3020
ah ok - i was working with an older version of the code, so when i copied it into the current version of the code i must have missed that
I think a cleaner fix is simplify the loop, what do you think ?
while (desc_end - p_desc > 0) {
if (TUSB_DESC_ENDPOINT == tu_desc_type(p_desc)) {
const tusb_desc_endpoint_t* desc_ep = (const tusb_desc_endpoint_t*) p_desc;
TU_ASSERT(usbd_edpt_open(rhport, desc_ep));
if (tu_edpt_dir(desc_ep->bEndpointAddress) == TUSB_DIR_IN) {
tu_edpt_stream_open(&p_vendor->tx.stream, desc_ep);
tud_vendor_n_write_flush((uint8_t)(p_vendor - _vendord_itf)...
Each call to vendord_open() should "consume" all descriptors until the next interface descriptor, or until the end of all descriptors. So you need to check for whether the "next" descriptor is an interface descriptor, and if it is then you need to return at that point. So a check for desc type being interface needs to be added to your proposed loop.
Each call to vendord_open() should "consume" all descriptors until the next interface descriptor, or until the end of all descriptors. So you need to check for whether the "next" descriptor is an interface descriptor, and if it is then you need to return at that point. So a check for desc type being interface needs to be added to your proposed loop.
You are right. should be while (TUSB_DESC_INTERFACE != tu_desc_type(p_desc) && (desc_end - p_desc > 0)) {
Operating System
Linux
Board
STM32F746 Discovery
Firmware
examples/device/midi_rx
What happened ?
I get this error when I try to compile the host/midi_rx example using GCC 14.1
[...]/tinyusb/src/host/usbh.c: In function 'process_enumeration':
[...]/tinyusb/src/host/usbh.c:1529:11: error: 'BIT_FIELD_REF ' may be used uninitialized [-Werror=maybe-uninitialized]
1529 | if (!port_status.status.connection) {
| ^
I used `CFLAGS += -Wno-error=m...
I connected a debugger and problem appears in pcd_get_endpoint and pcd_get_endpoint:
According to stm32wb55 manual USBFS should point to 0x40006800:
I hardcoded FSDEV_REG to the previous value and it works both on that commit and current master branch. All mentioned examples are enumerating correctly and app...
Thank you for looking at it, FSDEV_BASE is define by ST's header file, maybe is a ST's issue.
It appears that tinyUSB uses v.10.0 of cmsis-device-wb (Nov 29,2021) and relevant address changed to proper value on v1.12.0 (March 10, 2023), we could bump to latest available v.12.2 (Jul 2, 2024) in get_deps.
I've done it locally and observe no issues.
I can confirm that DCD_EVENT_UNPLUGGED is not triggered for STM32F0 (uses FSDEV instead of DWC2). I've tried some of the hacks above unsuccessfully.
Polling tud_connected() is not really reliable as sometimes when the cable is disconnected, still returns true.
STM32F0 doesn't have a VBUS, so I guess my only chance here is to change my hardware and manually read voltage from the USB connection.
Operating System
Linux
Board
raspberry pi pico (rp2040)
Firmware
Just simpliest test:
#include
int main() {
stdio_init_all();
uint32_t cnt = 0;
while (1) stdio_printf(format: "!!! %d\n", cnt++);
}
What happened ?
When compiled by clang with LTO enabled, it outputs exactly one line per second.
Interchangingprintf and stdio_printf makes no difference.
std::cout << "!!! " << cnt++ << std::endl; outputs exactly one symbol per second
With LTO disabl...
same problem as @lunzima
can we use the osal_mutex instead https://github.com/hathach/tinyusb/blob/master/src/osal/osal_freertos.h#L152, there is an osal API for that ?
I decided for critical section instead of OS primitives because many of these sections are in ISRs
- ISR must not block. So calling
osal_mutex_lock()is not acceptable - With critical section we get minimal latency and overhead
- Intention and simplicity: We really just need an atomic access to
xfer_ctl_t.
Describe the PR
Fix: https://github.com/hathach/tinyusb/issues/3112 and bump cmsis-device-wb to latest available tag
This should be:
if (addr >= uncached_regions[i].start && addr <= uncached_regions[i].end)
I think?
ST's latest default linker files for NUCLEO-H7S3L8 seem to use
KEEP(*(noncacheable_buffer))
Across the board.
By default linker files, I mean these ones (also just for reference I think STM32H7S3L8HX_ROMxspi2.ld is the preferred/recommended one for bootflash/OctoSPI setup on NUCLEO-H7S3L8):
Since DMA can't access DTCM on H7 and H7RS. Might it be worth also defining the idiomatic ST noncacheable_buffer region in here?
It could be grabbed from symbols something like:
extern int __NONCACHEABLEBUFFER_BEGIN;
extern int __NONCACHEABLEBUFFER_END;
uint32_t *start = (uint32_t*)&__NONCACHEABLEBUFFER_BEGIN;
uint32_t *end = (uint32_t*)&__NONCACHEABLEBUFFER_END;
Since noncacheable_buffer should be set as non-cacheable in MPU configuration, I imagine the MPU probabl...
Do you know the proper way to compile TinyUSB with the right bsp ?
There is such topin in the esp32 forum: https://esp32.com/viewtopic.php?p=147573#p147573
@hathach could we get this merged?
Thank you, it's covered by #3121
Looks like STM32CubeH7RS is using noncacheable_buffer instead of noncacheable across the board.
Not a big deal, although keeping alignment with the section name they use probably will help with compatibility.
Been testing this on NUCLEO-H7S3L8 along with some of your DWC2 changes in separate PRs.
I left some review comments on those other PRs, just minor things, but I wanted to also comment on this one and say thank you so much for the great work on H7S3L8 and DWC2.
With a few tweaks for my specific requirements, it's working flawlessly and my basic CDC HS single endpoint setup is already hitting 18MB/s in a super quick benchmark task I wrote, with the only real optimisation I've had to do b...
Hi Roma,
It is my topic on the esp32 forum you mentioned, as explained in the post I actually managed to compile tinyusb with esp-idf. It works like a charm and in the end it's not so difficult when you understand how to compile it with the module provided by espressif.
I don't know if the post is sufficient to help others to get it compile on the p4, or if it's can be useful if I provide somewhere a full working example ? ( if you know a good place to store such example I can provide a sa...
I looked into src/common/tusb_common.h and the use of stdio.h.
It seems that stdio.h is included unconditionally, but from reviewing the codebase, most of TinyUSB's core functionality does not actually depend on it. The only potential usages appear to be in debugging macros (e.g., TU_ASSERT, TU_VERIFY) which rely on tu_printf() when CFG_TUSB_DEBUG is enabled.
To improve compatibility with custom embedded environments โ especially those providing their own lightweight `printf(...
the next interface can also start with IAD
the next interface can also start with IAD
oh yes, let me push a quick fix.
the next interface can also start with IAD
oh yes, let me push a quick fix.
I am already working on the fix :)
[hathach/tinyusb] New branch created: follow-up-pr3118
follow up to #3118, interface also end with IAD. Add more checks
Additions to USB descriptor utilities:
src/common/tusb_types.h: Added a new static inline functiontu_desc_is_validto check if a USB descriptor is valid by ensuring it is within the bounds ofdescanddesc_end. This helps improve robustness when working with USB descriptors.
[hathach/tinyusb] New branch created: fix/dcd_race_condition
thank you, that make sense. I think it is about time to add osal_critical_enter/exit() for this purpose. Since I cannot push to your fork, here is how it would be used. https://github.com/hathach/tinyusb/commit/53a83e1dfa0524d6e7918d43610c24a93202f74b . Let me know if this makes sense to you.
this is only relevant on SMP mcu like P4 right ? since when app enter critical, this isr shoud not be running ?
We contributed a simulated ESP32P4 board template to the TinyUSB project, which includes configuration headers, board initialization stubs, a device controller driver structure, and a minimal example under examples/device/. This demonstrates our understanding of the TinyUSB driver integration model and how to extend it for new MCUs.
sorry, I don't understand what you are trying to do with this PR.
continue to ignore iar capacity limit
Out of interest, have you happened to run your benchmarks ("cdc_task2" and such from https://github.com/hathach/tinyusb/issues/920#issuecomment-867994863) on this board?
I am primarily interested in the throughput I can get sending data from the board as device to the PC as host. I copied over your functions to expose the FIFOs and wrote something like:
static void USB_CDC_Benchmark2(void* params)
{
(void) params;
// 1) prepare ramp-data block
# if 0
// static uint8_t...
Out of interest, have you happened to run your benchmarks ("
cdc_task2" and such from #920 (comment)) on this board?
I haven't done it. I think your number is not bad, although maybe there are some chances of optimizations.
You can try to clear this bit:
https://github.com/hathach/tinyusb/blob/3024bff12f584302ec2aaa77bcbbb2faf17b183f/src/portable/synopsys/dwc2/dcd_dwc2.c#L428
Describe the PR A clear ๅ concise description of what this PR solve. Additional context If applicable, add any other context about the PR and/or screenshots here.
Out of interest, have you happened to run your benchmarks ("
cdc_task2" and such from #920 (comment)) on this board?I haven't done it. I think your number is not bad, although maybe there are some chances of optimizations. You can try to clear this bit:
WOAH
, and then via DMA from that point onwards?
Yes cdc driver always copy the data so the source data variable doesn't need to be static. If you need more throughput you can copy the driver (or vendor class driver) and make adjustments then register it as a custom driver.
Here is an example:
https://github.com/kkitayam/akiprobe/blob/c3...
Describe the PR
Thank you for this awesome project, very enjoyable to work with!
I've been integrating TinyUSB using custom firmware on the STM32F723E-DISCOVERY board and got stuck in reset_core when initializing the HS port. Waiting 2ms after PLL enablement fixes this issue.
Additional context
The solution for this was already discovered in https://github.com/hathach/tinyusb/issues/2074#issuecomment-2597894247, where the CubeHAL waits 2ms, since there's no USB_HS_PHYC_P...
I think the same race condition can happen on single core MCUs too.
For example
- Code from main app is modifying
xfer_ctl_tand is interrupted - Content of
xfer_ctl_tis now inconsistent - The ISR modifies
xfer_ctl_tagain - Main app continues
In steps 3 and 4 we can access inconsistent xfer_ctl_t which can lead to undefined behavior (division by zero in the cases I've seen)
but when application modify xfer_ctl_t it already disable irq with enter_critical() the irq shouldn't be invoked. since usb irq is the only irq making change to this xfer ctl, it isn't be preempted by other irq. I guess it would be safe for signle core CPU ? I am trying to see if we could optional omit this for s2/s3 ?
Yes, you're right. Although S3 is also dual-core, and the problem was reported and reproduced on S3 too.
Describe the PR
add osal critical API to fix dwc2 race condition updating xfer ctl. Follow up to #3109
thanks for confirmation, we can add an macro to only include this in multi core CPU. since many dwc2 stm32 is single core only. I move the critical API to osal layer here https://github.com/hathach/tinyusb/pull/3127 let me know what you think
Local variable address stored in non-local memory
A stack address which arrived via a parameter may be assigned to a non-local variable.
Hi, I'm having some issues testing the features from https://github.com/ennebi/tinyusb/tree/mtp, copying or creating files in Windows 10 doesn't work properly.
I printed some logs and found that the mtpd_handle_cmd_send_object_info function was called when the file was created, and the mtpd_handle_dto_send_object_info function was not called to write after that.
How do I solve the problem? These are my test environments:
Hardware: RP2040 SDK2.1.1
ok I made more changes to https://github.com/hathach/tinyusb/pull/3127 to have osal spinlock (SMP), which I think better name than critical section (single core). Would you mind testing it to see if it fix the race condition. In the future we can move the spinlock to usbd to make sure it works with other ports as well.
please try to either to read example or source code implementation, which is changing rather quickly. Currently I have no time to write docs.
try to use tud_disconnect() delay 10ms and tud_connect(). Closed since it is not a bug
can you provide the RM/specs that specify how long we should wait ?
Unfortunately no, the RM0431 p1560 does not mention anything about PLL stability.
thank you very much, this PR initiate a new osal spin lock API, which is implemented and merged https://github.com/hathach/tinyusb/pull/3127, which should fix this race issue on esp32 chip. I did a rebase there and github couldn't detect and mark this as merged. So we will need to close this manually.
[hathach/tinyusb] New branch created: max3421-use-spinlock
#2074 is tested with h747, which I don't think have USB_HS_PHYC as F723. I also have the F723 discovery and has no issue with stocked examples. Can you make an minimal changes to oone of stock example that coould cause the issue ?
add usbh_spin_lock/unlock()
use spinlock to replace atomic flag for hcd max3421
also add Adafruit feather esp32c6 board def
๐
Me too I didn't have this issue on STM32F723E-DISCOVERY, with both IAR 8.3 and GCC 12.3 compilers.
I printed some logs and found that the mtpd_handle_cmd_send_object_info function was called when the file was created, and the mtpd_handle_dto_send_object_info function was not called to write after that.<
Hi @diancity025.
Is the example code (read only FS) working?
Can you check if the bulk endpoints are numbered and opened correctly in the initialization sequence? The command phase is supposed to be followed by a data phase on bulk EP, unless there is an issue with the sequence.
...
[hathach/tinyusb] New comment on issue #3119: Compilation error about unitialized variable in usbh.c
this should be fixed by current latest, please pull and try again. tested with
arm-none-eabi-gcc --version
arm-none-eabi-gcc (Arm GNU Toolchain 14.2.Rel1 (Build arm-14.52)) 14.2.1 20241119
Copyright (C) 2024 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
there is moe update, please pull and test again. let me know if it works for you
Ah, wellโฆ at first I also couldn't reproduce this issue with the tinyusb examples, until I power cycled the board:
cd tinyusb
python3 tools/get_deps.py stm32f7
cd examples/device/cdc_msc
rm -rf _build; \
make BOARD=stm32f723disco RHPORT_DEVICE=1 LOG=2 all && \
openocd -f board/stm32f7discovery.cfg -c "program _build/stm32f723disco/cdc_msc.elf verify reset exit"
*power cycle board*
picocom --imap lfcrlf -b 115200 /dev/tty.usbmodem103
*reset board*...
maybe add the description on why this option is needed e.g when USB_VBUS pin is not connected to 5V
I installed the changed files in a PICO 2W with FreeRTOS (running on 2 cores) and it does seem to prevent the run away NAKs. However, After a few transfers (not always the same number) its is getting a panic in function hw_endpoint_lock_update() of rp2040_usb.c
@hathach I'm sorry for the late review, but could we add ESP32-P4 to the list of multiple core MCUs?
You can get the information also dynamically from SOC_CPU_CORES_NUM that can be included from #include "soc/soc_caps.h"
@tore-espressif P4 is here, thanks for the tip. I will check to see if we could include soc_caps.h here
No problems at all. We are all busy. Normally I am not in hurry, but this time I need to use this to fix other issue :)
Related area
Device drivers
Hardware specification
PC, test environments
Is your feature request related to a problem?
Testing and debugging class drivers, user code with MCUs is harder than necessary, but on PC it's way easier, faster and more automatable.
Describe the solution you'd like
For example, like Zephyr and [Rust](https://github.com/Sawchord/u...
I still can't reproduce the issue with your binary.
UART is connected from jumper CN6 to allow full power-off, no matter power cycle (cable unplug&re-plug) or press reset button it always runs correctly.
I'm wondering if it's related to chip/board revision, I have:
- MCU Rev A; PHL 7B 724
- Board MB1260-F723E-D03
@Lurcy38 Hi, do you know anything about this ?
Hm, I have the exact same board and MCU revison as youโฆ
Well maybe just leave it open then in case others have the same issue, I'm using a patched TinyUSB version anyways.
Related area
UAC2
Hardware specification
Any
Is your feature request related to a problem?
I'd like to make some major changes to UAC2 class:
Describe the solution you'd like
- Remove support FIFO
The UAC code is pretty complex and difficult for new comers to contribute. An obvious way to simplify is to remove support FIFO as the only use is channel muxing/demuxing, which can be (should be IMO) done in application layer.
At first it was planned to allow decoding for...
Nice to hear from you!
I don't mind - simplicity is better than too many features I guess. I implemented them with idea that users might need them as I did.
Please go ahead!
In general I like the idea, due to strict timing requirements, keeping isochronous in ISR would make sense.
Fortunately the application I've been developing had almost no other transfers in play so putting tinyUSB on highest prio task in the system was enough to keep the audio running smooth.
What I came across is that with multi-channel(up to 32ch 32bit) probably host is not capable of filling the transfers properly anymore as I've seen discontinuity in audio data without any under/over r...
PS. removing FIFO would also mean it would be user responsibility to calculate/fill feedback endpoint?
The main FIFO won't be changed, support FIFO refers to #define CFG_TUD_AUDIO_ENABLE_ENCODING & #define CFG_TUD_AUDIO_ENABLE_DECODING
Operating System
Windows 10
Commit SHA
Not sure what "Commit SHA" means..
Board
ESP32S3 Dev Module
Firmware
Latest USB Core installed and latest version of the TinyUSB library.
USB Mode set to "USB-OTG (TinyUSB)"
USB DFU on Boot "Enabled"
Flash Size "8MB 64Mb)"
Partition Scheme "8M with Spiffs (3Mb APP / 1.5MB SPIFFS)"
What happened ?
Flashed the "midi_test.ino" example but the ESP32-S3 doesn't appear on the PC as a Midi device, but as "COM 17 (ESP32 Family Devic...
you need to enabled USB CDC on Boot, if it still does nnot work, open issue on the Adafruit TinyUSB repo instead
Summary
NOTE: This is a DRAFT PR - the code has not yet been tested on hardware.
This PR adds the ability to control the link state of USB NCM (Network Control Model) interfaces, allowing applications to simulate "ethernet cable unplugged/plugged" events.
Changes
Core NCM Driver ():
- Add state tracking to NCM interface
- Modify notification system to support dynamic link state changes
- Add function to send link state notifications
- Change hardcoded "connected" notific...
you need to enabled USB CDC on Boot, if it still does nnot work, open issue on the Adafruit TinyUSB repo instead
Thank you for your reply. I thought yours was the TinyUSB repo. Is yours a different library?
When I download it from the arduino IDE, which one is it? Yours or Adafruit's??
That would be great, I also think the audio driver is a bit complicated at the moment. The example's descritpor can also be simplified by using app-level struct like uvc https://github.com/hathach/tinyusb/blob/master/examples/device/video_capture/src/usb_descriptors.c#L174 . I think both audio and video are too complicated for pre-defined macros, maybe we can have macro with simplest form. I plan to do the same with audio examples but haven't manage the time yet. And yes, isochronous can use ...
Describe the PR
Part 1 of #3133, tested on STM32C071.
It turns remove support FIFO is pretty straight forward.
The example's descriptor can also be simplified by using app-level struct like uvc
Using struct is cleaner although mixing classes is more complicate.
It appears that on RP2350, tud_task() is effectively a SEV due to use of the pico spinlock in the critical section, which inhibits the WFE and turns the main loop into a busy loop, consuming a lot of power.
Hi, developer of Pico-ASHA here.
I know it's a little off-topic, but I was wondering if there would be an opportunity to provide basic UAC1 support? Many applications don't require anything more than basic (at max) 24 bit 96 KHz stereo audio, so UAC2 is a bit overkill. For example, Pico-ASHA only requires 16-bit 16KHz stereo audio.
The downsides of UAC2 is compatibility. While UAC2 works on modern Windows/Mac/Linux systems, the chances of it working el...
I know it's a little off-topic, but I was wondering if there would be an opportunity to provide basic UAC1 support?
There are already request to support UAC1, mainly because feedback compatibility issue between Windows and OS X. However UAC1 and UAC2 descriptors and controls are pretty different, it will be a mess to support both of them in one driver.
Describe the PR
This PR adds support for the STM32N6, and BSP for the STM32N657 Nucleo Board.
Additional context
- This has been heavily based off @HiFiPhile's STM32H7RSxx port. The TCPP0203 code is directly copied from their port.
- Currently the FreeRTOS examples do not run. I haven't had the time to actually analyse what isn't working, and I probably won't get the time as I will be using Zephyr.
- USB Host ha...
I've added initial support for the WCH CH32X035 MCU to the TinyUSB library.
Here's a summary of the key changes:
- Core TinyUSB Modifications:
- I added
OPT_MCU_CH32X035tosrc/tusb_option.h. - I added CH32X035-specific definitions (e.g.,
TUP_USBIP_WCH_USBFS,
TUP_DCD_ENDPOINT_MAX) tosrc/common/tusb_mcu.h. - I created a skeleton register header
src/portable/wch/ch32x035_usbfs_reg.h.
You'll need to manually populate this file with ...
- I added
Iโm truly sorryโI meant to open a pull request to my own repository just to test something, but I accidentally submitted it to the main repository instead.
Thanks for your PR, please allow maintainers to edit your branch.
ERROR: Permission to moritz-fivi/tinyusb.git denied to HiFiPhile.
fatal: Could not read from remote repository.
Thanks for that final fixup commit, not sure when / how that snuck in. I had tested rndid/ECM but not much, I'm really only interested in NCM myself!
Operating System
Linux
Commit SHA
86ad6e56c
Board
Raspberry Pi Pico
Firmware
uac2_headset
What happened ?
build this project. sound card did not appear. I work under Ubuntu.
https://github.com/hathach/tinyusb/tree/master/examples/device/uac2_headset
alsamixer shows nothing. :(
[ 184.366820] usb 1-4: Product: TinyUSB headset
[ 184.366822] usb 1-4: Manufacturer: TinyUSB
[ 184.366824] usb 1-4: SerialNumber: E6605838835DC22F
[ 184.453661] mc: Linux media inte...
Thank for your PR, it does indeed resolve the ZLP issue in #2632.
However I've some issues on Chrome 136 Windows 10:
- Disconnect button has no UI update, although sending and receiving is stopped
- Sometimes ASCII get translated to hex, entering
aaaaareturns6/9/2025, 4:07:29 PM 97,97,97,97,97on serial console - Serial console get stuck on 1st connection, 2nd connection returns
Failed to execute 'open' on 'SerialPort': The port is already open., needs to refresh the page on 3...
TUH_EPSIZE_BULK_MPS should be set based on TUH_OPT_HIGH_SPEED, not TUD_OPT_HIGH_SPEED
Describe the PR
I'm trying to debug tinyusb a stm32h7 board with a full speed device (TUD) and high speed host (TUH).
The high speed CDC code doesn't work small 64-byte buffers.
My code is not yet working, but I think this is an obvious fix.
@fcooperti, please test my last commit.
After checking kernel source code, the access width change is not limited to the latest operation, for example 32b+16b+8b is allowed for 7 bytes I/O (not limited to 3*16b+8b).
I've updated the logic to make access width limit only applied to wrapped fifo part while keeping normal transfer and linear fifo part untouched.
Does this example work at 133 or 250mhz?
Sometimes ASCII get translated to hex
That's an odd one.
I will try to reproduce that on the weekend.
Did this happen with the stock webusb_serial example?
Are you sure this is not a firmware problem?
I can't find any place in the js that could cause this (don't have access to a mcu currently).
Serial console get stuck on 1st connection, 2nd connection returns...
Ugh. Fair enough.
That's an odd one.
I will try to reproduce that on the weekend.
Did this happen with the stock webusb_serial example?
Yeah I'm not tricking you :) Tested on STM32L053 and STM32F723.
I just recorded a video demonstration on my home PC with Chrome 137 Windows 10, the symptome is a little different
- At 00:10 when I connect to serial, the input box is grayed out until something is received
- For the hex ...
Thanks for the video that makes it very easy to reproduce. ๐คฃ
Having the dev tools open would have been even better (for the next time).
I will fix these four issues might take me a while though.
Describe the PR
- merge all maxim (32650, 32666, 32690, 78002) family into common bsp/maxim. Only support cmake build system
- remove max32666fthr from hil pool (removed for devloping atm).
I recently started looking over your implementation for my design and I wanted to know if it is possible to poll in main loop so that I can first get all the files stored in flash before creating object to usb
Hi @roundby Read-only works normally. The problem I encountered before could not create files and folders in WIN10. I added some changes through debugging and now it works fine. I'm not sure if this is a BUG.
Uploading DIFF.PATCHโฆ
perfect, hil server probably has some loose connection issue. I am current not at its place to re-connect. We can just merge this for now.
Hi @roundby, thanks very much for this!
I have encountered the same thing as @diancity025. I've extended the read-only example to allow adding new objects to the list (while ignoring the file contents for now). Without @diancity025's changes, I just get a progress bar stuck at 0% while copying a file to the device. With their changes everything works as expected. I'm running this on an RP2350 connected to a Windows machine (it's also sort of working on Linux using android-file-transfer, an...
slight typo here (mpt/mtp)
N6 has 2 indentiacal HS core with built-in HS PHY (+ typecd), probably the first stm32 mcu with this configuration
perfect, thank you. Everything look great. I don't have a hardware to test with, but did try to compile and make some minor update to fix cmake build and/or some configuration and docs. I also refactor to have TCPP0203 driver as depencency since it can be used by more st board in the future.
perfect thank you, I havent tested this, I will just trurst you on this audio driver.
Operating System
Windows 11
Commit SHA
Version bundled in framework-arduinoespressif32 version 3.20017.241212+sha.dcc1105b, "a0e5626bc" mentioned in docs
Board
Custom ESP32-S2 design, wifi inactive
Firmware
Custom firmware in PlatformIO env, sending 2x 64-byte raw HID packets every second. I haven't created a new minimal test case project yet, but I will try do so shortly.
What happened ?
Periodic HID output reports (from device to host PC) are sent in sets of 2, ...
Hi @marchingband,
there is a big refactoring in esp_tinyusb component on the way: https://github.com/espressif/esp-usb/pull/178
It will unlock the possibility to define user behavior on the tud mount/unmount callbacks as well as use the previous default internal logic (mount/umount on the callbacks).
With the already available option to re-install tinyusb driver from esp_tinyusb component, this could help you to achieve the initial goal:
it needs to change into a MSC device for a ...
Related area
tinyusb_msc
Hardware specification
every
Is your feature request related to a problem?
Not related to a problem.
Describe the solution you'd like
Configurable option to enable support, something like:
#define SCSI_SUPPORT_LONG_LBA
I have checked existing issues, dicussion and documentation
- [x] I confirm I have checked existing issues, dicussion and documentation.
@hathach I just rebased on master and did some cleanup.
CFG_TUD_MEM_ALIGN introduce a breaking change, but without this I don't know how to extract numeric value.
@hathach I just rebased on master and did some cleanup.
CFG_TUD_MEM_ALIGNintroduce a breaking change, but without this I don't know how to extract numeric value.
How about adding the CFG_TUD_MEM_ALIGN_BYTE/SIZE instead, CFG_TUD_MEM_ALIGN if not defined will be defined using that. That way people will have time to migrate (or just leave it if they don't need it). Btw, why you need the numeric value (haven't do review yet).
Operating System
Others
Commit SHA
e95973d3462cdacd165a4057632d46248ded7b8a
Board
GP2040-CE Development Kit (RP2040 with USB-Host Connected to Pins 23/24)
Firmware
Current main compilation of GP2040-CE from 'main' of https://github.com/OpenStickCommunity/GP2040-CE/
UF2 is flashed to an RP2040 based development board for GP2040-CE
What happened ?
After updating our project updated to Pico SDK 2.1.1, I am getting multiple failures in the USB host code using the lat...
How about adding the CFG_TUD_MEM_ALIGN_BYTE/SIZE instead, CFG_TUD_MEM_ALIGN if not defined will be defined using that.
Yeah it's a good idea. I need to align the buffer correctly if user need a higher alignment than cache line size.
Please open the issue in corresponding repo, Complete but not empty: 0/6 or TUSB:DCD is not covered here.
Please open the issue in corresponding repo,
Complete but not empty: 0/6orTUSB:DCDis not covered here.
I'm more than happy to do this, but can you point me towards the right repo? I feel dumb asking, but this was my best guess based on my understanding of the TinyUSB implementation for the ESP32/Arduino framework, and the log tag found here:
It looks like from https://github.com/espressif/esp32-arduino-lib-builder but dcd_esp32sx is obsolete and removed.
You can find it in older forks https://github.com/esp-arduino-libs/esp32-arduino-lib-builder/blob/c79c44c198629d3a4b28395e8aa73750403964bb/components/arduino_tinyusb/src/dcd_esp32sx.c#L805
It's worth noting that this same behavior is observed with several other non-PS4 HID devices.
Describe the PR
2nd part of #3133, ISO transfer management is moved into USB ISR to avoid timing conflict with other classes.
Tested on NUCLEO-H7S3L8 and NUCLEO-C071RB with all audio examples.
Demo
- Take
audio_test_freertosexample, add some processing delay to volume change request
diff --git a/examples/device/audio_test_freertos/src/main.c b/examples/device/audio_test_freertos/src/main.c
index 0a6cdfd4f..67d56b640 100644
--- a/examples/device/audio_test_...
I was trying to implement a minimal USB HCI bridge driver for a rtl8761 based Bluetooth 5.3 Dongle and use with BTStack. I surprisingly worked well until I realized that the ACL endpoints (especially Bulk In transfers) are limited to 64KB/s, while playing with the a2dp sink demo. I scratched my head for days as it worked perfectly with libusb port on linux PC, finally got my answers in here.
This PR works great with the MSC demos but as the HCI driver required a lot of control and interrup...
Describe the PR
To allow it be used in nested functions, I think most OSs already have the counter.
Im running the MIDI sketch on my ESP32-S3, but I can't get the device to show up on my Mac or PC. Attached are my settings.
Any ideas what could be the issue? I saw folks had similar issues on Github, but i don't see a definitive solution.
Im running 3.2.0 of the Espressif board
@mastupristi Hi, PR is up in #3150
great PR, sorry I was too busy with other works. I have synced the PR with master and reviewing and making change to PR myself, since I guess @IngHK is also busy atm.
I really hope this is able to be merged. The speed boost from this made CD-ROM emulation support on my PicoGUS project possible. Thank you @rppicomidi and @wbcbz7. Right now I'm using wbcbz7's branch as a submodule but it'd be great to go back to mainline TinyUSB!
Controlled by the embedder defining CFG_TUD_FSDEV_DOUBLE_BUFFERED_ISO_EP in tusb_config.h. If hardware does have SBUF_ISO bit it will use only one half of endpoint pair register.
Tested on G0.
Operating System
Linux
Commit SHA
espressif/tinyusb (0.18.0~2)
Board
ESP32-S3 based board
Firmware
What happened ?
I'm trying to implement a custom vendor class driver. I noticed that when using usbd_edpt_xfer to receive data from the OUT EP, the ZLP is misinterpreted and causes the ...
@wbcbz7 Thank you for continuing to work on this. I have had a lot of things going on. Do you plan to submit a separate pull request, or would you like me to merge your changes into this one?
@hathach
I try to get my head around this.
Can a simple matrix explain the possibly combinations in a system with multiple USB ports ?
Also the dual-role, possibilities if you tear down the interface completely.
With USB-C there is also the CC pins and some chips have CC-pin-handling built in, and for others we need to use external chip over I2C, is there some docs on dealing with DRD switching ?
I see there is a way to assign a pin for binary identification of the VBUS power.
I would also ...
Thank you @IngHK for the great PR and sorry for the delay. I have updated and refactored the PR to make it cleaner and move lots of code into common cdch driver.
Thank @robertlipe for helping with the review.
@rppicomidi Since my changes were mostly based on your pull request, I think either can be done. There is still some issues left, such as occasional asserts/panics if the device has been unplugged from a downstream USB hub during a bulk transfer - I could try to look for them and fix if it's possible and when time allows.
there is minimal docs for getting started. For this, you need to check code base.
There is lots of mcus with multiple usb ports already.
sure, do you know which host or any way to force host to use READ/WRITE16 instead of 10 for developing/testing.
I think we need to add in_isr since some I/O can be done in ISR. also I think we only need to defer function when it is invoked in ISR. Let me know if that makes sense to you.
@HiFiPhile I have made some changes, let me know if those makes sense to you.
Comparison result is always the same
Comparison is always false because resplen <= -1 and 0 <= bufsize.
Thank you, use cbw.command[0] for pending IO command made it easier to for command extension :)
Without usbd_defer_func proc_read_io_data\proc_write_io_data will be executed in IO task's context, I think it's risky to have both IO task and TUSB task to modify class internal state simultaneously.
Thank you,
use cbw.command[0] for pending IO commandmade it easier to for command extension :)Without
usbd_defer_funcproc_read_io_data\proc_write_io_datawill be executed in IO task's context, I think it's risky to have both IO task and TUSB task to modify class internal state simultaneously.
Yeah, I think you are right, I will revert that to force usbd defer
No trivial switch statements
This switch statement should either handle more cases, or be rewritten as an if statement.
midi host is implemented in https://github.com/hathach/tinyusb/pull/1627
closed since it has not been updated for too long
this can be closed, since debouncing is done in https://github.com/hathach/tinyusb/pull/3104 . feel free to re-open, or file another issue should it still occurs.
Describe the PR
- add docs for building with cmake
- remove make wrapper for espressif and rp2040
- update ci matrix
- github action: build make/cmake with only board per family
- circleci: build all make/cmake in PR
perfect, thank you. Also thank @gguichard for initial PR in #2395. I have update the PR, mostly rename,
- also add notify_conn_speed_change() as well.
CFG_TUD_CDC_NOTIFYis added for opt-out configuration- update cdc_msc/cdc_msc_freertos to support notification as well
- change bInterval for CDC notificaiton endpoint template from 16 to 1ms
Thank you, it looks good !
closed since this PR is rather out of dated. Please open a new one or update this if this feature is still needed.
implemnted by https://github.com/hathach/tinyusb/pull/2593, thank you very much for brining this feature into our attention.
can we remove this, and use the noncacheable_buffer instead, I like to keep thing closed to stock stm32 linker as possible.
Yes it's possible, MPU config need to be added to BSP to make noncacheable_buffer really non-cached. And I forgot this when I enable DCache for F7 & H7...
wait, does the current code configure this section as non-cacheable, while noncacheable_buffer section need extra works, or both of them need to be configured the same way ?
I am being lazy here to look up manual, why we need to reduce the sram size. H7 should have more than enough for demo ?
dtcm_data is only used by RTT to have a non-cached buffer, DWC2 doesn't relied on this.
I've added SCB_EnableDCache for benchmark only, to keep it simple we can also keep the DCache disabled.
ST reduced the value in newer linker file, I think it's because non-cached section is hardly used so better to keep it small by default.
I just wanted to bump this because there are already two people working on host support, see also #3094.
got it, then we keep it same value to stock linker
so it is possible to use the default noncacheable_buffer section instead of adding new one. That would allow us to use the stock IAR linker as well ? You may want to pull first, since, I push the fix for the linker issue with clang (need to have memory value before provide, and drop the READONLY keywords)
so it is possible to use the default noncacheable_buffer section instead of adding new one. That would allow us to use the stock IAR linker as well ?
I think so, hope MPU config generated by Cube support both compilers.
Operating System
Others
Commit SHA
latest git pull on pico-sdk v 2.1.1
Board
RPi pico (RP2040) - pico-sdk 2.1.1 on vscode pico plugin
Firmware
when used in the midi2usbhost project (https://github.com/rppicomidi/midi2usbhost) simple MIDI devices like the Korg NanoKontrol2 are discovered correctly, but Line6 Pod Go is not discovered. usb descriptor and debug output from tinyUSB lib attached below.
What happened ?
when used in the midi2usbhost project (https://githu...
Y'all are awesome. Thank you for this.
When a device it supports both Audio Streaming and MIDI Streaming, the TinyUSB driver expect it to publish descriptors like this:
- Audio Control
- MIDI Streaming
- Audio Streaming
Lines 225-228 of the TinyUSB MIDI Host driver stops parsing the descriptor if the the MIDI Streaming descriptor does not immediately follow the Audio Control descriptor.
The POD Go device descriptor attached to this issue publishes descriptors like this:
- Audio Control
- Audio Streaming
- MIDI Streaming
Th...
@rppicomidi I miss that in previous PR, do you mind to make a new one. Thank you
I don't see why we need to replace CFG_TUD_MEM_DCACHE_ENABLE by TUD_EPBUF_DCACHE_ALIGNED, DCACHE when enabled is certainly required the memory to be in cache line alginment ?
My idea is to control DCache alignment not only by CFG_TUD_MEM_DCACHE_ENABLE but by the necessity:
-
I set
CFG_TUD_MEM_DCACHE_ENABLE_DEFAULT=1for MCUs with internal cache soCFG_TUD_MEM_DCACHE_ENABLEdoesn't need to be set by the user, especially during family migration it could be forgot. -
DCache alignment is only needed when DMA is enabled, without
TUD_EPBUF_DCACHE_ALIGNEDit will be aligned by default even not needed. -
User imposed alignment
CFG_TUD_MEM_ALIGNalways ...
I've updated BSP:
- Keep DCache disabled for H7 & F7 for RTT compatibility
- Add MPU_Config to H7RS and use noncacheable_buffer for RTT buffer
Hi @diancity025.
Thank you for your tests. I checked directly on a RBPI Pico2 and investigated the issue. It is caused by the way mtpd_xfer_cb is implemented, as it was not expecting xferred_bytes to be more than CFG_MTP_EP_SIZE, but the call to usbd_edpt_xfer was requiring the whole remaining data size and the library does not enforce a limit if the hardware supports a larger endpoint buffer.
We tested the fix together with some corrections along with other refinements, a better e...
This is just to inform that we have submitted a simple implementation within PR #3023. You can find the details and test it from there.
Hi @f-hoepfinger-hr-agrartechnik
littlefs must work for us, to be useful.
i guess it will be hard with littlefs. easier to make 1 FAT Partition, and copy the stuff over to littlefs later.
Lately, I am replying to this.
We used this change in an internal test project, specifically designed to expose files from an SPI memory managed by littlefs. I can confirm that this setup is perfectly feasible, though there are some limitations depending on platform constraints.
You can ima...
Hi @roundby, thanks very much for this!
I recently had an issue where I couldn't store large files when I was using RP2040 to test mtp docking with littlefs, I saved the file handle via the LFS_TYPE_USERATTR attribute of the littlefs file. At the moment it is normal when reading and writing small files. But when I write to a relatively large file (368k), I have the problem that the transfer timeout cannot be completed. Can you help with that? Thank you.
Here are the logs I scraped.
I don't see the point to introduce TUD_EPBUF_DCACHE_ALIGNED macro, the existing CFG_TUD_MEM_DCACHE_ENABLE and CFG_TUD_MEM_DCACHE_ENABLE_DEFAULT should be good enough, the default value of dwc2 can be CFG_TUD_DWC2_DMA_ENABLE (same as P4)
#define CFG_TUD_MEM_DCACHE_ENABLE_DEFAULT CFG_TUD_DWC2_DMA_ENABLE
#define CFG_TUH_MEM_DCACHE_ENABLE_DEFAULT CFG_TUH_DWC2_DMA_ENABLE
perfect, thank you very much for this great PR. Sorry for the delay, I have tested with simple host/device_info and dual/host_info_to_device_cdc and it can enumerate device just well. haven't done more in-depth testing. Any issues can be resolved as follow-up PR later.
I have made some changes
- always add CFG_TUH_WCH_USBIP_USBFS=1 by default for ch32v20x since that is the only port that support host mode. Manual setting it isn't required.
@hathach I have sent a patch to @doughadfield to try. If it fixes the issue, then I will submit the patch as a pull request.
fixed vendord_open's tud_vendor_n_write_flush argument.
tud_vendor_n_write_flush argument should be _vendord_itf array index (0,1,2,...),
but "p_vendor - _vendord_itf" is 0, sizeof(vendord_interface_t), 2*sizeof(vendord_interface_t), ....
I have added support for the AT32 chip and currently it is compatible with seven models.
[hathach/tinyusb] Pull request review submitted: #2963 Add DWC2 cache maintenance routines for STM32
perfect, thank you. I have changed the IAR linker back to the stock (from cmsis package). change CFG_TUSB_MEM_DCACHE_LINE_SIZE_DEFAULT (not defined to 1), and other minor things. This is good to merge now.
Thank you, without the enabled switch it looks like the buffer will be aligned to cache size even if not needed on H7.
ah right, I think I messed up when switching between p branch
[hathach/tinyusb] New branch created: codex/find-and-fix-a-codebase-bug
Summary
- fix HID host parser: handle item size value
3as 4 bytes - avoid reading descriptor data when no bytes present
Testing
ceedling test:all(fails:ceedling: command not found)
https://chatgpt.com/codex/tasks/task_e_6868baec4d148331bb2aa023524eb1b3
thank you, I will trust you on the audio driver. I did mostly code format, add busy/claim status revert if xfer_isr() defer handler to xfer_cb() to prevent race condition, where app will claim another xfer before cb() is called by tud_task().
@HiFiPhile I think I fixed all the issues. Maybe you can give it one more look. Tell me if there is anything you want changed or a feature that you think is missing.
- Serial console get stuck on 1st connection, 2nd connection returns
Failed to execute 'open' on 'SerialPort': The port is already open., needs to refresh the page on 3rd attempt to make it work
I don't have a windows pc to test. Can you still reproduce that issue? I can set one up to reproduce though if need be.
perfect, this works well on both samd21 and samd51 on the first try. Great works, I have move board-specific code for enable vbus to the newly added board_vbus_set(). Sorry for the long delay, I have been pulling off to other works and kind of forgot about this great PR.
even device is disconnected, previous complete transfer e.g succesful should still be handled to notify application e.g.
- xfer complete -> put to usbd queue
- device disconnected
- tud_task run --> should still be handle
[hathach/tinyusb] New branch created: feature/add_tusb_teardown
Describe the PR
update for https://github.com/hathach/tinyusb/pull/2904, since I cannot make changes to @roma-jam fork. tusb_deinit() for matching with tud/tuh_deinit(). Since it is new API, we don't have to cover the backward compatible case.
Hi @hathach,
the original idea was to allow the possibility to use pre-defined TUD_OPT_RHPORT or TUH_OPT_RHPORT to teardown the tinyusb and to call the API without any arguments:
tusb_init();
tusb_teardown();
After your changes it is no longer possible, so the idea is to call deinit for the device like this tud_deinit(TUD_OPT_RHPORT), am I right?
tusb_init() should be called with rhport and arguments. Since i made the tusb_init(void) previously, we need to keep it backward-compatible to prevent breaking app that simply update tinyusb and don't want to re-write code. For new API, user should specify which port to deinit().
@hathach ,
tusb_init() should be called with rhport and arguments.
I think that the macros tusb_init() is still available for usage: https://github.com/hathach/tinyusb/blob/master/src/tusb.h#L153
So it is possible to use it to init the tinyusb, which leads to the default call: tusb_rhport_init(0, NULL)
So, either we need to deprecate the macros completely (which would break the backward compatibility) or to provide another macros for tusb_deinit() which when called without...
Something like that:
bool tusb_rhport_deinit(uint8_t rhport);
#if defined(TUD_OPT_RHPORT) || defined(TUH_OPT_RHPORT)
#define _tusb_deinit_arg0() tusb_rhport_deinit(0)
#else
#define _tusb_deinit_arg0() TU_VERIFY_STATIC(false, "CFG_TUSB_RHPORT0_MODE/CFG_TUSB_RHPORT1_MODE must be defined")
#endif
#define _tusb_deinit_arg1(_rhport) tusb_rhport_deinit(_rhport)
#define tusb_deinit(...) TU_FUNC_OPTIONAL_ARG(_tusb_deinit_arg1, ...
at some point in the future release, we will deprecate the usage of tusb_init(void). For now, we will just leave it as it is. The new API should take new signature. New code should call tusb_deinit(TUD_OPT_RHPORT) if it currently use CFG_TUSB_RHPORT0/1_MODE for setting device/host stack
@roma-jam let me know if that sounds ok, and we are good to merge ?
[hathach/tinyusb] New comment on pull request #2923: Fix issues found using default CodeQL settings.
closed since I still prefer the simpler alt https://github.com/hathach/tinyusb/pull/2987. Thank you @henrygab for bring this issue into attention.
Describe the PR
In some cases, like when implementing a truly read-only MSC disk, the TinyUSB's built-in MSC SCSI commands may need to be overridden.
This is a small, fully backwards-compatible change that adds a new weak callback, tud_msc_scsi_pre_cb. If defined, this callback allows the user code to override also those SCSI commands that TinyUSB handles by default in its static proc_builtin_scsi function.
Additional context
An example how this new callback is need...
Oops. It appears that we will need slightly richer semantics. I'll try to provide a new version of this PR still today, covering also the cases where this callback needs to trigger an error and still bypass the default implementation.
I pushed another commit here, now changing the sematics slightly. This is needed to make a difference between two cases: the pre-callback wants to fall back to the default behaviour vs. the pre-callback wants to return an error.
This may not be the best way of implementing this, though. So, I presume some careful thought is needed.
And, if this PR is accepted as such, the two commits should probably be squashed together.
Hmm. Maybe this all should be implemented in a different way. I'm pulling back this, for now.
Hi @f-hoepfinger-hr-agrartechnik
littlefs must work for us, to be useful.
i guess it will be hard with littlefs. easier to make 1 FAT Partition, and copy the stuff over to littlefs later.Lately, I am replying to this.
We used this change in an internal test project, specifically designed to expose files from an SPI memory managed by littlefs. I can confirm that this setup is perfectly feasible, though there are some limitations depending on platform constraints....
Operating System
Others
Commit SHA
current master branch tested on ESP-IDF 5.4
Board
ESP32-P4-Function-EV-Board
Firmware
examples/host/hid_controller
What happened ?
Output transfers on interrupt endpoint fail after several successful transfers.
How to reproduce ?
Just compile standard hid_controller example from tinyusb and attach DualShock 4 controller.
Debug Log as txt file (LOG/CFG_TUSB_DEBUG=2)
Typical log with DualShock4 (logging for IN endpoints...
Related area
USB PTP Device Class
Hardware specification
esp32s3
Is your feature request related to a problem?
Already has USB MSC device which works. When USB plugged in, storage is unmount from internal and mounted to USB device. It mounts back to ESP internal when USB disconnected. But I have an application which needed to read the files when device USB plugged into USB host. The best protocol id PTP. File system is managing inside the ESP and candle any requests using spi...
[hathach/tinyusb] New branch created: msc-inquiry2-cb
add v2 for inquriy response callback tud_msc_inquiry2_cb(). When both are implemented, v2 will be used. close #2954
https://github.com/hathach/tinyusb/pull/3172 add a full inquiry response (v2) callback. It is the better approach since it also support vendor data if needed. Should have doone this from beginning.
Hm....could be cache-related.
Could you try to enable CFG_TUH_MEM_DCACHE_ENABLE ?
@hathach
We're good.
@hathach We're good.
thanks
Thank you for your response!
Cache flush/invalidation is working: it is set in usb_mcu.h automatially for OPT_MCU_ESP32P4:
// Enable dcache if DMA is enabled #define CFG_TUD_MEM_DCACHE_ENABLE_DEFAULT CFG_TUD_DWC2_DMA_ENABLE ...
@AndyDevLat ,
right now I don't think that mixing fifo settings from esp-idf and hcd_dwc2 from tinyusb somehow can help.
But the issue could be related to the way, how we access the resisters.
The one issue was on S3 (yes, not RISC-V, as P4 but stll): https://github.com/hathach/tinyusb/issues/3047#issuecomment-2759331873
Could you check the discussion from the link above and compare the description and the output with your case?
Cheer on <=25 pending PRs (displayed in one page) !๐
In my case device enumeration is always succesful, so no problem with control transfers. Only interupt OUT transfers exhibit problems. Also it does not matter if DMA is enabled or not, so it seems issue is a bit different, but maybe it is because of different architecture. If it is related to some registers or compilation issues, as mentioned in the above post, wouldn't it always fail immediately and not after some time? To me it looks more like some FIFO overflow or whatever, maybe somethin...
yeah, trying to get PRs merged as much as I could for now :tada:
Describe the PR
Replace #3115 since it can't be pushed
This PR add support for vendor-spicific command messages to the usbtmc_device
Additional context
Bevore messages with MsgID = REQUEST_VENDOR_SPECIFIC_IN and VENDOR_SPECIFIC_OUT where ignored. Now the vendor_specific messages are handled similar to normal ones, except that the MsgId is set to REQUEST_DEV_DEP_MSG_IN for the response of vendor-specific commands
FIXME comment
FIXME comment: Unsure how to check if the OUT endpoint fifo is non-empty....
Thank you for your update, but it didn't get better in my side.
With auto connect checked
- Once I tape something it returns
Attempting to auto-reconnect...thenSend error: Failed to execute 'transferOut' on 'USBDevice': The specified endpoint is not part of a claimed and selected alternate interface. - Any following sends are failed
- Date receiving works
https://github.com/user-attachments/assets/845cafd2-ac05-4bf5-9a6d-3023c8300144
With auto connect unchecked
...