#tinyusb

1 messages · Page 7 of 1

fallow birchBOT
#

thank you very much for your awesome work. PR works out the box with max32650/666/690 at first try. I have done quite a bit of refactoring mostly with dcd musb (hcd isn't touched yet) with

  • declare general musb register
  • add musb configuraation option MUSB_CFG_SHARED_FIFO/MUSB_CFG_DYNAMIC_FIFO which is the main difference between adi and ti implementation
  • indexed tx/rx register to make the code look cleaner
  • implement dcd_edpt_iso_alloc()/activate() for TI port, which makes it simple...
fallow birchBOT
#
[hathach/tinyusb] New branch created: minor-update
fallow birchBOT
fallow birchBOT
fallow birchBOT
#
[hathach/tinyusb] New branch created: circleci-make
fallow birchBOT
#
[hathach/tinyusb] New branch created: circleci-tweak
fallow birchBOT
#
[hathach/tinyusb] New branch created: hil-add-host-test
fallow birchBOT
#

thank you very much for bringing up and fixing the issue. I have done some testing and it does address the case for spamming CDC OUT. However, It also introduce another If my though right. Let say we have a device with 2 bulk out e.g cdc + msc, when scheduling 2 xfer

  • CDC got NAK --> flag sset
  • driver switch to MSC Out, make a couple of transfer
  • back to CDC bulk out, at this point: flag is set, but data is not available (overwritten by MSC out).

I am making some adjustment, hopefull...

fallow birchBOT
#

It was a pleasure for me to work on this, I was in the process of developing a usb dongle acting as a serial to ble bridge for connecting a wireless pendant to the machine and your library came quite handy.

During my testing with chips on both revision 2 (0x13) and 3 (0x13) I wasn't able to reset the send FIFO. Also the programming guide does not mention anything regarding that's possible. This issue has been discussed in their support forums and some other places. Unfortunately it does no...

glacial stratus
fallow birchBOT
#

Operating System

Others

Board

Raspberry Pi Pico 2 (RP2350)

Firmware

Pico SDK 2.0.0, which per its release notes includes TinyUSB commit 42326428 (0.17.0 WIP).

What happened ?

uint8_t midi_program_change[2] = { 0xc0 | channel, program};
tud_midi_stream_write(MIDI_cable, midi_program_change, 2);

This seems to change the program, but immediately after reverting back to program #0, possibly repeatedly (?) (i.e. getting stuck in some kind of loop doing so).

How ...

fallow birchBOT
#

Operating System

Linux

Board

Raspberry Pi Pico

Firmware

usb_midi_host_example

What happened ?

This is with regards the RP2040 USB Host mode chip bug described here: https://github.com/raspberrypi/pico-feedback/issues/394.

TinyUSB implements host mode bulk and interrupt endpoints using the automatically polled endpoint hardware on the RP2040. That hardware has a bug that pre...

fallow birchBOT
#

thank for more information. Regarding flushing fifo, I tried and I think we can just ignore the SNDBAVIRQ to overwrite sndfifo. I have update PR to add sndfifo ownver info which is invalidate on

  • a switch to another OUT endpoint
  • a successful OUT transfer.

I figured out that we only care about the owner of data in the fifo, we don't really need to pay attention when it is NAKed, or switching and having an successful IN transfer at all. Though when switching between multple OUT endpoin...

fallow birchBOT
#

Operating System

Others

Board

PCA10056

Firmware

Custom firmware which uses CDC-ACM for data transfer. On the other end BLE with old Nordic SDK.

TinyUSB is at the state as of 2024-08-26.

What happened ?

The test procedure does "connect CDC, get BLE device list, connect BLE, transfer little data, disconnect device, disconnect CDC"

After some iterations, TinyUSB has a failed assertion. I nailed that down before already, see #2626, that disable/enable IRQ at the cor...

fallow birchBOT
fallow birchBOT
#

thank you @kasjer. Problem with the code is, that it is owned by my company. I have to strip everything down to a minimum test case. Will again need some time.

My gut feeling is currently telling me, that it has something to do with disconnect/connect and pending data transfers.

Currently catching the debug output, but if there is bad luck than the problem does not happen with debug log on.

fallow birchBOT
fallow birchBOT
fallow birchBOT
#
[hathach/tinyusb] New branch created: update-hil-max32
fallow birchBOT
fallow birchBOT
#

@rgrr I'm processing your logs to understand the issue, if you can share some code it could help (especially host part). If you have traces from USB or logic analyzers it could also help understand timing. My wild guess right now is DMA access which must be serialized and can affect sequence of events when DMA is not ready at some point.

fallow birchBOT
fallow birchBOT
#

@kasjer : sorry, both sides are more or less complex. The host side requires a working client, so no easy way.

I have reintroduced the disable/enable interrupt around the above sequence and again the problem disappeared.

But my first interpretation was wrong: the function is not called when it is already active (never observed active interrupt in this function til now). The actual problem is, that an interrupt between the two calls edpt_dma_start() and dcd_event_xfer_complete() insert...

fallow birchBOT
fallow birchBOT
#

@hathach Really fixing this bug requires writing a new HCD for the RP2040 hardware that only uses epx hardware. These are my thoughts on the design. Do you have any comments or suggestions?

  • The interrupt handler must schedule every pending transfer
  • To do that, the interrupt handler must service SOF interrupts to properly allocate bandwidth per frame
  • The interrupt handler must service NAK interrupts to know when to try a different pending transfer
  • The HCD cannot rely on the automa...
fallow birchBOT
#
[hathach/tinyusb] New branch created: bump-pio-usb
fallow birchBOT
fallow birchBOT
fallow birchBOT
fallow birchBOT
fallow birchBOT
fallow birchBOT
#

@kasjer : the atomic flag functions used are

#define atomic_bool                    nrfx_atomic_flag_t
#define atomic_flag                    nrfx_atomic_flag_t

#define atomic_flag_clear(X)           nrfx_atomic_flag_clear(X)
#define atomic_flag_test_and_set(X)    nrfx_atomic_flag_set_fetch(X)

Code is as follows (sorry, I'm no Cortex-M assembler freak):

          xact_out_dma:
00031be4:   push    {r7, lr}
00031be6:   mov     r7, sp
00031be8:   sub     sp, #16
...
fallow birchBOT
fallow birchBOT
#

@kasjer here they are:

          nrfx_atomic_u32_fetch_or:
000374a8:   sub     sp, #20
000374aa:   str     r0, [sp, #16]
000374ac:   str     r1, [sp, #12]
 99           NRFX_ATOMIC_OP(orr, old_val, new_val, p_data, value);
000374ae:   ldr     r0, [sp, #16]
000374b0:   ldr     r1, [sp, #12]
000374b2:   ldrex   r2, [r0]
000374b6:   orr.w   r3, r2, r1
000374ba:   strex   r12, r3, [r0]
000374be:   teq     r12, #0
000374c2:   bne.n   0x374b2 <nrfx_atomic_u32_fetch_or+10>
000374...
fallow birchBOT
#

I think I understand the problem.
Your solution to swap lines is correct.

Here is what happens:

  • Set Line Coding request is received
  • Task schedules read of data (7 bytes)
  • Task also schedules write to EP 82 (14 bytes)
  • Interrupt send notification to Task that 7 bytes transfer is done
  • Task wants to send status (0 bytes that does not takes DMA for long)
  • Task sends 0 bytes data packet
  • Interrupt fires probably for EP 82 informing that packet was received by host and send tra...
fallow birchBOT
#

Now that I know how it works it's easy to reproduce not even data endpoints traffic is needed.
Adding TU_LOG() between those lines will suffice to trigger the problem.

  if (control_status) {
    // Status Phase also requires EasyDMA has to be available as well !!!!
    edpt_dma_start(&NRF_USBD->TASKS_EP0STATUS);

    TU_LOG2("Not so fast\n");

    // The nRF doesn't interrupt on status transmit so we queue up a success response.
    dcd_event_xfer_complete(0, ep_addr, 0, XFER_...
fallow birchBOT
fallow birchBOT
fallow birchBOT
fallow birchBOT
fallow birchBOT
fallow birchBOT
fallow birchBOT
fallow birchBOT
fallow birchBOT
fallow birchBOT
#
[hathach/tinyusb] New branch created: enhance-disconect-connect-esp32
fallow birchBOT
fallow birchBOT
fallow birchBOT
fallow birchBOT
fallow birchBOT
fallow birchBOT
#

Hi,
Thank you for bringing this up. We certainly plan to upstream P4 support, we only got a little delayed with testing.
The new High-Speed support for P4 introduces many changes also for S2 and S3 with high regression risk, so we want to be sure we don't break anything.
@hathach Is there any timeline for next TinyUSB release? It would be nice to include this feature in it :)

fallow birchBOT
#

Hi, is there a planning to migrate to the generic dwc2 driver instead of dcd_esp32sx ?

@HiFiPhile this is done in our fork of TinyUSB. Adding the high-speed support was a lot easier this way, as HS is already supported on STMs and other platforms. This is the huge, risky change I had in mind (most of bugs that we encountered are coming from the DCD layer)

We also wanted to evaluate changes from https://githu...

fallow birchBOT
#

This PR adds HCD for WCH CH32V20x USBFS (USBOTG_FS).

The following issue will be closed:

CH32V20x has two USB peripheral; FSDEV and USBFS. In this PR, USBFS Host driver is enabled when PORT=0 (FSDEV is selected).

I tested on my original CH32V203C8T6 board "Suzuno32RV" (8MHz external crystal, Type-A connector is assigned for USBFS, Type-C connector is for FSDEV).
Please refer for schematic: https://github.com/verylowfreq/board_suzuno...

fallow birchBOT
#

@tore-espressif next release is coming very soon, I actually want to release it for quite some time but got busy with lots of other works. I think we can make a 0.17.0 this week or so. And then when P4 got merged, we can make an additional release e.g 0.17.1, that way if there is a serious bug with P4, user can easily roll back.

PS: Thanks to @ladyada I will have the P4 eval board in a week, and can start to help testing and get it upstream.

fallow birchBOT
fallow birchBOT
#

@HiFiPhile thank you for the PR and sorry for huge delay. I initially want to migrate vendor driver to use new edpt stream API ( only used by host cdc but running rather well so far), therefore didn't review this as fast as I could. I think it is a good chance to do so, also update the edpt stream to also support fifo depth = 0 (no fifo/bufferred mode).

In the future, we can migrate most of the buffered driver e.g cdc/midi to use this stream API to reduce duplication (once it runs stable...

fallow birchBOT
fallow birchBOT
fallow birchBOT
fallow birchBOT
#

@HiFiPhile just notice you want to make an cmsis dap, maybe just using pico debugdap, I have been using it with other mcus, and it works rather well with openocd https://github.com/raspberrypi/debugprobe

Didn't know that :)

@kkitayam wrote a cmsis-dap class: https://github.com/kkitayam/akiprobe/blob/main/src/cmsis_dap_device.c, based on that
I did an implementation on LPC55. Speed is pretty good, ram download can achieve 1MB/s.

But it fell short compared to J-Link for debug, whe...

#

@HiFiPhile just notice you want to make an cmsis dap, maybe just using pico debugdap, I have been using it with other mcus, and it works rather well with openocd https://github.com/raspberrypi/debugprobe

Didn't know that :)

@kkitayam wrote a cmsis-dap class: https://github.com/kkitayam/akiprobe/blob/main/src/cmsis_dap_device.c, based on that I did an implementation on LPC55. Speed is pretty good, ram download can achieve 1MB/s.

But it fell short compared to J-Link for...

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

Just for completeness: ESP32-P4 has two USB peripherals, one FS and one HS, each with its dedicated PHY. So theoretically, one can work as Host and the other as Device (or both device, or both host).

As of now, we only have support for the HS peripheral. FS peripheral support is still work in progress

We'd love to do both! Device on high speed and full speed host. Support for HS first would be good so we can have device support in CircuitPython.

fallow birchBOT
fallow birchBOT
#

After further testing, I noticed that disabling the USB CDC Serial (which is enabled by default) in the Adafruit TinyUSB library results in the polling rate to get limited to 500Hz on macOS.
On Windows it's still 1KHz, and that is consistent with the problems we had before using TinyUSB directly.

If the USB CDC Serial is enabled, it has zero problems reaching the full 1KHz on both macOS and Windows.

fallow birchBOT
#

Operating System

Windows 11

Board

esp32s3

Firmware

hid.zip

This python code is a test case for the computer
def mouse_report(buttons: int, x: int, y: int) -> bytes:
return bytes([
0x02,
buttons,
x,
y,
])

if name == 'main':
ser = serial.Serial("COM6", baudrate=9600, timeout=1)

report = mouse_report(0, 500, 300)
print(f"Sending press report...
fallow birchBOT
#
[hathach/tinyusb] New branch created: add-pico2
fallow birchBOT
#
[hathach/tinyusb] New branch created: release-0.17.0
fallow birchBOT
#
[hathach/tinyusb] New tag created: 0.17.0
#

Just for completeness: ESP32-P4 has two USB peripherals, one FS and one HS, each with its dedicated PHY. So theoretically, one can work as Host and the other as Device (or both device, or both host).

As of now, we only have support for the HS peripheral. FS peripheral support is still work in progress

That is great to hear, yeah, @tore-espressif I just made an new release for 0.17.0. And will receive my P4 eval board real soon (in a day or two). Would you mind making an PR for P4....

fallow birchBOT
fallow birchBOT
fallow birchBOT
#

I would like to know how to run two TinyUSB stacks on the P4, creating two USB devices that each operate through different USB ports.

Currently it's not possible, some works have been done with the port number but multi port simultaneously is not implemented yet.
bool tud_init(uint8_t rhport) {

PS: I guess it is time to review and work on host driver for dwc2.

I hope dwc2 HCD will be much simpler than DCD, at least no need to deal with fifo allocation ;)

fallow birchBOT
#

Operating System

Windows 11

Board

ESP32S3

Firmware

I use the same code on the computer and it can output A normally, but there is no response on Android.

What happened ?

I use the same code on the computer and it can output A normally, but there is no response on Android.

How to reproduce ?

I use the same code on the computer and it can output A normally, but there is no response on Android.
![image](https://github.com/user-attachments/assets/c68dc528-02ca-499a-...

fallow birchBOT
fallow birchBOT
fallow birchBOT
#

Operating System

Others

Board

ESP32S3

Firmware

const uint8_t hid_report_descriptor[] = {
TUD_HID_REPORT_DESC_KEYBOARD(HID_REPORT_ID(HID_ITF_PROTOCOL_KEYBOARD)),
TUD_HID_REPORT_DESC_MOUSE(HID_REPORT_ID(HID_ITF_PROTOCOL_MOUSE)),
0x05, 0x0d, /* USAGE_PAGE (Digitizer) /
0x09, 0x04, /
USAGE (Touch Screen) /
0xa1, 0x01, /
COLLECTION (Application) /
0x85, HID_ITF_PROTOCOL_ABSMOUSE, /
...

fallow birchBOT
#

Hi guys, in case you are still interested in USB Host applications, we have it supported on ESP32-S2 and ESP32-S3 in esp-idf

Hi Tomas,

Does your usb stack support connecting a hub, and then connecting multiple HID devices to that hub (e.g., keyboard and mouse)?

I see in this directory https://github.com/espressif/esp-idf/tree/master/components/usb that there are some files related to hubs, but I can't find any information about if hubs are actually supported.

fallow birchBOT
#

Operating System

Linux

Board

esp32s2 module

Firmware

esp-idf v5.3.1

What happened ?

I'm trying to send "hello esp" from a custom linux usb driver to an esp32s2 esp-idf application running the tinyusb stack. I enabled "TUH_VENDOR 1" in tusb_option.h". When I send a 64 byte packet to the esp32s2, the stack detects the packet, but its contents are random/empty.

I added some logging statements here and there in esp-idf & tinyusb, to try to pinpoint the problem. But I ca...

fallow birchBOT
#

What you met is really awkward, never heard something like this.
What I can suggest is try to rule out problems:

  1. ESP's USB wrapper layer is not covered by this project, try to test without it: https://github.com/hathach/tinyusb/tree/master/examples/device/cdc_msc_freertos
    You can find build instrction here: https://github.com/hathach/tinyusb/blob/master/examples/device/audio_test_freertos/README.md
#

your suggestion seems to be rubberstamped. could you try something relevant to the actual logs?

That's why I said it's really awkward, after read your logs !

why do you think that the espressif wrapper is the source of this behavior

It's an unknown factor.

does tinyusb provide a working example for vendor class on espressif mcus?

WebUSB example use vendor class, unfortunately no FreeRTOS version is done.
https://github.com/hathach/tinyusb/tree/master/examples/device/web...

#

What I got in translation is : "to officially approve a decision or plan without thinking about it:"
Correct me if was wrong, what I thought is you are accusing me of blindly reply without understand the issue.

I said the issue is awkward since bulk in & out transfer is a basic function that maybe half of the people use, if it's broken we should already received many manifestations. That's why I suggest to rule out other factors first.

fallow birchBOT
fallow birchBOT
fallow birchBOT
#

@moefear85 Thank you for the detailed logs.

In the 'ESP additions to TinyUSB' we focus on classes that need some ESP specific handling, eg. port to our network layer, or port to our storage layer. The Vendor specific class can be used directly from TinyUSB.

Anyway, the support of Vendor Specific class will be improved in https://github.com/espressif/esp-usb/pull/62 . You descriptors will get a default values, so you can start developing you application faster.

fallow birchBOT
#

Describe the PR
I'm a user of tinyusb via pico-sdk. I wanted to use tinyusb_pico_pio_usb and found it wasn't working because hw/mcu/raspberry_pi/Pico-PIO-USB is no longer included in tinyusb repo and needs tools/get_deps.py to fetch it. I found that get_deps.py wasn't working because my environment (WSL2) didn't detect the file as python. I took opportunity to fix all python files in current tinyusb repo.

Additional context
pico-sdk should probably be modified to invoke get_d...

fallow birchBOT
#

Is there a brief way to explain why this is especially challenging for the developers?

I checked with Arduino team and this is what I got: It should be technically possible, there are two approaches

  1. Use Arduino as esp-idf component, then you can easily use USB Host Library that is part of esp-idf. Here are some resources about this option:
    https://docs.espressif.com/projects/arduino-esp32/en/latest/esp-idf_component.html
    https://www.youtube.com/watch?v=8w3MmsZBa9o&ab_channel=Espres...
#

Would you mind making an PR for P4?

Yes, sure. Our current timeline is roughly like this.

  1. Beginning of October: Rebase our changes on release v0.17 and retest
  2. Mid/End October: Open PRs with P4 support

I hope dwc2 HCD will be much simpler than DCD, at least no need to deal with fifo allocation ;)

This will greatly depend on which memory mode you choose. There is Slave, Buffer DMA and Scatter-Gather DMA.
But my guess is that you'll go with Buffer DMA, because the Slave mod...

fallow birchBOT
fallow birchBOT
#

@tore-espressif @HiFiPhile

thx for recognizing the effort in preparing the logs, to help in debugging. I noticed, the dcd driver being used (in tinyusb) is src/portable/synopsys/dwc2/dcd_dwc2.c, which includes dwc2_esp32.h although there is also a driver in src/portable/espressif/esp32sx/dcd_esp32sx.c. Why are there 2 drivers (the contents are very similar), why is one chosen not the other, is this choice configurable, and is it possible to test the dcd_esp32sx driver instead, as p...

fallow birchBOT
#

Will try to describe the patch here which worked for me, as was asked from me, and might be useful for others:

src/class/msc/msc_device.c and .h are involved.

In the header, the followings are added:

#define TUD_MSC_SIGNAL_DATA INT32_MAX
This is for tud_msc_read10_cb(), an additional return value indicating the application is not ready yet, for example disk I/O busy. The application would call tud_msc_data_ready() when the data becomes available (Should add this to the API descri...

fallow birchBOT
fallow birchBOT
#

I just checked the esp32s2 errata. It says:

3.5 [USB OTG] Abnormal data during AHB bus arbitration by USB OTG
Affected revisions: v0.0
Description
When the USB OTG peripheral and some other competing peripherals (listed below) simultaneously execute a
request on the Advanced High-performance Bus (AHB), the AHB may generate incorrect arbitration signals, which
results in the USB OTG peripheral reading or writing erroneous data. The competing peripherals include:
• I2S
• SPI
Worka...
fallow birchBOT
fallow birchBOT
fallow birchBOT
fallow birchBOT
fallow birchBOT
#

I tried add_definitions(-DCFG_TUD_VENDOR=1). It had no effect. I already put it in the right place in espressif__esp_tinyusb/include/tusb_config.h with the rest of the class definitions, so this was expected.

If that does not help we will publish a fix soon

tyt. I've compiled a troubleshooting list which I will be going over methodically. Although this is a hobby project, I intend to get to the bottom of this. I came across the debugging fifo read/write USB registers in the TRM. I...

fallow birchBOT
#

@HiFiPhile thanks a lot for your effort. I looked through this and was wondering if it's wise to use the BOS Descriptor for the quirk detection because apparently the BOS Descriptor is mandatory only for USB versions > 2.0 if I read correctly.

In addition, device, config and string Descriptor order is already enough to distinguish between MacOS and not-MacOS.

What do you think?

You are right, config and string Descriptor is already enough to distinguish between MacOS and no...

fallow birchBOT
#

Operating System

Windows 11

Board

正点原子stm32f429开发板

Firmware

这是工程链接地址:https://github.com/qwer-zxcv/stm32f429_usb_cdc_tinyusb 麻烦大家帮忙看看

What happened ?

初始化全速usb cdc设备一直没有进行枚举,usb无任何反应

How to reproduce ?

下载https://github.com/qwer-zxcv/stm32f429_usb_cdc_tinyusb工程编译固件到板子上可以复现

Debug Log as txt file (LOG/CFG_TUSB_DEBUG=2)

USBD init on controller 0, Highspeed = 0
sizeof(usbd_device_t) = 44
sizeof(dcd_event_t) = 12
sizeof(tu_fifo_t) = 12
sizeof(tu_edpt_stream_t) ...

fallow birchBOT
fallow birchBOT
fallow birchBOT
fallow birchBOT
#

This commit fixes issue #2776
https://github.com/hathach/tinyusb/issues/2776.
The HCD now routes all USB transfers through the EPx endpoint. It no longer uses the "interrupt" endpoint hardware to handle INTERRUPT and BULK endpoints. The fix avoids the data sequence error handling bug in the RP2040 USB IP's "interrupt" endpoint hardware
and allows the host to correctly drop the IN packet with the error without locking up. That fixes
https://github.com/rppicomidi/usb_midi_host/issues/14

...

fallow birchBOT
fallow birchBOT
#

really long review with incorrect poking. It turns out H743 USB DMA cannot access DTCM ram. Though that force me to do lots of reading and have a better understand of the dwc2 register for EPInfo for DMA. Which store 1 words for normal DMA, and 4 words for scatter/gather. We can dynamically configure gdififocfg with epinfo base to save footprint. Since currently we does not support scatter/gather, we only need 2xep_count.

While troubleshooting, I also rewrite to simplify the fifo allocati...

fallow birchBOT
fallow birchBOT
#

h743 usb dma cannot access DTCM

Oh it's a little pity for performance. I think we need to update the BSP with MPU config to make the region non-cacheable.

For gdfifocfg.EPINFOBASE (max is ghwcfg3.dfifo_depth) I'm the max is more like OTG_DFIFO_DEPTH ? Since ghwcfg3.dfifo_depth is already the value subtracted EP_LOC_CNT.

I'll test with my boards if everything works.

fallow birchBOT
#

h743 usb dma cannot access DTCM

Oh it's a little pity for performance. I think we need to update the BSP with MPU config to make the region non-cacheable.

Maybe just leave it as it is if it isn't much of an issue. I prefer to have generic/simpler code to maintain :)

For gdfifocfg.EPINFOBASE (max is ghwcfg3.dfifo_depth) I'm the max is more like OTG_DFIFO_DEPTH ? Since ghwcfg3.dfifo_depth is already the value subtracted EP_LOC_CNT.

I'll test with my boards if ev...

fallow birchBOT
fallow birchBOT
fallow birchBOT
fallow birchBOT
#
[hathach/tinyusb] New branch created: add-esp32p4
fallow birchBOT
#

Operating System

Windows 10

Board

Custom STM32U585 PCB

Firmware

tinyusb + FreeRTOS based project which unfortunately I can not share completely
With the following initialisation of an MSC and Vendor Class device

/* This variable uses the defines from usb_dwc2_cfg.h */
uint8_t const g_ConfigDesc[] =
{
  /* Config number, interface count, string index, total length, attribute, power in mA */
  TUD_CONFIG_DESCRIPTOR(1, ITF_NUM_TOTAL, 0, CONFIG_TOTAL_LEN, 0x00, 100),
...
fallow birchBOT
#

Related area

New port support.

Hardware specification

STM32H7R/STM32H7S

Is your feature request related to a problem?

While TinyUSB already supports the H7 series, it uses an off-chip PHY over ULPI for the HS port. The H7RS series has a dedicated on-chip HS PHY, making it similar to the U5 series. The H7RS series is also distinct from the remaining H7 series, with different pin ports, and they even have their own separate HAL file, "stm32h7rsxx_hal.h".

Describe the solut...

fallow birchBOT
#

I was trudging through the ST's implementation of MTP in the latest release of their USB library (the only USB stack I could find that has support for MTP). However, it's poorly-written, difficult to understand, and requires that you do everything in an ISR.

So, I'm feeling (foolishly) optimistic that I might be able to implement the MTP class in TinyUSB (even though I am just learning how the USB stack works). I'm reading through the MTP spec and ST's implementation, and making use of W...

fallow birchBOT
fallow birchBOT
#
[hathach/tinyusb] New branch created: migrate-hil-vm
fallow birchBOT
#

Describe the PR

Resolve:

USBD Setup Received 00 09 01 00 00 00 00 00 
  Set Configuration
  Open EP 03 with Size = 64
  Open EP 83 with Size = 64
    Allocated 64 bytes at offset 1152  Queue EP 03 with 31 bytes ...
  MSC opened
  Bind EP 03 to driver id 0
  Bind EP 83 to driver id 0
process_set_config 1049: ASSERT FAILED

Close #2815

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

Why is the additional close suddenly necessary?

It's not the fifo who cause the issue. In old version vendor class is erased on reset https://github.com/hathach/tinyusb/blob/8d345cde66374468c901eed023853e64563fc046/src/class/vendor/vendor_device.c#L185
Since 0.17.0 transfer management has been migrated to stream api but forgot to erase endpoint on reset, the next class opening attempt will fail.

fallow birchBOT
fallow birchBOT
#
[hathach/tinyusb] New branch created: hil-piousb-host-optional
fallow birchBOT
#

P4 initial support is added by https://github.com/hathach/tinyusb/pull/2818, using dwc2 generic driver. @tore-espressif unfortunately your fork is based on rather old commit, I have to cherry pick and also do manual code as well. I got working great with IDF 5.3.1 which does a great phy set-up. Though I think I haven't picked all the features (especially otg a/b signaling), but this will help @tannewt to start developing for circuitpython. @tore-espressif please feel free to make a full featu...

fallow birchBOT
#

Hello ,

i added the basic support for STM32U0 devices. As it uses the same usb core than the U5 series it's just some defines to add.
It was tested with a custom board as a cdc device. No further tests are done.

Are there any further needs to get merged into the main repo ?

Thanks in advance
Maerdl

fallow birchBOT
fallow birchBOT
#

When I tried cdc_dual_ports on STM32F103 Blue Pill, the Windows Device Manager recognizes both ports as TinyUSB CDC ports, but only one of them was able to open. It seems like that the example should echo the input, but nothing had shown on the serial monitor.

By the way, I tried cdc_msc example on STM32F401 Black Pill and both MSC and CDC classes worked well. But when I tried cdc_dual_ports on STM32F401, Windows devmgmt shows error on USB Composite Device and none of the ports are...

fallow birchBOT
fallow birchBOT
#

Operating System
Linux

Board
esp32s2 module

Firmware
esp-idf v5.3.1

What happened ?
I'm trying to send "hello esp" from a custom linux usb driver to an esp32s2 esp-idf application running the tinyusb stack. I enabled "CFG_TUD_VENDOR 1" in tusb_config.h". When I send a 64 byte packet to the esp32s2, the stack detects the packet, but its contents are random/empty.

I added some logging statements here and there in esp-idf & tinyusb, to try to pinpoint the problem. But I can't go ...

fallow birchBOT
fallow birchBOT
#

Operating System

MacOS

Board

ESP32-S3

Firmware

Custom firmware with Arduino Core 3.x.x. See the issue: https://github.com/espressif/arduino-esp32/issues/10296 for more details and a demo sketch.

Sketch

#include 
#include 
#include 

USBHIDKeyboard m_keyboard;
USBCDC         m_serial;
ESPUSB*        m_usb;

static void
usbEventCallback(void*            arg,
                 esp_event_base_t event_base,
                 int32_t          event_id,
 ...
fallow birchBOT
fallow birchBOT
fallow birchBOT
fallow birchBOT
#
[hathach/tinyusb] New branch created: ci-dwc2-dma
fallow birchBOT
fallow birchBOT
fallow birchBOT
#

Operating System

Others

Board

Raspberry Pi Pico WH

Firmware

̀ net_lwip_webserver`

What happened ?

If you call pbuf_free on the frame when ethernet_input returns ERR_OK you will get either pbuf_free: p->ref > 0 or worst steal the buffer ownership from the HTTP server.

How to reproduce ?

Try run net_lwip_webserver on Pico.

Debug Log as txt file (LOG/CFG_TUSB_DEBUG=2)

Sorry won't bother, description is good enough.

Screenshots

lwIP ticket: https...

fallow birchBOT
fallow birchBOT
#
[hathach/tinyusb] New branch created: update-dwc2
fallow birchBOT
fallow birchBOT
fallow birchBOT
#

Operating System

Others

Board

Raspberry Pi Pico WH

Firmware

lnet_lwip_webserver

What happened ?

OOM errors in lwIP logs.

Enable logs like that:

#define LWIP_DEBUG
#define HTTPD_DEBUG LWIP_DBG_ON
//#define TCP_OUTPUT_DEBUG LWIP_DBG_ON
//#define TCP_INPUT_DEBUG LWIP_DBG_ON
#define MEM_DEBUG LWIP_DBG_ON

How to reproduce ?

Enable logs and maybe use some larger web page.

Debug Log as txt file (LOG/CFG_TUSB_DEBUG=2)

Not so relevant, that's abou...

fallow birchBOT
fallow birchBOT
fallow birchBOT
#

its not the driver. the driver works with cdc-acm using unbind method. don't esp & pico use same synopsys hardware? rp2040 is also already riddled with so many usb errata.

rp2040 doesn't use dwc2 ip.
https://github.com/hathach/tinyusb/blob/master/src/portable/raspberrypi/rp2040/dcd_rp2040.

Maybe your driver missing something initialization stuff that usb_acm driver already did before it's unbinded.

ill check the driver first. maybe what wireshark captures isnt what actually get...

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

A lot has change in my project since I first came across this issue and now somehow even with the workarounds I had built-in I found a use case where I would always get PANIC ep 0 out was already available

So I eventually decided to checkout your branch gemarcano:rp2040_irq_lock_fix and sure enough it worked 🥳

Then I decided to remove the workaround I had in place to take care of the worst cases. It's basically filtering...

fallow birchBOT
#

Operating System

Others

Board

STM32U5 custom

Firmware

STM32U5 (dwc2) – FS USB – 1 CDC class – minimal implementation, unmodified from examples/device/cdc_dual_ports besides buffer sizes (and using only one CDC class).

What happened ?

Two bugs occur:

  1. If CFG_TUD_CDC_RX_BUFSIZE is less than CFG_TUD_CDC_EP_BUFSIZE, no tud_cdc_rx_cb RX callback happens and the stack stalls (see https://github.com/hathach/tinyusb/issues/1924#issue-1598567744 for the same problem).
    ...
fallow birchBOT
fallow birchBOT
fallow birchBOT
#
[hathach/tinyusb] New branch created: add-tusb_int_handler-update-tinyusb_init
fallow birchBOT
#

I started to work on extending TinyUSB Auduino to provide the missing audio functionality.

Unfortunately I was struggeling, so I decided to go back to basics and confirm that the functionality is really working.

  • I was missing a 2 channel microphone example. I think 2 channels are the most useful scenario, so I decided to add an example for this case. This will be the base for the Arduino functionality.
  • Unfortunatly I could not make any of the speaker examples work. The uac2_headset...
fallow birchBOT
#

I can also reproduce what @jncronin is describing. If I have high load on my STM2U585 MCU, probably some response is handled too late, which results in a bus reset from the host. Since this DCD_EVENT_BUS_RESET resets the device info in _usbd_dev , but the event queue is not cleared, the already present DCD_EVENT_XFER_COMPLETE is read in the next round and tries to find drivers in an empty _usbd_dev , which fails into the Assert.

fallow birchBOT
#
[hathach/tinyusb] New branch created: more-tusb_init()
fallow birchBOT
fallow birchBOT
#

+1 for merging this patch.

I am maintaining and using a local copy of this patch and it works brilliantly.

Without this patch, https://github.com/kholia/Global-Communications-Transceiver and other radio firmwares crash very soon. With this patch applied, the radio firmware runs 'forever' (1 week plus and counting).

Thanks @hathach for considering this PR <3

...

PS: This patch is powering my main HF rig now.

![picture_reduced](https://github.com/user-attachments/assets/dcae2...

fallow birchBOT
fallow birchBOT
#

Operating System

Linux

Board

RP2040

Firmware

standard example with standard firmware as documented in this project

What happened ?

The processor is hanging after connecting to the device from Audacity under Linux

After implementing this pull request, it's working w/o problems.
How can I help that this correction is moving agead ?
I finally want to have it finally in the Adafuit TinyUSB....

How to reproduce ?

  • C...
fallow birchBOT
#

Hi,

As @hathach said last year, many things has been changed since this PR, notably the introduce of dcd_edpt_iso_alloc() and `dcd_edpt_iso_activate() to facilitate ISO endpoint FIFO management.

There is no more need to track the FIFO usage of each endpoints since the audio (also video) class will claim the maximum FIFO needed with dcd_edpt_iso_alloc() during initialization. Then dcd_edpt_iso_activate() is called instead of dcd_edpt_open() when the endpoint is opened. So only on...

fallow birchBOT
fallow birchBOT
#

Fixes #2322

Describe the PR
In cases of bus reset, there can be pending transfers in the queue. Or a defective host just sends transfers without a proper setup. In both cases this lead to null pointer access after driver lookup(or assert if debug is enabled).
This small check fixes this.

Additional context
I checked the throughput on my STM32U5 base MSC device and could not see a performance hit. Though I am limited at around 256KB/s read speed anyway. I have seen pending ...

fallow birchBOT
fallow birchBOT
fallow birchBOT
#

Related area

Examples

Hardware specification

ESP32 S3

Is your feature request related to a problem?

I'd like to built a force feedback (FFB) steering wheel with an ESP32 S3, yet I'm having trouble getting started.
There are a lot of helpful examples. A HID example with FFB capabilities would be awesome.

There are also some existing projects for arduino, e.g. https://github.com/hoantv/VNWheel, but I cannot find any project related to ESP32 or tinyusb.

Any help is ver...

fallow birchBOT
#

Thank you for your interest in improving audio support.

  • For the 2CH microphone example, it's better to extend the 4CH example to support both 1CH and 2CH with a#if switch, since 95% of code is identical. We can call it uac2_microphone.
  • For the compilation error fixing, are you using a special gcc version or compilation flags ? We have RP2040 included in the CI and no error was reported. You can find the cmake file here:
    https://github.com/hathach/tinyusb/blob/master/hw/bsp/rp2040...
#

Thanks for your feed back:

  1. I will look into this, but I might just remove this because in my Adafruit solution, I will rely on a fully dynamically calculated descriptor.
  2. The example was excluded from the overall cmake build: I needed to include it to pick it up in the overall generation
  3. Makes sense: I assume, I can decide on the naming myself

One final question: I noticed that the pull request has somehow added plenty of things that were not changed by me. Is this part of som...

#

The example was excluded from the overall cmake build: I needed to include it to pick it up in the overall generation

Hum... RP2040 is not skipped in examples/device/uac2_speaker_fb/skip.txt, maybe I should get a RP2040 board to checkout one day.

One final question: I noticed that the pull request has somehow added plenty of things that were not changed by me. Is this part of some automatic process that runs in the background ?

It's because you opened the PR with your master ...

#

Following the discussion that the RP2040 is missing the new ISO API, here is my take on it.
I added the 2 following methods

  • bool dcd_edpt_iso_alloc(uint8_t rhport, uint8_t ep_addr, uint16_t largest_packet_size)
  • bool dcd_edpt_iso_activate(uint8_t rhport, tusb_desc_endpoint_t const * p_endpoint_desc)

I was keeping the existing logic and I just needed to split up some functions to fit the new logic.

This is addressing [this issue](https://github.com/hathach/tinyusb/issues/2838...

fallow birchBOT
#

Following the discussion that the RP2040 is missing the new ISO API, here is my take on it.
I added the 2 following methods

  • bool dcd_edpt_iso_alloc(uint8_t rhport, uint8_t ep_addr, uint16_t largest_packet_size)
  • bool dcd_edpt_iso_activate(uint8_t rhport, tusb_desc_endpoint_t const * p_endpoint_desc)

I was keeping the existing logic and I just needed to split up some functions to fit the new logic.

This is addressing [this issue](https://github.com/hathach/tinyusb/issues/2838...

fallow birchBOT
#

The following issues are addressed

  • Building all examples with cmake is giving compile errors mainy due to data conversion
  • uac2_spaker_fb is missing in the cmake file, gives compile errors and has missing c file in cmake

Many issues could be resolved by treating conversion not as error, but I did not find the place to change this.

Detailed changes

  • .gitignore to ignore .vscode
  • examples/device/CMakeLists.txt add missing uac_speaker_fb
  • examples/device/uac_speaker_fb/CMakeLi...
fallow birchBOT
fallow birchBOT
#

Thanks. Could you give some recommendation how to avoid the issue with the many generated files
I tried to

  • branch from master and merge to master
  • branch from testing and merge into testing

Both options created a big mess. I tried to find some documentation about this, but I only found some generic description that when creating a branch, I can indicate the source...

#

Thanks. Could you give some recommendation how to avoid the issue with the many generated files I tried to

  • branch from master and merge to master
  • branch from testing and merge into testing

Both options created a big mess. I tried to find some documentation about this, but I only found some generic description that when creating a branch, I can indicate the source...

Your initial attempt with master branch is correct, except the commit https://github.com/hathach/tin...

#

Follow up of https://github.com/hathach/tinyusb/pull/2845

The following issues are addressed

  • Building all examples with cmake is giving compile errors mainy due to data conversion
  • uac2_spaker_fb is missing in the cmake file, gives compile errors and has missing c file in cmake

Many issues could be resolved by treating conversion not as error, but I did not find the place to change this.

Detailed changes

  • .gitignore to ignore .vscode
  • examples/device/CMakeLists.txt add mis...
#

Follow up of https://github.com/hathach/tinyusb/pull/2844

Following the discussion that the RP2040 is missing the new ISO API, here is my take on it.
I added the 2 following methods

  • bool dcd_edpt_iso_alloc(uint8_t rhport, uint8_t ep_addr, uint16_t largest_packet_size)
  • bool dcd_edpt_iso_activate(uint8_t rhport, tusb_desc_endpoint_t const * p_endpoint_desc)

I was keeping the existing logic and I just needed to split up some functions to fit the new logic.

This is addressin...

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

Related area

new example

Hardware specification

NXP i.MX RT1175

Is your feature request related to a problem?

There is no example running on core CM4 of an RT1176. I tried to take the code that works successfully on CM7, but it doesn't works on CM4

Describe the solution you'd like

I would like to have an example running on CM4 of dual-core RT117x.

I have checked existing issues, dicussion and documentation

  • [X] I confirm I have checked existing issues, dicussion ...
fallow birchBOT
fallow birchBOT
fallow birchBOT
fallow birchBOT
fallow birchBOT
#

Build works with:

cdc_msc$ make BOARD=at32f403a_weact_blackpill all

Memory region         Used Size  Region Size  %age Used
           FLASH:       23104 B         1 MB      2.20%
             RAM:       11816 B        96 KB     12.02%
CREATE _build/at32f403a_weact_blackpill/cdc_msc.bin
arm-none-eabi-objcopy -O binary  _build/at32f403a_weact_blackpill/cdc_msc.elf _build/at32f403a_weact_blackpill/cdc_msc.bin
CREATE _build/at32f403a_weact_blackpill/cdc_msc.hex

   text    dat...
fallow birchBOT
#

Describe the PR
Adds a necessary define for OPT_MCU_STM32H7

Additional context
I'm attempting to get tusb running on the STM32H7B3I-DK. While this doesn't totally solve my issues, I did notice that without this #define, if I had

// tusb_config.h
#define CFG_TUD_MAX_SPEED OPT_MODE_DEFAULT_SPEED ///< Default (max) speed supported by MCU

Then I would wind up with TUD_OPT_HIGH_SPEED == 0

https://g...

jolly scroll
#

@cursive bone i hear that your working on dwc2 host? got time to talk about it?

#

ive also got a dwc2 driver working on the rpi
it currently lacks split-transaction support, and some of the NAK handling is funky

but it is able to do both MSD and usb-ethernet

fallow birchBOT
#
[hathach/tinyusb] New branch created: hcd-dwc2
jolly scroll
#

@robust walrus maybe you could help get his attention?

fallow birchBOT
#

Hi @hathach ,
currently, I am verifying the compatibility for esp32p4 and during the verification I run into some places, where I should change the code.

I thought that it is better to create a PR to upstream.

Also, regarding the debug line: It is relevant when we use tinyusb with esp-idf, and, maybe it is not relevant to tinyusb only. So, let me know, I could revert this change.

robust walrus
fallow birchBOT
#

In debugging this further, I've found that the STM32H7B3LI MCU which is on this board spits out the following dwc2 configuration values:

guid, gsnpsid, ghwcfg1, ghwcfg2, ghwcfg3, ghwcfg4
0x00002300, 0x4F54330A, 0x00000000, 0x229FE190, 0x03B8D2E8, 0xE3F00030

These are identical to those listed in the ST H743/H750 column of [dwc2_info.md](https://github.com/hathach/tinyusb/blob/master/src/portable/syno...

fallow birchBOT
#

Related area

hcd

Hardware specification

pi0-pi3

Is your feature request related to a problem?

@hathach i notice that your working on a dwc2 hcd, and i thought id share the code ive written to do the same thing
https://github.com/librerpi/lk-overlay/blob/master/platform/bcm28xx/dwc2/dwc2.c

ive got bulk endpoints working, and its able to read from mass-storage, and do dhcp/tftp with LWIP and the built-in nic on an rpi

Describe the solution you'd like

.

I have che...

fallow birchBOT
fallow birchBOT
#

Operating System

MacOS

Board

Custom

Firmware

Trying to link TinyUSB as static library into pre-existing STM32U575 codebase. The makefile-based builds for the TinyUSB examples are not suitable for us as we'd need to basically rewrite our existing software.

What happened ?

TinyUSB when built from the provided tinyusb/src/CMakeLists.txt file as a static library compiles and builds library file. However when attempting to use it, the project fails to link with missing refer...

fallow birchBOT
fallow birchBOT
#

We were able to get the system to link by manually adding the DCD driver to our project's CMakeLists.txt and building it externally. (reverse engineered the example makefiles to find what file was needed)

I had expected TinyUSB to handle including the DCD driver automatically since all the defines needed to select the correct one are in tusb_config.h and the DCD drivers are located in the tinyusb/src folder.
Since the logic to select the correct DCD is built into the makefiles for the exa...

fallow birchBOT
fallow birchBOT
fallow birchBOT
fallow birchBOT
#

I would also like to see STM32H7RS support added to TinyUSB.

I've just started trying out the H7S3L8 on its Nucleo. I might try out tinyusb on this chip in some time, if I do I will report any results. The UART is good enough for what I need to do immediately, though, so it might take a little while.

Here's some possibly useful information:

  • The chips seem to have two USBs, a USB FS and a USB HS, both with on-chip PHYs and both OTGs
  • Both the FS and HS sections of the datasheet ar...
fallow birchBOT
#

Thanks for the confirmation, could we get a mention of needing to manually include the DCD file in the CMakeLists or getting started guide? It looks like the information is already available at

fallow birchBOT
fallow birchBOT
#

Operating System

Linux

Board

RP2040

Firmware

Specifically this version, this fragment: https://github.com/MrJake222/pico-ice-sdk/blob/473e38978f7f8caab7e20c6b49f9f48623158dcf/src/ice_usb.c#L169-L175

What happened ?

When transmitting data over CDC from UART interrupt, the tud_cdc_n_write function can cause a flush, which is highly unwanted in an IRQ. I want to write 64/512 bytes to the buffer, and the rest shouldn't be written (return 0 for example). Flush will be call...

fallow birchBOT
#

Describe the PR

  • Replace cache clean/invalidate by MPU config. Since we can't guarantee buffer sizes are multiple of cache line size, doing cache clean/invalidate can cause data consistency issue, it also hurts performance. Use MPU to set RAM as non-cacheable like mcux-sdk example.
  • Add M4 core ram image build support
    • cmake -DCMAKE_BUILD_TYPE=RelWithDebInfo -DBOARD=mimxrt1170_evkb -DM4=1 -G Ninja -B rt1170_cm4
    • make BOARD=mimxrt1170_evkb M4=1
fallow birchBOT
fallow birchBOT
fallow birchBOT
fallow birchBOT
fallow birchBOT
fallow birchBOT
fallow birchBOT
fallow birchBOT
fallow birchBOT
#

@hathach
Thank you so much for checking the PR!

Meanwhile, I am not sure that it solves all the dependencies completely and provides the fully compatibility to tusb_init() call.

  1. When we use the previously used call tusb_init() without arguments, it leads to macro call _tusb_init_arg0() which in its own calls the tusb_rhport_init(0, NULL) with the constant argument rhport = 0
  2. The rhport itself, should be selected, based on the configuration values `CFG_TUSB_RHPORT0...
fallow birchBOT
fallow birchBOT
#

@hathach

the old tusb_init(void) use CFG_TUSB_RHPORT0_MODE/CFG_TUSB_RHPORT1_MODE to init the device stack

Currently, it doesn't make any difference which CFG_TUSB_RHPORT_* is defined, because for device stack the tusb_rhport_init(0, NULL) is being called. And here, for tud_rhport_init(rhport, &dev_init) argument rhport is always 0.

For the Host Mode it works, as we call TU_ASSERT( tuh_rhport_init(TUH_OPT_RHPORT, &host_init) );, line 70.

So, for device (if we want to ...

fallow birchBOT
#

Describe the PR
Add host driver for synopsys dwc2 (esp32-s2/s3/p4, stm32, etc..)

  • Support cpu slave and dma architecture
  • Support both OTG full speed and highspeed
  • Support Control/Bulk/Interrupt . ISO isn't tested
  • Support HS/FS/LS devices
  • Support hub with multiple devices
  • Support split control/bulk/interrupt i.e FS/LS device attached via highspeed hub
  • Following family is updated and test: stm32 f4/f7/h7, esp32-p4

Known issue: For esp32-p4, buffer DMA doees not work ...

fallow birchBOT
fallow birchBOT
#

Describe the PR
Add (partial) support for the STM32H7RSxx MCUs, see #2816.

Additional context

This has been tested with USBCDC through the USB HS peripheral of the STM32H7S3L8 on the chip's Nucleo board. I am presently unable to test the USB FS peripheral on this board, but from what I can see I expect it should work as is.

Note that this chip also has a UCPD peripheral to control USB C PD, which I have not tried to use.

fallow birchBOT
#

@hathach

For esp32-p4, buffer DMA doees not work (use slave for now). Not entirely sure why

Hint: cache synchronization is absent.

Thank you for the hint, I am a bit exausted with hcd dwc2 feature for now and not used with debugging esp32p4 (got openocd run, but one it hit breakpoint any futher steps cause it to panic), also printf in isr may also cause panic. I will call it a day for now, since it still function well with slave mode. I will come back to this later on.

fallow birchBOT
fallow birchBOT
fallow birchBOT
fallow birchBOT
#

of note, cache coherency is also a problem with my own dwc2 hcd on the rpi (need to test this PR out and see how it behaves)

in my case, i have cache management hooks in the HCD, but one of my buffers was stack allocated, and some activity on the stack caused it to get pulled back into the cache before a control-in could complete
so the ARM core saw a stale version in the cache, despite the HCD flushing the cache before the operation started

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

@HiFiPhile actually, we can also support dcache clean/invalidate as well, application only need to have the CFG_TUH_MEM_ALIGN to 64 for cache line. It can cost ram, but for some port such as broadcom bcm2711 (pi4) it does not matter. So yeah, I don't rule out option for dcache support. Though I haven't added dcahe for dwc2 yet (I think we did it for chipidea), will do later.

The buffer size also has to be multiple of cache line size, otherwise cached data will be crashed doing cache clea...

fallow birchBOT
#
[hathach/tinyusb] New branch created: hil-dwc2
fallow birchBOT
#

I'm using the following board:
https://stm32-base.org/boards/STM32F407VGT6-STM32F4XX-M.html

Board's schematic:
https://stm32-base.org/assets/pdf/boards/original-schematic-STM32F407VGT6_STM32F4XX_M.pdf

I don't use stock examples and here us a snippet with USB initialization of my project:

        long do_init(void) {
                GPIO_InitTypeDef gpio = { 0 };

                __HAL_RCC_GPIOA_CLK_ENABLE();

                //
                // NOTE: We use that code t...
fallow birchBOT
fallow birchBOT
fallow birchBOT
fallow birchBOT
#

something ive been thinking, is that a cache discard (no clean allowed) would also be of use

basically, you have buffers in 2 pools, cpu->device, and device->cpu

any time you write to a cpu->device buffer, you can do a cache clean, to flush the changes to dram, because the region is only ever written by the cpu, there is never dirty data at risk of being caught up, so you dont have to align by cache line size

any time the device is done doing dma and your informing tinyusb, you disca...

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

@rppicomidi - It's hard for me to grok the code since it is very compact and there is a lot going on. I've started the other project to try to create a simpler and dynamic version of USB Host. Ha Thach has done an AMAZING job with TinyUSB though and has had a huge impact. My small little library is primarily nowhere near close to a fraction of what he has done, but it is a small effort to understand how the rp2040 USB Host mode works and hopefully it will inspire someone else. Thank you for y...

fallow birchBOT
fallow birchBOT
#

Describe the PR

  • Add stm32f723disco with port0 as fs device (slave only), and port1 as HS host (dma)
  • Update host/device_info to compile with/without freeRTOS to build with esp32p4.
  • Add host/device_info to test host stack for stm32f723disco and esp32p4 (thanks to https://www.adafruit.com/product/5871 to mux and test both device and host on the same HS port)
  • improve hil_test.py and hil json
  • temporarily disable metro m4 with max3421 dual test since cdc printing to fast for hil...
fallow birchBOT
fallow birchBOT
#
[hathach/tinyusb] New branch created: enhance-dwc2-dcd
fallow birchBOT
fallow birchBOT
#

@hathach @HiFiPhile
Hi,
may I ask to briefly check the changes in dcd_dwc2.c and share your opinion?

I've implemented the cache synchronization for Device and tested it on esp32p4, port1 (HS).
I've tried to implement the feature and:

  • Not to break the dcd_dwc2 for other controllers (where cache calls are not necessary or not implemented)
  • Put the calls in the logically important places in the code (to be clear why do we need sync cache/mem)
  • Use the sections and memory align...
fallow birchBOT
#

Thank you for your effort, I only have a preliminary datasheet in which it mentioned cacheable and non-cacheable access for L1 cache, maybe it supports configuring memory attribute like Cortex-M MPU ?

I think this is not necessary:

    if(dma_device_enabled(dwc2)) {
      dep->doepdma = (uintptr_t)xfer->buffer;
      dsync_c2m(xfer->buffer, total_bytes);

Also we need to ensure _setup_packet is aligned to cache line and has a size of cache line

fallow birchBOT
fallow birchBOT
#

Hi @tore-espressif may I ask a question, does ESP32P4 support memory management to mark a RAM section as non-cacheable for DMA use, similar to Cortex-M MPU ?

Do you know any other scenarios, when we need to provide CFG_TUD_MEM_ALIGN which is different from attribute ((aligned(4))) ?

For Cortex-M if cache invalidate/clean is used instead of making non-cacheable section by MPU, _setup_packet has to be aligned to 32 or 64 bytes depending the core, also it's size has to be grown to ...

fallow birchBOT
#

@HiFiPhile

I think this is not necessary:

Unfortunately, it is necessary. At least in current implementation when the class driver is using class specific requests.
For example, in msc class, when we schedule the cbw, we need to sync c2m before getting the IRQ.
Otherwise, the data will be lost.

I will think, where to move the c2m call in case of OUT scheduling not to confuse developers that much.

fallow birchBOT
#

For example, in msc class, when we schedule the cbw, we need to sync c2m before getting the IRQ.
Otherwise, the data will be lost.

I don't know if ESP32P4 does speculative accesses or not, to make the cache maintenance compatible with Cortex-M7 it's more complicated (sorry I missed this case).

https://developer.arm.com/documentation/ddi0489/f/memory-system/speculative-accesses

  • Speculative cache linefills can be initiated to any Cacheable memory address, and in rare cases, regardle...
fallow birchBOT
#

@HiFiPhile ,

Thanks for the reason to double check it!

It is not necessary. What I had before - was a collateral damage because of this TODO: https://github.com/hathach/tinyusb/blob/0569188aed17d19d5954f1e1b911e989814ec93d/src/class/msc/msc_device.c#L58

If mscd cbw and csw buffers will be not the members of _mscd_itf and cache line aligned - no problem and we don't need the initial line to synchronize cache.
When I synchronize it before, I damaged the ep_out member in memory...

fallow birchBOT
fallow birchBOT
fallow birchBOT
fallow birchBOT
fallow birchBOT
#

Describe the PR
Improve dcd dwc2 driver

  • rename CFG_TUD_DWC2_DMA to CFG_TUD_DWC2_DMA_ENABLE, also add CFG_TUD_DWC2_SLAVE_ENABLE
  • separate handle_epin/out_slave/dma to make it easier to wrap around CFG_ macro
  • generic clean up
  • fix cmake build with CFLAGS_CLI not added to tinyusb target (affected DMA HIL option)
fallow birchBOT
fallow birchBOT
#

@HiFiPhile @roma-jam The ESP32-P4 uses RISC-V cores, so while there are differences, the concept is similar. Specifically, the ESP32-P4 implements RISC-V Physical Memory Attribution (PMA), which functions similarly to ARM's Memory Protection Unit (MPU).

The PMA imposes certain constraints on memory sections, such as requiring sizes to be powers of 2 and start addresses to align with the section size. Addressing these limitations in TinyUSB would require some refactoring, and certain change...

fallow birchBOT
fallow birchBOT
#

@roma-jam just merged https://github.com/hathach/tinyusb/pull/2881 . It mostly clean up and move thing around without behavioral changes, could you mind updating this PR using latest master. Then I will check this out, I am still open to cache sync. FYI, chipidea hs https://github.com/hathach/tinyusb/blob/master/src/portable/chipidea/ci_hs/dcd_ci_hs.c (device) and ehci (host) are one of those port use dcache sync for imxrt (M7) for dtcm. Maybe you can take a peek at for reference.

#

@roma-jam just merged #2881 . It mostly clean up and move thing around without behavioral changes, could you mind updating this PR using latest master. Then I will check this out, I am still open to cache sync. FYI, chipidea hs https://github.com/hathach/tinyusb/blob/master/src/portable/chipidea/ci_hs/dcd_ci_hs.c (device) and ehci (host) are one of those port use dcache sync for imxrt (M7) for dtcm. Maybe you can take a peek at for reference.

You haven't slept yet ? 🤣

I prefer to use...

fallow birchBOT
#

I have just waked up, I have an early trip to visit relative today :). I still prefer to support both, once we got dcache sync work, there will be an CFG option to disble dcache function, user can then configure their own mpu as they prefer. Otherwise we will impose the mpu requirements on user, some may not be trivial for port such as ehci/ohci since it may also need virtual to physical as well since some of them are cpu

fallow birchBOT
fallow birchBOT
#

This is a manual tweak to protect memory after the aligned _setup_packet buffer.
I have doubts, that __attribute__((aligned(x)) protects the memory after non-aligned variable, so I decided to solve it this way. At least there is nothing about that in the GCC doc.
Anyway, suggestions are welcome.

I referred to: https://gcc.gnu.org/onlinedocs/gcc/Common-Variable-Attributes.html#index-aligned-variable-attribute

For class buffers (such as mscd cbw and csw, cdc epout and `epin...

fallow birchBOT
fallow birchBOT
fallow birchBOT
fallow birchBOT
#

Got curious, checked out master and recompiled my application, and the issue is still there. However, it seems my original finding and the above reported issue may actually be a secondary effect; when I first noticed the repeating behaviour as outlined above, I was working on some Program Change related things, so my focus was on that specifically. However, looking at it again now, I see other things being repeated too, so I tried to trace further backwards, and it seems it could be related t...

fallow birchBOT
#

@roma-jam would you giving me the write permission to your fork's branch PR. I have made some updated to the PR to get it compiling and have the DMA somewhat working based on you cach hint. I think the only issue now is the class driver and the m2c that corrupt the data after variable e.g (64-8) after setup when we sync. (these space can be occuiped by other system variable). I think we can introduce an CFG DCACHE LINE SIZE and use that to make sure all buffer (dcd to class driver is place co...

fallow birchBOT
fallow birchBOT
#

Operating System

Others

Board

custom

Firmware

v0.17.0

What happened ?

When consecutively poll for CDC RX data tinyUSB hangs after some time.

How to reproduce ?

Use some echo device. Write around 100-200 bytes every few seconds. Read echoed answer by polling for 1byte after every write. During 0.5-1h of testing tinyUSB should hang.

Debug Log as txt file (LOG/CFG_TUSB_DEBUG=2)

I have no logs.

Screenshots

No response

I have checked existing issue...

fallow birchBOT
#
[hathach/tinyusb] New branch created: feature/esp32p4_dma_cache_syncronization
fallow birchBOT
fallow birchBOT
fallow birchBOT
fallow birchBOT
#
[hathach/tinyusb] New branch created: esp32p4-dma
fallow birchBOT
#

Describe the PR
Follow up to #2883 #2877 to support P4 DMA with cache sync. This PR make sure the usb/dma buffer occupies at least the whole cache line (for larger buffer with odd number e.g 100, it isn't have correct padding just yet). but this cover most of the case.
hil test with CFG_TUD_DWC2_DMA_ENABLE=1 is enabled for p4, and it seems to work well cdc/msc/hid

@roma-jam @HiFiPhile let me know what you think, we can make the rest of driver to follow these dcache line padding. For ...

fallow birchBOT
#

Looks good for me, how about add something like this to manage odd size:

#define EP_BUFFER_SIZE  100
#define CACHE_LINE_SIZE 64

#define BUFFER_CACHE_ALIGNED(name, size) \
    union { \
        uint8_t name[size]; \
        uint8_t TU_XSTRCAT(dcache_padding_, _TU_COUNTER_)[(size / CACHE_LINE_SIZE + 1) * CACHE_LINE_SIZE]; \
    };


typedef struct {
    uint32_t dummy1;
    BUFFER_CACHE_ALIGNED(ep_in, EP_BUFFER_SIZE);
    uint8_t dummy2;
} intf_t;
fallow birchBOT
#

I did exclude the mscd buffers from the interface struct exactly not to bother about the odd size. (here is the link to refactoring in mscd: https://github.com/espressif/tinyusb/pull/37/commits/77797984429b3a35a2c08f112f4eae99397f10a0 to explain better what am I talking about)
At least for cdc and mscd buffers it seems doable. Probably, for other device classes also, haven't check yet.

Or do we want buffers to be in the interface struct?

But in general, it is strange to keep the whole...

#

hil test with CFG_TUD_DWC2_DMA_ENABLE=1 is enabled for p4, and it seems to work well cdc/msc/hid
Cool! Glory to the tests!

Also, regarding the note:

Note: to enable DMA, CFG_TUD_DWC2_DMA_ENABLE=1 (default 0) must be set in tusb_config.h or CFLAGS.

Now a situation when both CFG_TUD_DWC2_DMA_ENABLE = 0 and CFG_TUD_DWC2_SLAVE_ENABLE = 0 is possible and this could be a bit tricky, if in this case the handle_ep_irq is like that:

static void handle_ep_irq(uint8_t rhp...
#

@roma-jam does not solve the issue, with high optimization, gcc will realize that cbw/csw is only 31/13 bytes, it will put other stuff/variable at the address after those, then we could risk corrupt those memory when do memory -> cache. So I think we need to make an union to make sure the whole cache line is occuiped and gcc can't allocate that for other.

CFG_TUD_MEM_SECTION CFG_TUSB_MEM_ALIGN tu_static mscd_interface_t _mscd_itf;
CFG_TUD_MEM_SECTION CFG_TUSB_MEM_ALIGN tu_static msc...
#

hil test with CFG_TUD_DWC2_DMA_ENABLE=1 is enabled for p4, and it seems to work well cdc/msc/hid

Cool! Glory to the tests!

Also, regarding the note:

Note: to enable DMA, CFG_TUD_DWC2_DMA_ENABLE=1 (default 0) must be set in tusb_config.h or CFLAGS.

Now a situation when both CFG_TUD_DWC2_DMA_ENABLE = 0 and CFG_TUD_DWC2_SLAVE_ENABLE = 0 is possible and this could be a bit tricky, if in this case the handle_ep_irq is like that:

static void handl...
fallow birchBOT
#

@HiFiPhile your suggestion look great, maybe we should name it TUSB_EP_BUFFER() to declare buffer that use for endpoint transfer. Will try to sort this out.

With a little modification the macro can take care of other variable types, reduce line count back to 1:

#define TUD_BUF_DEF(_var, _size) \
    union { \
        CFG_TUD_MEM_ALIGN _var; \
        uint8_t TU_XSTRCAT(dcache_padding_, _TU_COUNTER_)[(_size / CACHE_LINE_SIZE + 1) * CACHE_LINE_SIZE]; \
    };

typedef struct {...
fallow birchBOT
#

@HiFiPhile your suggestion look great, maybe we should name it TUSB_EP_BUFFER() to declare buffer that use for endpoint transfer. Will try to sort this out.

With a little modification the macro can take care of other variable types, reduce line count back to 1:

#define TUD_BUF_DEF(_var, _size) \
    union { \
        CFG_TUD_MEM_ALIGN _var; \
        uint8_t TU_XSTRCAT(dcache_padding_, _TU_COUNTER_)[(_size / CACHE_LINE_SIZE + 1) * CACHE_LINE_SIZE]; \
    ...
fallow birchBOT
#

Hi all, seems that I'm later for the party, I prepared a sum-up of the discussion, I will leave it here if anyone is ever interested in this thread:

Summary

  1. When the CPU accesses buffers in memory, we must:
    • Either perform explicit cache synchronization.
    • Or access the buffers via non-cacheable addresses (or place them in non-cacheable memory).
  2. Both approaches work for ESPs.
  3. In both cases, the buffer's address and size must be aligned to the cache line s...
fallow birchBOT
fallow birchBOT
fallow birchBOT
#

NCM class needs to add a ep_notif_buf for ncm_notify_connected and ncm_notify_speed_change, I totally forgot that...

Ah thanks, I overlook that as wel, making update now

Do you want me to also update audio class ?

Yeah sure, audio is too complicated for me just now. But maybe wait for me to merge this first (soon), then it will be easier for you (to prevent conflict).

fallow birchBOT
#

Hi all, seems that I'm late for the party, I prepared a sum-up of the discussion, I will leave it here if anyone is ever interested in this thread:

Not at all, there is on-going follow up for dma (device stack), there will be a host PR afterwards

Summary

  1. When the CPU accesses buffers in memory, we must:

    • Either perform explicit cache synchronization.
    • Or access the buffers via non-cacheable addresses (or place them in non-cacheable memory).
  2. Both ...

fallow birchBOT
#
[hathach/tinyusb] New branch created: change-dcd_dcache_return-to-bool
#

This pull request includes multiple changes aimed at improving the handling of data cache (DCache) operations and configuration. The most important changes involve the introduction of new macros for host DCache declarations, changes to DCache-related function signatures, and the unification of DCache line size configurations.

DCache Handling Improvements:

fallow birchBOT
fallow birchBOT
#
[hathach/tinyusb] New branch created: esp32p4-host-dma
#

Describe the PR

Copilot

This pull request includes several changes across multiple files to improve memory alignment and buffer handling, particularly for USB/DMA operations. The changes also include some code clean-up and refactoring for better readability and maintainability.

Memory Alignment and Buffer Handling Improvements:

  • [examples/host/cdc_msc_hid_freertos/src/msc_app.c](diffhunk://#diff-c764769fa58349082fb52da8f38d57ad8366621781f9399f12b3b3a32384df57L28-R31...
fallow birchBOT
fallow birchBOT
#
[hathach/tinyusb] New branch created: chore-dwc2
fallow birchBOT
fallow birchBOT
fallow birchBOT
#
[hathach/tinyusb] New branch created: circleci-iar
fallow birchBOT
#

as mentioned in esp32p4 cache, I would still wnat to keep the dcache clean/invidate. IMO, it does not hurt performance but actual improve it (depending on the usage). As one of the main difference between M7 and M3/M4 is actually the cache (data + instruction). M7 can run insanely fast (up to 1Ghz), and can perform lots of computattion on data e.g video before passing it to USB/DMA for transfer.
@HiFiPhile If you are busy, I can make pull and make the change myself later on when I got time.

fallow birchBOT
#

as mentioned in esp32p4 cache, I would still want to keep the dcache clean/invidate. IMO, it does not hurt performance but actual improve it (depending on the usage).

I was thinking about add back cache support for M7 core but didn't have the time. Secondary M4 core uses a customized cache controller which is more complicated.

As one of the main difference between M7 and M3/M4 is actually the cache (data + instruction). M7 can run insanely fast (up to 1Ghz), and can perform lots of...

fallow birchBOT
fallow birchBOT
#

@HiFiPhile thanks for the detailed test ersult, though this may not reflect all usage. Dcache clean/invalidate as any solution does introduce overhead, in a scenario when user need to do heavy computation on memory such as encrypting a large block of bytes and/or lots of video/dsp processing. It would outweight the overhead. As general rule of thumb for cpu world, I still think the more cache the better/faster in general.

fallow birchBOT
fallow birchBOT
#

Anyway for most applications TCM is used as the buffer, as the default linker script.

In a later test when both buffer are inside TCM I got a result of less than 500 cycles, while testing from OCRAM without cache clean still cost 900 cycles. I'm curious to find out why cache is slower than TCM in this case.

I have no idea though, tbh I am new to these dcache as well. These mpu configuration is also bit complicated for me :)

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

@HiFiPhile I found the errata ERR050396 that says what is necessary to do if you intend to use the M7's TCM as the destination for USB writes. I didn't understand if this is already done or not

It's good to know that, it's not fixed in the dcd driver but with a quick search it's included in kSDK:
https://github.com/hathach/mcux-sdk/blob/e8902892850385d8fb99e01b785852df4691604b/devices/MIMXRT1176/system_MIMXRT1176_cm7.c#L125
https://github.com/hathach/mcux-sdk/blob/e8902892850385d8f...

fallow birchBOT
fallow birchBOT
fallow birchBOT
fallow birchBOT
fallow birchBOT
fallow birchBOT
fallow birchBOT
#
[hathach/tinyusb] New branch created: update-h5-bsp
fallow birchBOT
#

Hi @hathach!

The following patch break USB (in particular the CDC+UAC2 composite device example) on a Pico 2 board.

commit 7f61a5a43b4637afc323f6e63cc59330f1b1e5a6
Author: hathach <thach@tinyusb.org>
Date:   Thu Nov 28 15:56:47 2024 +0700

    made change per reviews, remove dcd_edpt_close(), rename and move thing around

 src/common/tusb_common.h                     |   1 +
 src/portable/raspberrypi/rp2040/dcd_rp2040.c | 167 +++++++++------------------
 2 files chang...
fallow birchBOT
fallow birchBOT
fallow birchBOT
fallow birchBOT
#

There were some recent changes in the rp2040 code adding ISO endpoints, so I had to tweak this PR a little bit to carry over the null-pointer dereference checks. The main change is that ep->configured = true; in dcd_rp2040.c is now set in the hw_endpoint_init function so it is set when either type of endpoint is initialized. This is similar to what happens in hcd_rp2040.c.

Thinking about it more, I should probably split the locking implementation from the null-pointer deref checks/...

fallow birchBOT
fallow birchBOT
fallow birchBOT
#

Related area

Causes the last endpoint to be unusable。

Hardware specification

dwc:Number of Device Endpoints (NumDevEps) Indicates the number of device endpoints supported by the core in Device mode in addition to control endpoint 0. The range of this field is 1-15.

Is your feature request related to a problem?

When there are 8 endpoints, endpoint 0 is included. At this time, there are only 7 defined endpoints, resulting in the last endpoint being unusable.

Describe the s...

fallow birchBOT
fallow birchBOT
#
[hathach/tinyusb] New branch created: fix-dwc2-epcount
fallow birchBOT
#
[hathach/tinyusb] New branch created: skip-iar-on-fork
fallow birchBOT
#

Requirements

To change the USB device function or re-initialize the tinyusb stack there should be an option to teardown the lower layer (disable the phy and flush the registers).

The public API for init tinyusb stack for USB Device is tusb_init() for versions = 0.17.

Teardown feature should be implemented as a public API for Device and Host role and provide the possibility to use the teardown call in both (legacy and new API way)

Description

The same mechanism for legacy...

fallow birchBOT
#
[hathach/tinyusb] New branch created: add-ra8m1
fallow birchBOT
fallow birchBOT
#

Describe the PR

  • Update RA family to use fsp v5.6.0
  • added smart configurator (rasc) support for board: clock/pin config, linker script
  • add ra8m1_ek support
    • LED and button work
    • usbfs works though msc enumeration is kind of slow
    • usbhs does not work, probably due to clock/setup/usbip init. Will fix later when having time.
fallow birchBOT
ripe isle
#

hey @cursive bone I have been working off and on to port CircuitPython to an STM32L433-based board. I've gotten everything to compile but it's crashing on startup and while stepping through, it appears to be hitting a hard fault in tinyusb in the tusb_inited function, specifically

bool tud_inited(void) {
  return _usbd_rhport != RHPORT_INVALID;
}

I take this to mean that my port config is invalid, but I am not suere where to go from here and wonder if you could point me in the right direction.

robust walrus
#

Is it an assertion failure?

ripe isle
#

@robust walrus do you mean the VID/PID?

#

yeah it's happening here:

 #if CFG_TUD_ENABLED
  ret = ret || tud_inited();
  #endif
robust walrus
#

Nope, device instance number

ripe isle
#

ah, I don't recall setting anything explicitly in the port, or seeing that set in others. Where would I set that?

robust walrus
#

I’ll be on my laptop later

ripe isle
robust walrus
ripe isle
#

@robust walrus I think I removed an essential config flag that led to that issue and I believe I am past it at the moment. Now dealing with an error on flash erase on the part but I think I am unblocked for now

robust walrus
#

nice! 🎉

fallow birchBOT
fallow birchBOT
fallow birchBOT
fallow birchBOT
fallow birchBOT
#

I tried to compile and flash both with cmake and make with M4=1, but somehow flashing doesn't seems to get the mcu running at all. I will only run the last CM7 binaries. If I erase the chip and only flash the cm4 image, mcu won't boot at all. Maybe I miss something.

Hum... What happens if you erase the chip, then in Jlink commander load the binary and go ?

fallow birchBOT
#

I tried to compile and flash both with cmake and make with M4=1, but somehow flashing doesn't seems to get the mcu running at all. I will only run the last CM7 binaries. If I erase the chip and only flash the cm4 image, mcu won't boot at all. Maybe I miss something.

Hum... What happens if you erase the chip, then in Jlink commander load the binary and go ?

Here is my log, even though jlink report that loading file is OK. It may not, normally when erase/flashing, there is a p...

fallow birchBOT
#

normally when erase/flashing, there is a progresss windows pop-up. That only appear with normal M7 build. I guess it is not actually flashed at all

Since M4 is linked as a RAM image maybe the popup is only displayed during ROM flashing, I'll take a look later.

oh it runs from SRAM ? I miss that, do i need any code running on M7 first e.g blinky, or change any boot switch ?

fallow birchBOT
fallow birchBOT
#

Operating System

Linux

Board

N/A

Firmware

Any example will not build.

What happened ?

I am working on an M0 device that is utilizing a Mentor Graphics USB controller. When trying to compile any of the examples the compilation fails highlighting that taking an address of packed struct can result in an unaligned memory access. Specifically for M0 unaligned memory accesses will result in hard faults.

I have been able to get the a subset of the examples working, but I ha...

fallow birchBOT
#

In fact it's more complicated to run M4 core:

  • 1st way is burn the fuse to set M4 core as the startup core instead of M7 which is irreversible

  • 2nd way:

  1. Put M7 core in a while loop. I tried simply erase the flash but M7 core will enter ROM bootloader with a device shown as NXP SEMICONDUCTORS SE Blank RT Family - HID and interfere with M4 core.
  2. I suspect J-Link is buggy and can't reset M4 core correctly, after loading the file loadfile rt1170_cm4/cdc_dual_ports.hex, I have ...
fallow birchBOT
#

In fact it's more complicated to run M4 core:

  • 1st way is burn the fuse to set M4 core as the startup core instead of M7 which is irreversible
  • 2nd way:
  1. Put M7 core in a while loop. I tried simply erase the flash but M7 core will enter ROM bootloader with a device shown as NXP SEMICONDUCTORS SE Blank RT Family - HID and interfere with M4 core.
  2. I suspect J-Link is buggy and can't reset M4 core correctly, after loading the file `loadfile rt1170_cm4/cdc_dual_ports...
fallow birchBOT
fallow birchBOT
fallow birchBOT
#

This is still broken despite merges ISO API changes #2847

Pi Pico Device, Pico-SDK 2.1.0, Results are the same on multiple windows hosts as well as linux hosts

Output (CFG_TUSB_DEBUG=1) is as follows:

Headset running
Get channel 0 volume range (-50, 0, 1) dB
Get channel 1 volume range (-50, 0, 1) dB
Get channel 2 volume range (-50, 0, 1) dB
Clock get 2 freq ranges
Range 0 (44100, 44100, 0)
Range 1 (48000, 48000, 0)
Get channel 1 volume 0 dB
Get channel 1 mute 0
Get chann...
fallow birchBOT
#

Describe the PR
add hid stylus pen device.
this works with android, for bypassing that absmouse does not support android.
note that, to hide cursor on android for every touch signal, find cursor option in android settings menu.

references:

  1. https://stackoverflow.com/questions/28536602/hid-digitizer-descriptor-doesnt-perform-well-with-landscape-orientation
  2. https://github.com/jonathanedgecombe/absmouse/blob/master/src/AbsMouse.cpp
fallow birchBOT
fallow birchBOT
#

Operating System

MacOS

Board

Custom PIC32MM board

Firmware

Main program

examples/uac2_speaker_fb with a few tweaks:

  • Fixed sample rate: 192000
  • Bytes per sample: 2
  • Max EP IN size for all AS: 772
  • EP_OUT_SW_BUF_SZ: 772*4

Globals

static int32_t spk_buf[CFG_TUD_AUDIO_FUNC_1_EP_OUT_SZ_MAX / 4 * 2];
static uint16_t spk_buf_chunk_size = 768;
static volatile uint8_t spk_buf_idx = 0;
static volatile uint8_t buffer_changed = 0;

static inline ui...
fallow birchBOT
fallow birchBOT
#
[hathach/tinyusb] New branch created: release-0.18.0
fallow birchBOT
#
[hathach/tinyusb] New tag created: 0.18.0
#

can you try to see if this can be fixed by adding TU_ATTR_ALIGNED(4) to the struct around line 76

typedef struct
{
   TU_ATTR_ALIGNED(4) tusb_control_request_t setup_packet;
  uint16_t     remaining_ctrl; /* The number of bytes remaining in data stage of control transfer. */
  int8_t       status_out;
  pipe_state_t pipe0;
  pipe_state_t pipe[2][TUP_DCD_ENDPOINT_MAX-1];   /* pipe[direction][endpoint number - 1] */
  uint16_t     pipe_buf_is_fifo[2]; /* Bitmap. Each bit means ...
fallow birchBOT
#

Describe the PR

  • Adds a README that describes current state and caveats
  • Change license header and credit people accordingly
  • Let the user deal with shared GPIO/VBUS pin
  • Fix incorrect (missing) bus resume interrupt handling
  • Improve remote wakeup timekeeping
  • Implement dcd_deinit()
  • Fix incorrect usage of the UOWN bit after EP0 timeout/stall [most important]

Additional context
See the README.md file for more info.

#

Operating System

MacOS

Board

ESP32-S3-PICO-1, custom PCB

Firmware

Using tinyusb through the esp_tinyusb component. These are the relevant callbacks defined in my code:

void tud_vendor_tx_cb(uint8_t itf, uint32_t sent_bytes) {
    ESP_LOGI(TAG, "tx cb: %lu", sent_bytes);
}

void tud_vendor_rx_cb(uint8_t itf, uint8_t const *buffer, uint16_t bufsize) {
    ESP_LOGI(TAG, "%.*s", bufsize, buffer);
    tud_vendor_read_flush();
}

/* Handle a couple request bytes spec...
fallow birchBOT
#

connected computer is sending 'BULK in' packets

IN packets are sending from the device to host, in opposite of OUT packet.

https://www.beyondlogic.org/usbnutshell/usb4.shtml#Bulk

What you see URB_BULK in is only the request that the host is ready to receive (sending IN token).

Without sending anything with tud_vendor_write() tud_vendor_write_flush() of cause the sending complete callback tud_vendor_tx_cb() wont be called.

fallow birchBOT
#

The problem completely disappears when I enable CFG_TUSB_DEBUG.

That's quiet interesting, the opposite case will be easier explained.

What's inside your volume callback (tud_audio_feature_unit_set_request), is there anything needs extra processing time ?

This situation only happens when a 1000Hz report rate USB mouse is connected to the same hub and the mouse is being used for dragging the volume slider.

My surmise that you have a STT (single Transaction Translator) hub, where...

#

The problem completely disappears when I enable CFG_TUSB_DEBUG.

That's quiet interesting, the opposite case will be easier explained.

What's inside your volume callback (tud_audio_feature_unit_set_request), is there anything needs extra processing time ?

It's the same as the example, that is, merely overwriting the values in the volume and mute arrays. Nothing else is done.

This situation only happens when a 1000Hz report rate USB mouse is connected to the same...

fallow birchBOT
#

I think an analyser is needed to see what happened.

Maybe there is something related to bus time allocation and incomplete ISO transfer. Ideally 2 FS ISO packets have 1ms interval, if the bus is occupied the interval could be altered. (On a poorly Intel Gen11 PC I saw 20us between 2 HS ISO packets instead of 125us, wondering why my DAC keeps popping)

At least for DWC2 DCD a special sequence is needed when incomplete IN/OUT ISO transfer happens.

fallow birchBOT
#
[hathach/tinyusb] New branch created: board-doc
fallow birchBOT
fallow birchBOT
#

Operating System

Linux

Board

STM32L4R5 Nucleo-144,STM32F412 Nucleo-144

Firmware

When the host stack is activated, it always happens.

Tested with GCC, IAR, Keil.

gcc version 13.3.1 20240614 (Arm GNU Toolchain 13.3.Rel1 (Build arm-13.24))

What happened ?

I've encountered an issue with the DWC2 Host stack where device removal events are not correctly detected. This problem arises because the HPRT_CONN_DETECT bit in the hprt register is not set when the conn_status ch...

fallow birchBOT
#

Some more detailed information about this bug:

  1. Cheap ass hubs are required
  2. Must have a specific USB mouse or its wireless receiver plugged to the same hub(in this case the Keychron M6, which is very likely to have a poorly implemented USB stack)
  3. Must be Mac mini M4 as host, not sure if other M1-M4 Macs are affected, but Intel ones are fine

The problem does not go away completely when debugging is enabled, it'll still stuck for around 5secs and then reply the control request. It can...

fallow birchBOT
fallow birchBOT
fallow birchBOT
fallow birchBOT
#

Operating System

Windows 11

Board

all

Firmware

n/a

What happened ?

Tinyusb appears to expect symbol CFG_TUSB_MCU to be set via command line or some make file as a #define for it isn't present in the source files. This may be fine when compiling from a shell prompt via Linux but causes issues when compiling the code as I do via an IDE in Windows (specifically, Segger Embedded Studio).

In the project settings I have a CFG_TUSB_MCU=OPT_MCU_STM32F4 entry that gets m...

fallow birchBOT
#

Describe the PR

This fix does the following:

  1. Fix the CodeQL alert by changing the loop variable type to use int.
  2. Explicitly limiting the loop to MAXIMUM_TOTAL_DRIVER_COUNT.
  3. Sets the originally named variable to the loop variable (but c-style cast to type uint8_t).

In addition, because there was not previously any code to ensure that TOTAL_DRIVER_COUNT would be in the expected range of [0x01..0xFF], added a TU_ASSERT() at the appropriate location to ensure this ...

fallow birchBOT
fallow birchBOT
#

… MCXA156 and N947 and need this in place.

It is similar to A153 but with FPU,SIMD enable int the CM33 core. It has much more flash/ram/peripherals and uses the chipidea FS controller.

I repointed the entry in the get_deps script to use NXP MCU repo. The existing current code couldn't build as the MCX Xpresso SDK was old.

For now, I put a copy of fsl_spc.c in the drivers folder for the mcx family. None of the ports could build with the version in the mcux github sdk. The sdk on g...

#

@hathach

1.) I saw the ci failed on LPC55. It will need to have some minor updates to the make file as the structure of the mcuxpresso sdk is a little different. I can make this change if it is OK for us to point to the nxp github repo

2.) the ci also failed on the mcxn947-brk board. This board is now deprecated and used prototype silicon. NXP never release the board publicly. I can patch the make file to be like the FRDM board, we can delete the board. The FRDM-MCXN947 is...

fallow birchBOT
#

Related area

device stack?

Hardware specification

ESP32-S3

Is your feature request related to a problem?

I am working on a device where most of the time, the ESP32 is a USB serial device, but then sometimes, it needs to change into a MSC device for a while, and then back to serial again.
This is to allow users to upload config files, which they will only do sometimes, and which should not be active all the time.
I see the example in the esp-idf for composite cdc and msc dev...

fallow birchBOT
fallow birchBOT
#
MWP

Operating System

Others

Board

Custom

Firmware

Custom STM32H7A3 based device build.

What happened ?

When CFG_TUD_MEM_DCACHE_ENABLE is set, dwc2_dcache_clean() function is missing.

How to reproduce ?

Build a project using TinyUSB for STM32H7xx with CFG_TUD_MEM_DCACHE_ENABLE set.

Debug Log as txt file (LOG/CFG_TUSB_DEBUG=2)

N/A

Screenshots

No response

I have checked existing issues, dicussion and documentation

  • [X] I confirm I have checked existi...
fallow birchBOT
fallow birchBOT
#
MWP

I cannot :(

It's pretty clear though.
It seems the data cache handling functions were added for the esp32 target, but were not for the stm32.

A quick fix for the problem is adding the following to the end of dwc2_stm32.h

TU_ATTR_ALWAYS_INLINE static inline bool dwc2_dcache_clean(const void* addr, uint32_t data_size) {
  data_size = round_up_to_cache_line_size(data_size);
  SCB_CleanDCache_by_Addr((uint32_t*)addr, data_size);
  return true;
}

TU_ATTR_ALWAYS_INLINE static in...
#

Operating System

Others

Board

Any build using src/class/usbtmc/usbtmc_device.c class driver

Firmware

CodeQL reported:

Local variable address stored in non-local memory

While this alert is only a warning, further investigation suggests this
may be a latent stack corruption bug, and whether the corruption occurs
may be affected by compiler optimization settings (or prevented when
compiled with other optimization settings). Thus, this appears to be
a subtle bug tha...

fallow birchBOT
#

Hi @marchingband,

The esp-idf is using the esp-tinyusb wrapper, which provides the configuration and and other things for the classes and simplify the final usage.
In the example for the composite device both classes must be initialized.

For the MSC device there is also a way to insert and remove the media (without a media your device will be represented in the system as a SD card reader without a card). But for t...

fallow birchBOT
fallow birchBOT
#

@hathach May I ask you to check why pre-commit is failing please?

unit-test................................................................Failed
- hook id: unit-test
- exit code: 1

🚧 Loaded project configuration from working directory.
 > Using: /home/runner/work/tinyusb/tinyusb/test/unit-test/project.yml
 > Working directory: /home/runner/work/tinyusb/tinyusb/test/unit-test
/home/runner/work/tinyusb/tinyusb/test/unit-test/vendor/ceedling/vendor/diy/lib/diy.rb:6: warning: al...
fallow birchBOT
#

Can't disagree more with this assessment. The next failure I find in SES' symbol highlighting will be the first one. You can sit there and add & remove symbols on the fly and the highlighting will correctly update even if you don't save the file.

Also, if you read what was written you will find absolutely NO mention of the highlighting, so it's not clear why that was even brought up. All of the points I raised have nothing to do with how SES or any IDE is highlighting code.

Once aga...

#

Once again, the header path for dwc2_stm32.h doesn't include tusb_option.h

dwc2_stm32.h is used by dwc2_common.h in which tusb_option.h is included:
https://github.com/hathach/tinyusb/blob/2495563600f1cd2220d740895fad701dd48f1fb6/src/portable/synopsys/dwc2/dwc2_common.h#L30

so if files using that header are compiled before a file invoking tusb_option.h, the OPT_MCU symbols will not be defined causing those files to compile incorrectly.

Header files should NOT be compiled d...

fallow birchBOT
#

Operating System

Others

Board

All (portable)

Firmware

class/hid/hid_device.c

tud_hid_set_report_cb() is invoked in two contexts, with inconsistent argument usage:

  • From hidd_control_xfer_cb(). Before invoking the callback, the caller removes the first byte of the buffer IF it matches the HID report ID in the control request.
  • From hidd_xfer_cb(). In this case, the caller leaves the whole buffer intact unconditionally and passes HID report ID == 0.

It's up to th...

fallow birchBOT
#

A way to fix this without breaking any existing application code might be to layer in a new "version 2" callback:

void tud_hid_set_report_cb2(uint8_t instance, int report_id, hid_report_type_t report_type, uint8_t const* buffer, uint16_t bufsize);

hidd_control_xfer_cb() would be changed to call the new callback, passing in the report ID from the control request, and NOT stripping the report ID prefix byte from the buffer.

hidd_xfer_cb() would also be changed to call the new callbac...

#

One more note: src/class/hid/hid_device.c incorrectly compares HID report ID bytes to HID_REPORT_TYPE_INVALID at lines 302 and 327 (as of 090964c). This is a type clash that the compiler doesn't catch, thanks to automatic coercion to int: HID_REPORT_TYPE_INVALID is a member of enum hid_report_type_t, which is a Control Report element; report IDs are a separate namespace conceptually. This accidentally work...

fallow birchBOT
#

I was testing your changes to the dcd_rp2040.c and noticed that the audio is not working after your correctins. I could trace down the issue to your version of the following method

// New API: Configure and enable an ISO endpoint according to descriptor
bool dcd_edpt_iso_activate(uint8_t rhport, tusb_desc_endpoint_t const * ep_desc) {
  (void) rhport;
  const uint8_t ep_addr = ep_desc->bEndpointAddress;

  // Fill in endpoint control register with buffer offset
  struct hw_en...
fallow birchBOT
#

There is one bug(?) where the driver does not respect tud_msc_test_unit_ready_cb at initialization time.
I can set it to always return false and it still takes the drive. This only happens once, during init, later it respects tud_msc_test_unit_ready_cb.
I setup a workaround to just always unmount from the MSC following initialization, but I think it will be pretty common for user to want to initialize the USB driver at boot (because they are doing a composite device for example), but ...

fallow birchBOT
#

Thank you for the clarifications.

The reason you're seeing that apparent "error" is that even though CFG_TUSB_MCU=OPT_MCU_STM32C0 is set, none of the OPT_MCU symbols exist at that stage. The preprocessor will replace CFG_TUSB_MCU with OPT_MCU_STM32C0, so the expression you have highlighted there equates to "#if OPT_MCU_STM32C0 == OPT_MCU_STM32F1". As none of the OPT_MCU symbols exist yet, this is "#if (not defined) == (not defined)", so the highlighting is correct. If you add `#include ...

fallow birchBOT
#

Operating System

Windows 10

Board

Custom design

Firmware

Modified uac2_headset example

What happened ?

I've noticed that whenever only one sampling frequency is available in sample_rates, Windows stops asking for current frequency and this is the only way(to my knowledge) to get sample_rate_tx initialized which leads to no flow control working(due to uninitialized sample_rate_tx.

How to reproduce ?

Configure a single frequency in sample_rates.

Debug L...

fallow birchBOT
fallow birchBOT
fallow birchBOT
fallow birchBOT
fallow birchBOT
#

Operating System

Linux

Board

pico

Firmware

don't know

What happened ?

/pico-sdk/lib/tinyusb/src/tusb_option.h:238:12: fatal error: tusb_config.h: No such file or directory
238 | #include "tusb_config.h"

How to reproduce ?

i include this:
#include
#include "pico/stdlib.h"
#include "hardware/gpio.h"
#include "bsp/board.h"
#include "tusb.h"

Debug Log as txt file (LOG/CFG_TUSB_DEBUG=2)

In file included from /mnt/e/Genoce/pico/pico-sdk/lib/tinyusb/src/...

fallow birchBOT
#

Related area

VENDOR Driver

Hardware specification

rp2040, but probably relevant to all

Is your feature request related to a problem?

Yes, I can't seem to be able to handle SOF interrupts using the VENDOR driver.

Describe the solution you'd like

I'd like the tud_sof_cb SOF callback to be called when using the VENDOR driver. It seems one just needs to add function pointer to https://github.com/hathach/tinyusb/blob/707a633de3b4f47cf00396e16adb7946fa127880/src/device/usb...

fallow birchBOT
fallow birchBOT
fallow birchBOT
#

Description

This PR addresses a potential buffer overflow issue in the tud_msc_read10_cb function. Previously, the function did not validate whether the combination of offset and bufsize exceeded the disk block size, which could result in out-of-bounds memory access during the memcpy operation.

Changes

Added a validation check to ensure offset + bufsize does not exceed the defined DISK_BLOCK_SIZE. If this condition is violated, the function now returns -1.

fallow birchBOT
fallow birchBOT
#

Operating System

Linux

Board

stm32h750

Firmware

dcd_dwc2.c、hcd_dwc2.c

What happened ?

The DWC2 driver accesses registers with unaligned access, which leads to exceptions.

How to reproduce ?

It is reproducible on the STM32H750 board.

Debug Log as txt file (LOG/CFG_TUSB_DEBUG=2)

no

Screenshots

x

I have checked existing issues, dicussion and documentation

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

Is there a way to allow unaligned access on Cortex-M7?

Unaligned access is enabled by default on H7 and stock examples don't have this issue. I think you have misconfigured MPU and disabled unaligned access.

Please add details about your full code, where did exception occurred, compiler used.

Yes, I tried disabling the Cortex-M7 unaligned access exception, but it didn't work. This is the MPU configuration code:

void MPU_Config(void)
{
    MPU_Region_InitTypeDef...
#

Is there a way to allow unaligned access on Cortex-M7?

Unaligned access is enabled by default on H7 and stock examples don't have this issue. I think you have misconfigured MPU and disabled unaligned access.

Please add details about your full code, where did exception occurred, compiler used.

For example, the code dwc2->hprt_bm.speed will inevitably trigger an unaligned access exception on Cortex-M7. I don't know how to allow unaligned access. The compiler being used is...

#

Is there a way to allow unaligned access on Cortex-M7?

Unaligned access is enabled by default on H7 and stock examples don't have this issue. I think you have misconfigured MPU and disabled unaligned access.
Please add details about your full code, where did exception occurred, compiler used.

For example, the code dwc2->hprt_bm.speed will inevitably trigger an unaligned access exception on Cortex-M7. I don't know how to allow unaligned access. The co...

fallow birchBOT
fallow birchBOT
fallow birchBOT
#

I've successfully reproduced the issue by manually adding , since I don't use Keil and both GCC and IAR are not affected.asm("LDRH R0, [R0, #0x441]");

I think it's a armclang bug: https://developer.arm.com/documentation/ka004594/latest/

Version prior to 6.16 doesn't access volatile bit-field using an access width appropriate to the type of its container.

I was wrong about the MPU, since peripheral address space (0x40000000-0x5FFFFFFF) is marked as Device memory to...

#

I've successfully reproduced the issue by manually adding , since I don't use Keil and both GCC and IAR are not affected.asm("LDRH R0, [R0, #0x441]");

I think it's a armclang bug: https://developer.arm.com/documentation/ka004594/latest/

Version prior to 6.16 doesn't access volatile bit-field using an access width appropriate to the type of its container.

I was wrong about the MPU, since peripheral address space (0x40000000-0x5FFFFFFF) is marked as Device memory to...

#

I've successfully reproduced the issue by manually adding , since I don't use Keil and both GCC and IAR are not affected.asm("LDRH R0, [R0, #0x441]");

I think it's a armclang bug: https://developer.arm.com/documentation/ka004594/latest/

Version prior to 6.16 doesn't access volatile bit-field using an access width appropriate to the type of its container.

I was wrong about the MPU, since peripheral address space (0x40000000-0x5FFFFFFF) is marked as Device memory to...

#

In theory, this assembly instruction should trigger an unaligned access exception in both GCC and IAR compilers, unless GCC and IAR do not generate the LDRH instruction for bit-field accesses.

Yes, they don't generate LDRH for unaligned access as speed is uint32_t :

https://github.com/hathach/tinyusb/blob/2495563600f1cd2220d740895fad701dd48f1fb6/src/portable/synopsys/dwc2/dwc2_type.h#L413

image

#

In theory, this assembly instruction should trigger an unaligned access exception in both GCC and IAR compilers, unless GCC and IAR do not generate the instruction for bit-field accesses.LDRH

Yes, they don't generate for unaligned access as speed is uint32_t :LDRH

https://github.com/hathach/tinyusb/blob/2495563600f1cd2220d740895fad701dd48f1fb6/src/portable/synopsys/dwc2/dwc2_type.h#L413

IAR: ![image](https://private-user-images.githubusercontent.com/4375114/40235...

fallow birchBOT
fallow birchBOT
#

Related area

common includes

Hardware specification

hardware independent

Is your feature request related to a problem?

I'm using TinyUSB with a custom embedded stack which implements its own printf and associated functions.

TinyUSB includes stdio.h in src/common/tusb_common.h. This results in multiple declarations of sprintf(), which results in compile time errors.

It is unclear to me which parts, if any, of stdio.h are used by tinyusb. With the basic setup of tinyUSB ...

fallow birchBOT
fallow birchBOT
#

Operating System

Linux

Board

Adafruit Metro ESP32-S3 and other ESP32-S3 boards

Firmware

Works: CircuitPython 9.2.1 using TinyUSB at 5217cee
Problem: CircuitPython 9.2.2 using TinyUSB at eabf68bd9 (and also tip of master, right now 2495663)

What happened ?

USB devices do not appear when an ESP32-S3 board running CircuitPython 9.2.2 is plugged directly into a host computer port. When a USB hub is interposed it works.

This seems like some kind of timing problem.

I ...

fallow birchBOT
fallow birchBOT
fallow birchBOT
#

Does -mno-unaligned-access fix the issue ? https://developer.arm.com/documentation/dui0774/l/Compiler-Command-line-Options/-munaligned-access---mno-unaligned-access

This can solve the problem of unaligned access, but the return value is incorrect, for example, dwc2->hprt_bm.speed returns a high-speed device, but it is actually a full-speed device

Seems like armclang is really bugged. Also the fix you found may work currently but there is no guarantee that it won't break some...

#

Does -mno-unaligned-access fix the issue ? https://developer.arm.com/documentation/dui0774/l/Compiler-Command-line-Options/-munaligned-access---mno-unaligned-access

This can solve the problem of unaligned access, but the return value is incorrect, for example, dwc2->hprt_bm.speed returns a high-speed device, but it is actually a full-speed device

Seems like armclang is really bugged. Also the fix you found may work currently but there is no guarantee that it ...

#

Does -mno-unaligned-access fix the issue ? https://developer.arm.com/documentation/dui0774/l/Compiler-Command-line-Options/-munaligned-access---mno-unaligned-access

This can solve the problem of unaligned access, but the return value is incorrect, for example, dwc2->hprt_bm.speed returns a high-speed device, but it is actually a full-speed device

Seems like armclang is really bugged. Also the fix you found may work currently but there is no guarantee that it ...

#

Does -mno-unaligned-access fix the issue ? https://developer.arm.com/documentation/dui0774/l/Compiler-Command-line-Options/-munaligned-access---mno-unaligned-access

This can solve the problem of unaligned access, but the return value is incorrect, for example, dwc2->hprt_bm.speed returns a high-speed device, but it is actually a full-speed device

Seems like armclang is really bugged. Also the fix you found may work currently but there is no guarantee that it ...

fallow birchBOT
#

I was able to get TinyUSB logging. At logging level 3, when the board does not connect to USB, only this is
printed (output from CircuitPython was edited out here):

USBD init on controller 0, speed = Full
sizeof(usbd_device_t) = 48
sizeof(dcd_event_t) = 12
sizeof(tu_fifo_t) = 20
sizeof(tu_edpt_stream_t) = 112
CDC init
MSC init
HID init
MIDI init
guid, gsnpsid, ghwcfg1, ghwcfg2, ghwcfg3, ghwcfg4
0x00000000, 0x4F54400A, 0x00000000, 0x224DD930, 0x00C804B5, 0xD3F0A030
Fullspeed...
fallow birchBOT
fallow birchBOT
fallow birchBOT
#
[hathach/tinyusb] New branch created: fix-ceedling
fallow birchBOT
fallow birchBOT
fallow birchBOT
fallow birchBOT
fallow birchBOT
fallow birchBOT
#
[hathach/tinyusb] New branch created: fix-dwc2-issue
fallow birchBOT
fallow birchBOT
#

Related area

hid class driver

Hardware specification

rp2040

Is your feature request related to a problem?

hello,
im currently developing hid-compatible touchscreen on custom RP2040 boards. my issue is, the size of touchscreen hid report size(83) is too big for CFG_TUD_HID_EP_BUFSIZE, as it can't be larger than 64 otherwise tinyusb init will fail.

Describe the solution you'd like

Would you developers add some kind of "mechanism" that can deal oversized hid buffer trans...

fallow birchBOT
fallow birchBOT
#

Requirements

Unlock CI for tinyusb component repository

Description

  • Added usbtool. USB teardown feature were added in ESP USB repository. To run USB Test Application in tinyusb repository, usbtools should present in docker image.
  • Fixed ceedling.
  • Remove fast-fail: false option from strategy.

Limitations

N/A

Breaking change

No breaking changes

Testing:

N/A

Checklist

  • [x] Pull Req...
fallow birchBOT
#

Your post helps a lot, thanks.
I have the exact same problem with STM32F723IE MCU.
Custom firmeware, board and using the internal hs phy of the f723.
Your solution does not work on my board, but the problem does not happen when I add a delay at the end of dwc2_phy_init().

TinyUsb Configuration

  • NO OS
  • CDC + MSC
  • USB HS
  • DMA

Personal solution in dwc2_stm32.h

static inline void dwc2_phy_init(dwc2_regs_t* dwc2, uint8_t hs_phy_type) {
  if (hs_phy_type == GHWCFG2_HSPHY_NOT_...
fallow birchBOT
#

This apparently also affects STM, since STM uses synopsis too: https://github.com/adafruit/circuitpython/issues/9971. That may be another test platform.

Based on the recent post in #2074, I tried moving the AHBIDL test to the top and adding a delay. Byt that did not help this problem:

static void reset_core(dwc2_regs_t* dwc2) {
  while (!(dwc2->grstctl & GRSTCTL_AHBIDL)) {} // wait for AHB master IDLE    ///// MOVED from end of this routine

  // reset core
  dwc2->grstctl |= GRSTCTL...
fallow birchBOT
#

@HiFiPhile It fails on various platforms:

  • Dell Optiplex Intel i7-8700, Q370 chipset. Ubuntu 24.04.
  • Dell Optiplex Intel i5-9500T, Windows 11. Interestingly (?) when plugged in, the board shows up in Device Manager as "USB JTAG/serial debug unit" (!).
  • Mac Mini M1 running Sequoia 15.2.

I have more I could try: no AMD, but more Intel.

I am plugging directly into the front or rear panel USB2 or USB3 ports when the problem manifests. Interposing a fancy USB3 or an old USB2 hub fixes the pr...

#

I am currently working on the fix for this and able to reproduce it with macos (it works with my amd debian 12 though). I have narrowed down its root cause. It is because S3 power up with DP/DM muxing to Serial JTAG USB. By the time circuitpython invoke dcd_init(), the JTAG USB is already enumerated. dcd_init() disconnect/connect and only cause several us reset, macos decide to just keep that. I am trying to find a best way to fix this. Latest IDF can also play a part, since I notice they als...

fallow birchBOT
#

Hi @dhalbert,

Based on the info, you are using 4 classes and 7 channels.
Config descriptor states, that device is a Bus-Powered and is required 100 mA.

Does your device not exceed this draining power from the bus?

Otherwise, it fits the states, that:

  • external hub helps
  • problem is platform dependent (maybe, not all manufacturers keep an eye on the draining power from the bus and the value)

Maybe it is worth trying to increase the bMaxPower to 500mA?

fallow birchBOT
fallow birchBOT
#

thanks @roma-jam I am pretty sure this has something with new phy init code in latest IDF. After updating tinyuf2 to use IDF v5.3.2 from v5.1.4, tinyuf2 behaves the same as cpy, it couldn't enumerate properly on my intel macos (JTAG Serial is enumerated instead). I pretty much sure that in latest IDF usb phy change drop some code, maybe the RTC CONF USB to change the mux from JTAG to OTG or didn't do it quick enough and the JTAG is enumerating/ted when it do.

@dhalbert at least I got an e...

#

It is because S3 power up with DP/DM muxing to Serial JTAG USB. By the time circuitpython invoke dcd_init(), the JTAG USB is already enumerated.

This explains perfectly why I saw JTAG in Windows Device Manager. 😄

I pretty much sure that in latest IDF usb phy change drop some code, maybe the RTC CONF USB to change the mux from JTAG to OTG or didn't do it quick enough and the JTAG is enumerating/ted when it do.

I wonder if an issue will need to be raised in ESP-IDF about this. I think...

fallow birchBOT
#

I wonder if an issue will need to be raised in ESP-IDF about this. I think I tried the latest TinyUSB with 5.3.1 and had the same issue, so it may be 5.3.x vs 5.2.x.

test with 5.2.3, 5.3.1 and 5.4 as well, it still has the same issue, this quick hack will get this problem solved using the good-old phy init code.

#include "soc/rtc_cntl_struct.h"
#include "soc/usb_wrap_struct.h"

void init_usb_hardware(void) {
    #if CIRCUITPY_USB_DEVICE
    // Configure USB PHY
    #if 1...
fallow birchBOT
fallow birchBOT
#

Operating System

Linux

Board

pico

Firmware

don't know

What happened ?

/pico-sdk/lib/tinyusb/src/tusb_option.h:238:12: fatal error: tusb_config.h: No such file or directory 238 | #include "tusb_config.h"

How to reproduce ?

i include this: #include <stdio.h> #include "pico/stdlib.h" #include "hardware/gpio.h" #include "bsp/board.h" #include "tusb.h"

Debug Log as txt file (LOG/CFG_TUSB_DEBUG=2)

In file included from /mnt/e/Genoce/...

fallow birchBOT
fallow birchBOT
fallow birchBOT
fallow birchBOT
fallow birchBOT
#

I finally spot the troublesome code

https://github.com/espressif/esp-idf/blob/0f0068fff3ab159f082133aadfa9baf4fc0c7b8d/components/usb/usb_phy.c#L337-L339

    if (config->otg_speed != USB_PHY_SPEED_UNDEFINED) {
        ESP_ERROR_CHECK(usb_phy_otg_dev_set_speed(*handle_ret, config->otg_speed));
    }

I am not entirely sure but The DM/DP pull override probably mess up the dwc2/jtag reset sequence or something. this is a timing/racing issue. Since the issue does not appear when adding...

fallow birchBOT
#

Describe the PR
USB CDROM support requires that the SCSI INQUIRY command returns a different device type and qualifier. The current API for MSC devices doesn't allow the caller to influence these or appear as any other device type. This PR adds a new API function tud_msc_scsi_device_type(uint8_t lun) that enables expandability of SCSI device types as well as two new commands SCSI_CMD_READ_TOC and SCSI_CMD_READ_DISC_INFO.

In order to appear as a CDROM the caller must:

  • Implement tud_...
fallow birchBOT
#

The current walkaround have the speed as USB_PHY_SPEED_UNDEFINED to skip the usb_phy_otg_dev_set_speed() in question.

  usb_phy_config_t phy_conf = {
    .controller = USB_PHY_CTRL_OTG,
    .target = USB_PHY_TARGET_INT,
    .otg_mode = USB_OTG_MODE_DEVICE,
    // https://github.com/hathach/tinyusb/issues/2943#issuecomment-2601888322
    // Set speed to undefined (auto-detect) to avoid timinng/racing issue with S3 with host such as macOS
    .otg_speed = USB_PHY_SPEED_UNDEFINED,
  };

...
#

This pull request includes updates to the toolchain configuration, improvements to the Docker setup process, and fixes for USB initialization and event handling. The most important changes are summarized below:

Toolchain Configuration Updates:

  • Updated the ESP-IDF toolchain version from v5.3.1 to v5.3.2 in the .circleci/config2.yml file.
  • Removed the toolchain_version input from .github/actions/setup_toolchain/action.yml as it is no longer required. [[1]](diffhunk://#diff...
fallow birchBOT
fallow birchBOT
fallow birchBOT
#

ugly workaround:
assume CFG_TUD_HID_EP_BUFSIZE is 64.

uint8_t buffer[83] = {0x00};
tud_hid_report(1, &buffer, CFG_TUD_HID_EP_BUFSIZE - 1);
bool part_transfered = true;

void tud_hid_report_complete_cb(uint8_t instance, uint8_t const *report,
                                uint16_t len) {
  if (part_transfered) {
    tud_hid_report(
        0, (void *)((uint32_t)&buffer + CFG_TUD_HID_EP_BUFSIZE - 1),
        sizeof(buffer) + 1 - CFG_TUD_HID_EP_BUFSIZE);
    part_transfered = false;
  }
}...
fallow birchBOT
#

This apparently also affects STM, since STM uses synopsis too: adafruit/circuitpython#9971. That may be another test platform.

Based on the recent post in #2074, I tried moving the AHBIDL test to the top and adding a delay. Byt that did not help this problem:

static void reset_core(dwc2_regs_t* dwc2) {
while (!(dwc2->grstctl & GRSTCTL_AHBIDL)) {} // wait for AHB master ...

fallow birchBOT
fallow birchBOT
#

@hathach @HiFiPhile

it rather easy to reproduce with S3 + intel macos using https://github.com/adafruit/tinyuf2/tree/update-idf-5.3.2/ports/espressif

guys, apparently I need some assistance from your side. I tried the tinyuf2 self_update example and espressif_esp32s3_devkitc_1 board on macbook (Intel i7) and I have the drive device: "S3DKC1BOOT" at every connection.

Do I need to provide the valid application? Based on the example, I have the debug output:

TinyUF2
App invalid...
fallow birchBOT
#

@roma-jam I am glad you are giving it a try. I haven't try using self-update target, the PR is merged to master of tinyuf2 now,. maybe try again with the tinyuf2 target using this CMakeLists.txt (you can compile and flash with idf.py) with following modification to line https://github.com/adafruit/tinyuf2/blob/master/ports/espressif/boards/boards.c#L271

  usb_phy_config_t phy_conf = {
    .controller = USB...
fallow birchBOT
fallow birchBOT
#
[hathach/tinyusb] New branch created: zephyr-support
fallow birchBOT
fallow birchBOT
#

Describe the PR
When not using uart the macro UART_CLK_EN is most likely also not defined (as it is defined in the board.h alongside UART_DEV). On some stm32 families (i.e. l0 and f1) this is handled correctly and the UART_CLK_EN macro is called from the #ifdef UART_DEV section, but on some families the macro is always called.

This pr moves the call to UART_CLK_EN into the conditional section for the families with the wrong behaviour. It also only creates the UartHandle v...

fallow birchBOT
#

Describe the PR

Add NUCLEO-H7S3L8 support.

Status:

FS port HS port
Device Unknown Working
Host Unknown *Has issues

* Unattach is not detected, resulting _usbh_devices overflow.
* High speed device can't enumerate.

Either not advacning:

USBH init on controller 1, speed = Full
sizeof(usbh_device_t) = 86
sizeof(hcd_event_t) = 12
sizeof(_ctrl_xfer) = 16
sizeof(tuh_xfer_t) = 24
sizeof(tu...
fallow birchBOT
#

Hello, I also observe this behavior on a STM32F411CEU6 (WeActStudio.MiniSTM32F4x1). I am on release 0.18.0 and use examples\device\audio_4_channel_mic. In Audacity I only see CH0 (saw wave) and CH1 (inverted saw wave) with small amplitude. I defined CFG_TUSB_MCU as OPT_MCU_STM32F4. Is there anything else I need to consider?
My OS is Windows 10.

If you have any suggestions on what I could try, I'm happy to test it on my hardware if y...

fallow birchBOT
fallow birchBOT
#
[hathach/tinyusb] New branch created: revert-2939-patch-1
#
[hathach/tinyusb] New branch created: fix-2939
fallow birchBOT
fallow birchBOT
fallow birchBOT
fallow birchBOT
fallow birchBOT
fallow birchBOT
fallow birchBOT
#

Operating System

Windows 10

Board

ST32c071RB

Firmware

I have a nucleo board that uses a ST32c071RB mcu. It runs my own project generated by using CubeIDE. I added TinyUSB (0.18.0) by copying only the /src and /hw directories. I also followed the instructions to modify USB_DRD_FS_IRQHandler() so it calls tud_int_handler(BOARD_DEVICE_RHPORT_NUM), and i use tusb_init() to initialize the stack.

My project also uses RTOS, so I run the mainloop in a seperate RTOS task, calling tu...

fallow birchBOT
fallow birchBOT
fallow birchBOT
#

Works great for me, both for CDC and UVC. Thanks !
In addition to #define CFG_TUD_DWC2_DMA_ENABLE 1 I also had to add #define __CORTEX_M 7

Thanks for your test. It's little strange that you need to define __CORTEX_M, normally stm32h7xx.h includes devcie header eg. stm32h747xx.h which includes core_cm7.h and __CORTEX_M is defined inside. Did I miss something ?

I don't think so. I'm using a custom RTOS which relies on its own set of headers, that's why.

fallow birchBOT
fallow birchBOT
#

Describe the PR

Currently, mixing the MSC class with other classes could be problematic since IO operations could block tud_task() for a long time and degrade real-time performance, especially for isochronous and interrupt transfer-based classes.

Now, it's possible to delegate IO operations to a background task.

The cdc_msc_freertos example has been updated for demonstration. One can change SIM_IO_TIME_MS to a high value and type in the console while doing disk IO. With `CF...

fallow birchBOT
fallow birchBOT
#

Operating System

Others

Board

esp32s3 wroom1

Firmware

espressif tinyusb port, tusb_msc_storage.c

What happened ?

In tinyusb\src\portable\espressif\esp32sx\dcd_esp32sx.c, in function dcd_int_enable, the return code is not checked or returned
If the esp-idf fails to allocate an interrupt, the usb device will not work but the usb task has no way of knowing
See below the log output
In the example the system resets, on my full system it does not reset but does not work
Note...

fallow birchBOT
#

Operating System

Linux

Board

Feather RP2040 with USB A Host

Firmware

https://github.com/rppicomidi/usb_midi_host/tree/main/examples/C-code/usb_midi_host_pio_example

I think the version in GitHub may not have specific support for the Feather board yet, but it will shortly.

What happened ?

I have connected a powered USB 2.0 hub to the USB A port of the Feather board. If I plug a MIDI device to the hub, it enumerates correctly and starts working. If I unplug the hub from ...

fallow birchBOT
fallow birchBOT
fallow birchBOT
#

Operating System

Linux

Board

rp2350

Firmware

RPI Pico SDK

What happened ?

During processing of a SETUP message in process_control_request() there is an unconditional call to dcd_sof_enable(rhport, false). This ignores the SOF user state set with tud_sof_cb_enable(true).
The workaround is to do a:

tud_sof_cb_enable(false);
tud_sof_cb_enable(true);

in tud_mount_cb() as well as tud_umount_cb(). This comes with the penalty of a potential SOF miss.

SOF should only be disa...

fallow birchBOT
#

Related area

Optimum audio buffer placement in RAM

Hardware specification

rp2350

Is your feature request related to a problem?

For rp2350 USE_LINEAR_BUFFER gets defined. This causes IN_SW_BUF_MEM_SECTION and OUT_SW_BUF_MEM_SECTION to be defined to nothing. Thus one can't specify a memory location for audio_ep_in_sw_buf_N as well as audio_ep_out_sw_buf_N.

Even if one could, this would be via a global CFG_TUD_MEM_SECTION which is shared for various allocations. This results i...

fallow birchBOT
#

Hi @inbarab ,

that is right, thank you so much for such detailed description.
That is why tusb_msc example is not able to build with such configuration (#error Unsupported console type): because the USB CDC for the serial device output shares the same peripheral as (in this particular case) TinyUSB MSC device.

Anyway, the issue could be reproduced with an adding just one line: call the interrupt enable twice:

void dcd_int_enable(uint8_t rhport) {
  dwc2_dcd_int_enable(rhport);
  ...
#

Hi,

Thanks for your reply

I hope my input was useful.

Do you know if there’s a way to remove the esp32s3’s ROM usb stack once it’s started? If there is a way, maybe the usb can be switched from the rom usb stack to the tiny usb stack. I have not found a solution to this.

Cheers,

Inbar

From: Roma Jam @.>
Sent: Tuesday, 4 February 2025 17:38
To: hathach/tinyusb @.
>
Cc: inbarab @.>; Mention @.>
Subject: Re: [hathach/t...

fallow birchBOT
fallow birchBOT
#

@hathach I pushed some changes to remove dead code and make this HCD even faster. Even if you don't care about the original data sequence error bug, the speed improvement should make this worth the time to merge. I do understand that the pull request is complicated, that it will take time to review, and that you are very busy, so I will remain patient if you do not have time. Thank you for this project.

fallow birchBOT
fallow birchBOT
fallow birchBOT
fallow birchBOT
#
[hathach/tinyusb] New branch created: fix-407blackvet
fallow birchBOT
#
[hathach/tinyusb] New branch created: iar-for-forked-pr
fallow birchBOT
fallow birchBOT
#
[hathach/tinyusb] New branch created: skip-iar-forked-pr