#tinyusb

1 messages ยท Page 18 of 1

fallow birchBOT
#

Operating System

Windows 10

Board

stm32g474nucleo

Firmware

I was using the uac2_headset example code. I tried using it on a stm32g474nucleo board, but any mcu which uses stm32_fsdev should have this issue.

What happened ?

An assert is hit at runtime:

dcd_edpt_open 760: ASSERT FAILED

Which basically says that isochronous mode is not implemented in the stm32_fsdev driver.

Is there any interest in implementing the isochronous mode in this driver? Right now t...

fallow birchBOT
#

Operating System

Others

Board

raspberry pi pico (rp2040)

Firmware

examples/host/cdc_msc_hid commit cadfcd153e8fce804f38f0e19997c13bf6931a49

What happened ?

The hub appears to recognize the keyboard is attached, does a hub port clear feature reset change, and then fails to complete a transfer to get 8 bytes of the Dev. Descriptor. Unplug of keyboard is not recognized after that. If I unplug the hub, the code recognizes that and enumerates the hub again on plug in.
@hat...

fallow birchBOT
fallow birchBOT
fallow birchBOT
#
mkj

Avoids a linker conflict if programs are using that same function name.

Otherwise building a samd21 fork of apollo we get

/usr/lib/gcc/arm-none-eabi/9.2.1/../../../arm-none-eabi/bin/ld: _build/qtpy/obj/../../firmware/src/boards/qtpy/uart.o (symbol from plugin): in function `uart_configure_pinmux':
(.text+0x0): multiple definition of `uart_init'; _build/qtpy/obj/hw/bsp/samd21/family.o (symbol from plugin):(.text+0x0): first defined her...
fallow birchBOT
#
[hathach/tinyusb] New branch created: add\-s3\-devkitm
fallow birchBOT
fallow birchBOT
fallow birchBOT
fallow birchBOT
#

I assume you're working with FTDI/Bridgetek, so i'll ask you if you don't mind.

Afaik there is no toolchain for linux, I tried to compile gcc for it and had some luck, but the images were larger than expected, and they showed some erroneous behaviours.
Are the compilation options used by the original toolchain available somewhere? I can only assume that's what cause the differences.

fallow birchBOT
fallow birchBOT
fallow birchBOT
#

Describe the PR
This PR implements the board definition for the ST nucleo f439zi development board.
I tested the uac2_headset and cdc_msc examples and both worked as they should. The uart config also works since I got an assert error with cdc_dual_ports (not enough endpoints, 5 needed, 4 available).

Limitations:

  • The USB HS peripheral is not implemented. So only OTG_FS can be used. Nucleo boards have only one downstream USB port connected to OTG_FS.
  • The host mode power switch pi...
fallow birchBOT
#
  • The USB HS peripheral is not implemented. So only OTG_FS can be used. Nucleo boards have only one downstream USB port connected to OTG_FS.

OTG HS required external PHY, which is not available on nucleo platform. So it is the board limitation not your PR. HS work on other boards like f723 or h743.

  • The host mode power switch pin doesn't seem to be defined/initialized anywhere. This is also the case for the f412zg nucleo board definition, so I suspect this isn't working there as we...
fallow birchBOT
fallow birchBOT
#

This code is not perfect but it is far enough along that I believe it is ready for review. It handles concurrent MIDI send and receive. Whether the API I came up with is good for any host other than the RP2040 should be considered. I have tested it with the following MIDI devices:

  • Casio PS-X3000
  • Yamaha reface CS
  • Korg nanoKONTROL2
  • Korg nanoKONTROL Studio
  • Arturia Keylab 88 Essential
fallow birchBOT
fallow birchBOT
#

Operating System

Windows 10

Board

pca10056, fomu,

Firmware

examples/device/cdc_msc
or any other device build

What happened ?

Build fails when optimization is changed from -Os to -O2.
In several places get_driver() (which can return NULL) is used without checking for NULL dereference.

It could be that it is false positive but maybe not.
I'm using other compiler (xc32-gcc for microchip) that allows to have -Os only in PRO version (not free) so I'm stuck wit...

fallow birchBOT
fallow birchBOT
#

Describe the PR
Mynewt build fails when xc32 compiler is used.

definition of DEBUG breaks Microchip pic32 builds for Mynewt.
When MCU is not VALENTYUSB_EPTRI there is no need to have any
preprocessor definitions.
It may not look like a big deal but for xc32 builds, compiler
automatically force-includes some file that have structure with field name
DEBUG that result in build error in dcd_eptri.c when this file
is not really needed.

Moving DEBUG and LOG_USB few lines down shoul...

#

Describe the PR
Three changes are needed to accommodate xc32 compiler build:

  • optimized build flag other than -Os
    added CFLAGS_OPTIMIZED that defaults to -Os but can be overridden in boards
  • build without -lnosys
    added LIBS_GCC with default libraries that can be changed in boards
  • build without LD_FILE specification
    if LD_FILE is empty -Wl,-T options is not added to LDFLAGS

Additional context
xc32 compiler for Microchip mips chips i...

fallow birchBOT
fallow birchBOT
fallow birchBOT
#

@rppicomidi many thanks, I have revised hcd for rp2040 recently and also have some ideas on how to implement the bulk endpoints. Basically it is similar to your changes, we add an struct for each bulk ep and process them one by one after the previous one is complete. I will check this out asap I could. sorry for late response, I am still catching up with PRs

fallow birchBOT
#

It is definitely Windows UAC2 driver issue, despite of fullspeed detection, it still mis-interprets as highspeed endpoint

[USBAudio2]VID=0xcafe PID=0x4010 REV=0x0100
[USBAudio2]UsbSpeed = 2 FullSpeed
[USBAudio2]language ID = 0x0409
[USBAudio2]Product='TinyUSB speaker'

[USBAudio2]  AS OUT IfNb=0x01 AltSetting=0x01 '<NULL>'
[USBAudio2]     Format Type I PCM (0x00000001) SubSlotSize=2 BitsPerSample=16 ChannelCount=2
[USBAudio2]     Data Endpoint 0x08 Isochronous Asynchronous Data...
fallow birchBOT
fallow birchBOT
fallow birchBOT
#

I should be able to find some time in the next week or so. I need to think of how I would want to bake this into the driver properly. If at at all.

I actually wonder if just extending tud_audio_fb_set to take a parameter on which format to convert to. Or adding a function that does no conversion and letting the user handle it is the better choice, With documentation of course
Thoughts?

fallow birchBOT
#

So So sorry I became incredibly sick, But Im mostly back at it now! Thank you guys so much! This project has the best community! Ok So I made sum mistakes, I didnt know any and all git pushes I would do would immediately be added to PR so Things I didnt intend to make it hear did, Im fairly embarrassed. So the vector offset I will hafta try and see if it works without it being specifically listed under main. I currently have several stm32s with boot loaders that all seem to require different ...

fallow birchBOT
#

Ok so adding -DAPP_START=0x08040000 to the cflags with .ld set to offset didnt work and also cflags set and ldflags set with -Wl,-Ttext=0x08040000 and .ld set to flash base, but all fail, the leds turn on correct and it fails to enumerate. Im sure a simple way to add the offset to the board/family files exists but I just havent found it yet:) Ill keep on it!

fallow birchBOT
#

I should be able to find some time in the next week or so. I need to think of how I would want to bake this into the driver properly. If at at all.

That would be great

I actually wonder if just extending tud_audio_fb_set to take a parameter on which format to convert to. Or adding a function that does no conversion and letting the user handle it is the better choice, With documentation of course Thoughts?

It is also a good approach as well, I think we should also take this chance...

fallow birchBOT
fallow birchBOT
#

@t123yh no problem at all, I am downloading keil trial version on my VM windows, will try it out if you have any ready-to-build example

No you don't have to download keil. You can run my example totally within the tinyusb example framework. The code to reproduce the problem is based on gud-pico which is part of the gud project. You need to have RPi with the latest RPi OS (which backported gud to 5.10 kernel) or PC with ...

fallow birchBOT
fallow birchBOT
fallow birchBOT
fallow birchBOT
fallow birchBOT
#

In order to implement this, we'd also want to implement DMA in order to support the higher data rates. To perform DMA, we'd want some sort of abstraction layer in the case that DMA is used in other parts of the application code. Also, DMA will be slightly different on the various variants of the STM32, so I'd expect adding DMA support would be a large undertaking.

If you don't think that DMA is necessary, this could be done without too much effort, though I personally don't need ISO endp...

fallow birchBOT
#

Sorry for the late reply. I am not sure if it is a good idea to make the feedback function so flexible:

  • First of all, this sould not be a concern of the user as the value format was defined within the USB specs, so nobody would expect to set it on its own. The reason we would like to do that now is because we need a patch for Windows driver bug
  • There is no chance the driver knows if a corretly working Linux driver or a buggy Windows driver is hosting the audio driver. Hence, the flexi...
fallow birchBOT
#

I think tud_audio_n_feedback_set(func_id, fb, format) sounds reasonable.

But to clarify a couple things about original proposal https://github.com/vmilea/tinyusb/commit/ef879e8a8a43dfa34160f50d7f432c3140dec7fa:

  • It doesn't require changing the API.
  • With CFG_TUD_AUDIO_DISABLE_FEEDBACK_FORMAT_CORRECTION=1, we let the user handle the format. So they can change format at runtime like in @geekbozu's hack. In my opinion this kind of hack is better left do the user than integrating int...
fallow birchBOT
fallow birchBOT
#

@vmilea Well, i would strongly vote for not letting the user (i mean the poor developer) handle this case. IMHO the tinyUSB driver should take care of this matter. This saves the users a lot of time and us a lot of bug reports.

Nevertheless, the ALSA driver you mentioned kept me thinking. Against the specifications they check and allow different formats too. I guess to robustify their driver against other UAC drivers which also do not respect the specs. Maybe we should do that too? Since n...

fallow birchBOT
#

I guess to robustify their driver against other UAC drivers which also do not respect the specs. Maybe we should do that too?

Supporting both formats on host driver is trivial (shift feedback value by 2 if it's closer to the nominal rate).

On the other side, the client driver can't detect format mismatch directly. So tinyusb would just guesstimate after a number of frames based on data rate. In my experience, these heuristics are tricky to implement and tend to fail in surprising way...

fallow birchBOT
#

Thank you @PanRe and @vmilea for the feedback

Regarding cross-platform: Fixed 16.16 format is currently viable on Windows (10 / 11) and Linux (ALSA driver detects if the feedback rate is out of bounds and switches to the other format automatically). Unfortunately I don't have a Mac to check there as well.

I did a quick check with CFG_TUD_AUDIO_DISABLE_FEEDBACK_FORMAT_CORRECTION=1 on an macOS Big Sur and it works well.

Have you reported the Windows driver bug? I think there was...

#

Sorry for the late reply. I am not sure if it is a good idea to make the feedback function so flexible:

  • First of all, this should not be a concern of the user as the value format was defined within the USB specs, so nobody would expect to set it on its own. The reason we would like to do that now is because we need a patch for Windows driver bug
  • There is no chance the driver knows if a correctly working Linux driver or a buggy Windows driver is hosting the audio driver. Hence,...
fallow birchBOT
fallow birchBOT
#

Let em start with I am all for this. I think its a saner default.
However,
#1235 Documentation is not accurate,
The issue is the windows driver is assuming the format based on the bcdDevice field.
if bcdDevice = 0x01XX aka a 1.0 device windows assumes a 10.14 format.
if bcdDevice = 0x02XX aka a 2.0 Device makes windows expect 16.16.

All of our examples default to a usb2.0 device even though we are full speed.

If linux/mac support FullSpeed USB 2.0 16.16 out of the box. I agree...

fallow birchBOT
#

if bcdDevice = 0x01XX aka a 1.0 device windows assumes a 10.14 format.
if bcdDevice = 0x02XX aka a 2.0 Device makes windows expect 16.16.
All of our examples default to a usb2.0 device even though we are full speed.

Yeah, you are right. Since UAC 2.0 (2006) came after USB 2.0 (2000), it is absolutely normal to have fullspeed only to have bcd = 2.0. Since the new default does not correct format, application could just pass 10.14 when using with bcd = 1.1. We surely need to updat...

fallow birchBOT
fallow birchBOT
#

So do we want to make a separate PR to allow modifications at runtime to the Feedback value? Or is getting the documentation updated in #1235 enough for everyone?

your format mismatched detection snippet is awesome, I think we should also put it into the example with explanation (either enabled or commented out). If possible, it is probably better to be a separated PR after #1235.

@PanRe do you think having 16.16 as default is reasonable. If yes, we will wrap up #1235 . Of course, thi...

fallow birchBOT
fallow birchBOT
#

Describe the PR
Driver for Microchip PIC32MZ (mips architecture) High Speed USB.
CDC/MSC/HID/UAC2 tested with repository examples.
DFU/CDC/HID tested also with Mynewt system.

Additional context
For now driver only supports device role (even though chip has OTG support).
xc32 compiler from Microchip is needed to build with this driver (3.01 or 2.50 (with some unknown command line options removed)).
To build non-debug version -Wnull-dereference has to be remov...

fallow birchBOT
fallow birchBOT
fallow birchBOT
#

So do we want to make a separate PR to allow modifications at runtime to the Feedback value? Or is getting the documentation updated in #1235 enough for everyone?

your format mismatched detection snippet is awesome, I think we should also put it into the example with explanation (either enabled or commented out). If possible, it is probably better to be a separated PR after #1235.

@PanRe do you think having 16.16 as default is reasonable. If yes, we will wrap up #1235 . Of c...

fallow birchBOT
fallow birchBOT
#

Superb! thank you very much another excellent PR. Except for the minor OPT_MCU, I have an couple of questions:

fallow birchBOT
#

Superb! thank you very much another excellent PR. Except for the minor OPT_MCU, I have an couple of questions:

fallow birchBOT
fallow birchBOT
#

I'm in progress of trying out dcd_musb.c as indeed same IP is used.
Microchip has slightly different register/field names used in their headers but it all looks same.
dcd_musb.c has some ARM related stuff like NVIC and some CMSIS macros but not too much and that can be solved.

I will stick for now to xc32 compiler for it provides headers and linker scripts for PIC32 chips and there is no need to borrow/fabricate headers and put it in TinyUSB repository.

I will post progress here.

fallow birchBOT
fallow birchBOT
fallow birchBOT
fallow birchBOT
#

Latest changes:
OPT_MCU_PIC32MZ change to let a little space for more ARM-based MCUs from Microchip (SAM)
Some register manipulation moved to board setup just to make transition to common code easier in the future.

It would be possible to use code dcd_musb.c if file with USB0_Type and all bit field definition were available.

Changes needed to make it work require also NVIC related code removed.

PIC32 also works with high speed and dcd_musb.c assumes for now full speed which also co...

fallow birchBOT
#

I've been playing around with this code, and have run into some issues with customizing it for my application. First of all, I'm unable to change the frame rate at all. Anything other than 10 (higher OR lower) causes Windows to no longer recognize it as a connected video device. Also, I'm trying to increase the resolution, and have hit a few walls there. I know that there are going to be limits wrt frame buffer size, due to RAM and time constraints, but I thought I'd post my findings here...

fallow birchBOT
#

Operating System

Windows 11

Board

Original Raspberry Pico Board

Firmware

Micropython Build, current master (see e.g. https://micropython.org/download/rp2-pico/)

Host operating system is independanpt (can be windows based or linux / mac)

What happened ?

Pretty detailed here:
https://github.com/micropython/micropython/issues/7996

but to summarize it, the USB endpoint does not ACK anymore when after it has received one character.
(see also https://github.com/m...

fallow birchBOT
fallow birchBOT
#

@qwertymodo Thank you for your comments!

I'm able to make it work if I also increase CFG_TUD_VIDEO_STREAMING_EP_BUFSIZE in tusb_config.h, which seems to max out at 1023 (if I set it to 1024 or anything higher, Windows no longer sees the video device).

It is a limitation of the USB Full-Speed specification. Isochronous transfer of USB-FS up to 1023 bytes. Please find attached picture for USB 2.0 spec. Raspberry PI Pico supports only USB-FS in my understanding.
![image](https://user-...

fallow birchBOT
#

Good catch on the payload size limit, as well as the bandwidth discrepancy between isochronous and bulk transfers. It's been awhile since I did my last deep dive into the arcane lore that is the USB-IF documentation. Any ideas why I'm unable to change the framerate at all? Even lowering it to e.g. 8fps causes Windows to no longer recognize it as a video device.

fallow birchBOT
faint nexus
#

Hi, im stuck with my tinyusb implementation which does not work as intended on macos

#

it works on linux and windows.
E.g.:

  • sending ctrl+tab to switch tabs in browser

But on macos this is only acting like i press the tab key only
When i use a javascript keyscanner, it shows what i expect/the same as when i do ctrl+tab by hand
But it's not doing the browser-tab switch, only the tab

#

is there any known gotcha on macos that i should know about on macos?

faint nexus
#

ok. i found the problem.
im sending all keys at once [ctrl, f] for example
on windows and linux this works fine

but on mac it arrives as [f, ctrl] and this will only trigger the hotkeycombo when you hold it so the key gets repeated

fallow birchBOT
fallow birchBOT
#

Describe the PR
Mynewt (similar to Soft Device) has its own reference counting for
HFXO oscillator.
So far TinyUSB requested HFXO when VBUS was detected and stopped when
VBUS was removed.
But with Mynewt running HFXO can be stopped when other interested parties
don't require HFXO anymore. This results in very difficult to track
USB transmission errors when internal RC is used for USB clock source.

This change enables Mynewt specific HFXO management in Soft Device fashion.

...

fallow birchBOT
#

Any ideas why I'm unable to change the framerate at all? Even lowering it to e.g. 8fps causes Windows to no longer recognize it as a video device.

I had tested with 10FPS and 5FPS. If you change to 5FPS instead of 8FPS, it works with Windows.

I have reproduced that video_capture example fails enumeration process with #define FRAME_RATE 8 in usb_descriptor.h
And USB Device Tree Viewer shows warning messages below.

*!*WARN...
fallow birchBOT
#

I've done some initial testing on this PR, using @rppicomidi's repo's midihost branch as of 537150f931d218e16b88dc5ac50a625622812c2b. My test setup is the standard Pico-as-picoprobe to Pico arrangement, with the Pico's VBUSs connected together and a USB OTG adapter to provide a USB-A socket.

The Pico MIDI host is running the examples/host/midi/src/midi_app.c with LOG=1 but with test_tx() commented out to just test MIDI receive.

USB MIDI devices tested were:

  • Arturia Keyst...
fallow birchBOT
#

dwMinFrameInterval and dwFrameIntervalStep are calculated by 10000000/_fps. 10000000 is not evenly divisible by 8. Then the warning message occurs. So, in current video_capture implementation, FRAME_RATE must be a divisor of 10000000. Of course, I think it is better to be able to specify any FPS. I will attempt to fix it later.

10000000 / 8 = 1250000, so it's not that, but from that warning it's probably something in the interaction between dwMaxFrameInterval, dwMinFrameInterval, and...

fallow birchBOT
#

Ok, I think I might have found the solution, but as I said, it's been awhile since I've read through the docs, so this is just a "seems to work" fix, without really being sure it's correct. I think the only change that needs to happen is that dwFrameIntervalStep needs to include the _fps factor. Changing this

https://github.com/hathach/tinyusb/blob/3b09b82123a50bef6b18cf90c2734ae7581da4a3/examples/device/video_capture/src/usb_descriptors.h#L106

to

`(10000000/_fps), (10000000/_fps),...

#

@hathach I pushed some bug fixes. Somehow I broke a lot of the builds for processors I do not have access to. Any idea how I can fix it? Do I need to merge with the latest tinyusb?

@todbot I pushed an example project that uses the midihost code called (midi2usbhost)[https://github.com/rppicomidi/midi2usbhost] sends MIDI from the USB host to the Pico's UART1 TX pin and takes UART1 RX pin MIDI data and sends it back to the USB host. There are detailed instructions and pictures.

fallow birchBOT
fallow birchBOT
fallow birchBOT
#
fallow birchBOT
fallow birchBOT
fallow birchBOT
fallow birchBOT
fallow birchBOT
#

Describe the PR
When dcd_edpt_xfer() starts new transfer two separate problems were observed.
For both problems stream of OUT packets was pouring from host.

First problem was that total_len and actual_len were not atomic.
In case where incoming OUT packets are less (63) than MPS (64), actual_len and total_len
are set 63.
Then transfer complete from USBD is called that will schedule next 64 bytes transfer.
At that point incoming packet would start DMA if there is...

#

Describe the PR
In multi-thread mode starting DMA in thread mode was
prone to race condition resulting in infinite loop.
It may happen on single core CPU with strict priority based
tasks scheduler where ready high prio task never yields to
ready low prio task (Mynewt).

Sequence that failed (T1 - low priority task, T2 - high priority task)

  • T1 called start_dma()
  • T1 set _dcd.dma_running (DMA not started yet, context switch happens)
  • T2 took CPU and saw that _dcd.dma_running i...
fallow birchBOT
#

What's the point of the 3rd argument being divided by and then multiplied by _fps, doesn't that cancel out? Or does that achieve some kind of compile-time rounding?

Yes, the value of (10000000/_fps)*_fps will be truncated to an integer.

When _fps is an integer, (10000000/_fps) is evaluated an integer and the decimal part of the result is truncated. So, when _fps is not a divisor of 10000000, (10000000/_fps)*_fps will be an integer which is not equal to 10000000.

fallow birchBOT
#

It turns out that its not enough to handle races.
Another problem arise when two tasks are involved.
First blocks USB interrupt to set total_len and clear actual_len but between those two instructions
second task enters same function for other endpoint and while doing this enables interrupt again
while first task did not cleared actual_len yet and first problem shows up again.

To fix this:

  • CPU critical section should block interrupts during buffer, total_len and `actual_le...
fallow birchBOT
#
[hathach/tinyusb] New branch created: fix\-esp\-ci
fallow birchBOT
fallow birchBOT
fallow birchBOT
fallow birchBOT
fallow birchBOT
#

Describe the PR
Buttons for olimex_hmz144 and olimex_emz64 were incorrectly set to be active high.

Remote wakeup requires that RESUME bit be active for 10ms.
It was covered for OS build for non-OS build it is now handled by
utilizing board_millis() function.

Additional context
Changes needed for USB3V suite tests for remote wakeup functionality.
It was originally tested with Mynewt where remote wakeup was triggered
other way.

fallow birchBOT
#

tinyusb/src must be self-contained (except for external lib and os). The bsp is only for example, and is not available in external build. You could simply add TODO here, we will try another way for have a delay for no os later on. Something like this could work, but it is blocking, we could add an API for remote wakeup complete later on.

https://github.com/hathach/tinyusb/blob/master/src/portable/broadcom/synopsys/dcd_synopsys.c#L595

static void remote_wakeup_delay(void)
{
  //...
fallow birchBOT
fallow birchBOT
#

no problem at all, I am a bit busy as well.

I see you ask me to try your update, Im a lil confused do you mean you have a branch I should pull and try? Or try putting the offset in the init like you mentioned? So sorry I didnt understand, but yes I would love to test any updates

Thanks for your kind words and willingness to test it out, I haven't made any changes just yet. But will try to make some changes soon enough.

#

Ok so adding -DAPP_START=0x08040000 to the cflags with .ld set to offset didnt work and also cflags set and ldflags set with -Wl,-Ttext=0x08040000 and .ld set to flash base, but all fail, the leds turn on correct and it fails to enumerate. Im sure a simple way to add the offset to the board/family files exists but I just havent found it yet:) Ill keep on it!

Sorry for late response, I have been a bit busy lately with other works. I will try to make an update on linker stuff later on base...

fallow birchBOT
#

I reckon that could be the bug that was causing this in my testing on the Espressif ESP32S2:

https://github.com/espressif/arduino-esp32/issues/5727#issuecomment-950043421

Problem for me was, they were not interested in checking and simply closed the issue, and they don't compile from source but instead supply a pre-built library, meaning I was never going to find the problem.

If that's the issue though, thank you! You're worth more than Espressif are, that's for sure!

fallow birchBOT
fallow birchBOT
fallow birchBOT
fallow birchBOT
fallow birchBOT
#

yeah, indeed it is lacking the physical descriptor support. It seems to be an straight forward modification. Since you are working on it, do you have time to make an PR for this ? I could help if you share your example that has the physical descriptor. It probably need to include the physical descriptor in the interface as well.

fallow birchBOT
#

@Jasoroony The way I found this problem was that my FreeRTOS task was getting stuck in the lock function after writing a lot of data out while the host was not reading it from the USB serial port. To know whether it is related check with a debug probe and gdb where is your device getting stuck.

Anyway this bug is a really easy fix, just wanted some confirmation from the tinyusb devs that I'm not missing anything.

fallow birchBOT
#

I, unfortunately, don't have the tools needed to see where it gets stuck. I also can't easily test if the code fix works (though I'm sure it will - at least, it looks perfect to me). I had considered setting up the needed & completely different build environment for ESP32, but it didn't seem worthwhile once I realised "support" there is so fickle. So I stopped testing these devices over 2 months ago, even though I had mostly worked around the problem - but when you know a problem can still...

fallow birchBOT
#

There is no standard SystemCoreClock as provided by CMSIS
There is CPU0 register COUNTER that is kind like Cortex SysTick, I can use it if you insist.
In fact 2000 NOPs at 200MHz is much faster then time you mentioned from datasheet but in my case it was enough to trigger remote wake up every time in contrast to where there is no delay between toggling bit and remote wake up is not activated.

fallow birchBOT
fallow birchBOT
#
[hathach/tinyusb] New branch created: fix\-fifo\-mutex\-when\-full
fallow birchBOT
#

@hathach Thank you for the update. It looks like #1285 is also looking at bulk endpoints for the RP2040.

@todbot When does the M-Audio Keystation panic? Has it successfully enumerated and panics on the first attempt at MIDI transfer, or does it panic during enumeration? The former indicates an issue with the bulk endpoints, the latter with the control endpoint. Also, can you confirm the RP2040 is only attempting 8-byte transfers before it panics? Finally, please have a look at the USB desc...

fallow birchBOT
fallow birchBOT
#

Thank you very much for this excellent PR and sorry for the huge delay in response. I have been lagging behind due to overwhelming work. The PR look great

hcd_port_reset() has a busy loop to assert USB reset signaling during 10-20ms. I think it is not a good way. I guess after hcd_port_reset_end() is implemented, refactor these implementation.

indeed the port reset with blocking delay is not ideal. It is better with RTOS thanks to scheduler but totally not great with non-OS. We will f...

#
[hathach/tinyusb] New branch created: rx\-host\-example\-ci
fallow birchBOT
#

Describe the PR
Other drivers already have notification about data sent.
It allows batter control in application on vendor protocol level.

So far tud_vendor_n_write() always flushed data.
It requires to have whole vendor packed constructed before in one buffer.

With this change data do get flushed when endpoint size
is filled on write, when there is no enough data to
fill endpoint data is not sent and subsequent calls to
write functions can add more bytes.

Vendor code ne...

fallow birchBOT
#

Describe the PR

  • Add support for multiple levels of USB hubs. For your consideration Hathach ๐Ÿ˜„

To get this working reliably I also added a few additonal changes/fixes:

  1. Check if the shared control buffer is busy and assert if it is. This happened alot on hub status checks, it is aleast visible now if we mess up and conflict multiple control transfers.
  2. Prevent another device from enumerating if another device is currently being enumerated.
  3. These tweaks also seems to improv...
fallow birchBOT
fallow birchBOT
#

More thinking out loud - even though it's declared in the descriptor as a Bulk endpoint, is there any reason the host can't operate the IN endpoint as if it's an Interrupt endpoint? That would result in automatic polling and (presumably) correct NAK handling without any special consideration.
(Perhaps this is already standard practice - or there's a glaringly obvious reason why this can't be done. I have no idea.)

fallow birchBOT
#

Describe the PR
Entering suspend mode clears bit USB_RX_EN in USB_RXCx_REG.
Resuming after suspend state did not enable reception on non-0 endpoints.
It resulted in incoming packets being NAK'ed after resume.

Now, on resume event, all OUT endpoints are checked for pending transfers
and when transfer is not completed USB_RX_EN bit is set by start_tx_packet.

Additionally over-run/under-run masks were off by 4 bits so those interrupts
would never be enabled.

fallow birchBOT
#

This is a concurrency issue when running in a RTOS environment. When receiving data on a device CDC, in short the issue is that both cdcd_xfer_cb() and tud_cdc_n_read() can call _prep_out_transaction(), but the cdcd_xfer_cb() uses the buffer that _prep_out_transaction() repurposed for the next transfer after the endpoint was released, potentially overriding old data in that buffer with new one before it was consumed and added to the fifo.

The [_prep_out_transaction()](https://g...

fallow birchBOT
fallow birchBOT
#

the issue there would be that i don't actually have any working example yet, because i'm currently still stuck struggling getting HID to work. having issues with the standard contradicting itself yet again, and the old classic of applications not giving a damn about the standard to begin with... the funniest bit is that a piece of code copied essentially verbatim from mbed-os which definitely used to work 100% correctly with that application suddenly seems to be not even seen as a HID device ...

fallow birchBOT
#

Operating System

Linux

Board

Raspberry Pico

Firmware

examples/device/midi_test with modifications

What happened ?

When trying to add multiple MIDI ports, the device will enumerate, but aconnect won't show MIDI ports anymore.

How to reproduce ?

  1. Clone the midi-test example
  2. Change #define CFG_TUD_MIDI 4 in tusb_config.h
  3. In usb_descriptors.c add..
To enum:
  ITF_NUM_MIDI_0 = 0,
  ITF_NUM_MIDI_STREAMING_0,
  ITF_NUM_MIDI_1,
  ITF_NUM_MIDI_STREAMING...
fallow birchBOT
#

Operating System

Others

Board

Pi Pico RC2040

Firmware

Checkout v 0.12.0
Build example cdc_msc_hid:
cd ~/path/tinyusb/examples/host/cdc_msc_hid
cmake -DBOARD=raspberry_pi_pico -DCMAKE-BUILD-TYPE=DEBUG -DPICO_DEFAULT_UART=0 -DPICO_DEFAULT_UART_TX_PIN=0 -DPICO_DEFAULT_UART_RX_PIN=1 -DFAMILY=rp2040 -DPICO_SDK_PATH=~/pico-sdk .
make -j

What happened ?

Attaching a USB keyboard to the Pico's USB socket causes an assert fail on the log and the example crashes (LED stops fla...

fallow birchBOT
fallow birchBOT
fallow birchBOT
fallow birchBOT
fallow birchBOT
#

I'm sad to say, I don't think the ESP32-S2 usbser library uses the single byte write function that was fixed here. I had zapped the library to rename this function, thinking I could compile my own replacement when the linker complained of the missing import, but it never complained. Then I replaced the entire libarduino_tinyusb.a library with a very small .a library (a copy of another small one in the same directory, but renamed) and I got all the unresolved links I expected... Then I copi...

fallow birchBOT
fallow birchBOT
#

Not yet, but it's a public holiday in my country tomorrow... So I will take a look. The thing is though, this test case has been run on a number of micro-controllers, and the Raspberry Pi in gadget mode (it's a really simple test, for each byte the MC gets, it outputs it 16 times) and they all work for as long as the test runs. The ESP32-S2 quickly fails and no longer responds. My request above was to track down which source files (Espressif or yours) were the likely issue.

fallow birchBOT
fallow birchBOT
#

@t123yh sorry I am lacking behind PRs/issues. I still haven't managed time to look at musb and test the above problem just yet. This PR is already pending for a while and is relatively large. I think we should merge this as it is for now, since it has good running example already. And then do another PR to fix the problem, we could create an github ticket/issue for discussion. That would also minimize effort for other contributors to fix the issue as well. What do you say ?

fallow birchBOT
#

@t123yh sorry I am lacking behind PRs/issues. I still haven't managed time to look at musb and test the above problem just yet. This PR is already pending for a while and is relatively large. I think we should merge this as it is for now, since it has good running example already. And then do another PR to fix the problem, we could create an github ticket/issue for discussion. That would also minimize effort for other contributors to fix the issue as well. What do you say ?

Yes, I agree ...

fallow birchBOT
#

The issue I'm having appears to be because there is traffic in both directions within a short time period. PC sends two 64 byte packets, ESP32-S2 starts sending back packets (a multiple of what it received) as soon as it sees the first PC packet. Within a few seconds of it running, there is some sort of clash with the 2nd incoming PC packet (in dcd_esp32sx.c maybe) and one ESP packet (Queue EP 84) does not get a queue entry for tud_task() to process saying it ever finished (USBD Xfer compl...

fallow birchBOT
#

From some logging, I can see, if in dcd_esp32sx.c - dcd_edpt_xfer() - it manages to set both an in packet request and out packet request, just a little bit before the PC sends data, then you only get an interrupt for the packet from the PC, the transmitted data complete interrupt doesn't fire. A lot of the time, you will get an interrupt as soon as a TUSB_DIR_OUT request is made (this is why it runs for a few seconds) but eventually the two will be set together, and it all stops working.

...

#
[hathach/tinyusb] New branch created: fix\-mynewt\-sunxi
fallow birchBOT
fallow birchBOT
fallow birchBOT
#

Describe the PR
Add a HCD driver for NXP FRDM-KL25Z.
The HCD driver works with only HCD class.

Additional context
In order to operate as a USB host function, J21 must be shorted. The schematic is shown below.
image
This PR was tested on cdc_msc_hid example with a low speed mouse(Logitech M-UB48) and a full speed mouse(Logitech G403).

When running with a HUB, some patc...

fallow birchBOT
#

Describe the PR
If using a USB hub with OHCI host backend will result in a array index out of bounds error.

Additional context
Original line:
https://github.com/hathach/tinyusb/blob/ffb257ac17f162bc5a4c26596d7a1e954db98aa5/src/portable/ohci/ohci.h#L162

It can happen in a few places but one such example is here:
https://github.com/hathach/tinyusb/blob/ffb257ac17f162bc5a4c26596d7a1e954db98aa5/src/portable/ohci/ohci.c#L460

ie. As HUB addresses are >=5, this results in a arra...

fallow birchBOT
fallow birchBOT
fallow birchBOT
fallow birchBOT
#

No, no actual software bugs, so you're golden, just bad hardware here. But it seems I can reliably detect the Tx FIFO being loaded with 64 bytes of data to send to the PC, but the "clashing" Rx FIFO interrupt reports (with some new scanning of all the registers) that the Tx FIFO has emptied in that next interrupt... And any attempt to reset or retry that transmit also doesn't work. I guess Adafruit's first ESP32-S2 attempt here....... doesn't really work...... But in most other cases, lik...

fallow birchBOT
fallow birchBOT
fallow birchBOT
fallow birchBOT
fallow birchBOT
#
  1. I have never tried multiple MIDI, however string index for interface cannot be 1,2,3 since those are already used for manufacturer, product string. If you dont have any use for those, try to change it to all 0

    1. Please provide your example code which is compilable for reproducing

    2. Also provide usb log with LOG=2 and/or 3

I have tried with string index 0.

Here are the files attached:
https://gist.github.com/DatanoiseTV/2499fee93d23234048e8d7b6cea88a38

fallow birchBOT
fallow birchBOT
#

Operating System

Linux

Board

ESP32-S2-Saola-1R

Firmware

ESP-IDF v5.0-dev-1437-gb092fa0730

What happened ?

I am trying few days cdc_msc_freertos to get working. Unfortunately I'm not able to build example project.
I followed up this pull request: https://github.com/hathach/tinyusb/pull/319

So I am able to build every example (yes, hello worl was first where i started) but cdc_msc_freertos I am not...

idf.py build not working properly... so I tried `idf.py -DFAM...

fallow birchBOT
#

This PR solves two issues that happens with the CCRX toolchain.

The first issue was found in the TU_ARGS_NUM macro. Without this modification it is not possible to build the tinyUSB successfully.

The second issue belong to local pointer variable definition of the type reg_pipetre_t, which is mapped over the PIPExTRE register of the RX USB hardware. To ensure access in the correct size the keyword __evenaccess needs to be used.
Note: Without this modifier, it seems that receiv...

fallow birchBOT
#
hdo

Operating System

Windows 10

Board

Raspberry Pi Pico RP2040

Firmware

Pico C SDK firmware examples and TinyUSB audio examples

What happened ?

Trying 2 examples from TinyUSB examples and both failed with different errors:

  • tinyusb\examples\device\audio_4_channel_mic (not recording anything, should at least record dummy packages)
  • tinyusb\examples\device\audio_test (not recognized by Windows 10 -> ERROR_GEN_FAILURE (because the device is in low power state)

H...

fallow birchBOT
#

Ha Thach,

Thanks for this library!

I have been writing some functions to make make interpreting HID report descriptions easier.

I have tried to avoid 'unwrapping' the descriptor which can end up using lots of RAM.
Instead, I've provided functions to help step through it.

Please see:

https://github.com/fruit-bat/tinyusb/compare/master...fruit-bat:hid_micro_parser

I would like to get to the point where the application code can use the parser to interpret joystick/gamepad repo...

fallow birchBOT
fallow birchBOT
fallow birchBOT
fallow birchBOT
#

Operating System

MacOS

Board

ESP32-S3 Devkitm

Firmware

Based on example/hid_composite_freertos and modified to have more interfaces.
Just some modifies to usb_descriptors.c and

#define CFG_TUD_HID 3
#define CFG_TUD_HID_EP_BUFSIZE 64
uint8_t const desc_hid_report1[] =
    {
        TUD_HID_REPORT_DESC_KEYBOARD(HID_REPORT_ID(REPORT_ID_KEYBOARD))};
uint8_t const desc_hid_report2[] =
    {
        TUD_HID_REPORT_DESC_MOUSE(HID_REPORT_ID(REPORT_ID_MO...
fallow birchBOT
#

Is your feature request related to a problem? Please describe.
There is supported MSC host classes for many MCUs but I couldn't find any host part for STM32 ARMs.
Is there any possibility of creating HCD drivers for STM32 for USB host applications?

Describe the solution you'd like
I need the HCD port implementation for STM32F7 (STM32F756) device to use as MSC host application. I've already tried my best to implement that port, but I've ended with infinite waiting loop for contro...

fallow birchBOT
fallow birchBOT
fallow birchBOT
#

The S2 and the S3 datasheets describe the endpoints as follows:

Device Mode Features
โ€ข Endpoint number 0 always present (bi-directional, consisting of EP0 IN and EP0 OUT)
โ€ข Six additional endpoints (endpoint numbers 1 to 6), configurable as IN or OUT
โ€ข Maximum of five IN endpoints concurrently active at any time (including EP0 IN)
โ€ข All OUT endpoints share a single RX FIFO
โ€ข Each IN endpoint has a dedicated TX FIFO

fallow birchBOT
fallow birchBOT
fallow birchBOT
#
[hathach/tinyusb] New branch created: msc\-request\-sense
fallow birchBOT
#

Describe the PR

  • add callback for msc request sense
TU_ATTR_WEAK int32_t tud_msc_request_sense_cb(uint8_t lun, void* buffer, uint16_t bufsize);
  • change most default sense error to medium not present (0x02, 0x3A, 0x00), which is better suite for most user scenario.
  • response to SCSI_CMD_PREVENT_ALLOW_MEDIUM_REMOVAL as unsupported request in all msc examples. This is required for macos to send TEST_UNIT_READY regularly for "SDCard reader" application. Response OK t...
fallow birchBOT
fallow birchBOT
fallow birchBOT
fallow birchBOT
#

Operating System

Others

Board

Not hardware specific

Firmware

No custom firmware present

What happened ?

This line in src/class/hid/hid.h is incorrect:
#define HID_REPORT_ID_N(x) HID_REPORT_ITEM(x, RI_GLOBAL_REPORT_ID, RI_TYPE_GLOBAL, n),

It should read:
#define HID_REPORT_ID_N(x, n) HID_REPORT_ITEM(x, RI_GLOBAL_REPORT_ID, RI_TYPE_GLOBAL, n),

How to reproduce ?

Source inspection

Debug Log

No response

Screenshots

No response

fallow birchBOT
#
[hathach/tinyusb] New branch created: fix\-esp\-build
fallow birchBOT
fallow birchBOT
#

Operating System

Windows 11

Board

B-L475E-IOT01A

Firmware

example/device/hid_composite_freertos

Modify the way FreeRTOS creates tasks, the hardware interface is adapted, and no data is sent during this example.

What happened ?

It will assert failure whether in debug or run mode.

I'm sure it's not a hardware issue, it's an official ST development board and works fine using the official USB library, but even if the tinyusb assertion fails, it also still works fine, ...

fallow birchBOT
#

For your consideration.

Introduces a micro HID report description parser and provides an example of its use by mapping HID joystick reports.
Combined with Ryzee119's mulit-hub modifications it works on an RP2040. Sorry, but it's not tested on any other architectures. On the RP2040, it works nicely with a hub hosting several joysticks.

I've tried to keep the existing tinyusb API the same but made some additions in hid_ri.h and hid_ri...

fallow birchBOT
fallow birchBOT
fallow birchBOT
#

Thanks a lot for your input. I've looked it up but it's hard to understand it for me, because there is no comments and it looks (style) like my code - no comments but with attempt of something like self-descriptioning code by usefull naming patterns.
Anyway, I've created CubeMX project with HAL layer for my F756 MCU and I've implemented TinyUSB and your HCD driver there. After succesfull port with no error build I've tried to run it, but unfortuanelly, it didn't work well.
After attaching...

fallow birchBOT
fallow birchBOT
#

@DatanoiseTV I do not think the issue is with TinyUSB. I modified the example descriptors.c using the following code snip. Now amidi -l shows all 4 virtual cables. Please note the change to the CONFIG_TOTAL_LEN macro. I hope this helps.

$ amidi -l
Dir Device    Name
IO  hw:1,0,0  TinyUSB Device MIDI 1
IO  hw:1,0,1  TinyUSB Device MIDI 2
IO  hw:1,0,2  TinyUSB Device MIDI 3
IO  hw:1,0,3  TinyUSB Device MIDI 4

Code Snip:

#define CONFIG_TOTAL_LEN(num_cables_)  (TUD_CONFIG_D...
fallow birchBOT
fallow birchBOT
fallow birchBOT
fallow birchBOT
#

Operating System

Others

Board

Custom i.MX1064RT, running FreeRTOS and custom application

Firmware

src/portable/ehci/ehci.c

hcd_int_handler() clears the interrupt status register in a way that can result in lost status and system hang.

I looked through the repo, and can see the error in commits going back at least nine years, through present day.

What happened ?

hcd_int_handler() clears the interrupt status register using an |=, rather than a simple =. The status ...

fallow birchBOT
fallow birchBOT
#
[hathach/tinyusb] New branch created: release\-0\.13\.0
fallow birchBOT
#
[hathach/tinyusb] New tag created: 0\.13\.0
fallow birchBOT
#
[hathach/tinyusb] New branch created: enhance\-multipl\-ports
fallow birchBOT
#

Describe the PR
Updates the host HID code to open the OUT endpoint (if it exists). Also adds handling for interrupt OUT to the RP2040 host code. (at least, that seemed to be enough)

Additional context
I've been trying to connect a Wii U GameCube adapter, which requires some data to be sent to it before it starts sending reports. This PR doesn't add any code for actually doing that, but having the endpoint open helps.

(I've only tested this as far as sending the one byte I need...

fallow birchBOT
#

Operating System

Windows 11

Board

Any

Firmware

Compile a simple cpp file including tusb.h

// main.cpp
#include 

int main(void)
{
  return 0;
}

What happened ?

Cpp compiler complains about TU_VERIFY_STATIC with the following errors:

  • this declaration has no storage class or type specifier
  • too many initializer values
  • variable "_Static_assert" has already been defined

How to reproduce ?

Create an empty IAR project with includi...

fallow birchBOT
fallow birchBOT
fallow birchBOT
#

This PR adds support for RNDIS with the CCRX toolchain. It also adds endian independent support (means it is working in big and in little endian configuration).

Note: This PR needs the modification in the PR #1311 to work without any problems.

Modification
dnsserver.c: Use of the pack macros from the cc.h port file (required for every port of the lwIP)
rndis_report.h: New macros that are be calculated by the preprocessor and are used within compile-time constants only (so tha...

fallow birchBOT
fallow birchBOT
#

Describe the PR
The standard inquiry response additional length field needs to be set to the length in bytes of the remaining standard inquiry data (i.e. N - 4), otherwise the kernel driver issues a warning about short inquiry response.

Additional context
On Linux I see the following warning, it seems the driver assumes the response is the minimum 36 bytes:

[53564.998251] usb-storage 4-2:1.2: USB Mass Storage device detected
[53564.998424] scsi host0: usb-storage 4-2:1.2
...
fallow birchBOT
fallow birchBOT
fallow birchBOT
#

I was wrong, I did some more testing and even though the specs say it'sN - 4, I can confirm it should be N - 5. I used sg_inq util to send a standard inquiry, and with N - 4 I get the following response (Note the length):

> sudo sg_inq --only /dev/sda
standard INQUIRY:
  PQual=0  PDT=0  RMB=1  LU_CONG=0  hot_pluggable=0  version=0x02  [SCSI-2]
  [AERC=0]  [TrmTsk=0]  NormACA=0  HiSUP=0  Resp_data_format=2
  SCCS=0  ACC=0  TPGS=0  3PC=0  Protect=0  [BQue=0]
  EncServ=0  Mult...
fallow birchBOT
fallow birchBOT
fallow birchBOT
fallow birchBOT
#

โ€ฆ', rather than an '|='. Use of the latter caused an extra, unwanted read of the status register before the write-to-clear operation, which, in some cases, allowed new status bits to assert (relative to the initial read of the status register two statements earlier), and then be cleared blindly and unconditionally during the write-back. This had the potential (and, in my case, observed) effect of dropping the handling of an enabled interrupt. Ultimately, the system would lock up in a busy ...

fallow birchBOT
#

Calling this macro with an argument TU_CHECK_MCU(OPT_MCU_RX72N) :

with _TU_NARG(_0, ##__VA_ARGS__,_RSEQ_N()) sub-macro
-> compiles with an error with the CCRX toolchain

with _TU_NARG(_0, __VA_ARGS__,_RSEQ_N()) sub-macro
-> compiles successful with the CCRX toolchain

Calling this macro without an argument TU_CHECK_MCU()

with _TU_NARG(_0, ##__VA_ARGS__,_RSEQ_N()) sub-macro
-> compiles with an error with the CCRX toolchain

with `_TU_NARG(_0, VA_ARGS,_RS...

fallow birchBOT
#

โ€ฆous structs defined within the usbh_dev0_t and usbh_device_t structs as they are defined. The problem seems to relate to the placement of the 'volatile' keyword at the struct level. I fixed the problem by removing the 'volatile' from the struct level, and instead placing it on each of the field declarations within the structs.

Describe the PR
IAR compile-time errors on src/host/usbh.c are removed by reassigning 'volatile' keyword from the struct level in two anonymous structs withi...

fallow birchBOT
#
[hathach/tinyusb] New branch created: mcu\-specific
fallow birchBOT
#

MCUboot is a very capable bootloader that is being adopted across the industry and has many advanced features, but a special emphasis on security. While some of the ports have USB DFU support (I think just Zephyr atm,) there isn't a complete USB solution in the bootloader.

What inspired this idea was me looking into UF2 support for Zephyr, but being able to use the secure boot features of MCUboot (see mcu-tools/mcuboot#1309.) I'd imagine it could look similar to...

#

I don't see any points of adding bootloader support to a usb stack feature unless the mcuboot has some specific needs for the stack. Top of my head it would be a special minimal for size optimization, you can open an ticket later with more specific requirement from the mcuboot team.

fallow birchBOT
fallow birchBOT
fallow birchBOT
#

Operating System

Others

Board

Custom NXP i.MX1064 RT board w/ FreeRTOS

Firmware

The tusb_option.h file causes an error during a host build because the #define of TUD_OPT_HIGH_SPEED uses TUD_OPT_RHPORT as a shift value. TUD_OPT_RHPORT is set to -1 for host-mode builds.

A likely fix would be to condition the #define of TUD_OPT_HIGH_SPEED on CFG_TUD_ENABLED (defined on the previous line) evaluating to "true". I do not want to propose that fix specifically, as I do not have ...

fallow birchBOT
fallow birchBOT
#
[hathach/tinyusb] New branch created: pio\-host
fallow birchBOT
fallow birchBOT
#

For DMA support, we would need the dcd_edpt_xfer_fifo() to get working. I once pushed some untested code implementing that feature. Curiously, right now all of that code is commented out but present in the main branch. All parts are marked with // TODO support dcd_edpt_xfer_fifo API. I was not able to test the code because i don't have any hardware.
Directly copying data into the USB hardware buffer by use of DMA is not possible also not in the synopsis case. The trick is to copy the dat...

fallow birchBOT
fallow birchBOT
#
hdo

Thanks for reply.

Actually i managed to get it working with the UAC Headset example. I stripped it down to mic only:

MIC ONLY


// Unit numbers are arbitrary selected
#define UAC2_ENTITY_CLOCK               0x04
// Speaker path
#define UAC2_ENTITY_SPK_INPUT_TERMINAL  0x01
#define UAC2_ENTITY_SPK_FEATURE_UNIT    0x02
#define UAC2_ENTITY_SPK_OUTPUT_TERMINAL 0x03
// Microphone path
#define UAC2_ENTITY_MIC_INPUT_TERMINAL  0x11
#define UAC2_ENTITY_MIC_FEATURE_UNIT    0x12
#d...
#
hdo

Even mic stereo works :-)


// #include "tusb.h"

// Unit numbers are arbitrary selected
#define UAC2_ENTITY_CLOCK               0x04
// Speaker path
#define UAC2_ENTITY_SPK_INPUT_TERMINAL  0x01
#define UAC2_ENTITY_SPK_FEATURE_UNIT    0x02
#define UAC2_ENTITY_SPK_OUTPUT_TERMINAL 0x03
// Microphone path
#define UAC2_ENTITY_MIC_INPUT_TERMINAL  0x11
#define UAC2_ENTITY_MIC_FEATURE_UNIT    0x12
#define UAC2_ENTITY_MIC_OUTPUT_TERMINAL 0x13


#define ITF_NUM_AUDIO_STREAMING_SP...
fallow birchBOT
fallow birchBOT
fallow birchBOT
fallow birchBOT
fallow birchBOT
#
[hathach/tinyusb] New branch created: fix\-esp\-idf
fallow birchBOT
#
[hathach/tinyusb] New branch created: perigoso\-patch\-1
fallow birchBOT
#

thank you for PR, I make some changes to the API

  • skip get index, and straight to get manufacturer/product/serial string (you may need to update the cpythong accordingly)
  • add more API for all descriptor: device, configuration, string
  • add configuration_set() not required to be called by application, added just it is there
  • There is other unrelated name change for max endpoint macros. Just do it since I am already there.

I also add an stub example bare_api to demonstrate the api...

fallow birchBOT
fallow birchBOT
#

Describe the PR
This PR adds support for STM32WB55 MCU.
p-nucleo-wb55 board is also added.

This MCU has stm32_fsdev FS device USB block same as some others ST devices (F1, Gx)

Additional context
ST provided headers have incorrect value of USB_PMAADDR that is used in stm32_fsdev code.
Issue is filed on their github.
So for now this is fixed on TinyUSB side.

fallow birchBOT
#

Thank for your issue, to be honest, I am not familiar with xinput and xbox controller ( I dont have one to test it out), however, we can thing easier for user with predefined hid descriptor and structure report. I could made an example for ps4 controller since it is what I have. Hopefully that would pave the way for adding similar pr for xbox one. Will post ps4 here whenever it is available

fallow birchBOT
fallow birchBOT
fallow birchBOT
fallow birchBOT
fallow birchBOT
fallow birchBOT
fallow birchBOT
#
[hathach/tinyusb] New branch created: add\-sof\-isr
fallow birchBOT
#

Describe the PR
mostly implement and close #1231 , add new

  • dcd_sof_enable(uint8_t rhport, bool en)
  • void tud_sof_isr_set(tud_sof_isr_t sof_isr)
  • implement dcd_sof_enable() for rp2040
  • add dcd_sof_enable() stubs for other ports for now

Other unrelated clean up

  • remove broadcom/synopsys (replaced by synopsys/dwc2)
  • add CFG_TUD_INTERFACE_MAX for max number of interfaces, default to 8.
#

2 Questions to go with this as my memory is failing me.
1: Queuing it with in_isr set to true means that the event fires in the ISR context? SoF entry timing tends to be quite critical so would like to confirm.
2: This "breaks" the current Driver convention of specifying the callbacks/event handlers in the Driver Structs. Should the initializers be updated to support that instead of just this "new api" specific to SoF as it is now?

Great work as always happy to see this getting imple...

fallow birchBOT
#

2 Questions to go with this as my memory is failing me. 1: Queuing it with in_isr set to true means that the event fires in the ISR context? SoF entry timing tends to be quite critical so would like to confirm. 2: This "breaks" the current Driver convention of specifying the callbacks/event handlers in the Driver Structs. Should the initializers be updated to support that instead of just this "new api" specific to SoF as it is now?

Great work as always happy to see this getting imple...

fallow birchBOT
#

I would love to hear @PanRe 's opinion as well. This is also something that can be dealt with later. More of a "trying to keep everything unified" and not have a ton of specific extensions to things.

SoF is not needed for every application, but those who need it tend to always need it. Being how expensive it is however I definitely think being able to disable it should be kept as part of the API.
I think for the user land driver specifying that sof callback should populate the ISR callb...

fallow birchBOT
fallow birchBOT
#

Operating System

Linux

Board

esp32s3

Firmware

https://github.com/kaspernyhus/tinyusb/tree/audio_test_freertos/examples/device/audio_test_freertos

What happened ?

I made a freertos version of the audio_test example.
Audio samples are coming through, but every other usb packet is missing data (see wireshark screenshots)
48kHz/16bit, 1 channel.

How to reproduce ?

clone my fork
go to tinyusb/examples/device/audio_test_freertos
make BOARD=espressif_s3_devkitc all...

fallow birchBOT
#
[hathach/tinyusb] New branch created: fix\-1359
fallow birchBOT
fallow birchBOT
#

[I'm developing on a Raspberry Pi and I'm not sure how to get rx-elf-gcc setup... so some of the builds may still be a bit hit and miss - sorry - and hope this is ok!]

I tried to compile with rx-elf-gcc. Some errors were reported shown below. Of course, it is OK by adding two options -Wno-error=unused-parameter and -Wno-error=format= for the errors to CFLAGS in examples/host/cdc_msc_hid/Makefile.

C:/tinyusb/examples/host/cdc_msc_hid/src/hid_app.c:52:46: error: un...
fallow birchBOT
#

I think it is a great feature! The correct place to impment this in the audio driver is the audiod_set_interface() function. There, the interfaces are open and closed. I lookup the implementation details this week (i hope). Unfortunately, i miss the hardware to test the speaker functionality, @geekbozu i guess you could test it?

fallow birchBOT
#

Hello,
No such thing as a stupid questions here!
I have filtered for EP1 messages 3.65.1 (bus 3, device 65, EP1). I believe EP 0x81 means an IN endpoint at EP1 for data, yes.
What the pictures show is that for every second packet there is no data payload, only header bytes (176 bytes when full / 80 bytes with no data). There should be 96 bytes in the payload every 1ms, I believe. I cross checked with the same example on the pi pico, and there was indeed data in every packet.
Does that mak...

fallow birchBOT
#

Ah now i am on track, thanks for the clarification. Indeed that seems weired, there should be a packet scheduled every ms. What puzzels me right now is that the saw-tooth-test signal looks without gaps. The audio_test example sends increasing values from 0 - 2^16-1. So in the first packet, there sould be numbers ranging from 0 - 47, in the second from 48 - 95, etc. If every second packet is missing, there sould be jumps of 48 in that signal. There "might" be jumps in your plot but i am not ...

fallow birchBOT
fallow birchBOT
#

Here I have decoded three concecutive packets containing data 2ms appart:

raw data packet 1 [f0fff1fff2fff3fff4fff5fff6fff7fff8fff9fffafffbfffcfffdfffeffffff00000100020003000400050006000700080009000a000b000c000d000e000f0010001100120013001400150016001700180019001a001b001c001d001e001f00]
raw data packet 2 [20002100220023002400250026002700280029002a002b002c002d002e002f0030003100320033003400350036003700380039003a003b003c003d003e003f0040004100420043004400450046004700480049004a004b004c004d...
fallow birchBOT
#
MicNode
Manufacturer: PaniRCorp
Serial Number: 123456
Speed: 12Mb/s (full)
Bus:   3
Address:   6
USB Version:  2.00
Device Class: ef(misc )
Device Subclass: 02
Device Protocol: 01
Maximum Default Endpoint Size: 64
Number of Configurations: 1
Vendor Id: cafe
Product Id: 4010
Revision Number:  1.00

Config Number: 1
	Number of Interfaces: 2
	Attributes: 80
	MaxPower Needed: 100mA

	Interface Number: 0
		Name: snd-usb-audio
		Alternate Number: 0
		Class: 01(audio) 
...
fallow birchBOT
#
[hathach/tinyusb] New branch created: more\-host\-bare\-api
#

Interesting. However, we may not trust the time scale of audicity (maybe, i don't know audicity this well). It could be, that audicity just uses the information, that 48 kHz is the sample frequency. Can you test this another way? Can you schedule a recording lasting exactly 2 * 1.365 seconds? Not the corresponding amount of bytes but really in time. If the received signal has two saw-tooths also the timing is ok. If the bandwidth was halfed, only one saw-tooth should be received (half the byt...

fallow birchBOT
fallow birchBOT
fallow birchBOT
fallow birchBOT
fallow birchBOT
fallow birchBOT
fallow birchBOT
fallow birchBOT
fallow birchBOT
#

I'm not sure how I would do that.
However I think you are correct in not trusting audacity!
I tried to do a recording on my macbook using reaper and the results are very different indeed! Are we seeing the consequences of the missing packets here maybe?

To have a reference I made a recording of the original audio_test example on an rp2040.

<img width="1672" alt="Skรฆrmbillede 2022-03-10 kl 12 23 09" src="https://user-images.githubusercontent.com/46648238/157653881-75b3af42-235f-4225-b...

#

Ok, then the MCU is too slow in loading the 48 samples or 96 bytes into the fifo and from the fifo into the usb buffer. Can you increase the clock frequency to speed the MCU up? Another possibility would be to reduce the workload in the example... but this would be a bit of work. One idea would be to trick the fifo into thinking something is contained in the fifo (by use of tu_fifo_advance_read_pointer()). Another one would be, to use a DMA to load data into the fifo.

fallow birchBOT
fallow birchBOT
fallow birchBOT
#

Describe the PR
Several enhancement to host stack

  • refactor endpoint claim/release shared (host & device)
  • fix several enumeration issue with hub
  • add mutex support for host control transfer, return false if there is on-going transfer already.
  • merge usbh_control.c to usbh.c
  • rename host descriptor API e.g tuh_descriptor_device_get() --> tuh_descriptor_get_device()
fallow birchBOT
#

I've added a speed print to the example.

I tested a second mouse of the same type and it shows the same issue. So, it is that particular mouse that has this issue.

I tested a bunch of other devices that do work:

Joystick from Thrustmaster:

1 vid 044f pid b10a
Full speed
Product: T.16000M
Manufacturer: Thrustmaster

EZUSB bootloader for Intellikeys:

1 vid 095e pid 0100
Full speed

Kensington trackball:

1 vid 047d pid 2048
Low speed
Product: Kensin...
fallow birchBOT
fallow birchBOT
#
[hathach/tinyusb] New branch created: merge\-host\-example
fallow birchBOT
#
[hathach/tinyusb] New branch created: rework\-host\-control\-xfer
fallow birchBOT
fallow birchBOT
fallow birchBOT
fallow birchBOT
#

Operating System

Others

Board

EPS32-S2 ro S3

Firmware

Tinyusb with SD card as MSC device

What happened ?

1.Function:Mass Storage Class (MSC) .
2.EPS32-S2 ro S3 with SD card whole as MSC device.
3.Error1:on PC(personal computer) internal efi shell environment,Pull and insert Tinyusb's usb device(base on EPS32-S2 ro S3 with SD card),will lose Tinyusb's usb MSC device.
3.1:you can reboot your PC and press keyboard [F12],you can see boot device:[UEFI:Built-in EFI Shell],...

fallow birchBOT
fallow birchBOT
#

The following definition would do it for your case without doing changes umpteen times across the whole usb driver file

If you looked closer you would see that it's not quite as simple as that, the register definitions are not compatible, that's why I created a local register definition.

I didn't complicate anything, the fundamental driver did not change, only the registers.

fallow birchBOT
#

I am currently composing something, however, it would be nice to already have a working example of what should be done in the SOF isr. @geekbozu could you post a snippet here? @hathach i already implemented SOF for synopsis. I am aware that my implementation will not meet all your considerations but once i pushed it your are free to go to improve it! :)

fallow birchBOT
#

I would like to update the feedback value within the audio class driver. For that, however, i need the cpu_cycle_count value at the time of the SOF interrupt. To be more precise, the cycly count of any master clock locked to the sample frequency. Most often, f_cpu is locked to f_s but it might be a different clock source as well. Is there a chance to introduce some callback function tud_get_master_clock_cycle_count() which need to be set from the user and i can call within the SOF interru...

fallow birchBOT
#

I would like to update the feedback value within the audio class driver. For that, however, i need the cpu_cycle_count value at the time of the SOF interrupt. To be more precise, the cycly count of any master clock locked to the sample frequency. Most often, f_cpu is locked to f_s but it might be a different clock source as well. Is there a chance to introduce some callback function tud_get_master_clock_cycle_count() which need to be set from the user and i can call within the SOF inter...

fallow birchBOT
#

I have picked up this pull request in my own fork, and successfully used it to read and write to a USB flash drive using a RP2040 in host mode. There is a full working example here: examples/host/msc_with_fatfs. However, it has an outstanding problem. If this could be resolved then we would have the ability to use standard USB flash drives from RP2040 boards.

The problem is that the USB hardware randomly fa...

sterile axle
#

@cursive bone If I haven't told you directly, thank you for doing this USB Host mode for the RP2040 PIO system - it will be wonderful.

fallow birchBOT
#

Describe the PR

  • change API of tuh_control_xfer and its callback
  • rename tuh_control_complete_cb_t to tuh_control_xfer_cb_t
  • add user argument to control callback
  • rework usbh enumeration process using user arg from control transfer as state
  • add synchronous version of all get descriptor API
  • update bare example to use sync API for string descriptor
  • change order of index, language_id in tuh_descriptor_get_string() to
    match similar API of libusb
  • add index to tuh_descript...
fallow birchBOT
fallow birchBOT
#

I would like to update the feedback value within the audio class driver. For that, however, i need the cpu_cycle_count value at the time of the SOF interrupt. To be more precise, the cycly count of any master clock locked to the sample frequency. Most often, f_cpu is locked to f_s but it might be a different clock source as well. Is there a chance to introduce some callback function tud_get_master_clock_cycle_count() which need to be set from the user and i can call within the SOF inter...

fallow birchBOT
#

I would like to update the feedback value within the audio class driver. For that, however, i need the cpu_cycle_count value at the time of the SOF interrupt. To be more precise, the cycly count of any master clock locked to the sample frequency. Most often, f_cpu is locked to f_s but it might be a different clock source as well. Is there a chance to introduce some callback function tud_get_master_clock_cycle_count() which need to be set from the user and i can call within the SOF int...

fallow birchBOT
#

Die you try the example without rtos?On 3/14/22, 21:32 kaspernyhus @.***> wrote:

If it is indeed an rtos error, I'm not sure where to start looking. If we don't get the interrupt because the system is blocking, how can we test for that? Any ideas?
โ€”Reply to this email directly, view it on GitHub, or unsubscribe.Triage notifications on the go with GitHub Mobile for iOS or Android. You are receiving this because you commented.Message ID: @.***>

fallow birchBOT
#

I've get myself a bit closer to function part of the code. I've continued in my own hcd driver for that STM and now it's cappable of getting full identification of the flash drive, its size and that's all for now. I'm bit confused, because all transfer seems correct but in attempt of reading from flash drive I'm receiving just missmash from the bus. There isnt any real data transfer nor control packets etc after identification.
I'm also done some refactorization of first 1/3 of the code so i...

fallow birchBOT
fallow birchBOT
fallow birchBOT
fallow birchBOT
#
[hathach/tinyusb] New branch created: audio\_make\_dma\_ready
#

Describe the PR
Implement SOF ISR for audio driver and synopsis dwc2 driver. Still work in progress.

Additional context
This version is only a preview of what i am intending to do. The SOF interrupt is enabled and disabled by the audio driver in case an active alternative interface setting is set. The SOF ISR in the audio driver tries to calculate the 16.16 feedback value in order to avoid confronting the user with those details. The "only" thing the user needs to do is to provid...

fallow birchBOT
#

I have been digging around in the dcd_esp32sx.c file trying to identify possible bottlenecks.
In the interrupt handler _dcd_int_handler I taken some timestamps to see if we got stuck somewhere - one at the top and one at the end:
__________________ name ______timestamp (us) ___ deltaT

I (8154) : 706: _dcd top          935207        1
I (8164) : 707: _dcd end          935213        6
I (8174) : 708: _dcd top          935222        9
I (8184) : 709: _dcd end          935226        ...
fallow birchBOT
#

Can you somehow measure the CPU load? If it is very high the mcu might Hang in some buggy loop, if the load is low there might be a missing interrupt flag... The error might be in the dcd ISO related transfer functions...On 3/15/22, 21:41 kaspernyhus @.***> wrote:

I have been digging around in the dcd_esp32sx.c file trying to identify possible bottlenecks. In the interrupt handler _dcd_int_handler I taken some timestamps to see if we got stuck somewhere - one at the t...

#

Can you profile how long the write functions for loading the data into the buffers last?On 3/15/22, 21:41 kaspernyhus @.***> wrote:

I have been digging around in the dcd_esp32sx.c file trying to identify possible bottlenecks. In the interrupt handler _dcd_int_handler I taken some timestamps to see if we got stuck somewhere - one at the top and one at the end: __________________ name ______timestamp (us) ___ deltaT
I (8154) : 706: _dcd top 935207 1
I...

fallow birchBOT
fallow birchBOT
#

What i pushed is work in progress and i wanted to share what i have so far. I added:

  • SOF ISR routine in audio driver, in addition to the user SOF. The audio driver enables/disables SOF interrupt when needed. If no alternate setting is active, SOF is disabled. There is still some logic missing such that the disabling of the SOF interrupt is coordinated between the drivers (e.g. video and other iso related drivers) and the user. Currently, the driver would switch the ISR interrupt off alth...
fallow birchBOT
#

Can you somehow measure the CPU load? If it is very high the mcu might Hang in some buggy loop, if the load is low there might be a missing interrupt flag... The error might be in the dcd ISO related transfer functions...>
My tracing shows that the cpu running the tud_task is mostly idle - the other cpu has only systicks. So cpu load is assumed to be quite low, right?

#

Mh i see... @HiFiPhile have you any experience with rtos and uac?

I didn't use RTOS on SAME70 & LPC4322. I doubt there is some issue in esp-idf since personally I'm not impressed by it's robustness. (5-6 issues submitted in 2 weeks and more minor glitches)

I have contacted Espressif as well, and they just replyed they will provide me with a test example later this week !

fallow birchBOT
#

I'll give this some attention soon! Looks way more robust then my current solution hah!

A gut reaction I have is setting the FB value on the USB stack is VERY costly todo in the ISR, and probably should be deferred to the task loop. I can re-evaluate this eventually as well. I remember having "issues" with it eating up to much CPU time on my application.
Rational: I don't have much left for USB, my variant of the SOF interrupt is eating about 10% of my CPU time after overheads are accoun...

fallow birchBOT
#

@geekbozu Thanks for the first remarks! Just for conformation: do you mean the calculation of the feedback value within the SOF ISR is too costly or the setting of the feedback value by use of the tud_audio_n_fb_set() function? I thought calculating and setting the feedback value in the SOF ISR was the very point of this pull request? This was the key question in #1231 in order to reduce the jitter. There are a number of possibilities now:

  • The MCU is fast enough to conduct everything w...
fallow birchBOT
fallow birchBOT
#
[hathach/tinyusb] New branch created: host\-edpt\-xfer
fallow birchBOT
fallow birchBOT
fallow birchBOT
#

@geekbozu No worries, i think these a fruitful discussions here :). I had some thougth about the possible bottle necks. As for the math calcuations i found that in case of power of two shifts 1 cycle for computation will be needed and in case a FPU is available, 3 cycles will be needed. If non is present, then what i currently pushed can be used i.e. roughly 20 cycles. So i guess the computation should not be a concern. I will put the required logic into the next push.
Regarding `tud_audio_n...

fallow birchBOT
#

@geekbozu No worries, i think these a fruitful discussions here :). I had some thougth about the possible bottle necks. As for the math calcuations i found that in case of power of two shifts 1 cycle for computation will be needed and in case a FPU is available, 3 cycles will be needed. If non is present, then what i currently pushed can be used i.e. roughly 20 cycles. So i guess the computation should not be a concern. I will put the required logic into the next push. Regarding `tud_audio_...

fallow birchBOT
fallow birchBOT
#

Describe the PR

  • More major changes for host stack transfer, include support for generic endpoint transfer.
  • tuh_control_xfer(), tuh_edpt_xfer() and callback follow similar API with 1 unique tuh_xfer_t following the libusb convention https://libusb.sourceforge.io/api-1.0/group__libusb__syncio.html
    • required CFG_TUH_API_EDPT_XFER=1 since it requires 8 more bytes per endpoint
    • does not requires to alloc or keep the xfer struct memory lasting for transfer to complete (usbh will...
fallow birchBOT
#

Ok, the pushed verions would be ready for testing. All that needs to be done is to enable SOF ISR feedback calculation and the desired calculation mode by setting (your parameter are suitable for a power of two shift, but you may try all three)
#define CFG_TUD_AUDIO_ENABLE_FEEDBACK_DETERMINATION_WITHIN_SOF_ISR 1
#define CFG_TUD_AUDIO_ENABLE_FEEDBACK_DETERMINATION_MODE CFG_TUD_AUDIO_ENABLE_FEEDBACK_DETERMINATION_MODE_POWER_OF_TWO_SHIFT

The parameters required for calculation of the...

fallow birchBOT
#

I'm sorry, I didn't find at https://www.espressif.com/sites/default/files/documentation/esp32-s3_technical_reference_manual_en.pdf relevant introduction of the usb register, but I did an experiment, in the hid device 1ms to send out a data, is can produce the corresponding interrupt signal ,I wonder if it has something to do with endpoint initialization or configuration, but I don't know how to verify this

fallow birchBOT
fallow birchBOT
fallow birchBOT
fallow birchBOT
fallow birchBOT
#

Describe the PR
Add initial driver/port for the CH32V307 series from WCH. This is a RISCV (rv32imac) with integrated High Speed USB PHY.
The targets the WCH development board CH32V307V-R1-1v0, which is a lowish cost ~$10 board from LCSC.

Additional context
The xpack-riscv-gcc compiler is used. The official wch packaged gcc appears to have some custom changes to support the interrupt controller in this part that handles hw stack save/restore. Fortunately that's reasonably eas...

fallow birchBOT
fallow birchBOT
#

Look info the device controler driver file tinyusb/src/portable/espressif/esp32sx/dcd_esp32sx.c. The registers are set within dcd_edpt_open().Check if the registers are correctly set for the ISO endpoint!On 3/21/22, 06:38 LiTongXue98 @.***> wrote:

I'm sorry, I didn't find at https://www.espressif.com/sites/default/files/documentation/esp32-s3_technical_reference_manual_en.pdf relevant introduction of the usb register, but I did an experiment, in the hid device 1ms to ...

fallow birchBOT
fallow birchBOT
fallow birchBOT
#

I've not tested with a Full Speed only host/hub.
Which I think will be the same as trying to configure the device as Full Speed only. Which should work, but does not appear to right now.

  • Only supports bulk endpoints.
  • Only supports device mode.
  • No host mode.

I've also not done extensive testing yet, I've only had the dev board for <1week.

fallow birchBOT
#

I think this project could really benefit from a Hardware In The Loop setup (think of it like a workflow to test the code, but with actual hardware)

There's a lot that goes into this, just leaving this here for documentation and future discussion

fallow birchBOT
#

Current code did not prevent race condition if transfer was
started from non-usb interrupt.
testing and modifying dma_running flag was not nested-interrupt-proof.

Describe the PR
This uses standard C library atomic functions to access dma_running flag.
For Cortex-M4 (NRF52) and Cortex-M33 (NRF53) compiler generates code
that uses LDREX/STREX instructions along with memory barriers.

Additional context
Issue was detected during BLE throughput tests that also stressed USB.
I...

fallow birchBOT
#

I'm very eager to help bugfix this, but I'm also not at all sure what to look for.
Here is a probing of the USB0.gintsts register when it enters the _dcd_int_handler

I (3246) : USB0.gintsts:         0x00040020      47
I (3256) : USB0.gintsts:         0x00008038      1248
I (3256) : USB0.gintsts:         0x00000030      15
I (3266) : USB0.gintsts:         0x00080020      2
I (3266) : USB0.gintsts:         0x00040020      18
I (3276) : USB0.gintsts:         0x00040020      34
I (...
fallow birchBOT
fallow birchBOT
#

The CH32V307 USB FS/OTG interface looks to be identical to, or else very
very similar to, the STM32 USB FS/OTG interface on e.g. the STM32F103, so
it would probably be fairly simple to add support. (I know, easy for me to
say.) There are also STM32 parts that have basically the same dual USB (FS
& HS) as the CH32V307.

On Tue, Mar 22, 2022 at 6:09 PM Greg Davill @.***>
wrote:

I should also mention. The CH32V307 has 2 separate USB
interfaces/peripherals, One is FS/OTG and then one i...

fallow birchBOT
fallow birchBOT
fallow birchBOT
#

@cr1901 thanks for asking now that I looked again there is just one line to be removed and then it will be clear.
Problem with current code is that place that checks whether dma is currently running is separated from place that sets this flag.
It takes some measures to ensure that change and check is consistent but when we have two interrupts involved checking in interrupt that dma is not running is not enough since after check another interrupt can check again if dma is running and can see...

fallow birchBOT
fallow birchBOT
#

Well, according to the manual on page 602, the interrupt for the IN EP is always set (bit 18). Unfortunately, the manual does not tell the meaning of the other bits. Can you also check for the masking register USB_GINTSTS_REG and SB_GLBLINTRMSK. In this registers you can check if the interrupt was masked out. Furthermore, please check USB_DAINT_REG to check the number of the EP int...

fallow birchBOT
#

I've been digging into this a tad more, there is actually 4 different USB peripherals in the CH32FV32x_V3x Reference manual.

  • USBD Looks compatible with the STMF103, WCH have a CortexM3 device that is pin compatible with the F103
  • USBHD Register equivalent to the USBHS but FS only.
  • USBHS This port, Host/Device with integrated HS PHY.
  • OTG_FS/USB_OTG Doesn't match the STM32's USB peripheral.

Config summary

| | V203 | V303 | V305* | V307 | V208 |
...

fallow birchBOT
fallow birchBOT
fallow birchBOT
#

No worries at all! I hope you are well soon! Take care :)!On 3/24/22, 19:23 Ha Thach @.***> wrote:

@PanRe sorry for keeping you waiting again, I have spent last 2 day with sleep-eat cycle in high fever due to covid-19. I feel much better now, but will take a couple more day to rest, I was in the middle of reviewing this PR before that, but It is kind of erased now. I will start to look at this again next week or so. Thanks.
โ€”Reply to this email directly, view it on...

fallow birchBOT
fallow birchBOT
#

On Thu, Mar 24, 2022, 06:55 Rafael Silva @.***> wrote:

to clarify, does USBHS in any way look compatible with the STMF103 usb
registers?

I don't think so. Judging by a somewhat cursory comparison of the CH32V307
docs to various ST docs:

The CH32V307 USBHS looks like the USBHS on the bigger/newer STM32 parts.
AFAIK it doesn't look like any STM32 USBFS controller.

The CH32V307 USBFS looks like the STM32F103 (and many other STM32) USBFS.

Some STM32 have both, in the same way the CH32...

fallow birchBOT
#

The CH32V307 USBFS looks like the STM32F103 (and many other STM32) USBFS.

I agree with this, I suspect since WCH has already used this IP on it's STM32 replacements it makes sense.

The CH32V307 USBHS looks like the USBHS on the bigger/newer STM32 parts.
AFAIK it doesn't look like any STM32 USBFS controller.

Some STM32 have both, in the same way the CH32V307 has both. I think
STM32F205 or STM32F207 have both, but I haven't double-checked.

Looking through the STM32F207 Ref...

fallow birchBOT
fallow birchBOT
#

Operating System

Linux

Board

Any

Firmware

Haven't compiled yet.

What happened ?

When cleaning up generated pycache directories from esp-idf repository tree I've noticed that the tinyusb submodule becomes "dirty" (modified) from git perspective. Turns out that tinyusb includes a Python bytecode file at hw/mcu/sony/cxd56/tools/pycache/xmodem.cpython-36.pyc. Python bytecode files are usually considered to be local, temporary ...

fallow birchBOT
#
[hathach/tinyusb] New branch created: remove\-pycache
fallow birchBOT
#

thank @perigoso for helping with the PR so far. @gregdavill I took a quick look at ch32v307

  • USBD (FS) is exactly like the stm32 fsdev
  • USBHS D/H on the other hand is completely new to me, and definitely not dwc2. Therefore we are good with current file structure.

I still haven't looked at actual code changes, will do that later on.

junior basin
#

Can someone help me get started building a proprietary device emulator? (Not HID or any other documented standard). I'm having trouble finding examples on doing just this.
I'm a noob trying to build a USB device emulator and can't find any documentation on this :(

fallow birchBOT
#

@PanRe reviewed the changes, everything look ok. To be honest, though I don't quite understand the feedback computation, I don't think that we could implement one-fit-all computation for feedback. also, required an pointer-to-cycle may not work on other platform.

In my opinion, it is just better to invoke user isr callback and let application to do the computation itself. Since this is most often got tweaked to specific application. We can provide some compute helper, with nominal value et...

fallow birchBOT
#

I thought about this long time ago, but couldn't manage time to do so. We can write a python script to run on a pi4 to deploy and test much like production tester

  • to flash example and test if new firwmare run OK like Serial,MSC is enumerated correctly.
  • #1059 USBCV auto test would be great, unfortunately, the suite only runs on windows which is hard to automate and script, but also cost more in electricity bill.

Currently tinyusb supports too many platforms, we probably only pick up...

fallow birchBOT
#

This is something I would love to play with, there's a personal project that could benefit from a similar system, unfortuantely I don't have that much time either, but this is something we can gradually build.

It's unfortunate USBCV is windows, didn't realise it, it would be one of the more useful things we could use this for. maybe making a similar test tool might be feasible, provided someone finds time to do it.

#

thank @kasjer very much, I actually tried something similar previously with exactly atomic_bool, and expect compiler to generate LDEX/STREX. But somehow I failed mysteriously :face_with_head_bandage: and didn't have the time to investigate. Since I really need to fix the race and switch works. I am glad that finally you could address this, could you share how to do the ble throughput test so that I could help

PS: hmm, last time I try to use atomic to also replace mutex as well, do you thin...

fallow birchBOT
#

@hathach I think that it's possible that edpt_dma_start() could be reduced to

static void edpt_dma_start(volatile uint32_t* reg_startep)
{
    if (atomic_flag_test_and_set(&_dcd.dma_running))
    {
      //use usbd task to defer later
      usbd_defer_func((osal_task_func_t) edpt_dma_start, (void*) (uintptr_t) reg_startep, true);
    }else
    {
      start_dma(reg_startep);
    }
}

...deferring DMA start in every case that DMA seems to be still running.
There was stil...

fallow birchBOT
#

@kasjer I remembered doing exactly just that and also apply for the thread-mode case as well , but it did not work out.

https://github.com/hathach/tinyusb/blob/edd8eb3279c2440e9d4590312f2104e58beafe12/src/portable/nordic/nrf5x/dcd_nrf5x.c#L156-L165

However, there are a few race fixed since then. It could have been caused by other bugs and/or I made my own mistakes. I would love to have the tests, however, if it is too troublesome, don't worry I figure out my way by pulling out one of p...

fallow birchBOT
fallow birchBOT
#

It is an interesting chip indeed, I have a couple on the cart waiting for an order

There is a dev board you can find on aliexpress, it's not very affordable but it's an option https://aliexpress.com/item/1005003617496688.html

yeah, I saw that board as well, but I will wait for a cheaper option. I won't have time to do anything with it anything soon.

What would need to be done on the usb stack side to get usb 3.0? enumeration is still done on the usb 2.0 right?

hard to tel...

fallow birchBOT
fallow birchBOT
fallow birchBOT
#

Oh i wasn't trying to bundle the ch569 on here at all, just a suggestion for a possible way of getting a dev board, since you were interested

thanks for your suggestion.

I'm planing to poke around with the ch565/ch569 at some point too. Have some of the ICs.

Let me know when you get your CH32V307 devkit. Loading firmware currently requires the use of a "patched" openOCD, which can be downloaded as part of the MounRiver Toolchain (http://www.mounriver.com/download). I hope tha...

fallow birchBOT
fallow birchBOT
#

@hathach Thanks for the review! Well, the feedback value computation follows the official USB specification. IMHO, the specification is not written very clear and may cause a lot of frustration for the user to implement (especially for new users). What i came up with aims to support those poor souls by providing a framework which should be applicable in many cases.

Boild down, the feedback value is n_samples per frame i.e. fb = n_s / frame. The feedback value must be accurate up to 1 sa...

#

when the 2ms delay starts USB0.in_ep_reg[1].diepint is oscillating between 0x80/0x81 - what does that mean??
I guess the interrupt flag is not cleared. The error may be in the function handle_epin_ints() as there these flags are cleared. Or this function does not get called every second time?!

Is this essentially a job for Espressif to fix, since it seems to be quite deep down in the handling of interrupts?
I guess yes, the device controler dcd_esp32sx.c was also written by Espre...

fallow birchBOT
#

Something happened and the docs builds are now failling.

I don't think it's related to anything on our side, probably just an upstream update that broke something, let's wait to see if it fixes itself.

/home/docs/checkouts/readthedocs.org/user_builds/tinyusb/envs/1381/bin/python -m sphinx -T -E -b html -d _build/doctrees -D language=en . _build/html
Traceback (most recent call last):
  File "/home/docs/.pyenv/versions/3.8.6/lib/python3.8/runpy.py", line 194, in _run_module_as_ma...
fallow birchBOT
#

@PanRe I still think check I2S buffer count is the most reliable way for feedback calculation, due to MCLK measurement error with a timer and error accumulation over time.
Beside with a high frequency MCLK it's hard to get it's exact value. I believe the calculation method in UAC spec fit better the case of ASIC, where the MCLK/USB clock relationship can be calculated by hardware directly.

One thing which is not very clear right now are those "magic" rules to tweak the feedback value. I...

#

thank you @PanRe for a very in-depth explanation, For clarification, I just added the bracket for the formula (please correct if I get it wrong).

fb = (n_cycles / n_frames) * (f_s / f_m)

I have no doubt that will enormously help lots of other audio newbie including me. My point is that, we don't have to compute it internally within the audio driver, making it difficult for user that want to adjust/tweak the feedback value since any correction will require PR and could affect...

fallow birchBOT
#

@HiFiPhile Thanks a lot! I will have a look into it! I am completely aware, that you have the most experience with audio speakers of us and i value your opinion a lot. It is just that @vmilea and @geekbozu voted for the SOF option and since they made this approach work already i thought it would be a good idea to incorporate that into the audio driver. This would save us some PR in the future too. As for the precision (please tell me if i am wrong on this) i thought the only sensitive part is...

fallow birchBOT
fallow birchBOT
#

I have tested following device examples on RX65N target board with WIndows 10.

example result note
cdc_msc โœ”๏ธ
cdc_dual_ports โœ”๏ธ
cdc_msc_freertos โŒ Enumeration failed
hid_composite โŒ Enumeration OK, but the behavior is not correct.
msc_dual_lun โœ”๏ธ
net_lwip_webserver โŒ Enumeration probably OK, but the behavior is not correct.
uac2_headset โŒ Enum...
fallow birchBOT
#

It is just that @vmilea and @geekbozu voted for the SOF option and since they made this approach work already i thought it would be a good idea to incorporate that into the audio driver.

Yes as you said it's a good idea to have something that should be work in most cases.

My idea here would be to use a DMA which copies the counter register value to some variable from where audiod_sof() can read it.

It's rather a hardware question, let's take an example of 72MHz STM32F1 & 12.28...

fallow birchBOT
fallow birchBOT
#

Actually true, after some research i also did not find the possiblity to trigger a DMA from a SOF interrupt signal... sorry i was too enthusiastic ^^. Regarding the timer, yes i had your second version the counter mode in my mind. A constant delay from the SOF interrupt to reading the counter value within the ISR would not be a problem iff it keeps constant from interrupt to interrupt. The SOF interrupt therefore should have a high priority such that the reading is "precise" as you said.

W...

#

Yes the brackets are corret. As for your idea, it appears a bit "split up" to me, leaving one half of the compuation in the driver and the other half in the user isr. Would it not be ok to declare audiod_sof() and tud_audio_set_fb_params() as weak and give the user the possiblity to copy and paste the code from the driver into his own files and change it to his needs? This way he can change everything if he wants.

@PanRe uh hmm, why would it result in "split up", the application could co...

fallow birchBOT
fallow birchBOT
fallow birchBOT
fallow birchBOT
#

sorry, I haven't actually got the time to look at this. The bug look easy to reproduce though I am not also too familiar with MP. I will try it out when having time

No problem. I think the direction at the moment is to merge https://github.com/micropython/micropython/pull/8040 once the reviews are done.

Yet I'm still curious if there is anything that we have overlooked... so if you find some time to look into it would be greatly appreciated. Especially since it doesn't seem to be rel...

fallow birchBOT
#

Operating System

Windows 10

Board

new MCU port from pic32mz

Firmware

cdc_msc demo

What happened ?

the second CBW , bulk out EP got 62 bytes

How to reproduce ?

dcd_pic32mz.c: line 565
after xfer_complete(xfer, XFER_RESULT_SUCCESS, true);
add xfer->transferred = 0;

Debug Log as txt file

No response

Screenshots

No response

fallow birchBOT
fallow birchBOT
fallow birchBOT
#

Operating System

Windows 10

Board

Raspberry pi pico

Firmware

examples/device/hid_multiple_interface

What happened ?

  • Put windows10 to sleep, and confirm RPi pico is suspended (Slow LED blink pattern)
  • Wake up windows10 by pressing button on RPi pico
  • windows10 wake up, but RPi pico is still suspended (Slow LED blink, No HID report is sent)

This is because DCD_EVENT_RESUME does not occurs after remote wakeup, and _usbd_dev.suspended is not cleared.

As the name...

fallow birchBOT
#

Is your feature request related to a problem? Please describe.
Hi, I'm trying to use an rp2040 to create an hardware project which uses CTS and DSR lines.
I see the current CDC code doesn't support them.

Describe the solution you'd like
I'd like to know how to implement CTS and DSR control in tinyusb.
I'm also able to read DTR, but RTS is not update. Host is Windows 11.
Thanks

fallow birchBOT
fallow birchBOT
#

thanks for detail report on the issue. We shouldn't submit DCD_EVENT_RESUME right after remote_wakeup() since device need to keep the RESUME signal for at least 1 ms, and host needs at least several ms more. Ideally DCD_EVENT_RESUME should only submitted when bus is fully already in operating state. I will poke around the rp2040 datasheet to see what is best way to detect this.

fallow birchBOT
#

Hi, I don't have those information. I'm using comtestserial to interact with the CDC port. I had success moving DSR with this function:


void set_dsr(uint8_t itf, bool value) {

    cdcd_interface_t* p_cdc = &_cdcd_itf[itf];

    uint8_t packet[10];

    packet[0] = 0xA1;                        //   bmRequestType
    packet[1] = CDC_NOTIF_SERIAL_STATE;                //   bNotification
    packet[2] = 0x00;                        //   wValue
    packet[3] = 0x00;
    packet[4...
fallow birchBOT
fallow birchBOT
fallow birchBOT
fallow birchBOT
#

@kkitayam

I had a look into the code and did a quick test with the CCRX toolchain in big and little endian mode. After doing the quick hacks on the code (add the correct #pragma directive and add __evenaccess keyword, see the description below), the CDC test was successful.

Unfortunately the code as it is, is not endian independent. For the CCRX we could solve this with a #pragma directive. But to be more independent of the toolchain (and invest into the future), we could use so...

fallow birchBOT
fallow birchBOT
fallow birchBOT
fallow birchBOT
fallow birchBOT
fallow birchBOT
fallow birchBOT
#

Is your feature request related to a problem? Please describe.

Feature request.

I was looking at Adafruit's TinyUSB Arduino library and one thing I noticed is despite the Arduino part is in C++, handling control packets within a e.g. protocol class for HID is a pain because passing C++ method as a C function pointer is not straightforward. The current construction more or less assumes the class needs to have a (effectively) singleton object and the object reference can be passed either...

fallow birchBOT
fallow birchBOT
#

One example would be https://github.com/adafruit/Adafruit_TinyUSB_Arduino/blob/master/src/arduino/hid/Adafruit_USBD_HID.cpp

But not looking at it closely, I think it's probably just because of how it's coded to use the USB hardware for HID only, instead of allowing adding/removing protocol handlers, and that the callback names are actually hardcoded in tinyusb and not set by the user.

For the goal I described above I think it would need more code to achieve, and that code will likely not re...

fallow birchBOT
#

Describe the PR
This adds a meson build file that exports a dependecy for use in projects using the meson build buildsystem
This is just for convenience of said projects and won't be used internally, in the future it might be worth considering switching to meson to build the examples too, as it's much easier to maintain than make

As for know projects that will benefit from this, that I know of, icebreaker, that is being...

#

We might want to switch to a more modern and friendly buildsystem, as the make we have is becoming unwieldy

This is is something I'm willing to work on myself, not wanting to add more burden

until then this serves as a reminder and discussion

fallow birchBOT
fallow birchBOT
fallow birchBOT
#

I'm comparing against OPT_MCU_NONE because it's not done lol

not sure making this a subproject is the best approach, it's not really meant to be compiled as a library, and it needs an external configuration file, which is doable, but i usually just subdir() this file where it declares a dependency and use that in the main project

but this is which I made a draft

fallow birchBOT
#

I would like to finalize this PR so i have taken the liberty to introduce the desired changes of @hathach. After some thinking i came to the conclusion, that the easiest most convenient way would be to have 3 options:

  • no SOF and feedback calculation done by user (default as done all the time)
  • SOF and feedback value calculation within the audio driver (my approach - nice for rapid prototyping and evaluation if it could work)
  • SOF and feedback value calcuation by the user (as desired by...
fallow birchBOT
#

Operating System

Linux

Board

Raspberry Pi Pico

Firmware

Custom CDC class extension to support notify (similar to HID class reports) and mount/umount callbacks. The hardware is a Telit LE910C1 LTE module that interfaces via "CDC" interfaces over USB, although they aren't quite CDC, they are 99% (class is vendor and no data interface, just two extra endpoints instead.
telit_driver.zip
)

What happened ?

...

fallow birchBOT
fallow birchBOT
#

Started to look at this again, unfortunately, the USB cores are very similar, but just different enough to make it quite hard to make compatible, so I just forked the original samx7x driver and made the necessary changes.

I simply translated as best I could the register from the samx7x to the 3u, but there are a couple features that apparently have slightly different implementations, so I don't believe this is going to work out of the box.

also unfortunately, I don't have any boards wit...

fallow birchBOT
fallow birchBOT
fallow birchBOT
#

Operating System

MacOS

Board

ESP32-S3-DevKitC-1

Firmware

Custom, with only few changes.

What happened ?

Every single hid example seems to declare no Interrupt OUT pipe so devices like keyboards retrieve host control data from the control pipe. I made it to have an Interrupt OUT pipe and the host PC do leave the control pipe sending instructions (NumLock, CapsLock etc.)

However when I try to retrieve these using tud_hid_set_report_cb(), the data is not as expect...

fallow birchBOT
fallow birchBOT
#

Operating System

Windows 10

Board

NUCLEO-STM32H723ZG

Firmware

Any firmware

What happened ?

The STM32H7 family have 2 sub families:

  • H74x and H75x have 2 USB, and USB2 have an internal FS PHY. No problem with this sub family.
  • H72x, H73x, H7Ax, H7Bx have only 1 USB named USB1 with an internal FS PHY (this USB1 is equivalent to the USB2 of the other sub family). And in the CMSIS files of this sub family the values USB_OTG_FS_PERIPH_BASE and OTG_FS_IRQn are not decla...
fallow birchBOT
#

Add support for BULK endpoint transfers. This is achieved by allocating hw_endpoint for bulk transfers, not just interrupt. These endpoints can perform transfers in a non-blocking manner, whereas using EPx would block all other (non interrupt) transfers.
This change also allows interrupt transfers in both IN and OUT directions now.

fallow birchBOT
fallow birchBOT
fallow birchBOT
#

Thanks for the report, though the bug should be exactly reproduced, can you

  1. Provide link to modified example that can be compiled to flash to reproduce the issue
  2. Which steps that you do on host pc to cause the issue
  3. โ€œThe data is not as expectedโ€ is not analyzable, can you provide the expected vs the actual data (contents of those variables in the callback)
  4. Attach debug log as txt file for analysis
fallow birchBOT
#
  1. https://github.com/Huckies/tinyusb-bugreport I do the minimal modification on example hid_boot_interface to reproduce this. All I did was adding an Interrupt OUT endpoint to the keyboard interface and left everything else 'as is'.
  2. Press 'NumLock', 'CapsLock' or 'ScrollLock'
  3. I expected to have instance=0 report_id=0 report_type=HID_REPORT_TYPE_OUTPUT(aka 2) in callback ```void tud_hid_set_report_cb(uint8_t instance, uint8_t report_id, hid_report_type_t report_type...
fallow birchBOT
#

If you read the code, the report id as invalid is intended behavior

https://github.com/hathach/tinyusb/blob/9c8c5c1c53214b8954bb28c33a496b5b423d5ecc/src/class/hid/hid_device.c#L408-L412

The reason is report parser is not implemented for hid device and it cannot tell if report id is used and part of the output report or not. And present report as raw as it is. You have to do your own parsing (read report id, and byte++).

duplicated to #1095, I will add a simple hid parser later on ne...

fallow birchBOT
#

I get it.
But a parser is for host, isn't it? The device claims its report using a report descriptor and a parser allows the host to read the report correctly. Since we are implementing a device, we claim our own report descriptor so adding 'report id version' of TUD_HID_DESCRIPTOR and TUD_HID_INOUT_DESCRIPTOR macros should work. After all, you only need to tell the stack if it's using reportids

fallow birchBOT
fallow birchBOT
fallow birchBOT
#

Support STM32H7 with only 1 USB port: H72x / H73x / H7Ax / H7Bx

Describe the PR
The STM32H7 family have 2 sub families:

  • H74x and H75x have 2 USB, and USB2 have an internal FS PHY. No problem with this sub family.
  • H72x, H73x, H7Ax, H7Bx have only 1 USB named USB1 with an internal FS PHY (this USB1 is equivalent to the USB2 of the other sub family). And in the CMSIS files of this sub family the values USB_OTG_FS_PERIPH_BASE and OTG_FS_IRQn are not declared, so the file synopsys/...
fallow birchBOT
fallow birchBOT
#
[hathach/tinyusb] New branch created: osal\-queue\-timeout
fallow birchBOT
#

Describe the PR

  • add mili-second timeout to osal_queue_receive (mynewt does not support this).
  • tud_task() and tuh_task() timeout in 1 ms on event queue to allow RTOS thread to be shared with other background work e.g cdc flush().
  • In case where 1 tick > 1ms (e.g 1 tick = 10ms), at least 1 tick will be used.
  • add TU_ATTR_ALWAYS_INLINE to most of osal function.
  • add tinyusb docs and disable blank issue

@dhalbert

fallow birchBOT
#

Please set a configurable timeout for each queue (something like CFG_TUSB_TMO_xxx). Not a hard value. Currently there is no timeout so I managed it in the OSAL layer: sometimes 0 and other times infinite. The value 1 is not practical because it leads to useless context switches when there is nothing to do, and a waste of time if we wanted 0. Moreover, if tud_task() is called by an interrupt, it is forbidden to have a timeout!
You say that a 1KHz SOF interrupt is expensive, but you are going ...

fallow birchBOT
fallow birchBOT
fallow birchBOT
fallow birchBOT
fallow birchBOT
fallow birchBOT
fallow birchBOT
fallow birchBOT
#

Operating System

Windows 10

Board

NUCLEO-H743ZI2

Firmware

irrelevant custom firmware

What happened ?

USB HID Device does not appear at all on the host computer

How to reproduce ?

Issue :
USB HID Device does not appear at all on the host computer

Workaround :
I added some additional bit set before and after your init

In my usb device task :

void usb_device_task(void* param)
{
  (void) param;

  SET_BIT(USB_OTG_FS->GUSBCFG, USB_OTG_GUSBCFG_FDMOD...
fallow birchBOT
#

Operating System

Others

Board

Feather M4 Express

Firmware

Custom firmware using the audio functions to make a 2-channel speaker with TYPE_I_PCM decoding

What happened ?

Code will not build with CFG_TUD_AUDIO_ENABLE_DECODING && CFG_TUD_AUDIO_ENABLE_EP_OUT if the corresponding EP_IN and ENCODING defines are not set.

I believe line 539 of audio_device.c should actually be format_type_I_rx - changing it to that allows code to compile and works as expected.

How to ...

fallow birchBOT
#

_osal.h isn't considered as public header
This is strange.
An application should include tusb.h wich is public.
And tusb.h includes osal.h. So an application can use what is in osal.h.

Anyway, we are not talking about application code, but about USB stack code. In my opinion the USB stack code should use its own definitions.

fallow birchBOT
#

I'm not up to date with the latest version of tinyUSB but have had some experience with this board on an older version. If you take a look in the BSP init function for this platform you'll notice that some of your additions are already present.

For FS: https://github.com/hathach/tinyusb/blob/6ec5174d8b24d1f01a443c74a0a3dbee00523efc/hw/bsp/stm32h7/family.c#L151-L167
Or if HS https://github.com/hathach/tinyusb/blob/6ec5174d8b24d1f01a443c74a0a3dbee00523efc/hw/bsp/stm32h7/family.c#L195-L208
...

fallow birchBOT
fallow birchBOT
fallow birchBOT
fallow birchBOT
#

@cjhilder I encountered a similar issue with transactions not completing when I implemented bulk endpoints for MIDI Host using a shared EPx endpoint for both bulk endpoints and the control endpoint. EPx sharing works but is not great (see discussion #1261). My workaround for the endpoint not completing bulk transfers looks like the code below. Did you try this fix already? I would dearly love to get rid of EPx sharing in my code.

        uint32_t flags = SIE_CTRL_BASE |
               ...
fallow birchBOT
fallow birchBOT
fallow birchBOT
#

Is your feature request related to a problem? Please describe.
I just started using a Mac as a development platform for rp2040. I find .DS_Store files show up as untracked files. It would be too easy to commit them by accident.

Describe the solution you'd like
This Apple developer forum discussion suggests to add the following to the .gitignore. I can create a pull request for this if you would like.

# macOS-specific files
...
fallow birchBOT
fallow birchBOT
#

@Skyler84 @bohdan-tymkiv Did you try this patch with a hub? I am finding it works fine when only one device is plugged in but if two devices are plugged in and packets are being sent to both devices, packet corruption occurs. Also, the IN transfers complete on both devices but the second device plugged in has an all-zero packet buffer even though the connected device should be sending data.

fallow birchBOT
#

I have not tested this with a hub yet! Definitely something I can take a look at with my logic analyzer. I've also found that it doesn't work with transfers >64B since that's all that's allocated, and the double buffering is not complete in the HCD i dont think?
It's a fairly close solution but I think needs some refinement.

fallow birchBOT
fallow birchBOT
fallow birchBOT
#

Describe the PR
For PIC32 OUT packets that were sent from host and not handled
fast enough could lead to memory corruption.
When transfer was complete OUT endpoint was left open for
host to send more data (which is fine and allow for faster transfer).
however if data packet arrived before new transfer was scheduled
code was reading endpoint and writing past buffer that was filled
with previous transfer data.
To prevent such scenario RX interrupt is disabled when transfer is
finis...

fallow birchBOT
#

Operating System

Others

Board

STM32L472 custom

Firmware

Custom Firmware FreeRTOS, audio+cdc composite device

What happened ?

On closing an endpoint the txfifo may not be flushed properly, which leads to no data transfered on a reopen.

How to reproduce ?

  • attach device to a host having 2 in endpoints configured
  • close the 2 endpoints one after another
  • txfifo of the even endpoint number is not flushed due to a wrong register value on dwc2->grstctl

Debug...

fallow birchBOT
#

Solves issue discussed in:
https://github.com/hathach/tinyusb/discussions/1439

This is not a complete solution as we only can re-open an endpoint with the same size.
But it improves the behaviour allowing to close and re-open an endpoint that is not opened at last

We now let fifos allocated if we can't free them.
We check if there is already an allocated fifo for that endpoint.
Assert when that fifo has the wrong size

This could be further improved by collecting the already allo...

fallow birchBOT
#

@cjhilder I encountered a similar issue with transactions not completing when I implemented bulk endpoints for MIDI Host using a shared EPx endpoint for both bulk endpoints and the control endpoint. EPx sharing works but is not great (see discussion #1261). My workaround for the endpoint not completing bulk transfers looks like the code below. Did you try this fix already? I would dearly love to get rid of EPx sharing in my code.

        uint32_t flags = SIE_CTRL_BASE |
   ...
fallow birchBOT
fallow birchBOT
#

Operating System

Linux

Board

imxrt 1060, imxrt

Firmware

examples/device/cdc_msc_freertos
examples/device/dynamic_configuration
examples/device/hid_composite_freertos
examples/device/usbtmc

None of these examples work on the teensy 4.0, using etither tag 0.13.0, or the latest fa895ed3dc46d5aa5e11b19ff07beb6fcfc62655.

all other device examples work

What happened ?

I compile all examples using the tools/build_family.py. They all compile properly with the late...

fallow birchBOT
#

Oh! Found that on the 1060 EVK, some demos are on USB1 whereas others are on USB2.

So, it appears the 1060 EVK works on all examples, so now just left wondering why it doesn't work on all examples on the tensy 4

teensy 1060evk example
OK OK USB1 audio_4_channel_mic
OK OK USB1 audio_test
OK OK board_test
OK OK USB2 cdc_dual_ports
...
fallow birchBOT
#

Update:
edited hw/bsp/imxrt/boards/mimxrt1060_evk/board.mk to change

BOARD_DEVICE_RHPORT_NUM = 1

to

BOARD_DEVICE_RHPORT_NUM = 0

and recompiled. Now the 1060 works on USB1 instead of USB2 (as expected), and that exact same 1060.hex file loads into the teensy and runs (since they use the same chip, I was expecting it to). So... chasing the difference now...

fallow birchBOT
#

This fixes issue https://github.com/hathach/tinyusb/issues/1457.

The problem is that somehow, someway, the IOMUXC_GPIO_AD_B0_09_GPIO1_IO09 pin gets
configured wrong, which interferes with the way the teensy boots. I don't
know what's messing it up, or any. But I do know that this fix corrects
non-functioning usb examples on the teensy:

examples/device/cdc_msc_freertos
examples/device/dynamic_configuration
examples/device/hid_composite_freertos
examples/device/usbtmc

fallow birchBOT
#

sorry @PanRe for the huge delay, I have been overwhelmed with work with rp2040 pio usb, and just able to pull it off.

SOF and feedback value calculation by the user (as desired by @hathach. The user can apply what he tried with option 2 on his own)

I prefer this option more, since this has been awhile and you are probably busy with other work. Hence, I could do the change myself, will make it as an pr to this branch for your review :)

fallow birchBOT
#

Describe the PR
For FreeRTOS, This PR sets the USB interrupt priority to configLIBRARY_MAX_SYSCALL_INTERRUPT_PRIORITY, which is where it should be in order to not cause problems for freeRTOS. it was initially there, then commented out for some reason. Not sure exactly why it was removed.

This sets the interrupt priority for both USB ports, if they exist.

fallow birchBOT
fallow birchBOT
#

@hathach No worries, glad you are back ;) I already implemented everything, all is now possible, the original solution without SOF, SOF with feedback calculation within the driver (this is a good starting point to start testing if it works with your hardware), and SOF based feedback handling where everything is implemented by the user. You can choose which version you would like by use of defines. So, there is nothing much to implement more, just have a look on what is in now give me feedback...

fallow birchBOT
fallow birchBOT
#

@hathach No worries, glad you are back ;) I already implemented everything, all is now possible, the original solution without SOF, SOF with feedback calculation within the driver (this is a good starting point to start testing if it works with your hardware), and SOF based feedback handling where everything is implemented by the user. You can choose which version you would like by use of defines. So, there is nothing much to implement more, just have a look on what is in now give me feedba...

fallow birchBOT
fallow birchBOT
fallow birchBOT
#

Operating System

Linux

Board

pimoroni_tiny2040

Firmware

Simple host example using printf to show "attach / "detach message on callbacks.

The single additional difference was using tuh_vid_pid_get() to also print the VID:PID on attach (but nothing else on detach).

The tinyUSB library version in use was unmodified "0.13.0" source tag.

What happened ?

In certain situations it is possible to make the TinyUSB library to panic with:

Device attached, ad...
fallow birchBOT
fallow birchBOT
fallow birchBOT
fallow birchBOT
fallow birchBOT
#

My mistake when I checked head. Was looking at the head of a more recent branch, not master HEAD.

With current HEAD (d23c9b7) the panic does not happen anymore. It seems it was fixed.
On the other hand, a race condition seems to be still happening if you try to slowly detach and attach a device several times.
Eventually an ASSERT is raised on each new attach:

Device attached, address = 1
Device removed, address = 1
Device attached, address = 1
Device removed, address = 1
Devi...
fallow birchBOT
#

With a clean project [1] I got a panic on a different place when slowly inserting and removing the same device:

...
Device attached, address = 1
Device removed, address = 1
Device attached, address = 1
Device removed, address = 1
Device removed, address = 1


*** PANIC ***

ep 0 in was already available

But I lost the call stack on this attempt, which seems to be a new problem as we have the umount callback called twice in a row.

Repeating the test, got the same asser...

fallow birchBOT
fallow birchBOT
#

That is correct, my original intention was to save N and D as unit32 in order to save space. 13/3 was chosen because i wanted f_s to be able to hold frequencies of bigger than 500 kHz (just to cover a large space also for application other than audio). And i wanted the scale on n_cycles to be a small as possible because n_cycle must cover the same range as f_m, for which we need a huge number. I think 8/8 would be not a good choice therefor.
During rewriting the code, i realized that N * n_c...

fallow birchBOT
#

Why this (more complicated) partial fix that actually seems to introduce a new issue (see below) instead of simply not assigning endpoint buffers multiple times?

Assuming reset_non_control_endpoints() will be called at a safe time: in _hw_endpoint_alloc() an if (!ep->hw_data_buf) around the assignment from next_buffer_ptr would fix it for all cases, right? That is, the warning will remain but no panics anymore and everything keeps functioning as expected. Note that `hw_endpoint_clo...

fallow birchBOT
#
[hathach/tinyusb] New branch created: sof\-isr\-update
fallow birchBOT
#

@PanRe I made an PR-to-PR #1463 as update proposal. Thanks to your hard work with the calculation. I have come up with something hydrid solution without hard-coded into compiler macro. For actual code changes, please check out the other PR, here is my sum up

  • First of all tud_audio_sof_isr() must be implemented, which will be invoked every polling interval, which is 2^(bInterval-1) in (micro) frames. User can then
    • compute their own feedback and call tud_audio_fb_set() or
    • use b...
fallow birchBOT
#

Hi @hathach,

  • if tud_audio_sof_isr() is invoked only every bInterval, it should be renamed to tud_audio_interval_isr(). Otherwise i would expect it to be called every (micro) frame!
  • Could you rename fb_param_factor_N to f_s and fb_param_factor_D to f_m? (I guess this is what you ment with cleaning up ;))
  • We definitely need a minimum example for users such that they get the approach of how to implement everything
    I left a few comments in the PR but i like your approach!
fallow birchBOT
#

Since the focus has changed from SOF to UAC feedback, I think we could add something to facilite feedback calculation based on FIFO count.

It's rather a hardware question, let's take an example of 72MHz STM32F1 & 12.288MHz MCLK.

Because MCLK frequency is relatively high to system clock, timer capture & compare shouldn't be used to measure MCLK frequency otherwise the obtained result will be horrible (72/6=12MHz ~ 72/5=14MHz).

Only option is drive the timer with MCLK and count tim...

fallow birchBOT
fallow birchBOT
#

Do you mean to add some option like FEEDBACK_COMPUTE_FIFO_COUNT, which does not need the SOF interrupt?

Actually I'm not 100% sure if it should be based on SOF or not. All my tests was based on High-Speed which is easier to regulate the FIFO level, because frame interval is 125us instead of 1ms and less samples are arrived each frame.

It's better to test with FS to see if my method works.

fallow birchBOT
fallow birchBOT
fallow birchBOT
#

@HiFiPhile do you have an example code on how to calculate feedback on fifo count work ? I will try to find a way to fit it as well or give some option to do so.

Full code is in https://github.com/HiFiPhile/i2s_bridge, UAC related code is in audio_callbacks.c

  1. I define a feedback min/max of 0.1%, in UAC spec clock deviation is 0.05% for HS so 0.1% should cover it.
    https://github.com/HiFiPhile/i2s_bridge/blob/1d6a24fdd0f70d150a88d85d63ed4b583b3b6b30/audio_callbacks.c#L101
    Actual ...
fallow birchBOT
#
  • if tud_audio_sof_isr() is invoked only every bInterval, it should be renamed to tud_audio_interval_isr(). Otherwise i would expect it to be called every (micro) frame!
  • Could you rename fb_param_factor_N to f_s and fb_param_factor_D to f_m? (I guess this is what you ment with cleaning up ;))
    I left a few comments in the PR but i like your approach!

Yeah, will rename sof_isr(), and fs fm as you suggested, will also make a union to group all method variable to save...

fallow birchBOT
fallow birchBOT
fallow birchBOT
#

Implementing the change by @hoihu at the SAMD port revealed another (or the same) problem. If text is pasted to the device and echoed, the USB stack locks up. Data will not be sent any more from the device. Incoming data is for a while accepted. That can easy be replicated by loading the actual MicroPython firmware to a device and then with the REPL prompt either typing very fast or pasting some text, like a piece of code. When characters are not echoed (like in REPL RAW mode), everything is ...

fallow birchBOT
fallow birchBOT
fallow birchBOT
#

@HiFiPhile I made a draft idea on how to add the fifo count method, the params_cb with struct for input. Fifo count method seems to reply on a few params: std (nominal) value, variation, and buffer threshold. The buffer threshold is a bit tricky, since it requires application to respect this. The rest can be computed within the stack. Let me know if I miss something before adding the actual code.

fallow birchBOT
#

I like the idea of union.

The buffer threshold is a bit tricky, since it requires application to respect this.
Yes indeed. It can be calculated in the stack because normally it's N*PacketSize, or add a macro for easier threshold calculation in application.

https://github.com/HiFiPhile/i2s_bridge/blob/1d6a24fdd0f70d150a88d85d63ed4b583b3b6b30/audio_callbacks.c#L186
Here 8000 is for HS (125us), FS need 1000.

fallow birchBOT
fallow birchBOT
fallow birchBOT
fallow birchBOT
fallow birchBOT
#
  • Removed some compiler warnings, and cleaned out unnecessary warning suppression from CMake suppress_tinyusb_warnings()
  • Made explicit family_configure_dual_usb_example() for DUAL mode examples as family_configure_target() may not generally be called multiple times for the same target
  • Renamed library pico_pio_usb to tinyusb_picio_pio_usb to be clearer and avoid conflict if someone already has a pico_pio_usb in their project
  • Added family_add_pico_pio_usb() method for add...
fallow birchBOT
#

We can start a discussion again on the code. Particularly, the user should explicitly opt into "dual" USB, and the existing TinyUSB base INTERFACE libraries should not include it.

Right, I agree that user need to explicitly specify the dual USBs. I am not too familiar with the way pico-sdk wrapper for tinyusb lib/target definition, but I did try to add a separated target/lib for pio_usb, and user indeed need to initialize that in addition to normal tinyusb_device/host.

actually, i j...

fallow birchBOT
fallow birchBOT
fallow birchBOT
#

Right, I agree that user need to explicitly specify the dual USBs. I am not too familiar with the way pico-sdk wrapper for tinyusb lib/target definition, but I did try to add a separated target/lib for pio_usb, and user indeed need to initialize that in addition to normal tinyusb_device/host.

Yes, it was actually nice and separate, the weirdness we have with keeping things happy when doing raw TinyUSB examples (which includes pico-sdk within it's build) and SDK (which includes TinyUSB wi...

fallow birchBOT
fallow birchBOT
#

Operating System

Windows 10

Board

pca10095

Firmware

custom firmware running mynewt OS

What happened ?

Problem was detected on IN transfers over vendor interface on NRF5340 (but it's not MCU specific).
It may be that other driver has similar problem.
Here is sequence that fails.

  • Vendor interface IN packet is sent to host.
  • vendord_xfer_cb() is called
  • it calls maybe_transmit()
  • endpoint is not busy (yet) `TU_VERIFY( !usbd_edpt_busy(TUD_OPT_RHPORT, p_itf->e...
fallow birchBOT
fallow birchBOT
#

No. I tried it now, and as expected, it makes no difference. MICROPY_EVENT_POLL_HOOK consists of a call to mp_handle_pending() and __WFI(). Since the scheduler is not enabled, mp_handle_pending() is practically a NOP.

And anyhow, when the device stops sending on UART, the MP VM still runs, and data received by USB are still processed, until eventually the UBS output buffer the TinyUSB stack is full, and no characters are accepted any more.

So it looks like the other problem here, in th...

fallow birchBOT
#

Operating System

Linux

Board

Custom STM32L052k8 board (pretty much just a STM32L052k8 with headers)

Firmware

Based on examples/device/cdc_msc_freertos code, but modified to expose an HID gamepad instead of a mass storage device.

Code is here: https://gitlab.com/gemarcano/stm32_snes_controller/-/tree/b2c5a2273929153d082b73aa137b25dd956410a0

This uses meson to build, and it relies on FreeRTOS and a separate stm32 hal and start files being available as libraries (https:/...

fallow birchBOT
fallow birchBOT
#

The issue seems to be the stack's vendor driver, currently it doesn't guard against race condition as cdc. I haven't updated the vendor driver once introducing the usbd_edpt_claim() for race protection. I actually have an plan to abstract these to stream/buffered endpoints API for driver and haven't got time to do so.

https://github.com/hathach/tinyusb/blob/master/src/class/vendor/vendor_device.c#L109
https://github.com/hathach/tinyusb/blob/master/src/class/cdc/cdc_device.c#L83

_Or...

fallow birchBOT
#

The bug goes away if all I do is reduce optimization to -00 or -0g, or add -fno-inline-functions-called-once to the compilation flags, which is indicative of undefined behavior. And again, if all I do is make _cdcd_itf[0].line_state volatile, the bug also disappears regardless of optimization level. This makes me believe the problem is very much what I already analyzed, that line_state needs some kind of synchronization between tasks if it's to be used in multiple tasks at once.

...

fallow birchBOT
fallow birchBOT
fallow birchBOT
#

Operating System

Linux

Board

pca10095 or pca10056 or other NRF52/NRF53

Firmware

Latest master can be 0.13.0.
mynewt/nimble build with BTH and MSC enabled

What happened ?

When DMA is started for one OUT endpoint values read from SIZE.EPOUT[n] for other endpoint are not valid.
This behavior is not documented (yet) by Nordic but it can be observed on NRF52/NRF53.
When two packets arrive on two different endpoints single interrupt will detect and try to handle bot...

fallow birchBOT
#

The defined in cmakelist.txt is added in this commit
https://github.com/hathach/tinyusb/commit/95f2478146ef83d18b52408c0692222bf2a15053#diff-12cfd80973cd9c09e8493c08a1eb623365231a9e2b0db14d109e9b6836985830R71-R74

PBUF_POOL_SIZE=2
HTTPD_USE_CUSTOM_FSDATA=0

are also redefined with the same values, maybe we should drop it altogether in cmakelist and adjust/use value in the header file only for consistency

fallow birchBOT
fallow birchBOT
#

everything looks great, except, maybe we should remove re-define of network example in cmakelist. If you agree, I could merge this first, and make an changes as separated PR afterwards.

Sure. i wasn't sure why why was overridden in the CMakeLists.txt to start with, so didn't want to change that to remove the error. I 100% defer to your better knowledge of what it does, and if it is safe for all boards to change (or if it is even needed)

fallow birchBOT
#

everything looks great, except, maybe we should remove re-define of network example in cmakelist. If you agree, I could merge this first, and make an changes as separated PR afterwards.

Sure. i wasn't sure why why was overridden in the CMakeLists.txt to start with, so didn't want to change that to remove the error. I 100% defer to your better knowledge of what it does, and if it is safe for all boards to change (or if it is even needed)

ok thanks, I will do that later on with a ...

fallow birchBOT
fallow birchBOT
fallow birchBOT
fallow birchBOT
fallow birchBOT
#

Hi, @hathach,

unfortunately I currently don't have the test-equipment on desk any more currently, so no further possibility to test.

I'll do further tests with this software in the 2nd half of the year and also might test that change then, but I'd propose to first merge the current solution.

Regards Pascal

Am 26.05.22 um 16:34 schrieb Ha Thach:

@.**** approved this pull request.

Sorry for late response, and thank for your PR. This somehow falls off my radar. The code is spot...

fallow birchBOT
#

Operating System

Windows 10

Board

Custom based on STM32H7B3

Firmware

portable/st/stm32_fsdev/dcd_stm32_fsdev.c

What happened ?

Dear,

I have followed the example for CDC/MSC using FreeRTOS and have got pretty much everything working. Expect for the disconnection event: unmount callback (tud_umount_cb) is not being called for this platform and driver. Mount callback (tud_mount_cb) happens as expected.

I am new to this library, so maybe I have messed up something, bu...

fallow birchBOT
#

@hathach It took a while but we now have opensource throughput test application for nimble that can be also used to with USB transport for NRF52840/NRF5340/DA1469x.

With this software it's possible to trigger race condition that this PR fixes.
Testing application is part of nimble and is written in python and it runs on Linux.

I was able to reproduce problem only on NRF5340 where bluetooth stack runs on separate core.

This is how to test:
get go compiler if not installed

fallow birchBOT
#

Okay... sorry for any confusion here, but now I pretty much understand what's going on. In order for teensy to work as expected, it needs the pins configured in JTAG mode so that the reboot-to-bootloader command works (there's a separate bootloader microcontroller that connects to the jtag pins).

This patch now fixes it, and allows rebooting to the application or to the bootloader.

fallow birchBOT
fallow birchBOT
#

Operating System

Linux

Board

STM32F723 Discovery

Firmware

examples/device/audio_4_channel_mic
examples/device/audio_test
examples/device/uac2_headset

What happened ?

The UART Log print's "check_dwc2 462: ASSERT FAILED"

How to reproduce ?

Compile firmware using make BOARD=stm32f723disco LOG=2 PORT=1 clean all in the relevant project folder
Open UART LOG
Flash controller
Reset controller and connect (USB connection to PORT1 is irrelevant, assert fails regardl...

fallow birchBOT
#

Describe the PR

  • Add support for multiple levels of USB hubs. For your consideration Hathach ๐Ÿ˜„

To get this working reliably I had to relax the assert on failed port_status control transfer. Currently with multiple hubs it may perform a control xfer if the ctrl buffer is busy.

Additional context

  1. Developed on imxrt (Teensy41) with EHCI.
  2. Tested with 3 USB hubs levels, combination of low speed and full speed devices. (HID devices) Not tested with Bulk or Iso but this is ...
fallow birchBOT
#

Hi, @hathach, unfortunately I currently don't have the test-equipment on desk any more currently, so no further possibility to test. I'll do further tests with this software in the 2nd half of the year and also might test that change then, but I'd propose to first merge the current solution. Regards Pascal Am 26.05.22 um 16:34 schrieb Ha Thach:

No problems, I think it is safe to do so when observing code from linux driver. I will make the change to pr and merge asap.

fallow birchBOT
fallow birchBOT
#

Describe the PR
Consider the following contrived MSP430 code and linker script:

#include 

extern volatile unsigned int USBVECINT; // PROVIDE(USBVECINT = 0x0932);

int main()
{
  uint16_t curr_vector = USBVECINT;
  volatile uint8_t ep; // Call into function in another TU has same effect.

  switch(curr_vector)
  {
    case 2:
    case 1:
      ep = curr_vector;
  }

  return 0;
}
OUTPUT_ARCH(msp430)

MEMORY {
  ROM (rx)         : ORIGIN = 0x4400,...
fallow birchBOT
#

thanks @HiFiPhile , I kind of getting the idea, filtered ~ average here

filtered = 255 * old + raw_count
feedback = nominal - (filtered/256 - threshold)

out of curiosity, how would you come up with the filtered/avg formula and how does it depend on sample rate, FS/HS link. Sorry for more question, I am trying to figure out the big picture and normalize the argument for this compute method.

fallow birchBOT
fallow birchBOT
#

thanks for the explanation, unfortunately, I still pretty much have no ideas how to generalize this into generic code. Apparently, there is no formula to fit all, I am just hoping to make some skeleton and allow user to simply tweaking a parameter or two with actual hardware. However, this is really out of my knowledge, and don't actually have any real application on hardware to test these out.

Since this has been pending for quite some time, I would like to merge this as it is and come b...

fallow birchBOT
#

thank you @PanRe and @HiFiPhile for reviewing and discussing this PR. I think we finally got everything together with frequency method (power of 2 / fixed / float). Regarding the fifo count, due to my inexperience and lack of actual app-on-hardware testing, I comment it out still having place holder to add support later on as follow up PR.

detail on fifo count method discussion https://github.com/hathach/tinyusb/pull/1463#discussion_r885637209

fallow birchBOT
fallow birchBOT
fallow birchBOT