#tinyusb

1 messages · Page 1 of 1 (latest)

fallow birchBOT
#

fyi - The RP2040 has a hardware PHY and dedicated DPSRAM, available to both the device/host controller hardware and the CPU cores. More information on this can be found in section 4.1 in the RP2040 datasheet https://datasheets.raspberrypi.com/rp2040/rp2040-datasheet.pdf.

From testing, I can tell that once an OUT packet is received and an interrupt is triggered, the hardware buffer for the endpoint is marked as being full and exclusive to the CPU core (controller can no longer access it). ...

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

In case anyone is still looking into this; I've updated the comment section above about tests with another board as the host (a H5 based board from FriendlyElec). No problems there either. Given other problems with the USB stack on Raspberry Pi (e.g. https://forums.raspberrypi.com/viewtopic.php?t=245931) I'm writing this off as a hardware specific RPI issue, and I do not have the tools to investigate any further.

fallow birchBOT
fallow birchBOT
fallow birchBOT
#

Since setting up a new project takes some time, I decided to look further into the composition of my descriptors.
I am sure they contain correct data since I checked them multiple times.

The only real difference is that in the device descriptor I set .bcdUSB = 0x0210 or .bcdUSB = 0x0200 respectively.

Here is some log output which hopefully helps with understanding my issue:

.bcdUSB = 0x02100 (not working):
[bcdUSB_0x0210.txt](https://github.com/hathach/tinyusb/files/9196051/...

fallow birchBOT
fallow birchBOT
fallow birchBOT
#

I kind of forgot about this bug-thread, but the Arduino-ESP32 people have agreed they see my issue in the library here using this example:

https://github.com/espressif/arduino-esp32/issues/6221#issuecomment-1090173420
and
https://github.com/espressif/arduino-esp32/issues/6221#issuecomment-1138671766

They also say the same issue happens in their IDF using the SuGlider's python test module posted in that thread:

https://github.com/espressif/arduino-esp32/issues/6221#issuecomment-1126...

fallow birchBOT
fallow birchBOT
#

Describe the PR
The Renesas RX controllers possess system-wide write protection for certain registers. Setup functions within the tinyUSB stack have to disable this write protection. This happens in order to disable the USB hardware's module stop function (e.g. MSTP(USB0) in dcd_init).
I changed the the write protection register's value handling in a way that the previous state is recovered. This leads to a more intuitive behavior of tinyUSB's initialization code

**Additional con...

fallow birchBOT
fallow birchBOT
fallow birchBOT
fallow birchBOT
#

@rolandvs, It's not really on my list of things to do, since I'm not that interested in media streaming. I don't think anyone else has worked on it.

I have, however, been thinking about the implementation of double-buffering, and using FIFO for data transfer, and ISO should be simple after double-buffering is implemented. I'd like @hathach's input on how endpoint configuration could be implemented: How should an application request that an endpoint be double-buffered or not, and also allow...

fallow birchBOT
#

Switched to head and it also seems to be working with the fix above. Note however, there is another bug if running in HS mode with an STM32H7. You will need to modify a section in tusb_mcu.h to add #define TUP_RHPORT_HIGHSPEED 1 - in this section:
https://github.com/hathach/tinyusb/blob/fd5bb6e5db8e8e997d66775e689cc73f149e7fc1/src/common/tusb_mcu.h#L158-L163

I can create a PR to add #define TUP_RHPORT_HIGHSPEED 1 if needed.

#

@Iktek Is there any change you or perhaps others @hathatch are/have been working on getting this to work or made any progress since the last post?

Hi @rolandvs , there have been some "experiments" in https://github.com/Iktek/tinyusb/tree/1249-feature-stm32_fsdev_isocronous_support where I enabled ISO without doublebuffering, which did not work out, so: nothing worthy I think. Unfortunately project priorities shifted and other things got more urgent for now (thanks to the chip-crisis).. S...

fallow birchBOT
fallow birchBOT
fallow birchBOT
#

mjan-jansson

When are NAK sent?
When are packets ignored?
How are packets processed while the AVAIL bit is cleared?

Each time the device controller receives an IN or an OUT packet from the host, it will read the buffer control DPSRAM. If the available bit (and the full bit 1 for an IN TO HOST transfer, or the full bit 0 for an OUT FROM HOST transfer) is set then the data is transferred. If not a NAK is sent. This is the same for both directions.

fallow birchBOT
#

I noticed an additional change that needs to be made. It has to do with the software configurable peripheral interrupt of the USB hardware.

The interrupt vector (PERIB_INTB185) needs to know which peripheral triggers it, therefore the following line needs to be added:

ICU.SLIBR185.BYTE = 62; /* set software configurable interrupt vector 185 to USBI0 */

Please add this line to the files "dcd_usba.c" (insert at 632) and "hcd_usba.c" (insert at 554).

Not adding the line mea...

fallow birchBOT
#

The endpoint-ix vs endpoint-ix separation isn't necessarily needed if the application doesn't have a second endpoint with that particular ID (e.g., if the ISO EP is 3OUT, then there couldn't be a 3IN endpoint).

The driver already has an allocation method for the PMA. It's correct for most cases (where PMA is not also used for CAN).

The minimum changes need:

  1. Modify allocator to support double-buffering.
  2. Support longer PMA buffers (for packet lengths up to 512 bytes?), including c...
fallow birchBOT
#

TinyUSB is having great api for RNDIS. i used it with Raspberry PICO RP2040 earlier.
i wish i could find support for Arduino DUE SAM3X8E he will be great addidion as Arduino USB is limited to USB HID only.
And adding External Ethernet MAC (like W5500 for referance) to Arduino DUE SAM3X8E is bit complicated because of certain library conflicts.

An simple TinySB port which will help to bring RNDIS feature to Arduino DUE SAM3X8E will be great for community.

Cheers!
sdrshnptl

fallow birchBOT
fallow birchBOT
#

Operating System

Linux

Board

Raspberry Pi Pico

Firmware

https://github.com/czietz/pico-usb-speed-check built with current TinyUSB (commit fd5bb6e5d).

What happened ?

I wanted to test my USB speed checker (see above) with the current TinyUSB instead of the version 0.12.0 provided in the Pico SDK. It did not work because an incorrect endpoint size was determined here:
https://github.com/czietz/pico-usb-speed-check/blob/0524ce5e430261d9852ee842e3d5cf67ca310512/usb_descrip...

fallow birchBOT
#

Operating System

Windows 10

Board

STM32L053 nucleo

Firmware

fd5bb6e5db8e8e997d66775e689cc73f149e7fc1

What happened ?

stm32_fsdev dcd_pma_alloc causes an off-by-one error when the max packet length is not an even multiple of PMA blocks (2 bytes or 32 bytes), causing one word to be allocated for multiple endpoints.

How to reproduce ?

Define an interrupt endpoint with an odd number of bytes, along with a second endpoint which is opened after the first.

Debug L...

fallow birchBOT
#

Thanks for all your comments. I'll see if I can make an effort, but unfortunately it will have to wait as I'm currently working on some issues with higher priority.

I started looking at the driver, too, and have found at least one bug (#1583), and got confused about error handling while trying to fix it (#1584 ). I'm reworking the code with a goal of handling double-buffering and searching for race conditions. I'll submit it as a PR once I have it working better than the current code. It...

fallow birchBOT
#

Operating System

Linux

Board

stm32L4x2

Firmware

Compilation to a stm32l4x2.

What happened ?

I tried to compile stm32fs_dev driver for stm32l4x2, I configured CFG_TUSB_MCU to OPT_MCU_STM32L4 as needed, but the linkage step failed.
When diving into stm32fs_dev, it seems like the stm32l4x2/stm32l4x3 are missing there, although it says in the description they are supported.

How to reproduce ?

  1. add #define STM32L432xx
  2. run the cdc_msc example while doing the...
fallow birchBOT
#

The endpoint-ix vs endpoint-ix separation isn't necessarily needed if the application doesn't have a second endpoint with that particular ID (e.g., if the ISO EP is 3OUT, then there couldn't be a 3IN endpoint).

Hi pigrew: Unfortunately the UAC2-Specification (Audio-Streaming) is expecting exactly that. An explicit sync endpoint needs necessarily have the same endpoint-ix as its corresponding stream endpoint.
I wonder if there are also other classes which expect this to be possible.
So...

fallow birchBOT
#
[hathach/tinyusb] New branch created: fix\-TUD\_OPT\_HIGH\_SPEED
fallow birchBOT
#

You likely got the error in dcd_stm32_fsdev_pvt_st.h stating:

#error You are using an untested or unimplemented STM32 variant. Please update the driver.

Please edit the header file and test. the contents should be something like:

#elif CFG_TUSB_MCU == OPT_MCU_STM32L4
  #include "stm32l4xx.h"
  #define PMA_LENGTH (1024u)

Also, add the L4 to the check in dcd_stm32_fsdev.c:

#if CFG_TUD_ENABLED && \
      ( TU_CHECK_MCU(OPT_MCU_STM32F0, OPT_MCU_STM32F3...
fallow birchBOT
fallow birchBOT
#

This adds the ST STM32L052 since I encountered a target with said MCU and didn't find an existing board type in TinyUSB.

I tried to follow the newer TinyUSB convention of "boards" sub-directory for a given "family" (stm32l0). There is an existing "stm32l0538disco" board using the older convention that I left untouched since I don't know the reasons behind it still being in the main bsp directory.

I set the board name to "stm32l052dap52". The reason for the naming suffix is that the ta...

fallow birchBOT
#

@perigoso I totally agree with you. I prefer the stdint types over the underlying types, too. But in this specific file, the underlying types were used. Hence I tried to stay consistent with the existing code style.
Declaring a variable anywhere else than at the start of a scope can lead to problems when using older C standards such as C89 (I think). I just wanted to avoid that.

Thanks for your proposals though!
Since the build seems to have failed it looks like I'm going to have to make an ...

fallow birchBOT
#

Operating System

Windows 11

Board

lpcxpresso55s36

Firmware

We created a project that uses tinyusb as a submodule. It´s architecture is based on the example device/hid_generic_inout but uses freertos.

What happened ?

We perceived the tinyusb library does not detect when the lpc55s36 is unmounted or it does but several minutes or hours later. There are no problems with communication and plugging detection.

We detected the functions involved for this event (in order) we...

fallow birchBOT
#

I've started working on rewriting the fsdev driver, to add the layer of indirection between endpoint addresses and hardware endpoints, plus double-buffering... and finding tons of bugs.

Some bugs include:

  • Having different EP types with the same address was broken
  • Receiving odd numbers of bytes potentially causes memory overruns
  • Driver was broken if one attempts to open a control EP with address != 0 (changing to just error out if attempted)
  • Add check for CMSIS >=5.1
  • Broken w...
fallow birchBOT
#

Describe the PR
dfu_moded_open() only works correct when its called on DFU interface
descriptor. It means that DFU is the only one interface in configuration
or driver is called after all others interface drivers were tried and
gave up.

If other interface is supported and but driver for DFU is called first
(this is the case for BTH and RNDIS).
Code after while loop (that was not entered) has an TU_ASSERT that will
make set_configuration to fail.

Now TU_VERIFY is called first ...

fallow birchBOT
#

Discussed in https://github.com/hathach/tinyusb/discussions/1600

Originally posted by emonjak August 9, 2022
Hi all,
we use tinyusb on STM32H743. USB is configured to high speed, but runs in full speed mode because of USB 1.1 hub. It looks like the max. packet size for CDC transmitt is still 512 bytes. Therefore, the sending of the strings with the 64 characters length is not completed with ZLP. Call
tud_cdc_write(NULL, 0);
tud_cdc_write_flush();
has no effect.
Sending...

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

Could this bug cause data written out of usb to be read in? That's been a longstanding issue in CircuitPython on the nRF52840.

One of the issue this fixes is that DMA is reported as finished while number of bytes received is less than what was requested (including 0) in that case if same buffer was used for write and read it could manifest like echo I guess. I think that at one point I also had an impression about mismatch between what was send in both directions but it turned out that b...

fallow birchBOT
fallow birchBOT
#

Describe the PR
I have a USB Hub that generates a HUB_FEATURE_HUB_LOCAL_POWER_CHANGE interrupts. This is not currently handed in TinyUSB so this hub just didnt work.

This PR handles hub device changes and clears the respective feature (currently we only handle hub port changes).

I also have another hub that generates HUB_FEATURE_PORT_ENABLE_CHANGE, which was never cleared so I was just spammed with hub interrupts. This PR also clears other HUB port interrupts to prevent this happ...

fallow birchBOT
#

Brilliant !!! Thank you very much for the fix and great explanation. I am sorry for the super late response, I was too off schedule lately, and still catching-up with PRs/Issues.

The fix is spot-on, I have tried the blehci via usb, before this PR it will crash randomly, but got stable now. I remembered trying to use atomic bool previously, but got into a worse racing condition, probably due to missing the 2nd case where SIZE.EPOUT cannot be read after DMA started. Thanks again.

#

Could this bug cause data written out of usb to be read in? That's been a longstanding issue in CircuitPython on the nRF52840.

Yeah, I think this will possibly fix the hiccup issue with nrf cdc fast transferring.

@hathach , I see this is using the C11 atomics. I was thinking about using them in the STM32 driver, too, but was not sure if TinyUSB can require that new of a compiler?

I actually really like c11, we already in 22' already. C11 is much better and safer than C99, one of...

fallow birchBOT
fallow birchBOT
#

Operating System

Windows 11

Board

Teensy4.1 (EHCI)

Firmware

When unplugging a device on my Teensy4 board running the host EHCI backend I reliably hit this assert, particularing when using a USB Hub:

https://github.com/hathach/tinyusb/blob/585f37a7977c3ff7e00b1e2235eb0712b12c90d6/src/host/usbh.c#L496

I believe this is due to a race condition during device removal. Consider the following sequence:

  1. Device is unplugged - TinyUSB registers a detach event in IRQ. 👍
    2....
fallow birchBOT
#

Describe the PR
This PR adds MIDI host support for RP2040 boards based on work done by @rppicomidi in https://github.com/hathach/tinyusb/pull/1219 and @Skyler84 in https://github.com/hathach/tinyusb/pull/1434. I rebased all changed on top of master and fixed some compilation errors.

MIDI controller (behringer x-touch mini) enumerates and the data is received.

Creating this pull request as a draft for comments. I'm very new at this and I'm kind of surprised that it works :D

fallow birchBOT
fallow birchBOT
#
[hathach/tinyusb] New branch created: release\-0\.14\.0\-p2
fallow birchBOT
#
[hathach/tinyusb] New tag created: 0\.14\.0
fallow birchBOT
#
[hathach/tinyusb] New branch created: fix\-release\-body
fallow birchBOT
#

Operating System

Linux

Board

Custom

Firmware

`/*

  • tusb_config.h
  • Created on: Aug 23, 2022
  •  Author: DaGo1120
    

*/

#ifndef TUSB_CONFIG_H_
#define TUSB_CONFIG_H_

#ifdef __cplusplus
extern "C" {
#endif

//--------------------------------------------------------------------+
// Board Specific Configuration
//--------------------------------------------------------------------+

// RHPort number used for device can be defined by board.mk, default ...

fallow birchBOT
fallow birchBOT
fallow birchBOT
fallow birchBOT
#

Describe the PR
Field started (regarding transfer) was only cleared when transfer
was finished.
For audio devices set interface is called many times.
When there is no audio (silence) set interface requests zero
length bandwidth that in turn calls dcd_edpt_close().

When endpoint is closed due to set interface request transfer
should not longer be started since it will block next start transfer
with assert.

This just sets 'started' to false when endpoint is closed.

**Additio...

fallow birchBOT
fallow birchBOT
fallow birchBOT
#

The pin state can be checked with pySerial

Something along these lines

import serial

tty = serial.Serial(port = '/dev/AMA0', baudrate = baud, parity = serial.PARITY_NONE, stopbits = serial.STOPBITS_ONE, bytesize = serial.EIGHTBITS, xonxoff = True, timeout = 2.0)

if (tty.getCTS()):
   print("CTS")

You can also use coolterm under Linux for a checking the state of the cts/dsr pins with a nice GUI.

fallow birchBOT
#

Hi!
I'm very excited for this functionality. But I'm getting compile errors when I try this out. The process I'm using:

git clone https://github.com/atoktoto/tinyusb tinyusb-atoktoto
cd tinyusb-atoktoto
git checkout midihost-atoktoto
git submodule update --init lib
cd examples/host/midi
make BOARD=raspberry_pi_pico get-deps
make BOARD=raspberry_pi_pico all

And I get the error:

[...]/tinyusb-atoktoto/examples/host/midi/src/midi_app.c:195:16: error: unused variable '...
fallow birchBOT
fallow birchBOT
#

Operating System

MacOS

Board

Raspberry Pi Pico RP2040

Firmware

tinyusb/examples/device/cdc_msc
using pico-sdk 1.4.0 in $PICO_SDK_PATH

What happened ?

Cannot compile with LOG=1 or LOG=2, instead get error:

[ 23%] Building C object CMakeFiles/cdc_msc.dir/src/main.c.obj
: error: "CFG_TUSB_DEBUG" redefined [-Werror]

How to reproduce ?

git clone https://github.com/raspberrypi/pico-sdk
git clone https://github.com/hathach/tinyusb/
export PI...
fallow birchBOT
fallow birchBOT
#

Operating System

Windows 7

Board

Various

Firmware

Device CDC

What happened ?

I've tried 5 different ways to use TinyUSB to produce a CDC device and these are my varied results:

  1. ESP32-S2 (DWC2) - fails on a stress test (described in the ESP32 github) with a random IN packet (tx from device) not signalling an int. which halts that part of the stack.
  2. Pi Pico native USB (unknown) - works perfectly, stress test as described passes.
  3. Raspberry Pi Zero W (DWC2) - wo...
fallow birchBOT
fallow birchBOT
#

Operating System

Linux

Board

rp2040

Firmware

In
tinyusb-master/examples/device/audio_test/main.c
the body of the function audio_task() is left empty. I have tried to modify it so that it returns a constant value at 16Mhz with 2 bytes per sample. I believe I have modified the tusb_config.h and usb_descriptors.c correctly.

What happened ?

rather than a nice straight line, assigning a constant for each sample (rather than a value from the microphone) produces a saw-to...

fallow birchBOT
#

There are a number of compile errors for missing definitions when building against the library for an STM32L4 series IC.

It's possible there are other issues that need to be resolved to fully support this family of chips, but this did get us closer to being up and running.

While there are many compilation errors, here is one example:

tinyusb/src/portable/st/stm32_fsdev/dcd_stm32_fsdev_pvt_st.h:119:15: error: unknown type name '__IO'
  119 | static inline __IO uint16_t* pcd_...
fallow birchBOT
fallow birchBOT
fallow birchBOT
#

Operating System

Linux

Board

Custom stm32h769 with HS phy

Firmware

examples/device/cdc_msc_freertos with synopsis_dcd2

What happened ?

After booting and plugging in the first time everything works fine. But if I unplug USB cable when there is msc transmissions after plugging again tusb don't work correctly. Transmission stops every time in the same place:

USBD Setup Received A1 FE [00 00 02 00 01 00](tel:00 00 02 00 01 00)
  MSC control request
  MSC Get Max L...
fallow birchBOT
fallow birchBOT
#

Bad news, I'm sorry to say... Test number 2 above (Pi Pico native USB) with the loop part of my stress test moved from CPU0 to CPU1 (code moved from loop() to loop1() with a new small delay in start1() for coordination, but no other changes) cannot reliably transfer data either.

It all seemed to work OK at first, and while it was running I reviewed the Arduino code for Pico - seems to have extra mutexes that I don't see elsewhere, so that looked very well done. Then after about 10 minute...

fallow birchBOT
fallow birchBOT
#

@atoktoto In case you are interested, my fork of this project has a new branch pio-midihost that supports the Pico-PIO-USB as a host. I have a demo project pico-usb-midi-filter that passes MIDI data between the built-in USB configured as a device and a new USB Host port created from PIO. I suspect I duplicated some of your work in this pull request in my fork.

fallow birchBOT
fallow birchBOT
#

Related area

device stack

Hardware specification

N/A

Is your feature request related to a problem?

I am trying to implement a custom usb driver for xinput controllers, which I can't really do easily due to there not being a concept of custom app drivers for usb hosts.

Describe the solution you'd like

A solution to this would be copying how app drivers are implemented for usb devices, and just implementing the same logic for usb host.

I have checked existing issues,...

fallow birchBOT
#

@BennyEvans I can confirm that removing that line from the driver triggers the unmount event.
I am testing on v0.13, and the respective line is 514 instead of 525.

However, I am getting several triggers of this unmount event when I unplug the USB cable. Is it expected?

Also, I would like to try v0.14 to get things up to date, but it seems that there are some configurations that changed and I am stuck on check_dwc2 function.

This is the setup I have for v0.13:

#define CFG_TUS...
fallow birchBOT
#

Operating System

Others

Board

ESP32-S2

Firmware

ESP-IDF 4.4.2

What happened ?

occasionally messages sent are repeated infinitive . sending a new message stops this or get repeated infinitive as well.

How to reproduce ?

required a bigger application making use of stack and heap more exessive

Debug Log as txt file

No response

Screenshots

No response

I have checked existing issues, dicussion and documentation

  • [X] I confirm I have checked exist...
#

@atoktoto I agree #1434 seems to work. I am not arguing against your pull request. Thank you for doing the work. The pico-usb-midi-filter project uses a single Pico board to implement a bi-directional MIDI filter between a MIDI USB host (which I implemented using PIO from the Pico-PIO-USB project) and a MIDI USB device (which I implemented using the Pico's dedicated USB hardware). My comment was only wishing I had looked here before I did ...

fallow birchBOT
fallow birchBOT
#

Operating System

Others

Board

RP2040 / Pico

Firmware

Pico-SDK 1.4.0

What happened ?

I am using TinyUSB as a HOST in a noisy environment and sometimes I need to reset the USB bus. To do this I call "hcd_init(0)" as part of the reset process.

Previously in TinyUSB version 0.13.0, this wasn't an issue and it allowed me to do this without crashing.

After this was added in TinyUSB 0.14.0,
**rp2040: use shared IRQ handlers, so user can also hook the USB IRQ by @...

fallow birchBOT
fallow birchBOT
fallow birchBOT
fallow birchBOT
#

superb! thank you very much for the ports. Currently, I don't have any pic32mm board to test this out, but can you add the bsp for pic32mm board so that it can be easily tested for other users. If that is too much work, we can merge this as it is and do that later on.

Note: since pic32mm and nxp khci use the same chipidea fs usb, we can merge them into general drivers later on in the future. (just a head up).

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

Do you have a specific recommended build process for this PR?

I have tried both using standard Pico build process inside of midi_rx and moving midi_rx to pico-examples and building there. Specifically I have tried:

cd tinyusb-testmidihost/examples/host/midi_rx
mkdir build
cd build
cmake ..

And I have tried:

cd pico_examples
cp -a ../tinyusb-testmidihost/examples/host/midi_rx .
echo "add_subdirectory(midi_rx)" >> CMakeLists.txt
mkdir build
cd build
c...
fallow birchBOT
#

Generally I'm following this guide: https://datasheets.raspberrypi.com/pico/getting-started-with-pico.pdf and building from CLion IDE, but the commands it's running are:

cmake.exe -G Ninja -S E:\pico\pico-examples -B E:\pico\pico-examples\build
cmake.exe --build E:\pico\pico-examples\build --target tinyusb_host_midi_rx -j 9

(I ommited the env variables specifying the paths to compilers for the second command)

For any other example it would be as simple as:
cd pico-examples
`...

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

This is already modified in v 14:

`#elif CFG_TUSB_MCU == OPT_MCU_STM32H7
#include "stm32h7xx.h"
#define EP_MAX_FS 9
#define EP_FIFO_SIZE_FS 4096
#define EP_MAX_HS 9
#define EP_FIFO_SIZE_HS 4096
#if (! defined USB2_OTG_FS)
// H7 with only 1 USB port: H72x / H73x / H7Ax / H7Bx
// USB_OTG_FS_PERIPH_BASE and OTG_FS_IRQn not defined in CMSIS files
#define USB_OTG_FS_PERIPH_BASE USB1_OTG_HS_PERIPH_BASE
#define OTG_FS_IRQn OTG_HS_IRQn
...

fallow birchBOT
#

@atoktoto, I also can get it to compile now (with similar Makefile and changes as your commits, though I had to also fix casts on int -> uint conversion errors cable_num in midi_host.c). Not sure what that no macro name error was but I nuked the directory, recloned and re-pulled and that error is gone.

The pico-midi-usb-transport library is great! The 47effects MIDI library is wonderful.

The CMake files of `pico-midi-usb-...

fallow birchBOT
fallow birchBOT
#

Dear @BennyEvans,

The issue is worse than at first... It is calling the tud_umount_cb callback so many times that it is giving me a STACK OVERFLOW error at the TinyUSB task.

I had to work around it by setting a flag like this:

void tud_mount_cb(void)
{
  if(bIsMounted)
    return;

  // Do something here
  bIsMounted = true;
}

// Invoked when device is unmounted
void tud_umount_cb(void)
{
  if(!bIsMounted)
    return;

  bIsMounted = false;
  // Do something h...
fallow birchBOT
#

I'm aiming to get TinyUSB to build with the IAR Embedded Workbench toolchain (I'm testing against Arm version 9.20.4) and specifically, I'm trying to build it as part of the Raspberry Pi Pico SDK. In doing so, I've identified a number of issues. Some of these are in rp2040-specific source files, but many others are in platform-neutral ones.

I've grouped the changes into a series of commits based upon the diagnostic generated by IAR. The first four are errors, and prevent the build from pro...

light sleetBOT
fallow birchBOT
#

Related area

UVC

Hardware specification

rp2040

Is your feature request related to a problem?

If the PresentationTime or SourceClockReference bit is set in tusb_video_payload_header_t, currently there seems no way to set those extended fields as described in UVC 1.5 spec, table 2-6.

But what I want to do is add user defined data append after the payload.

Describe the solution you'd like

  • Add a user defined macro for custom data length, use to initialize header ...
fallow birchBOT
#
[hathach/tinyusb] New branch created: fix\-1634
fallow birchBOT
#

Describe the PR
ISO packet size is up to 1023 for full speed device. Upon completion of ISO reception, reported length of incoming packet was truncated to one byte only.
This results in incorrect data stream for higher bit rates 48 samples * 4 bytes per sample * 2 channels = 384 bytes of data and 128 was reported.

There is no change in logic extending xact_len to uint16_t fixes the issue.

fallow birchBOT
#

Thanks for the issue, unplug/suspend indeed isn't fully working with all STM32 mcus. Some requires an configure to OTG A/B register setting. Look like it is the case here, unplug is mistaken as suspend and device isn't reset/re-init state/endpoint as it should be. I think the old driver at st/synopsys does handle this better, maybe you could give it a try. I will revise this later on when having time.

fallow birchBOT
fallow birchBOT
#

Nop, it happens occasionally in the ESP-IDF implementation and when it happens is a backtrace impossible due to muktitasking. It must be that tinyUSB keeps thinking that the transmit buffer is not sent and sends it again. I was hoping that here somebody knows tinyUSB to point me to the source where (as CDC device) the data buffer is handled. I think that a byte buffer goes out of bound and overwrites e.g. the flag marking the buffer as sent.

fallow birchBOT
fallow birchBOT
fallow birchBOT
fallow birchBOT
#

Discussed in https://github.com/hathach/tinyusb/discussions/1636

Originally posted by jeroentaverne September 12, 2022
Hardware: Raspberry Pi Pico acting as USB host
Software: TinyUSB example cdc_msc_hid
Log: see attached file

This keyboard somehow shows up as a keyboard and mouse, but doesn't have any mouse/touchpad/trackball capabilities. Keyboard protocol shows up as instance 0, mouse protocol as instance 1, but HID_ITF_PROTOCOL_NONE isn't reported by this keyboard. Af...

#

This is the code I added. It will make the keystrokes work, but the "mouse" instance is not reported anymore. I will send you a logfile as well.

printf("HID Interface Protocol = %s\r\n", protocol_str[itf_protocol]);

  • if (itf_protocol == HID_ITF_PROTOCOL_KEYBOARD )
  • {
  • static uint8_t value = 0;
  • printf("Executing tuh_hid_set_report\n");
  • tuh_hid_set_report(dev_addr, instance, 0, HID_REPORT_TYPE_OUTPUT, (void*)&value, 1);
  • }

// By default host stack will use act...

fallow birchBOT
fallow birchBOT
#

I found your patch because my attempts to implement a host for device with a bulk in endpoint and a bulk out endpoint failed. With the patch it actually works, although I've stayed away from complicated setups with hubs.

However, I now have the issue that it's very slow as every new transfer has to wait for the start-of-frame marker because that's the only time where hardware actually polls the endpoint control “register” in DPRAM. If I understand the RP2040 datasheet correctly, the contro...

fallow birchBOT
fallow birchBOT
fallow birchBOT
fallow birchBOT
#

Describe the PR
Fixes the following compiler error when compiling an audio device with feedback enabled (no rtos, st/synopsys port).

lib/tinyusb/src/class/audio/audio_device.c:2051:13: error: conflicting types for 'set_fb_params_freq'; have '_Bool(audiod_function_t *, uint32_t,  uint32_t)' {aka '_Bool(audiod_function_t *, long unsigned int,  long unsigned int)'}
 2051 | static bool set_fb_params_freq(audiod_function_t* audio, uint32_t sample_freq, uint32_t mclk_freq)
      |   ...
fallow birchBOT
fallow birchBOT
fallow birchBOT
fallow birchBOT
#

@wrtlprnft Have you seen the discussion #1261? (TL;DR If a bulk IN transfer does not complete (because the device NAKs the transfer), epx is busy until the device sends some data back) I took an admittedly quick look at the PR and did not see such a mechanism. My attempt a while ago in PR #1219 does address receiving NAK on bulk IN, but it is a bit ugly.

fallow birchBOT
#

@rppicomidi I did not see that, but I was wondering about that myself. Thanks for the pointer!

My intended application, which I was doing a quick prototype for to see whether it was feasible and fast enough, was doing JTAG over an FTDI dongle. In that application, I have a clear command/response structure where I know more or less exactly how many Bytes of IN transfer I'll get at what point, so the issue never really arose.

As I said before, my code currently doesn't even attempt to sup...

fallow birchBOT
#

Operating System

Linux

Board

STM32F723

Firmware

Use/examples/device/video_capture

What happened ?

Use/examples/device/video_capture
#define CFG_TUD_VIDEO_STREAMING_EP_BUFSIZE has a value greater than 1880
The image cannot be transferred
I just want the transmission speed to be faster
Because transferring Yuy2 format is very slow
Or should it be solved from somewhere else?

How to reproduce ?

#define CFG_TUD_VIDEO_STREAMING_EP_BUFSIZE has a value greater than ...

fallow birchBOT
fallow birchBOT
#

Operating System

Others

Board

Custom (STM32H7)

Firmware

  • st/synopsys port
  • no RTOS
  • gcc

I don't think any of these are relevant though, it's a compile-time error.

I propose a fix in PR https://github.com/hathach/tinyusb/pull/1646

What happened ?

Compiler error, due to a symbol being used before it is declared:

lib/tinyusb/src/class/audio/audio_device.c:2051:13: error: conflicting types for 'set_fb_params_freq'; have '_Bool(audiod_function_t *, uint...
fallow birchBOT
fallow birchBOT
fallow birchBOT
fallow birchBOT
fallow birchBOT
fallow birchBOT
#

This is the macro that expands to something like:

typedef char Line<XY>[(const_expr) ? 1 : 0];

This commit changes the macro to:

typedef char Line<XY><Z>[(const_expr) ? 1 : 0];
With Z being the value of _TU_COUNTER_.

Yes, the number does not contain the exact line number (because _TU_COUNTER_ was appended). But this is not an issue since the compiler error generated in case of a failed verification is the following:
`E0520094: The size of an array must be greater than ze...

fallow birchBOT
#

Operating System

Linux

Board

Custom board with STM32H730 and USB3343

Firmware

tinyusb 111515a
FW based on custom RTOS
should not be relevant for this case

tusb port config

#define CFG_TUSB_RHPORT1_MODE     (OPT_MODE_DEVICE | OPT_MODE_HIGH_SPEED)

What happened ?

After init, there is just one GINTSTS_USBRST event followed by one GINTSTS_USBSUSP event and nothing else happens after that. Tested with HUB and also directly with PC.

This board used t...

fallow birchBOT
fallow birchBOT
#

Operating System

Others

Board

doesn't matter

Firmware

Patch: https://paste.debian.net/1255382/

What happened ?

The bitorder in the usb488 subclass capabilities is wrong. I tried to attach a Patch, but its format gets corrupted, even if i use the "code" formatter. So i pasted it to paste.debian.net, see above.

How to reproduce ?

.

Debug Log as txt file

No response

Screenshots

No response

I have checked existing issues, dicussion and documentat...

fallow birchBOT
fallow birchBOT
#

When using osal_queue_send to send events to the queue _usbd_q in udbd.c's dcd_event_handler, the queue may overflow (particularly if the application calls usbd_defer_func too often). In that case, events will be missed, leading to spurious and hard-to-debug errors (for example, IN data is sent, ISR is called, but nothing else happens).

Therefore I'd like to suggest adding TU_ASSERT around the calls to osal_queue_send in order to make finding these bugs easier.

fallow birchBOT
#

Operating System

Others

Board

Raspberry Pi Pico

Firmware

Custom firmware based on examples.

What happened ?

I have a specific keyboard which fails to mount and always reports 'Control STALLED' followed by process_set_config 428: ASSERT FAILED.

Other keyboards I have access to appear to work as expected.

How to reproduce ?

Plug in keyboard.

Debug Log as txt file

HID Set Protocol = 0
[0:1] Set Interface: 21 0B 00 00 00 00 00 00
hw_endpoint_init dev 1 ep ...

fallow birchBOT
#

@hathach, I've been working on this as I use cmake for all my projects.
I've got it working, including support for generating tusb_config.h
There are issues with the RNDIS support because of the dependency on lwip and lib/networking that I could use feedback for.
I also have not integrated into the existing cmake example projects yet; that would be a future change dependent on this.
Are you interested in reviewing a WIP pull request for this?

fallow birchBOT
#

The test code is a bit complicated for PIC devices. Basically there are 2 factions when it comes to PIC development - some people would just use everything supplied by Microchip (including their huge IDE & build system), and other people (like me) use as many free software components as possible. Currently the test firmware project of the both PIC32MM and PIC24 uses CMake and contains some out-of-tree BSP files, and it would be unwise to include all of them in the TinyUSB code tree (or you th...

fallow birchBOT
#
fallow birchBOT
#

The bitorder in the usb488 subclass capabilities is wrong. I tried to attach a Patch, but its format gets corrupted, even if i use the "code" formatter.

Seems to work fine here :

From ec1a30ded4f6c5580f99a6daa43d341f352920a0 Mon Sep 17 00:00:00 2001
From: Daniel Gorsulowski
Date: Thu, 29 Sep 2022 10:24:48 +0200
Subject: [PATCH] fixed usb488 subclass capabilities bitorder

See Test & Measurement Class Specification
https://www.usb.org/document-library/test-measurement-cla...
fallow birchBOT
#

Describe the PR
Add support for MJPG on UVC.

It is tested with video_capture example on frdm_kl25z and raspberry pi pico

Additional context
video_capture uses MJPG video instead of uncompressed video when it builds with CFG_EXAMPLE_VIDEO_READONLY defined.

If a MCU has not enough SRAM for frame buffers, CFG_EXAMPLE_VIDEO_READONLY is already defined in board.mk at hw/bsp/. For example, frdm_kl25z and so on. Any other MUC which has enough SRAM for frame buff...

fallow birchBOT
fallow birchBOT
#

Operating System

Others

Board

Pico Pi

Firmware

None - compiling on WSL in Windows.

What happened ?

I'm trying to build host_hid_to_device_cdc in my own directory.
I get an error saying can't find pio_usb.h - which seems fair because I can't find it.

It is referred to in /hw/bsp/rp2040/family.c:

#if CFG_TUH_RPI_PIO_USB || CFG_TUD_RPI_PIO_USB
#include "pio_usb.h"
#endif

But if I cd /root/pico/pico-sdk and ls -R | grep "pio_usb.h" I get n...

fallow birchBOT
#

Ok I found this site which took me a step closer:

https://github.com/bgni/minimal-pico-tinyusb-pio-project

I need to

cd ~/pico/pico-sdk/lib/tinyusb

git -C tinyusb submodule update --init hw/mcu/raspberry_pi/Pico-PIO-USB

Then the file now exists - not really sure why it wasn't 'somewhere' before, but this bit of magic made it appear.

Now the 'can't find' error moved to hcd_pio_usb.c so perhaps it is now just because I need to set a directory in the cmake stuff........

fallow birchBOT
#

Discussed in https://github.com/hathach/tinyusb/discussions/1631

Originally posted by morio September 10, 2022
Is it possible to use TinyUsb to control two physical USB host ports?
Specifically on the RP2040 I'd like to use the builtin USB as host and the Pico PIO USB also as a host port at the same time.
This would be to allow a USB keyboard in one port and a USB mouse in the other.

I've seen the host_hid_to_device example in the Pico PIO USB project (https://github.com...

fallow birchBOT
#

Operating System

Others

Board

STM32F429

Firmware

BOARD_DEVICE_RHPORT_NUM  0
BOARD_DEVICE_RHPORT_SPEED  OPT_MODE_FULL_SPEED
CFG_TUSB_MCU  OPT_MCU_STM32F4
CFG_TUSB_OS  OPT_OS_NONE
CFG_TUSB_RHPORT0_MODE  (OPT_MODE_DEVICE | OPT_MODE_FULL_SPEED)
CFG_TUSB_RHPORT1_MODE  OPT_MODE_NONE
CFG_TUSB_RHPORT_MODE  (OPT_MODE_DEVICE | OPT_MODE_FULL_SPEED)

What happened ?

Vendor-specific class (device mode):
In the device, when the size of the data to transmit is multip...

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

Operating System

Windows 10

Board

Raspberry Pi Pico

Firmware

examples/device/cdc_msc

What happened ?

I am attempting to utilize the CDC device class to stream a large amount of data to the host PC, for example, to implement an EEPROM reader. However, I am unable to transfer more than about 128 bytes before the tud_cdc_write function simply stops sending any more data. The only way I have been able to get around this is by adding hard-coded delays between calls to tud_...

fallow birchBOT
#

Hi @hathach - the keyboard itself is an OEM product, this is the product link but it doesn't contain too much detail.

https://www.keyboardspecialists.co.uk/collections/kbskeyboards/products/kbs-pc-c?variant=9634038775850

It works ok with Windows and a PIC based USB host (which we are looking to replace with a TinyUSB powered Pico).

I've since also tried it with my MacBook which definitely doesn't like it (see attached), this now makes me think the keyboard isn't 100% USB compliant.
...

fallow birchBOT
fallow birchBOT
#

thanks to @jepler find out, we have a better understanding of this issue now

Jeff: Linux initializes serial ports with "echo" mode by default. This causes Linux to echo back all bytes it receives to the device. Standard terminal software like tio opens the device and promptly sets "-echo", but there is a race from open() to ioctl() during which characters can be echoed.

This appear to be the way Linux driver handle ttyacm, acm has init io as tty_std_termios, which has c_flag with EC...

fallow birchBOT
fallow birchBOT
fallow birchBOT
fallow birchBOT
fallow birchBOT
#

I will also appreciate that TinyUSB can work with 2 physicals devices ports to permit to link 2 usb host systems.

I inquired about this a while back, for other devices that support multiple device interfaces (STM32, etc), and it was not considered a priority.

Maybe there's some issues that I don't understand with doing that, but, IMO, it would be more useful than dual host.

My use case is in emulating a device from a machine that doesn't support device mode, like a standard PC. AFI...

fallow birchBOT
#

It seems that the checks are failing based on some MCUs that I did not modify files for? Did I do something wrong or how should I go about resolving this?

no worries, it is ci issue, sometime when running multiple jobs too often. It runs out of bandwidth or got into network issue. I have re-run ci. Please give me a bit of time for reviewing and pulling out an lpc55 board for testing.

fallow birchBOT
fallow birchBOT
fallow birchBOT
#

It seems that the checks are failing based on some MCUs that I did not modify files for? Did I do something wrong or how should I go about resolving this?

no worries, it is ci issue, sometime when running multiple jobs too often. It runs out of bandwidth or got into network issue. I have re-run ci. Please give me a bit of time for reviewing and pulling out an lpc55 board for testing.

Ok no problem, thanks for letting me know

fallow birchBOT
#

I am working on another device which has similar issue. As long as the device needs to dynamically allocate memory for endpoints, the device driver may have this issue.

If we solved it in certain driver, other drivers also need to solve similar issue. For example, for rp2040 current solution is deallocating all the memory until all endpoints closed, which may be an issue for composite device.

Hence, I think we need a simple memory allocator independent of driver. Then each driver can us...

fallow birchBOT
#

Related area

ST Synopsys port

Hardware specification

Cortex M7, STM32H750, USB3300, custom board

Is your feature request related to a problem?

The port currently lacks support for USB SOF frames.

Describe the solution you'd like

I will provide a PR with my proposed solution

I have checked existing issues, dicussion and documentation

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

@kaspernyhus @PanRe I'm sorry this has sat around for an extraordinary long time without further feedback.

The current DCD implementation in dcd_esp32sx.c does not fully support isochronous transfers. Could you please try applying the attached patch, and let me know whether it works for you?

diff --git a/src/portable/espressif/esp32sx/dcd_esp32sx.c b/src/portable/espressif/esp32sx/dcd_esp32sx.c
index a9c31132..dee2c855 100644
--- a/src/portable/espressif/esp32sx/dcd_esp32sx.c
...
fallow birchBOT
fallow birchBOT
fallow birchBOT
fallow birchBOT
fallow birchBOT
fallow birchBOT
fallow birchBOT
fallow birchBOT
#

I think there is likely a better solution, but it was causing me some issues not assigning the offsets to another location.

In functions such as dcd_init() and others, the USB would write to the offset in _dcd.ep[...][...].buffer_xx.offset and I think because the value of the DATABUFSTART register is 0x2000000, the USB was overwriting some other values I had in SRAM. The reason I noticed it was because the LED blink_interval_ms in main() was not changing corre...

fallow birchBOT
fallow birchBOT
#

Hello,
this is not a bug, the audio_test example was written intentionally to send a sawtooth signal such that the tester can verify if all samples are received and nothing is lost due to e.g. too slow MCU or ISO driver issues or other shortcommings. The audio_task() is usually not used and only exists due to historical reasons - although it could be used in principle. The data sent is loaded into the audio buffers within the tud_audio_tx_done_pre_load_cb() callback function. This appr...

fallow birchBOT
#

Currently this is a tricky question. The problem is, that the drivers are not informed about how many EPs in total exist for the current configuration and how big they are. This was a design question some time ago and it was decided that the drivers shall not come in contact with the configuration stuff. Hence, the driver must be able to allocate the space solely from the information given by the dcd_edpt_open() function time by time. This results in a fragmentation problem e.g. for the syn...

fallow birchBOT
#

Operating System

MacOS

Board

BluePill STM32F103C8

Firmware

Custom firmware at https://github.com/manuelbl/JavaDoesUSB/tree/main/test-devices/loopback-stm32.

Build instructions are in the README. It's a PlatformIO project.

The code contains a copy of the relevant tinyusb parts including a fix for this issue.

What happened ?

When usbd_edpt_close() is called, the firmware crashes at https://github.com/hathach/tinyusb/blob/master/src/portable/st/stm32_fsdev/dcd_stm3...

fallow birchBOT
fallow birchBOT
fallow birchBOT
#

Since the previoused pull request not merged, I change the title. As disscussed in #540, memory fragmentation force drivers to manage memory. Some driver implement as release all memory unitl all endpoints(except ep0) closed.

It may solve the problem for certain usb class devie, however for composite device, like me, report a HID & UVC device, since HID host driver never clear the interface, the endpoints for HID never closed, this cause memory for UVC endpoints not released.

Of cours...

#

Hello - I know this is an old issue but I seem to be having the same issue as described by todbot on MacOS. I am currently testing this with a very generic python script to read/write HID devices (although have tested with multiple others). This script works on Linux but not on MacOS (I cannot confirm Windows). I can confirm my device is sending the hid report with no issues by using a Beagle USB protocol analyzer. The device in question is using the RP2040 chip. I am at a loss on where to go...

fallow birchBOT
#

it is not clear enough that USB overwrite the data, even if that is the case, I think we should properly fix it e.g explicitly set SKIP/DISABLE bit for endpoint first before zero it out. Otherwise we could run into issue that host may think we already received data (overwritten to zero), while it is ended up in dummy. Maybe we should do it in a separated PR.

#

as rule of thumb, dynamic memory won't be used in the stack since it is an errorr-prone. Could you explain your scenario in more detail. I have an idea to add max_iso_size to the dcd_edpt_open for ISO to help with reserving the max buffer without having to re-allocated when switching interface.

HID host driver never clear the interface, the endpoints for HID never closed, this cause memory for UVC endpoints not released.

fallow birchBOT
#

I see that a == was changed to >=. I'm not so familiar with SAMD, but I figure this could cause issues with INT IN endpoints:

  1. Class defines INT IN endpoint with wMaxPacketSize=10
  2. Driver sets hardware to use wMaxPacketSize=16
  3. Class starts transfer of 25 bytes.
  4. Peripheral transmits packet of size 10 which would confuse the host since it expects a max packet size of 10 bytes.

Thank you @pigrew for reviewing, this is SAMD port specific. SAMD endppoint can ...

fallow birchBOT
#

There should be no need to allocate memory dynamically, this functionality is already provided by the FIFOs! Or do i miss here something? Buffering data via FIFOs, for instance, is done in the audio driver under the hood.
Furthermore, it seems your solution only aims at rp2040? At least for the dwc2 driver we have the problem of USB hardware FIFO fragmentation... your approach would not solve this issue...

fallow birchBOT
fallow birchBOT
#

I think I have narrowed it down to dcd_edpt_xfer() when buffer is NULL, occurring for EP0 OUT ZLPs. The code below makes it modify dummy, and the other previous locations of dummy can be removed. From what I have seen, the USB writes 4 bytes of zeros to its offset location in this scenario. I am not sure if there is a proper solution to this aside from a dummy buffer?

bool dcd_edpt_xfer(uint8_t rhport, uint8_t ep_addr, uint8_t* buffer, uint16_t total_bytes)...
fallow birchBOT
fallow birchBOT
#

@hathach the approach to add max_iso_size to dcd_edpt_open means driver may reserve the memory for particular endpoint? But for UVC class, one interface may have multiple settings for different resolution and frame rate, hence need different packet size. If the high-framerate setting was set first, then switch to low-framerate setting (two setting has different max packet size), the driver may still reserve the bigger one? If so, other endpoints (like vendor device or other class) may not...

fallow birchBOT
#

@PanRe, I have traced the code for dwc2 driver but not test actually, just thought the close endpoint order depends on open endpoint order can be better.

Copy comments from dcd_synopsys.c

// "USB Data FIFOs" section in reference manual
// Peripheral FIFO architecture
//
// --------------- 320 or 1024 ( 1280 or 4096 bytes )
// | IN FIFO 0   |
// --------------- (320 or 1024) - 16
// | IN FIFO 1   |
// --------------- (320 or 1024) - 16 - x
//...
fallow birchBOT
#

If the high-framerate setting was set first, then switch to low-framerate setting (two setting has different max packet size), the driver may still reserve the bigger one? If so, other endpoints (like vendor device or other class) may not have theoretically much memory to use (some memory is reserved by driver, but actually not used).

For now, I think it should reserve highest memory for ISO, since host can switch to highest bandwidth at any time so we don't have to deal with run-time me...

fallow birchBOT
#

Closing of OUT EPs is not an issue since the memory of out EPs is shared for all OUT EPs. It is about the IN EPs (the TX buffers).You can close any IN EP any time, however, the allocated memory of the respective EP closed might be located in the middle of other allocated areas. The problem now is, that all TX buffers still existing would need to be relocated s.t. no gaps occur. However, doing so in the middle of ISO transfers would mean, that you need to wait until the TX buffer t...

fallow birchBOT
fallow birchBOT
#

For my application, I need to report as a HID device(interrupt ep) and UVC device(iso ep) and use the 2 devices independently. The following flow cause problem:

  1. open HID device -> allocate memory for interrupt ep
  2. open UVC device -> allocate memory for iso ep
  3. close UVC device -> as current rp2040 driver, since there are still eps other than ep0 opened(interrupt ep for HID) no memory will be deallocated.

Then repeat step 2) and 3) can cause out of bus memory.

fallow birchBOT
#

Related area

Audio class UAC2

Hardware specification

STM32H7 (probably not relevant)

Is your feature request related to a problem?

UAC2 supports an interrupt endpoint to provide notifications to the hose about control changes (e.g. mute button pressed on the device).

I see that there is some code for this, but it seems incomplete.
I see audio_device.c never assigns a value to audio->ep_int_ctr.
Compare to feedback endpoint (which I have working), which assigns and cl...

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

For a single active configuration descriptor, HID will not be closed but only opened once the configuation is setup by tinyUSB. This means in generall, that control, bulk, and interrupt EPs are usually (according to the USB protocol) not to be closed. This only happens if a new configuration descriptor is setup and in this case, all EPs are closed.
ISO EPs to the contrary are setup from a command sent from the host. This can only happen once tinyUSB already setup all the remaining EPs. This ...

fallow birchBOT
#

thanks @PanRe for detail explanation, indeed, so far for all practical usages, only ISO endpoint changes its size while in configured mode. for all other endpoints CBI (control bulk interrupt). @mingpepe your current issue with open/close ISO when switching alt interface can be resolved in much easier way in rp2040 driver. The upcoming max iso size when opening an iso can definitely help with this.

fallow birchBOT
#

This is using GCC 12.2.0, st/synopsys port, STM32H7.

The attributes (CFG_TUSB_MEM_SECTION CFG_TUSB_MEM_ALIGN) are being applied to a member of a struct.
I don't think it makes sense (regarding memory layout) for some members of a struct to be in a different linker section to the rest of the struct?

The only instance of the struct is (around line 413):

CFG_TUSB_MEM_SECTION audiod_function_t _audiod_fct[CFG_TUD_AUDIO];

So the struct (and therefore its members) are alrea...

fallow birchBOT
#

Yeah, thanks from me as well! I am currently trying to put the UAC2 audio class into a stm32.
I have built a lot of systems with USB interface and getting CDC class to run with the internal UART was exceptionally easy and I am really impressed by tinyusb.
This evening I tried the UAC2 stuff and I was very sad, when I found out, that it does not work at all.
I haven't done a lot with STM32's USB stuff, but if there is anything I could do to help, let me know.

fallow birchBOT
fallow birchBOT
fallow birchBOT
#

Since this is still open, with seemingly insufficient documentation, here's what I posted to the RPi forum a couple days ago:
https://forums.raspberrypi.com/viewtopic.php?t=341735
My entire project is over there, after paring it back down to what I think is equivalent to the uac2_headset example. (that's what I get for assuming that the examples "just work")


Essentially, it works immediately after plugging it in. It enumerates just fine, it appears on my Pi4 (Raspberry Pi OS, fu...

fallow birchBOT
#

Relates to issue https://github.com/hathach/tinyusb/issues/1697

Describe the PR

UAC2 supports an interrupt endpoint to provide notifications to the host about control changes (e.g. mute button pressed on the device).

The interrupt endpoint lives in the control interface, and transmits 6-byte messages to notify the host about control values changing.
The host may then decide to issue a get-entity request via the control endpoint in order to read the new control value.

These in...

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

Hi guys, I did not continue with my approach as I was waiting for a good state of @pigrew 's work. Because: my first approach still has the problem with different endpoint directions having the same address and this had to be tidied up first. This is mandatory because of UAC2 sync endpoint needing to have the same address as the corresponding data endpoint. Unfortunately I don't have much time to dig in the current changes of @pigrew, so I need to wait for some "stable" state of the code with...

fallow birchBOT
fallow birchBOT
#

Hi @skuep, yes you're mixing up UAC and UAC2.
I also hat tests in implementing UAC class but the UAC-driver on windows does not really allow syncing. So in order to get a valid synced audio you would need to implement UAC2. And UAC2 has removed the bSyncAddress field. From UAC2 on the sync-address needs to sit on the same index as the corresponding data endpoint. So if you don't want to implement an ASRC on your device, you'd either need to have a sync-endpoint or you need to live with fram...

fallow birchBOT
fallow birchBOT
fallow birchBOT
fallow birchBOT
#

Hi again, @Iktek,
Can you give me a link to the @pigrew tinyusb fork? Is he currently working on this feature?
I just had some spare time and I have implemented a rather crude way of handling this issue.
See this commit https://github.com/hathach/tinyusb/commit/af46a53bdfaf925332bbff4446bc2196972b2c69
By default, the tinyusb stack works just as normal, but I added an application callback, that you can use to alter the "mapping" of the endpoint address to the internal endpoint registers.
...

#

Hi again, @Iktek, Can you give me a link to the @pigrew tinyusb fork? Is he currently working on this feature?

I got sidetracked, and didn't get nearly as far as I had hoped.

The tricky part is handling the allocations of the PMA for double-buffered endpoints (and I found that the existing code had some rather substantial bugs). I was rewriting the PMA allocation code and endpoint housekeeping to handle double-buffering.

The link is https://github.com/pigrew/tinyusb/tree/stm32_doub...

#

@pigrew: Thanks for the heads-up. I will dig through your changes and see what's what :-)
What issues with the PMA for double buffered endpoints did you have? Since tinyusb does not seem to implement any double-buffering features (for now?) I basically now just left everything as-is with PMA allocation and just set both (TX and RX) (double-) buffer locations to the same buffer.

#

Also, to get this (and feedback) working on my STM32H7 board, I also had to use this patch (for enabling SOF interrupt):
https://github.com/hathach/tinyusb/issues/1684

This is with the st/synopsys port.
I recently and briefly tried the synopsis/dwc2 port, but it didn't work out-of-the-box.
So I switch back to st/synopsys for now, and will look into the dwc2 issue sometime in the future.

fallow birchBOT
#

@pigrew: Thanks for the heads-up. I will dig through your changes and see what's what :-) What issues with the PMA for double buffered endpoints did you have? Since tinyusb does not seem to implement any double-buffering features (for now?) I basically now just left everything as-is with PMA allocation and just set both (TX and RX) (double-) buffer locations to the same buffer.

EDIT: Had a look at your code. Yeah, you are totally right with the PMA allocation bug. I am going to steal...

fallow birchBOT
fallow birchBOT
#

Yeah, this is exactly the problem we are running into here. I am currently still using the method of custom mapping the endpoint address to the hardware endpoint using a callback function. However I have made some progress in my fork:

  • I added your fix regarding the buffer size during allocation to be aligned to the allowable hardware sizes
  • I added what you call "indirection" into the code where it was necessary. I re-used the already present xfer_ctl_tstructure

https://github.com...

fallow birchBOT
#

Ah sorry, this is leftover from when I initially hacked it together for my specific project. I'll generalise that soon.

Also, since there are several places where we sequentially search the descriptors for some specific descriptor, should I create a separate function for doing that, which takes a predicate as an argument?
It should reduce code-size a bit while not burning a significant amount of extra cycles as a result.
And the CPU overhead shouldn't matter much anyway since this is se...

fallow birchBOT
#

Thanks a lot! Indeed the interrupt EP was not implemented correctly! Since you are the first one who needs it, i am glad you fix the issues!
One thing, the naming convention CFG_TUD_AUDIO_INT_CTR_EPSIZE_IN was wrongly introduced and is misleading - CTR has nothing to do with the interrupt EP, so it should be skipped. Could you fix that if you have the time?

fallow birchBOT
fallow birchBOT
fallow birchBOT
fallow birchBOT
#

Thanks a lot and sorry for the late reply! I have but a few questions on this:

  • do we need a separate buffer for the interrupt messages to be sent?
  • where is the interrupt EP communication handled? I guess its outside the UAC2 driver currently. Does it make sense to incorporate the INT EP comunications somehow into the UAC2 driver?
  • i know this could be a lot of work but i wanted to ask: could you come up with some minimum working example such that other users could start on INT EPs wit...
fallow birchBOT
#

The buffer within the tinyusb audio device structure was there already when I started this work - I have no idea if it's required or if we can bypass it.

My board + build system are quite custom so I can't easily extract an example out or test an example project.

Here's the relevant code though for using this feature. I have a buffer containing three pre-determined messages, which I send incrementally when the audio controls have changed (which can happen by user using physical control...

#

Almost forgot, relevant part of descriptor. Goes in control-interface part of descriptor, i.e. before any of the streaming interfaces/alternates.

descriptor

#if USB_ENABLE_STATUS_EP
#define STATUS_INT_EP_DESC_LEN TUD_DESC_EP_LEN
#define STATUS_INT_EP_DESC() \
		TUD_DESC_EP( \
			ENDPOINT_AUDIO_INTERRUPT, \
			HOSTIN_AUDIO_INTERRUPT_TYPE, \
			6 /* Buffer size as per standard */, \
			CONTROL_UPDATE_INTERVAL_LOG2P1 \
		),
#else
#define STATUS_INT_EP_DESC_LEN 0
#define S...
#

Project-specific implementation details in my case:

Basically - each thing that cares about the audio controls has a value in a CONTROL_OBSERVER_* enum to represent it.
These are "observers", example:

  • The audio processor unit is an observer of the controls.
  • The USB control/status unit is an observer of the controls.
  • The serial user-interface is also an observer of the controls.

There's an array of observer flags (bool), one for each observer.

Whenever a control value...

fallow birchBOT
#

The included DHCP server fails to process DHCP DISCOVER or REQUEST packages that don't contain the "DHCP MESSAGE TYPE" option as the first option in the package.
The initial report that triggered me was in https://github.com/OpenLightingProject/rp2040-dmxsun/issues/53 and after some investigation, I found that the "dhcpcd" client (maybe others, too) don't send the MESSAGE TYPE as the first option (see Wireshark dump attached in the linked issue). This seems to be valid since the order of the...

fallow birchBOT
#

I've been using tinyUSB on the STM32L452 successfully for a few months, so I can confirm it works with the following changes:

In file dcd_stm32_fsdev.c:

+#if defined(STM32L452xx)
+#define STM32L4_FSDEV
+#endif
#if TUSB_OPT_DEVICE_ENABLED && \
      ( TU_CHECK_MCU(OPT_MCU_STM32F0, OPT_MCU_STM32F3, OPT_MCU_STM32L0, OPT_MCU_STM32L1, OPT_MCU_STM32G4) || \
-        (TU_CHECK_MCU(OPT_MCU_STM32F1) && defined(STM32F1_FSDEV)) \
+        (TU_CHECK_MCU(OPT_MCU_STM32F1) && defi...
fallow birchBOT
#

Related area

Fuzz testing

Hardware specification

Host only

Is your feature request related to a problem?

No

Describe the solution you'd like

I'd like to improve the security and robustness of the tinyusb stack by adding a set of fuzz tests.

I have checked existing issues, dicussion and documentation

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

Adds support for fuzzing with basic a cdc fuzzer.

Describe the PR
This fuzz harness adds the necessary build infrastructure for fuzzing tinyusb. As a proof of concept there is a cdc fuzz harness written in c++. The intention of this PR is to improve security and robustness of the tinyusb stack by tracking down bugs and performance problems using fuzz testing.

fallow birchBOT
fallow birchBOT
fallow birchBOT
#

Thank you very much for this brilliant PR and every for helping testing and verifying. Indeed the datasheet seems to hint that these "Interrupt" endpoints are used for Interrupt type. Using them with bulk in asynchronous manner is a great find out. Which simplify the usbh driver.

Basically the interrupt and bulk have the same packet layout (pid, data, crc, ack), the difference is that bulk endpoint will continuously transferring data as long as bus frame (1ms) is allowed. For example, we c...

fallow birchBOT
#

Related area

device stack

Hardware specification

rp2040

Is your feature request related to a problem?

I am currently working on porting https://github.com/rppicomidi/midi2usbhost to support USB host and device mode without providing different firmware and noticed that TinyUSB currently doesn't support compiling with USB host and device support at the same time.

Describe the solution you'd like

I would like to be able to deal with USB host and device switching in softwar...

fallow birchBOT
#

Operating System

Others

Board

Raspberry Pi Pico

Firmware

I am working on a mass storage class demo program here. I am able to mount a flash drive, list directories and display file contents, but only if double-buffering is disabled.

What happened ?

When the fatfs code attempted to read the 512 byte boot sector from the flash drive, the code hung up waiting for the transfer
callback to be called.

How to reprod...

fallow birchBOT
#

Operating System

MacOS

Board

raspberrypi pico rp2040

Firmware

examples/device/audio_4_channel_mic

What happened ?

The device succesfully shows up as a 4 channel USB device, but only 2 of 4 channels transmit the test data.

  • Channel 1 & 3 transmit a low amplitude saw tooth wave (as expected)
  • Channel 2 & 5 transmit total silence

How to reproduce ?

compile & flash example to rp2040
open in DAW (tested in Audacity & Ableton Live)

Debug Log as ...

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

Describe the PR
Implement #1406 with Raspberry Pi4 as self-host. Current self-hosted set up is

  • pico + pico-probe connected via USB
  • pico-probe is /dev/ttyACM0

There are only a handful of tests currently. Due to limited power of RPI4, test_hardware workflow only run with commit done by user hathach for now. We will see how this approach turn out and maybe adding more tests and/or expand the self-host instance.

fallow birchBOT
#

part of the HITL is implemented in #1724, It works with an RPI4 + pico running several device examples. The script does test try to interact with device image correctly e.g dual cdc, cat msc's readme, run dfu-util with dfu examples etc... It is neither perfect nor complete, but is a good start.

Note: due to limited resources on Pi4, currently only code committed by me (or after merged to master) could run the self-hosted instance

https://github.com/hathach/tinyusb/blob/master/.github/w...

fallow birchBOT
#

One of the builds has failed. But not due to my code changes. Rather it's an internal compiler error triggered by completely unrelated code (see below). This is not the only affected PR. I can see at least 3 more affected ones. And they don't all fail on the same code. It also affects the RP2040.

Are you aware of the issue? How should we proceed with this?

/home/runner/work/tinyusb/tinyusb/hw/mcu/nuvoton/nuc505/StdDriver/src/clk.c:26:5: internal compiler error: Illegal instruction
...
fallow birchBOT
fallow birchBOT
fallow birchBOT
#

Describe the PR
Add support for STM32L412 who use stm32_fsdev driver, Shuld also work for STM32L41xxx/42xxx/43xxx/44xxx/45xxx/46xxx.

Tested CDC ok on STM32L412-Nucleo.

Need to be tested with GCC since I'm using IAR.

Additional context
While trying to find a board for HITL setup, I found this board who use the same driver as STM32L0, which is used for our product.

fallow birchBOT
#

Operating System

Others

Board

RP2040

Firmware

examples/device/uac2_headset

What happened ?

After upload the .uf2 file from uac2_headset example compilation it works, but after changing a song or keep listening for a while it fails calling the function tud_audio_set_itf_cb with parameters interface 1 alt X (alt varies between 0~2) but it always fails on this function. I also connected an UART to the pins 0 and 1 of the raspberry and it says `*** PANIC *** Hard as...

fallow birchBOT
fallow birchBOT
fallow birchBOT
#

Related area

Security/vulnerability reporting

Hardware specification

N/A

Is your feature request related to a problem?

I think I've found a security vulnerability, but I don't want to publicly describe the problem on a GitHub issue until the problem is fixed. Having a security problem published publicly would open people up to attack.

Describe the solution you'd like

I'd like some procedures to be in place to;

  • Contact the maintainers of this repository with security ...
fallow birchBOT
#

Operating System

Others

Board

RP2040-Zero

Firmware

examples/device/hid_boot_interface

But really, every tinyusb example I tested exhibited the same problem.

What happened ?

On RP2040-Zero, immediately after flashing the firmware, a TinyUSB device shows up and can interact with the computer.

However, upon disconnecting and reconnecting, the device no longer shows. Plugging it in to other devices also do not recognize the TinyUSB device.

Have noticed this with ...

fallow birchBOT
#

Test with GCC 11.3, both cdc_dual_ports & cdc_msc runs well, while cdc_msc_freertos has some issues:

[79082.879597] sd 7:0:0:0: [sdb] Attached SCSI removable disk
[79246.553862] usb 4-1.2: USB disconnect, device number 7
[79247.544292] usb 4-1.2: new full-speed USB device number 8 using xhci_hcd
[79247.646280] usb 4-1.2: New USB device found, idVendor=cafe, idProduct=4003, bcdDevice= 1.00
[79247.646283] usb 4-1.2: New USB device strings: Mfr=1, Product=2, SerialNumber=3
[7924...
fallow birchBOT
fallow birchBOT
fallow birchBOT
fallow birchBOT
fallow birchBOT
#

Operating System

MacOS

Board

STM32 with OTG device (Synopsys DWC)

Firmware

--

What happened ?

The dwc2 code checks the wrong status register when processing the Rx FIFO:

    // Loop until all available packets were handled
    do
    {
      handle_rxflvl_irq(rhport);
    } while(dwc2->gotgint & GINTSTS_RXFLVL);

See https://github.com/hathach/tinyusb/blob/master/src/portable/synopsys/dwc2/dcd_dwc2.c#L1316

The correct line should be:

    } ...
fallow birchBOT
#

Thanks for that @rppicomidi

There is a typo though which causes issues on a mac:

#if MIDI_NUM_CABLES>1
  TUD_MIDI_DESC_JACK(2),
#if MIDI_NUM_CABLES>2
  TUD_MIDI_DESC_JACK(3),
#if MIDI_NUM_CABLES>3
  TUD_MIDI_DESC_JACK(3),

should be

#if MIDI_NUM_CABLES>1
  TUD_MIDI_DESC_JACK(2),
#if MIDI_NUM_CABLES>2
  TUD_MIDI_DESC_JACK(3),
#if MIDI_NUM_CABLES>3
  TUD_MIDI_DESC_JACK(4),
fallow birchBOT
fallow birchBOT
fallow birchBOT
#

I got here from googling when having a similar issue. Basically if you write into the cdc buffer (or vendor ifc buffer in my case) and then the host stops reading it just sits in there. Then when you say open up your PC program again and start reading again it will get that old data. It would be nice to have a way to flush it out on the device side if there is a timeout, but in my case I just made sure to write my host program and communication protocol in a way that at startup it reads out a...

fallow birchBOT
#

Hi guys, so I got UAC2 speaker and microphone working (thanks to @Iktek for the descriptor example above). See my tinyusb branch here:
https://github.com/hathach/tinyusb/compare/master...skuep:0.14.0-sk

Here is the device I have implemented. Note that currently, although feedback generation is working, it is lacking the long-term buffer drift prevention Feature required by the USB spec. So when playing an audio file for half an hour, buffer creeps dangerously low.
https://github.com/skue...

fallow birchBOT
fallow birchBOT
#

Cool thanks! I will have a look at it.

I have been reading and thinking about how to do this and (as other people do) I think that a feedback purely based on FIFO count is not according to specs because you basically implement a P controller on your device (i.e. you use some kind of feedback to keep the FIFO count constant).
However, only the host is supposed to have a controller, the device only states the number of samples played. The spec then goes on and says that over the long term,...

fallow birchBOT
#

So I am not sure if the dual controller scenario can result in instability issues in case the parameters are not chosen wisely.

In theory it's possible, so I've limited feedback min/max to a small interval.

I did all tests on HS, on which fifo level is easier to be regulated than FS, result is satisfying amount 44.1KHz to 384kHz.

However, only the host is supposed to have a controller, the device only states the number of samples played.

IMHO is the UAC specification who shoul...

fallow birchBOT
#

IMHO is the UAC specification who should be blamed. What it want to achieve is a regulated loop, but in real it's not a closed-loop system as the feedback is only an estimation.

I agree. The UAC spec is not really the USB consortium finest work if you ask me. Why didn't they just specify that the device regularly send a monotonically increasing counter (integral) of all samples played up to now (and let it wrap around at 2**32-1). There would be no issue whatsoever with buffer level drif...

fallow birchBOT
fallow birchBOT
fallow birchBOT
#

cd ~/pico/pico-sdk/lib/tinyusb

A little correction - for the submodule update this should be cd ~/pico/pico-sdk/lib (it's also best to reference $PICO_SDK_PATH environment variable instead of your directory).

However, git -C tinyusb submodule update --init hw/mcu/raspberry_pi/Pico-PIO-USB submodule update didn't work (same issue not finding pio_usb.h).

However, after some head-scratching, I performed a git submodule update --init --recursive in the Pico SDK source root (`...

fallow birchBOT
fallow birchBOT
fallow birchBOT
fallow birchBOT
#
[hathach/tinyusb] New branch created: add\-HiFiPhile\-selfhost
fallow birchBOT
fallow birchBOT
fallow birchBOT
fallow birchBOT
#

Operating System

Linux

Board

Custom RP2040 board

Firmware

https://github.com/rppicomidi/midi2usbhost custom version

What happened ?

I've built a custom board which has USB Type-C for Firmware Uploads (and during boot) and a USB Type-A which is switched to the D+/D- Pins with a FSUSB42 (and which power is controlled via MOSFET).

The select pin of the FSUSB42 is pulled low, so the device starts up with the USB-C being active for firmware upload.
Then the firmware puts...

fallow birchBOT
#

Operating System

Others

Board

Custom RP2040 board

Firmware

Stock TinyUSB

What happened ?

Devices which are bus powered don't enumerate or power up on iOS devices, such as iPad or iPhone.

How to reproduce ?

Connect a USB device running the TinyUSB stack to an iPad or iPhone.

Debug Log as txt file

No response

Screenshots

No response

I have checked existing issues, dicussion and documentation

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

sorry for late response as usual, yeah, I remembered seeing some issue with double buffering in device (out endpoint), and thought that would also apply to host in as well

https://github.com/hathach/tinyusb/blob/master/src/portable/raspberrypi/rp2040/rp2040_usb.c#L155-L157

I forgot the detail, but disabling double buffered is not really an option here due to rp2040 Errata E4 #891 (also it hurts throughput). The optimal solution is figuring out what is wrong with double buffered and fix...

fallow birchBOT
fallow birchBOT
#

As I recall Errata E4 has a workaround for single-buffered transactions, which you have already implemented in sync_ep_buffer(). I agree disabling double-buffering hurts throughput, but from my testing, it does not seem to hurt functionality.

The current code in _hw_endpoint_start_next_buffer() is

  // For now: skip double buffered for Device mode, OUT endpoint since
  // host could send < 64 bytes and cause short packet on buffer0
  // NOTE this could happen to Host mode IN ...
fallow birchBOT
#

@hathach
I just tried the following code patch and it worked for MSC. If I only disabled double-buffering for IN endpoints, then
IN endpoints work fine, but OUT transactions do not complete; f_mkdir(), for example, locks up.

  // For now: skip double buffered for Device mode, OUT endpoint since
  // host could send < 64 bytes and cause short packet on buffer0
  // NOTE this could happen to Host mode IN endpoint
  bool const force_single = (!(usb_hw->main_ctrl & USB_MAIN_CTRL_HOS...
fallow birchBOT
#

E4 requires a walkaround when using host with single buffered mode, which is removed when double buffered is implemented. From my experience, the walkaround has its own bizarre issue and not working reliably as well. As mentioned above, going back to single buffered + E4 + walkaround is not a good approach. The optimal solution is fixing what is breaking with double buffered, maybe we just miss some logic/buffer/sync/schedule etc ...

btw, I really like your msc demo, I have written an sim...

fallow birchBOT
#

@atoktoto I found a fix for hubs not working with this. I made the error in my original pull request. Would you consider adding this change to your pull request?

diff --git a/src/class/midi/midi_host.c b/src/class/midi/midi_host.c
index d242d33c5..bc87898cc 100644
--- a/src/class/midi/midi_host.c
+++ b/src/class/midi/midi_host.c
@@ -490,7 +490,7 @@ bool midih_set_config(uint8_t dev_addr, uint8_t itf_num)
   p_midi_host->configured = true;
 
   // TODO I don't think there are any ...
fallow birchBOT
#

Sure, I will to that tonight.

W dniu 18.11.2022 o 23:51 rppicomidi pisze:

@atoktoto https://github.com/atoktoto I found a fix for hubs not working with this. I made the error in my original pull request. Would you consider adding this change to your pull request?

`diff --git a/src/class/midi/midi_host.c b/src/class/midi/midi_host.c
index d242d33c5..bc87898cc 100644
--- a/src/class/midi/midi_host.c
+++ b/src/class/midi/midi_host.c
@@ -490,7 +490,7 @@ bool midih_set_conf...

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

Hi @atoktoto,

The last update from @rppicomidi fixed the enumeration problems but there are still data transfer problems, this fixes it:

diff --git a/src/class/midi/midi_host.c b/src/class/midi/midi_host.c
index bc87898c..8df1b200 100644
--- a/src/class/midi/midi_host.c
+++ b/src/class/midi/midi_host.c
@@ -529,7 +529,7 @@ bool tuh_midi_read_poll( uint8_t dev_addr )
   if (in_edpt_not_busy)
   {
     TU_LOG2("Requesting poll IN endpoint %d\r\n", p_midi_host->ep_in);
-    TU_...
#

Describe the PR

following discussion from #1721, this PR add an msc file explorer example with the help of following 3rd-party library

Tested on mcb1800 (ehci) and rp2040 pico with pio-usb as host controller (change CFG_TUH_RPI_PIO_USB =1 in tusb_config.h). Note: rp2040 native usb host controller has issue mouting msc device probably due to issue mentioned in #1721 ...

fallow birchBOT
fallow birchBOT
fallow birchBOT
#

@paulhamsh Apologies for the delay, here's my CMakeLists.txt for the project (with some cruft removed):

cmake_minimum_required(VERSION 3.13)

set(CMAKE_C_STANDARD 11)
set(CMAKE_CXX_STANDARD 17)

set(FAMILY rp2040)
set(BOARD pico_sdk)

include($ENV{PICO_SDK_PATH}/external/pico_sdk_import.cmake)
if (PICO_SDK_VERSION_STRING VERSION_LESS "1.4.0")
    message(FATAL_ERROR "Raspberry Pi Pico SDK version 1.4.0 (or later) required. Your version is ${PICO_SDK_VERSION_STRING}")
endif(...
fallow birchBOT
#

Related area

New Port Support

Hardware specification

Windows 10 PC

Is your feature request related to a problem?

So projects using TinyUSB can be tested on a Windows PC without hardwares

Describe the solution you'd like

https://github.com/microsoft/UDE

Seems like Windows 10 supports USB device emulation, does this mean TinyUSB can be ported on top of it and presented to Windows as a virtual USB device?

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

fallow birchBOT
#

OK. Something to note when you get back to it. From the RP2040 datasheet, double buffer does not work for Host Interrupt
endpoints. I presume the same applies for Host bulk endpoints given how they are implemented now.

4.1.2.7.4. Interrupt Endpoints
The host controller can poll interrupt endpoints on many devices (up to a maximum of 15 endpoints). To enable these,
the programmer must:
• Pick the next free interrupt endpoint slot on the host controller (starting at 1, to a maximum of 15...

fallow birchBOT
#

@rppicomidi yeah, I think you probably hit the nail on the head. I totally forget about this, and didn't pay attention to this. In this case we should disable double buffering for non-control endpoint with the current implementation + E4 walkaround. Hopefully this could buy us time to better support bulk endpoint without using interrupt endpoint for the sake of throughput later on.

fallow birchBOT
#

Related area

new port support

Hardware specification

STM32G0

Is your feature request related to a problem?

no

Describe the solution you'd like

Hi.

ST's Cortex-M0+ microcontroller G0 series has USB FS device and host controller on G0B and G0C.
It seems it only supports G4 series right now. Is there any plan to support STM32G0 series?

Thanks for checking this request.

I have checked existing issues, dicussion and documentation

  • [X] I confirm I have checked e...
fallow birchBOT
fallow birchBOT
#
[hathach/tinyusb] New branch created: rework\-host\-msc\-complete\-callback
fallow birchBOT
fallow birchBOT
#

I am new (clueless) to this microsoft UDE. But it sounds like a great way to emulate TinyUSB with windows. Also have you tried running Microsoft device examples, it would be helpful to detail the step to run/test since I am mostly on Linux and only has an decade-old windows laptop.

No yet. I wish I know more about how USB works at a lower level to port it myself.

fallow birchBOT
fallow birchBOT
rich holly
#

if i wanted to port TinyUSB to a new Arduino core, is Adafruit_TinyUSB_Arduino the correct starting place? how is it synchronized with the upstream TinyUSB?

odd swan
fallow birchBOT
#

I've tested this and still the system is freezing on f_open().

Last words before hangup:

SCSI Test Unit Ready
  Queue EP 02 with 31 bytes ...   EP STATE BUSY: 0OK
Buffer complete
on EP 02 with 31 bytes
MSC xfer callback
  Queue EP 81 with 13 bytes ...   EP STATE BUSY: 0OK
Buffer complete
on EP 81 with 13 bytes
MSC xfer callback
SCSI Read Capacity
  Queue EP 02 with 31 bytes ...   EP STATE BUSY: 0OK
Buffer complete
on EP 02 with 31 bytes
MSC xfer callback
  Queue EP 81 w...
rich holly
fallow birchBOT
fallow birchBOT
fallow birchBOT
fallow birchBOT
#

@HiFiPhile the callback is already existed, did you mean you want to implement it.

https://github.com/hathach/tinyusb/blob/081e4eecba3c91f08cdf96b0a090e7726cec3727/examples/device/cdc_msc/src/usb_descriptors.c#L254

Yeah, I am planning to add and board_get_uid()/board_get_usb_serial() similar to this implementation of tinyuf2 here, but always got too busy with other works.

https://github.com/adafruit/tinyuf2/blob/4fb0d86fe82659d599b034864f8b1aee1656de75/src/usb_descriptors.c#L190

fallow birchBOT
#

I just encounter this issue while working on other task. Could you confirm the failed control occurred with the very first control by adding TU_LOG_LOCATION() here (with LOG=1)

https://github.com/hathach/tinyusb/blob/081e4eecba3c91f08cdf96b0a090e7726cec3727/src/host/usbh.c#L1187

If yes, then the issue is not host stack not waiting, since stack already wait 500ms (longer than USB specs requires). The bug is caused by device side start up is taking too long. A proper fix would be retry a ...

fallow birchBOT
fallow birchBOT
#
[hathach/tinyusb] New branch created: host\-retry\-failed\-enumeration\-request
robust walrus
#

@rich holly I'd suggest posting a discussion topic on the tinyusb repo

fallow birchBOT
fallow birchBOT
fallow birchBOT
fallow birchBOT
fallow birchBOT
#
[hathach/tinyusb] New branch created: rp2040\-host\-bulk\-comment
#

Related area

Host Driver (HCD)

Hardware specification

rp2040

Is your feature request related to a problem?

BULK endpoint support for RP2040 HCD support is added thanks to #1434. Even though it works wonderfully However since the PR uses hardware "interrupt" endpoint to implement BULK, there is a drawback. The max throughput with "interrupt" endpoint is only 64 KB/s since controller will only carry 1 packet per frame which is max 64 bytes per 1 ms. This defeat the purpose of B...

fallow birchBOT
#

This PR will add FT9xx support for more of the USB device examples.
There are fixes for the FT9xx MCU port. Fixes for properly handling back-to-back transactions on the control endpoint as EP0 must always be enabled and receiving - extended to all OUT endpoints. Prevent interrupt endpoints from transmitting ZLPs.
Signal xfer completions correctly (multiple for OUT transfers). Remove unnecessary volatile qualifiers.
Build flags and function names renamed to ft9xx/ft90x/ft93x to indicate tar...

fallow birchBOT
fallow birchBOT
fallow birchBOT
fallow birchBOT
#

Hi @hatach ,

I have also added another 'FreeRTOS' related commit to this pull request to eliminate the need to repeatedly call the tuh_task() when using FreeRTOS. You can just start tuh_task() as a normal task from FreeRTOS like this:

xTaskCreate( (TaskFunction_t)tuh_task, "USB", THREAD_STACKSIZE, NULL, USB_PRIORITY, NULL );

This eliminates the very small overhead incurred when calling the function continuously in a loop from another FreeRTOS task which is not necessary...

fallow birchBOT
fallow birchBOT
fallow birchBOT
fallow birchBOT
#

Operating System

Windows 10

Board

Raspberry Pico

Firmware

Not sure

What happened ?

I took the steps mentioned here (https://docs.tinyusb.org/en/latest/reference/getting_started.html)

I've cloned tinyusb to a local folder. Included tusb.c into my project.
When I compile I get an error in osal_pico.h about unable to find "pico/time.h".
Indeed this file can't be found on my computer.

How to reproduce ?

See above

Debug Log as txt file

No response

...

fallow birchBOT
#

I have rebased this pr since latest master has some conflicts, also reverted changes to stm32 hal conf (HSI). I also install codespell and run it locally to catch a few more typos.

I will make a follow-up PR to add codespell as part of the ci as well, it would help to prevent future typos. Thank you again for the PR.

fallow birchBOT
#
[hathach/tinyusb] New branch created: add\-codespell
fallow birchBOT
fallow birchBOT
fallow birchBOT
#
[hathach/tinyusb] New branch created: hid\-fido
#

thank you for the PR, it looks good, though I would like to rename name symbol to sample uf2_hid.h from fido here https://web.archive.org/web/20210517033138/https://fidoalliance.org/specs/fido-u2f-v1.2-ps-20170411/inc/u2f_hid.h

unfortunately, I couldn't push to your fork's branch. I will made an separate PR with this commit as PR at #1776. Merging that will also have github marks this as merged as well.

fallow birchBOT
fallow birchBOT
#

sorry for late response, I was too busy with other works. The reason for change request: although it has more code, the additional condition CFG_TUD_CDC_TX_BUFSIZE < BULK_PACKET_SIZE is constant expression and will help the compiler to optimize it out.

Therefore we don't have to run tu_fifo_full() when bufsize is larger than the packet size (and const expression also not executed at all in other case)

#

I think I fixed the ci flake for the rp2040 in #1731.

Sorry for super later response, sometime CI just break due to network/bandwidth issue since I have tried to run too many concurrent jobs (each for 1 supported mcu). It happens now and then, and often is fixed by re-run the failed workflow. I guess #1731 isn't related, sorry for not be able to response to this question of your in time.

I am learning fuzzing and basically try to catch up with your PR and making a good progress. Thank...

fallow birchBOT
#

sorry for late response, the failed ci in #1716 is due to network/bandwidth issue (over use of ci jobs). I have re-run those failed jobs, it is a bit of a pain, but I will try to minimize number of running jobs (currently 1 job per supported mcu). So I guess this may not be needed. I often coordinate with rpi team to implement/test new changes/feature and having to run with latest pico-sdk is kind of neccessary.

fallow birchBOT
fallow birchBOT
fallow birchBOT
#

Sweet, I'll open a WIP progress PR over at OSS-fuzz to integrate tinyusb. Is your '@tinyusb.org` email address associated with a google account? I'm just going over the requirements for accepting new projects with OSS-fuzz and one of them is a google email address.

https://google.github.io/oss-fuzz/getting-started/accepting-new-projects/#accepting-new-projects

unfortunately not, it is an office 365 email provided by hosting company. I have just created an new gmail for this purpos...

fallow birchBOT
fallow birchBOT
fallow birchBOT
fallow birchBOT
#

An errata note will be published in due course.

I have pushed a testcase to https://github.com/P33M/rp2040-e15-testcase - this is an SDK-compatible widget that defines a vendor-specific interface using TinyUSB. Bulk OUT packets are discarded, bulk IN packets are pseudorandomly sized and submitted to the hardware at arbitrary times.
The expected behaviour with the included python script is that the transfer will continue forever, but with a pico plugged into a Pi 4 directly, will crash aft...

fallow birchBOT
#
[hathach/tinyusb] New branch created: update\-unit\-test
fallow birchBOT
fallow birchBOT
#
[hathach/tinyusb] New branch created: silvergasp\-master
fallow birchBOT
#

superb !! thank you very much for your time and effort (as well as your patient). Fuzzing is a realy useful/helpful testing for detecting memory overflow/leak issues. Which help to improve tinyusb a lot in the long run. Thank you very much for introducing and adding harness.

PS: I have move fuzz into test/fuzz and integrate build fuzzer into pre-commit since it is quick to run on linux host, so it kind of make sense to bundle them together to save concurrent ci instances.

fallow birchBOT
#
[hathach/tinyusb] New branch created: fix\-fifo\-memory\-overflow
fallow birchBOT
#

Operating System

Linux

Board

Raspberry Pi Pico

Firmware

Raspberry Pi SDK - master branch, using TinyUSB 0.12.0

What happened ?

A struct definition in header file src/class/audio/audio.h is missing two fields, compared to the definition in "USB Device Class Definition for Audio Devices Release 2.0".

See the definition of audio_desc_input_terminal_t starting in line 719 of file audio.h
Compare with table 4-9 in the USB document.

Missing fields are: bTerminalID ...

#

Code was only reading the first 64 bytes of a 512 bytes packet.

For some reason, code was working if receiving a single packet strictly below 512 bytes. But when sending a USBTMC message which lead to a data stage longer than a single packet, only the first 64 bytes where read.
This seems to be only due to the "arming" of transfer which where obviously only asking for 64 bytes (constant).

fallow birchBOT
fallow birchBOT
#

"Here is the device I have implemented."
Hi,
It means you succesfully implemented the TinyUSB audio class to the STM32F30x family? It's really good news, because the CubeMX generated audio code is not working on the F103 and F303 controllers, but works of the F4 family. I tried the TinyUSB audio test example a few months ago, same, it worked with the STM32F411, but not with F103 or F303.
Maybe your solution is working on the SRTM32F10x family as well, Bluepill etc.?
A simple example lik...

fallow birchBOT
fallow birchBOT
#

Describe the PR
Enumerating new devices starts with an HCD_EVENT_DEVICE_ATTACH event, but requires several more events to finish. If another HCD_EVENT_DEVICE_ATTACH event arrives before the current enumeration is complete, it will clobber _usbh_ctrl_buf and cause assertion failures. This can happen on a Raspberry Pi Pico with Pico-PIO-USB and multiple root hub ports.

This patch makes the host task enumerate one device at a time, by che...

fallow birchBOT
#

Jep, It is working so far with a STM32F302 which is, as far as I can tell, largely compatible with the STM32F103, therefore it should work.
However it needed a lot of tweaking of the STM32 driver in TinyUSB and also still has some crude solutions, like the static mapping of endpoint addresses to hardware endpoints using a callback function. Thus I use my own TinyUSB fork here: https://github.com/skuep/tinyusb/tree/0.14.0-sk

While the project I have linked above is not a USB audio speaker ...

fallow birchBOT
fallow birchBOT
fallow birchBOT
#

I did a quick test: downloaded your AIOC and TinyUSB code, and compiled it in STM32CubeIDE. Success, no errors.
Unfortunately I have no STM32F302, so I blindly uploaded the firmware to a STM32F303CCT6.
It enumerated as mono speaker and mic, plus serial port. Wow, this uC-s has to be very similar... :-)
No sound output on PA4, the pin is floating - probably the chip is different here. Also checked the Led outputs, 36MHz signal on one of them.
Next I try to port the code to the 303, figure...

fallow birchBOT
fallow birchBOT
#

Cool!
Yeah, I think those MCUs are similar enough :-) It is mainly a question of the USB peripheral. But as long as it is this USB-CAN combined peripheral with at least 512 Bytes of Packet-Memory-Buffer, it should work.
Can you try changing the MCU type to your STM32F303 type? (And check that a new define is set in the project settings). Maybe that it is already enough so that a different device header file is used during compilation.

Btw, did you connect the AIOC to a Windows PC? That...

fallow birchBOT
#

Btw, did you connect the AIOC to a Windows PC?
Sure, it enumerated as mono mic, speaker and serial port. When I plug in the usb, win11 selects it as audio output, and silence. If I select the audio output to the normal and back to the uC, it's always working. However no sound on PA4, probably there is a difference in the DAC peripheral. The absolute bare metal DAC init is a bit steep for me :-), I usually use CubeMX for the job.
I touched the pins to check if it's working as mic, no respo...

fallow birchBOT
#

Up to my knowlegde, dcw2 is intended to fuse all the device drivers of the individuel MCUs together. This, however, is work in progress and unfortunately bugs fixed in dwc2 may not be fixed in the individual drivers and vice versa. I think the docs should be improved to inform everybody of its purpose...

The audio class works fine so far, most bugs reported regarding audio concern the ISO EP support in the device drivers. The same holds true for fsdev.

I am happy there is progress for the 1...

fallow birchBOT
#

In order to port the code to the 303, I first started DAC with DMA in a new empty project. CubeMX generated me a faulty code. It initiated the DMA and the DAC in the wrong order, set a register in the DAC before it has clock. Takes me several hours to figure out, but now works. However, at first look no need for DMA in your project, so dont't know why I bother with it...

Just FYI: I also use CubeMX and had this issue. I posted it to the forum and it should be fixed in the current CubeMX ...

fallow birchBOT
#

In order to port the code to the 303, I first started DAC with DMA in a new empty project. CubeMX generated me a faulty code. It initiated the DMA and the DAC in the wrong order, set a register in the DAC before it has clock. Takes me several hours to figure out, but now works. However, at first look no need for DMA in your project, so dont't know why I bother with it...

I would just load the STM32CubeIDE project fromy AIOC repository. Then go into project settings and change the MCU to ...

fallow birchBOT
#

I would just load the STM32CubeIDE project from my AIOC repository. Then go into project settings and change the MCU to the STM32F303 instead of 302. Hit compile again and try the code.

It compiled without errors for STM32F303CC.
Enumeration on win11: mono speaker, mic (TinyUSB Device), serial port
The serial port is working.(tested using putty terminal and scope)

It's possible to select it from win11 as sound otput, volume control works (except no sound).
No sound from the DA...

fallow birchBOT
fallow birchBOT
#

Debugging captured my mistake immediately... :-)
I started the program in debug mode, then plugged in the USB cable. It enumerated. When I touched the volume control on the PC, debugging stopped, TU_Assert Isochronous not supperted yet.
It means I copied the official Tinyusb into your AIOC project instead of your mod. (I downloaded it in .zip format, this way without the linked TinyUSB).
After correcting my mistake it's working. :-)
Worth to mention, that in debug mode it still halts on a...

fallow birchBOT
fallow birchBOT
fallow birchBOT
#

Describe the PR

While trying to fix an issue reported in https://github.com/hathach/tinyusb/issues/1729 (detected using fuzzing #1716). I am able to fix a couple of issues with current tusb_fifo when using with overwritable mode

  • Prevent double overflowed to happen which make fifo count invalid. Though due to the cost of moving memory, the data at read index is not replaced by newer one.
  • fix _tu_fifo_remaining() return incorrect value which cause memory overflowed, detected by fuz...
fallow birchBOT
fallow birchBOT
#

It compiled without errors for STM32F303CC. Enumeration on win11: mono speaker, mic (TinyUSB Device), serial port The serial port is working.(tested using putty terminal and scope)
Nice! you can also theoretically wire those pins in loopback configuration to test it.

I am HAM, HA6TI, and often use FT8 mode on my Xiegu G90. I have a xgcomm USB-digimode-3 interface, it's basically an usb soundcard, no serial port, so no built-in CAT control. It has a high bit adc/dac, but it's proba...

#

It compiled without errors for STM32F303CC. Enumeration on win11: mono speaker, mic (TinyUSB Device), serial port The serial port is working.(tested using putty terminal and scope)
Nice! you can also theoretically wire those pins in loopback configuration to test it.

I am HAM, HA6TI, and often use FT8 mode on my Xiegu G90. I have a xgcomm USB-digimode-3 interface, it's basically an usb soundcard, no serial port, so no built-in CAT control. It has a high bit adc/dac, but it's proba...

fallow birchBOT
fallow birchBOT
fallow birchBOT
fallow birchBOT
fallow birchBOT
#

Operating System

Linux

Board

stm32f103_mini_2

Firmware

examples/device/dfu
all about stm32 board maybe have same problem

What happened ?

terminal print
`arm-none-eabi-gcc: error: unrecognized command line option '-Wcast-function-type'; did you mean '-Wbad-function-cast'?
../../rules.mk:130: recipe for target '_build/stm32f103_mini_2/obj/src/portable/st/stm32_fsdev/dcd_stm32_fsdev.o' failed
make: *** [build/stm32f103_mini_2/obj/src/portable/st/stm32_fsdev/dcd_stm32...

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

They are overlapped a bit but not the same. I did put a note on the header file (did mentioned you there). Overflowed (single/double) only occurred with over-writable fifo where we repeatedly write() without doing any read(). Which is a case of cdc when first enumerated but dtr/rts is not set. Or with DMA but the writer is running much faster than reader.

There is also a unite test case for this https://github.com/hathach/tinyusb/pull/1789/files/04a5c03ea8ea70510c332f0fafb44daf0ec7c7fb#di...

fallow birchBOT
fallow birchBOT
fallow birchBOT
fallow birchBOT
#

Operating System

Others

Board

Custom ARM CM33 board

Firmware

TinyUSB configured for one CDC and one USB Audio link

What happened ?

Lets describe a simple setup with 2 FreeRTOS tasks (Task1= TinyUSB, Task 2 = other process), with FreeRTOS scheduler not using time slicing (i.e same priorities tasks will run only when the other task will either suspend or yield):

  • Task2 is running
  • USB interrupt happens for audio EPOUT, which enqueue data using osal_queue_send function...
fallow birchBOT
#
[hathach/tinyusb] New branch created: update\-osal\-mutex
fallow birchBOT
fallow birchBOT
fallow birchBOT
fallow birchBOT
#

Looks good! Nice that the buffer would be fuzzing-proof :)

Is there anything else to improve since you mentioned there would be room therefore!

just update the PR with your feedback, thank you for reviewing. For room to improve, I feel that we could do better to simplify the current code, but it is not urgent. Like merging get_realitve_poiinter() and _ffmod() to idx2ptr(), mostly for readability and maintenance only. I will try to wrap this up soon enough.

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

Describe the PR
Running audio example on pico, I am still hitting the following assert:
hard_assert(hw_data_offset(next_buffer_ptr) <= USB_DPRAM_MAX);

Additional context
The issue is that pico implementation only reclaim the memory when all the endpoints are closed. In audio example, speaker and mic may not share the same lifecycle. This end up the crash.

I fixed this to implement a poor man allocation algorithm to track 64 of the blocks with 64 bytes. Since there are only 64...

fallow birchBOT
fallow birchBOT
#

Hi @hathach ,

Sorry for the delay but I am back on the ball now!

I have now added two new external weak function prototypes to hcd.h as follows:

// Optional MCU Data Cache control if you require this please implement the functions in your hcd_platform.c file
TU_ATTR_WEAK extern void hcd_dcache_flush(uint32_t addr, uint32_t data_size);
TU_ATTR_WEAK extern void hcd_dcache_invalidate( uint32_t addr, uint32_t data_size);

It also turned out with my platform I needed to...

fallow birchBOT
fallow birchBOT
fallow birchBOT
fallow birchBOT
fallow birchBOT
#

Personally, I wasn't keen on using cache functions inside the interrupt handler as it adds latency to the interrupt, on my platform that might be around 6uS worst case which isn't hideous but it will vary on other platforms. Do we want to try it this way or try and keep the cache code away from the ISR?

What do you think?

Thanks for your feedback @hathach.

Kind Regards,

Pete

fallow birchBOT
#

Related area

No NKRO possible with tinyusb?

Hardware specification

rp2040 feather

Is your feature request related to a problem?

I‘m currently facing the issue that I am unable to get N key rollover to work. If there is any way to do it currently please tell me.

Describe the solution you'd like

I don‘t know any solution.

I have checked existing issues, dicussion and documentation

  • [X] I confirm I have checked existing issues, dicussion and documentation.
fallow birchBOT
fallow birchBOT
fallow birchBOT
fallow birchBOT
#
[hathach/tinyusb] New branch created: fix\-cdc\-buf
fallow birchBOT
#

Hi @hathach ,

Just a quick update, this has turned out to be much more work than I expected. I am now spending some time reading up on the USB/EHCI specifications so I can do this correctly. I have also had a request from my boss to add MSC support also which means I really should get a good cached version of the EHCI driver working as the performance will be much better. It wasn't so important previously for my application as I was just handling HID devices. This also means I need to in...

fallow birchBOT
#

I compiled CircuitPython with p_cdc->epout_buf and with &p_cdc->epout_buf, and the resulting .elf and .asm's are identical.

This is a peculiarity of references to C arrays: https://stackoverflow.com/questions/2528318/how-come-an-arrays-address-is-equal-to-its-value-in-c.

So though it's a little "wrong", adding the & doesn't do anything.

There's a demo program in the link above, and here's one I wrote before finding that:

#include <stdio.h>

typedef struct {
    char b...
fallow birchBOT
fallow birchBOT
#
pho

Operating System

Linux

Board

Any

Firmware

This happens on current TinyUSB master branch

What happened ?

Both of these functions imply in their docstring that you can peek at any specific position in the FIFO, but then the offset parameter is missing

// Get a byte from FIFO at the specified position without removing it
bool     tud_cdc_n_peek            (uint8_t itf, uint8_t* ui8);

https://github.com/hathach/tinyusb/blob/master/src/class/cdc/cdc_device.h#L...

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

Related area

Documentation request

Hardware specification

A (possibly small) selection of supported architectures

Is your feature request related to a problem?

My apologies if I've missed this somewhere, but I've looked around and can't find any size metrics. I did find a mention in the getting started page for for checking the size...

It's hard to know what the actual resource requirements are without hard numbers. I would suggest adding columns for "code size" and "ram...

fallow birchBOT
fallow birchBOT
#

Operating System

MacOS

Board

STM32F103C8T6 Blue Pill

Firmware

examples/device/net_lwip_webserver

What happened ?

Building LwIP web server example for STM32F103C8T6 Blue Pill with NCM stack throws an error

How to reproduce ?

Steps to reproduce it:

  1. Go to examples/device/net_lwip_webserver/src/tusb_config.h, and modify CFG_TUD_ECM_RNDIS to 1
  2. Go to examples/device/net_lwip_webserver and build: make BOARD=stm32f103_bluepill all

Debug Log as txt file

...

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

Describe the PR
This is a minor change to the USB Video class implementation to accept a too small wLength during probe and commit requests in order to fix MacOS compatibility.

Additional context
My (UVC project)[https://github.com/Staacks/gbinterceptor] as well as a minimal example on a Raspberry Pi Pico based on the examples here fails on MacOS during SET CUR Probe because wLength is set to 0x22 instead of the expected 0x30. This behavior can actually be observed with WireShark...

#

Update:
I got it to work on a MacBook with Intel CPU by allowing too small wLength values (see this pull request). MacOS sets wLength to 0x22 instead of 0x30 during probe and commit and it does so consistently also with commercial devices.

However, I still have problems on a MacBook with M2 chip. Here the image is green and distorted and by comparing the raw data on the USB bus (which looks correct) with the data that actually reaches ff...

fallow birchBOT
fallow birchBOT
#

Hi @hathach ,

Just a quick update, this has turned out to be much more work than I expected. I am now spending some time reading up on the USB/EHCI specifications so I can do this correctly. I have also had a request from my boss to add MSC support also which means I really should get a good cached version of the EHCI driver working as the performance will be much better. It wasn't so important previously for my application as I was just handling HID devices. This also means I need t...

fallow birchBOT
#

late review since I was busy with other works. After going through the change, although the pr fix a severe issue, however due to the impact of this PR in performance i.e 20% off bandwidth and force to have sof (which will hurt power consumption). I would like to do actual hand-on testing with the PR before merging. Though I couldn't do that until another week.

Meanwhile there is a few issues I think we should fix first

  1. Since this only occurs with bulk in transfer, we should only enab...
fallow birchBOT
fallow birchBOT
fallow birchBOT
#

@skuep
Hi, I made some commits based on your fork, which includes:

  • Rebased on master
  • Minor fixes
  • Reworked FIFO based transfer
  • Added an endpoint allocator

I've tested with my CDC & HID composite device (mine FIFO enabled CDC class fork), could you test with your UAC enabled project ?
Especially if endpoint alloc/free goes well, you can also modify UAC class to enable FIFO based transfer.

https://github.com/HiFiPhile/tinyusb/tree/0.14.0-sk

fallow birchBOT
fallow birchBOT
fallow birchBOT
#

I'm working on the stm32_fsdev driver in order to add ISO and FIFO transfer support.
It has the same fifo allocation limitation as dwc2, currently the allocation size is decided when the first time EP is opened, it can't be reopened with a bigger size.

I plan to add max_iso_size to the dcd_edpt_open for ISO to help with reserving the max buffer without having to re-allocated when switching interface.

I think it's a good idea.

fallow birchBOT
fallow birchBOT
#

I'm working on the stm32_fsdev driver in order to add ISO and FIFO transfer support. It has the same fifo allocation limitation as dwc2, currently the allocation size is decided when the first time EP is opened, it can't be reopened with a bigger size.

I plan to add max_iso_size to the dcd_edpt_open for ISO to help with reserving the max buffer without having to re-allocated when switching interface.

I think it's a good idea.

Please do, I think the api is simple enough,...

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

I mean the audio_test example available in the example folder.

Yep, without changing CFG_TUD_AUDIO_EP_SZ_IN to 49*n Windows will report error 10, that's why I'm fixing it :)

You did the same thing in audio_4_channel_mic example

#define CFG_TUD_AUDIO_EP_SZ_IN                        (48 + 1) * CFG_TUD_AUDIO_FUNC_1_N_BYTES_PER_SAMPLE_TX * CFG_TUD_AUDIO_FUNC_1_N_CHANNELS_TX      // 48 Samples (48 kHz) x 2 Bytes/Sample x CFG_TUD_AUDIO_N_CHANNELS_TX Channels - the Windows driver alw...
fallow birchBOT
#

And what i also found was "noisy" recordings i.e. a saw tooth signal with noisy values added. You can test for that by sending only zeros.

This was an impact of the UAC driver chosen in Windows. One (i dont recall which) had this problem, another (the one for the 4 channel if i remember correctly) did not show this noisy samples. My guess was that some drivers conduct some digital filtering in some weired manner...

fallow birchBOT
#

At first glance i thought the MCU might have been too slow in updating the saw tooth values between the frames.

My logic analyzer attached to D+/D- line dumped correct 48 samples so it can't be the cause.

And what i also found was "noisy" recordings i.e. a sawtooth signal with noisy values added.

For a moment I had noisy sample on Linux, but it disappeared adjusting volume and I can't reproduce it.

My finding is Linux handle volume in host side, but volume set by SET_REQUEST ...

fallow birchBOT
spiral olive
#

Does anyone know how to build a simple RP2040 device version of tinyusb in C? The examples I worked through are too complex (I just want to send gamepad reports)

#

Composite device was dropping reports constantly (busy?) I can’t tell

spiral olive
#

Yes I stripped the composite example down but it is just a mess to follow. After successful init I constantly drop reports (they do not complete to the _cb)

#

I probably drop 1 in 10 reports issued

odd swan
#

Hmm okay, you might try using the Arduino examples for it. Then just use Adafruit HID libraries

spiral olive
#

Hmmm that’s a good idea I didn’t think of

fallow birchBOT
fallow birchBOT
fallow birchBOT
#

@HiFiPhile

Hi, thanks for your comments.

Maybe yes, the APIs would be suitable for UVC too.
My understanding is that UVC controls ISO EPs in basically the same manner as UAC.

By the way, UVC can also use bulk EPs instead of ISO EPs for non-linear editing. Current UVC implementation has not supported this.
If we try to add support bulk EPs for UVC, we might be need some APIs like as dcd_edpt_iso_alloc() / dcd_edpt_iso_activate() for bulk EPs. It's just a guess. I am not familiar fo...

fallow birchBOT
fallow birchBOT
fallow birchBOT
#

Related area

Port support.

Hardware specification

MSP430F5638.

Is your feature request related to a problem?

The current MSP430F5xx_6xx port fails to properly enumerate if the device is externally powered and

  1. The USB cable is inserted after calling tusb_init() or
  2. The cable is removed then re-inserted after a previously successful enumeration.

Describe the solution you'd like

I made some changes to the MSP430F5xx_6xx port that I believe resolve the issue. The...

fallow birchBOT
#

Operating System

Others

Board

Custom RP2040

Firmware

https://github.com/rabbitholecomputing/RP2040-TinyUsb-keyboard-leds

What happened ?

After multiple calls toggling a USB keyboard LEDs tuh_hid_set_report starts returning false.

Tracing my original code (https://github.com/rabbitholecomputing/QuokkADB-firmware) the issue is [_ctrl_xfer.stage == CONTROL_STAGE_IDLE);](https://github.com/hathach/tinyusb/blob/7004914d8c6c7d88908776eb153661b6b987e513/src/host/usbh.c#L5...

fallow birchBOT
fallow birchBOT
fallow birchBOT
fallow birchBOT
fallow birchBOT
#

Related area

FreeRTOS OSAL.

Hardware specification

Custom MSP430F5638.

Is your feature request related to a problem?

I'm getting an integer conversion resulted in truncation warning in osal_queue_send() from the third argument of xQueueSendToBack() when using TI's CGT compiler version 21.6.1 LTS. The warning stems from the fact my device is a 16-bit system and my port is configured for 16-bit ticks using configUSE_16_BIT_TICKS but OSAL_TIMEOUT_WAIT_FOREVER is defin...

fallow birchBOT
fallow birchBOT
#

Yeah I am also still on the fence with this callback.
From the looks of it, the generated feedback values in the speaker feedback endpoint had way less jitter for the UAC2 application. However I did not check if this actually makes a difference for the (stability of the) feedback control loop running on the Host. Since I can only test Linux hosts, I left it in there for a better gut feel in terms of compatibility.

I do however think it would be a nice addition, if this would be a more ge...

fallow birchBOT
#

Describe the PR
Seems IAR is not happy with empty ; in struct

typedef struct {
  bool is_host; // host or device most
  union {
      uint8_t daddr;
      uint8_t rhport;
      uint8_t hwid;
  };
  uint8_t ep_addr;
  uint8_t ep_speed;

  uint16_t ep_packetsize;
  uint16_t ep_bufsize;

  // TODO xfer_fifo can skip this buffer
  uint8_t* ep_buf;

  tu_fifo_t ff;

  // mutex: read if ep rx, write if e tx
  OSAL_MUTEX_DEF(ff_mutex);

}tu_edpt_stream_t;

*...

fallow birchBOT
fallow birchBOT
fallow birchBOT
fallow birchBOT
#

Meanwhile there is a few issues I think we should fix first

  1. Since this only occurs with bulk in transfer, we should only enable SOF when needed i.e when there is active bulk-in within 20% last frame. This will minimize the impact on current consumption. Since not all device make use of Bulk in endpoint e.g HID device. And even with MSC/cdc device, it is more often than not, device sitting idle than transferring data. and when it does, it is more often within first 80% frame.

...

fallow birchBOT
fallow birchBOT
#

Sorry for the delay in testing your branch. However I have found a serious bug in the code that you based your commits on.
I updated the original branch that you used. See the latest commit here:
https://github.com/hathach/tinyusb/compare/master...skuep:tinyusb:0.14.0-sk

I first noticed corrupted memory on only some of the devices, which was really hard to debug. I narrowed it down to the TU_ASSERT that I added to the code in this commit. It turns out, that you need to set the receive bu...

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

Related area

device stack

Hardware specification

rp2040,generic

Is your feature request related to a problem?

Kind of.

I'm trying to use tinyusb from adafruit tinyusb (which if I understand it correctly uses this project)

I made a wrapper class for the midi device but I would need two additional functions to manage cable_num:
tud_midi_n_available
tud_midi_n_stream_read

They take cable_num as arguments but do nothing with them.

Describe the solution you'd like

...

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

Hi @hathach ,

Thank you for your reply, I thought the link in my previous post might help everyone who is working on various MSC projects on this thread. I wasn't actually asking for help, but this is where I'm at with my port so far...

I am using FreeRTOS+FAT rather than the elm-Chan FAT so I have written my own drivers for +FAT. Currently I have managed to mount a filesystem and I can read files. I am currently able to write files but I am having issues with data corruption, these ar...

torn osprey
#

Hi, I have a QT py m0 (atsamd21e18a) board. I can run msc_ramdisk tinyusb version 1.17.0 on it. It works perfectly. Before that, I could run msc_sdfat (16Gb) on a seeeduino xiao (atsamd21g18a) on tinyusb version 0.10.5. but the problem is that I want to run msc_sdfat on QT py m0 (atsamd21e18a), the code compiles perfectly, and I upload it on the device. But the storage is not opening and OS shows this "please insert a disk into a removable device." I should mention that I checked the connection sd card reader to QT py m0 by running this example program SD -> ReadWrite, and it works. But I checked it by Sdfat-adafruit fork -> open-next it doesn't work.
Another point is I test QT py m0 by example program tinyusb msc_sd, the removable device opened, and I can open my files on it. But all options are not working. For instance, I can't copy a file into it.
All examples tinyusb msc work on seeeduino xiao perfectly but do not work on QT py m0. last point, tinyusb version 0.10.5 doesn't compile on QT py m0.
thanks in advance.

fallow birchBOT
fallow birchBOT
#

Describe the PR
Fix:
Warning[Pe188]: enumerated type mixed with another type dwc2_stm32.h 125
Warning[Pa082]: undefined behavior: the order of volatile accesses is undefined in this statement dcd_dwc2.c 532
Warning[Pa082]: undefined behavior: the order of volatile accesses is undefined in this statement dcd_dwc2.c 1221

fallow birchBOT
#

Operating System

Linux

Board

rp2040 PICO from RP

Firmware

//Modified midi_test example from Adafruit
//Added callback for handling clock ticks
//Output 1 byte sysex every 40 ms

/*********************************************************************
Adafruit invests time and resources providing this open source code,
please support Adafruit and open-source hardware by purchasing
products from Adafruit!

MIT license, check LICENSE for more information
Copyright (...

fallow birchBOT
fallow birchBOT
#
[hathach/tinyusb] New branch created: ch32v307
#
[hathach/tinyusb] New branch created: ch32v307
fallow birchBOT
fallow birchBOT
#

special thanks to @gregdavill for this brilliant PR and others joining this discussio, and sorry for my huge delay in reviewing and testing this. I struggled a bit with openocd on linux, but finally got everything running. (also put some doc to the family.mk for building it). USB highspeed work well with cdc and msc (hid example has some hiccups but we will fix it later on).

CH32V307 is really an interesting mcu with dual usb controllers, one of which is highspeed, and bundle lots of other...

#

Thanks @hathach! I think I might have found/fixed some of those issues.. I know I hit some issues trying to use multiple IN/OUT endpoints, after some adjustments to the endpoint handling code it was working nicely on a local project branch.
So I'll sync those changes and take a look at merging them in.

It's been a bit of time since I did the initial work, but supporting the FS PHY I think should be easy, since it's similar/the same as the STM's one.

fallow birchBOT
#

Thanks @hathach! I think I might have found/fixed some of those issues.. I know I hit some issues trying to use multiple IN/OUT endpoints, after some adjustments to the endpoint handling code it was working nicely on a local project branch. So I'll sync those changes and take a look at merging them in.

That is great to hear, I wished I could have more time to looked into ch32v307 dcd code and do more testing with other class drivers as well.

It's been a bit of time since I did the ...

fallow birchBOT
#
[hathach/tinyusb] New branch created: obsolete\-chipdea\-fs
fallow birchBOT
#

Operating System

Linux

Board

Teensy 4.0

Firmware

examples/dual/host_hid_to_device_cdc

What happened ?

I'm using a Teensy 4.0 with a USB port soldered to the host pads. The example works if I first connect the Teensy to a computer and then plug a mouse to the host port on the Teensy. But if I plug a mouse to the Teensy first and then connect the Teensy to a computer, it doesn't work.

With the change below applied, it works. (I'm not saying this is the proper fix, just...

fallow birchBOT
#

Operating System

Linux

Board

Teensy 4.0

Firmware

examples/dual/host_hid_to_device_cdc

What happened ?

I'm using a Teensy 4.0 board with a USB port soldered to the host pads. Plugging in a mouse and then unplugging it causes the board to crash (failing assert in usbh.c:481). If I comment out the assert, everything seems to work OK (I can plug the device back and it works).

How to reproduce ?

  1. Flash a Teensy 4.0 board with the host_hid_to_device_cdc example.
  2. P...
fallow birchBOT
#

thanks for reporting the issue, look like the usb transfer is complete -> device is unplugged --> usbh_task() is called and it asserts since it couldn't find the owner of the usb transfer (is unplugged now). Can you add the following log right above the assert and paste the log output here. I will pull out hardware and do more test later on.

                // no driver/callback responsible for this transfer
                TU_LOG2_INT(tuh_mounted(event.dev_addr));
                ...
fallow birchBOT
fallow birchBOT
fallow birchBOT
fallow birchBOT
#

@silvergasp thank you very much, tinyusb is accepted to oss-fuzz. Though strangely, I would expect an notification email from oss-fuzz but received none so far. Also the document said we could check build status after 1 day or so, but couldn't find it https://oss-fuzz-build-logs.storage.googleapis.com/index.html .

There is no rush, I just wonder if there is anything we should do or just simply wait for a few more days for it to get run.

fallow birchBOT
fallow birchBOT
#

Describe the PR
mute and volume arrays in main.c have wrong number of elements (2 instead of 3) because CFG_TUD_AUDIO_FUNC_1_N_CHANNELS_TX was used to calculate array lengths. CFG_TUD_AUDIO_FUNC_1_N_CHANNELS_TX changed to CFG_TUD_AUDIO_FUNC_1_N_CHANNELS_RX.

Additional context
Changing the volume of second channel ends up soft brick of device in my case because OS will remember last volume control.

fallow birchBOT
#

The NXP frdm_k32l2b BSP, as currently shipped with TinyUSB no longer build due to changes in the upstream NXP IDE and SDK.
The start up file and linker files currently referenced in board.mk no longer exist, making it impossible to build the BSP.

This PR modifies board.mk to reference the current NXP IDE and SDK files.
It also adds a README file to explain which files are needed from the SDK and how to set up the build using them.

fallow birchBOT
fallow birchBOT
#

Related area

Security

Hardware specification

N/A

Is your feature request related to a problem?

Beyond compiler warnings/errors tinyusb doesn't currently leverage static analysis to prevent bugs.

Describe the solution you'd like

I'd like to propose integrating clang-tidy into the continuous integration workflow. It's worth noting that clang-tidy is also capable of many other things statically like;

  • Identifying bugprone codi...
fallow birchBOT
#

Related area

DCD, ISO

Hardware specification

All

Is your feature request related to a problem?

Currently all transfer events go thorough the event queue and processed in tud_task()
https://github.com/hathach/tinyusb/blob/fa9d19027be7caa8dda2ab81ce8fda8b7f586a58/src/device/usbd.c#L534

While it's ok for most situations the timing could be hard to achieve for ISO transfer, like High Speed UAC class only has 125us to process each transfer.

A bad example would be UAC+MSC ...

fallow birchBOT
fallow birchBOT
fallow birchBOT
fallow birchBOT
#

Yeah clang-tidy is a nice easy one to use. In fact, I've already run it on tinyusb. Just go a bit of cleanup to do before a PR. Though I do have a question. Is there a way to build all of the source code under /src minus all the ports, in one make invocation? I've been using bear (a command line tool) to generate a compile-commands.json file which is used for clang-tidy but also clangd, but I need to be able to build all of tinyusb in one make invocat...

fallow birchBOT
#

Operating System

Linux

Board

ESP32-S3

Firmware

hid_generic_inout

What happened ?

The comment at https://github.com/hathach/tinyusb/blob/master/examples/device/hid_generic_inout/src/usb_descriptors.c#L106
is slightly misleading. It should be EP Out & In address instead of the other way around.

How to reproduce ?

Refer to the SRC

Debug Log as txt file

No response

Screenshots

No response

I have checked existing issues, dicussion and documentat...

fallow birchBOT
#
[hathach/tinyusb] New branch created: support\-iar
fallow birchBOT
#

what would be the issue you having, is it due to SYMBOL check e.g CFG_TUD_CDC that opt-out the code. We can add tusb_config.h or CFLAGS to enable all the feature. For the backend e.g dcd_*, we can use the port/template one, which is basically an stub for backend APIs.

I am not familiar with clang-tidy, though if you share your working, maybe I could help it out (not entirely sure though).

fallow birchBOT
#

I will take a look at the submodules. I was unaware of their use here.

While the two FRDM boards are similar, their cores, memory map and power management are different.
The B series is aimed at communication apps with dual core M4/M0+ while the A series is for security and has only single M0+ core. The B series is similar to most Kineits parts with SIM_OPTS etc. The A series is its own thing with Peripheral Clock Control (PCC) etc.

To unify the code how do I tell which board is be...

fallow birchBOT
fallow birchBOT
fallow birchBOT
fallow birchBOT
#

Yeah, it's looking like things are on track again. I don't think the fuzzer's have been run yet, but I'll check again tomorrow to see what's going on. We should be able to see some statistics once it's been run here;

https://oss-fuzz.com/fuzzer-stats?project=tinyusb&fuzzer=afl&job=afl_asan_tinyusb&group_by=by-fuzzer

You'll need to log in with your tinyusb.org@gmail.com email account to get access to that dashboard.

fallow birchBOT
#

Looks like it's running well. I've got a little bit of tweaking to get it working well with the AFL fuzzing engine. But other than that I'm super impressed that it hasn't found any new bugs. Its already done more than 1000x the iterations than i ever did on my laptop. Their servers are a lot quicker. You've done well writing tinyusb to be so robust against fuzzing!

fallow birchBOT
#

ah thanks, the dashboard starts to show some interesting statistic, though to be honest, I don't know these well enough.

Looks like it's running well. I've got a little bit of tweaking to get it working well with the AFL fuzzing engine. But other than that I'm super impressed that it hasn't found any new bugs. Its already done more than 1000x the iterations than i ever did on my laptop. Their servers are a lot quicker. You've done well writing tinyusb to be so robust against fuzzing!
...

fallow birchBOT
#

Not a problem :)

Well here's a more verbose rundown. There are multiple sanitizers (you can think of these as bug detectors). The ones that we have enabled with OSS-fuzz are;

  • Address sanitizer (ASAN), which among other things will detect buffer overflows.
  • Memory sanitizer (MSAN), which among other things will detect usage of uninitialised memory.
  • Undefined behaviour sanitizer (UBSAN), which will detect undefined behaviour e.g. an integer overflow.

Then we've got multiple fuzzin...

fallow birchBOT
fallow birchBOT
#

This allows transferring data IN from a const buffer without compiler warnings.

Also changed several uses of tud_control_xfer on const data to use tud_control_xfer_in instead, eliminating ugly casts. Did not change all uses - only the ones that were clearly acting on const data and had ugly casts that could be eliminated.

A more aggressive approach would be to modify all calls in the IN direction to use the new function.
An even more aggressive approach would be to modify all `tud...

fallow birchBOT
#

sorry for late response again, the Lunar New Year aka TET in my country forcing me to clean my house/desk and leave not much time for the work. I don't think I will have time to test this out on actual RPI4 in another couple of weeks, and this has been on pending for too long (my bad). If you could update the PR

  • to move the parked_ep into hw_endpoint array without the use of critical_section
  • comment out/revert the hw_endpoint_lock_update() implementation since there is other places tha...
fallow birchBOT