Skip to content

Conversation

esky-software
Copy link

Allows bulk endpoints to use entries in ep_pool, and forces only control endpoints to share ep_pool[0].

THIS IS A HACK.

It's only tested to the extent that the MSC example gets as far as invoking inquiry_complete_cb().
This exercises an input & an output bulk endpoints.
Coexistence of interrupt & bulk EPs is entirely untested and is sure to fail.

@rppicomidi rppicomidi mentioned this pull request Jan 19, 2022
@cjhilder
Copy link

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

The problem is that the USB hardware randomly fails to respond to an apparently valid usb_hw->sie_ctrl setting with an interrupt. I have found that I can improve the chances of success by inserting a delay immediately prior to setting usb_hw->sie_ctrl in line 569 of hcd_rp2040.c. I don't understand what is going on here. I presume there is some state that needs to be waited for, but I don't know what that state could be. Any help would be much appreciated, and we could maybe get this code into a state that it is ready for a final pull request (or at least useable).

@rppicomidi
Copy link
Contributor

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

        uint32_t flags = SIE_CTRL_BASE |
                 (ep_dir ? USB_SIE_CTRL_RECEIVE_DATA_BITS : USB_SIE_CTRL_SEND_DATA_BITS);
        // Set pre if we are a low speed device on full speed hub
        flags |= need_pre(dev_addr) ? USB_SIE_CTRL_PREAMBLE_EN_BITS : 0;
        // Set up the hardware with all flags except the start bit
        usb_hw->sie_ctrl = flags;
        // Now start the transaction; if you don't do this in two parts,
        // and the host has switched direction, sometimes the transaction
        // does not start
        flags |= USB_SIE_CTRL_START_TRANS_BITS;
        usb_hw->sie_ctrl = flags;

@rppicomidi
Copy link
Contributor

@cjhilder The hcd_rp2040.c code still shares EPx except for interrupt transfers. FWIW, I tried this hcd_rp2040.c in my fork with the MIDI host example and it works as long as I implement the fix I described above. The issues I described in discussion #1261 still apply.

@cjhilder
Copy link

cjhilder commented May 4, 2022

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

        uint32_t flags = SIE_CTRL_BASE |
                 (ep_dir ? USB_SIE_CTRL_RECEIVE_DATA_BITS : USB_SIE_CTRL_SEND_DATA_BITS);
        // Set pre if we are a low speed device on full speed hub
        flags |= need_pre(dev_addr) ? USB_SIE_CTRL_PREAMBLE_EN_BITS : 0;
        // Set up the hardware with all flags except the start bit
        usb_hw->sie_ctrl = flags;
        // Now start the transaction; if you don't do this in two parts,
        // and the host has switched direction, sometimes the transaction
        // does not start
        flags |= USB_SIE_CTRL_START_TRANS_BITS;
        usb_hw->sie_ctrl = flags;

This might be the problem I was encountering. I'm pretty interested in trying it out, but have now re-designed the project I was working on to use serial communication in device mode, so it's difficult for me to find the time to test it. Anyone else who is trying to access flash drives from RP2040 might like to pick this up and test it out, using my FATFs files: https://github.com/cjhilder/tinyusb/tree/master/examples/host/msc_with_fatfs/FATFs. I will get to it when I have a chance!

@FCare
Copy link

FCare commented May 17, 2022

I am using a CD ROm drive as device with a rp2040 as host. I can confirm that this patch prevent transfer to not start sometime.
Some added a delay but with this patch, I can read blocks on my CDROM without any interruption.

Thanks for finding it :-)

7FM pushed a commit to 7FM/tinyusb that referenced this pull request Aug 23, 2025
* Fix various non-GCC warnings (no effect on GCC)
* Reduce use of typeof since non GCC compilers may not support it
* Introduce PICO_C_COMPILER_IS_GNU, PICO_C_COMPILER_IS_CLANG, PICO_C_COMPILER_IS_IAR to CMake as if (CMAKE_C_COMPILER_ID STREQUAL "xxx") is a bit verbose
* Use "unified_asm" macro for all inline asm (it is "volatile __asm" on GNU with a .syntex unified)
* Use NOLOAD instead of COPY in linker scripts (arguably more correct anyway)
* Use the same style for setting _etext in all 4 linker scripts (to the beginning of .data). Clang aligns .data on a 16 byte boundary. Note ideally we'd
  add a new symbol __data_source, however that would break backwards compatibility with existing user linker scripts
* Use "a" for .stack, .heap sections because clang complains otherwise, and they are explicitly NOLOAD anyway
* Avoid duplicating __sev, __wfe, __wfi which Clang sometimes seems to provide as built-ins
* Add missing kitchen_sink_blocked_ram binary
* Allow build with LLVM Embedded Toolchain Form ARM v 14.0.0 (unsupported atm)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: 📋 Backlog
Development

Successfully merging this pull request may close these issues.

4 participants