#tinyusb

1 messages · Page 3 of 1

fallow birchBOT
#
[hathach/tinyusb] New branch created: cmake-ra
fallow birchBOT
fallow birchBOT
fallow birchBOT
#

It looks fine to me (I think at the time, I only focused on bus-powered applications b/c I found it difficult to reliably put the MSP-EXP430F5529LP into self-powered mode.

I do have a few questions:

  1. Is USBCTL &= ~FRSTE; and USBCTL |= FRSTE; intended to prevent a race due to power transients causing a second reset while in the process of handling the first reset? What happens if the reset vector is entered while processing the current r...
fallow birchBOT
#
  1. As this was 6 months ago I had to wrack my brain to try and remember the justification. I believe this was a partial implementation of TI's software fix for the USB4 errata affecting the MSP430F5529. According to the linked document FRSTE should be cleared on receipt of the reset interrupt and set on receipt of the suspend, setup and endpoint 0 interrupts.
    I'll be pushing a change later that correctly implements their...
fallow birchBOT
#

Describe the PR
console applications that expect "\r\n" as line ends will print lines ending only with "\n" in a star step fashion. They will not continue the next line at the beginning of the line, but at the current position.

Additional context
Most of the line ends in the log messages already were "\r\n" so I changed the few "\n" line ends to make it consistent.

fallow birchBOT
#

Sorry, just another addendum (doesn't change anything, but might prevent someone coming from Google drawing the wrong conclusions):
I might have mixed up bulk and isochronous in my testing. While preparing the 60fps MJPEG version for a beta release I stumbled upon a mistake in my defines, which mixed up both modes except for setting a smaller endpoint buffer size for the isochronous mode. I am not 100% sure, but I suspect that this mistake was already there when I did the bulk test before im...

fallow birchBOT
fallow birchBOT
fallow birchBOT
#

Describe the PR
Rework RA family support

  • Add RA to cmake (and make) build
  • Add ra6m1 tested with usb fs
  • Add ra6m5 only tested with led & switch. Trace ETM work well
  • move ra bsp and generated files around
  • move LTO check/enabled to family_support.cmake
  • freeRTOS with cmake not working yet with RA since RA needs custom port (will update later)
fallow birchBOT
#
[hathach/tinyusb] New branch created: renesas_ra_hs_rebased
fallow birchBOT
fallow birchBOT
#

Operating System

Linux

Board

stm32f746g-disco

Firmware

/device/video_capture
commit:433ffe2152ea3763fcd8d5b108f694d2c6cb826d
hs mode

What happened ?

ubuntu cannot enable UVC BULK transport
Don't support Linux?
Windows supports the display of images

How to reproduce ?

run demo
hs mode
CFG_TUD_VIDEO_STREAMING_EP_BUFSIZE 512

:~$ v4l2-ctl --device=/dev/video0 --set-fmt-video=width=640,height=480,pixelformat=YUYV --stream-mmap --stream-to=file.raw
VIDIOC_S...

fallow birchBOT
fallow birchBOT
#

Thank you very much for the PR and your patient, I am finally testing this out with actual hardware, ra6m5 ek first (then portenta C33 and Uno R4 Minima later on).

The PRs is great and both USB FS and HS work well. Though since there is a quite bit of changes I also want to make as well, mostly to refactor driver for better support multiple ports. I have pull and making more commits to this branch https://github.com/hathach/tinyusb/tree/renesas_ra_hs_rebased. There is a few more things bu...

fallow birchBOT
#

I tried to use bulk transport, but I couldn't get the video stream on Linux, and the picture could be produced normally in Windows

You will have to give more details like dmesg after connecting, software used to access the stream, the log of this software and ideally some code of yours. I have developed my project using TinyUSB's UVC primarily under Linux and had no problems with bulk transfer.

fallow birchBOT
fallow birchBOT
fallow birchBOT
#

There were typos in symlinks target names resulting in following warrning on checkout (at least in Mynewt newt tool):

  • Warning: stat mynewt/repos/tinyusb/docs/contributing/code_of_conduct.rst: no such file or directory
  • Warning: stat mynewt/repos/tinyusb/docs/info/contributors.rst: no such file or directory

Describe the PR
A clear and concise description of what this PR solve.

Additional context
If applicable, add any other context about the PR and/or screenshots here.

fallow birchBOT
#

It seems to be stripped by github preview but those symlinks have garbage suffixes:

[janc@ix tinyusb]$ ls -l docs/contributing/code_of_conduct.rst docs/info/contributors.rst
lrwxrwxrwx. 1 janc janc 26 07-10 16:21 docs/contributing/code_of_conduct.rst -> '../../CODE_OF_CONDUCT.rst'$'\n'
lrwxrwxrwx. 1 janc janc 23 07-10 16:21 docs/info/contributors.rst -> '../../CONTRIBUTORS.rst'$'\n'
fallow birchBOT
#

Device: ID cafe:4020 TinyUSB TinyUSB Device
Couldn't open device, some information will be missing
Device Descriptor:
bLength 18
bDescriptorType 1
bcdUSB 2.00
bDeviceClass 239 Miscellaneous Device
bDeviceSubClass 2
bDeviceProtocol 1 Interface Association
bMaxPacketSize0 64
idVendor 0xcafe
idProduct 0x4020
bcdDevice 1.00
iManufacturer 1 TinyUSB
i...

fallow birchBOT
#

@clhenry Just to be clear, @hathach may be very busy, and while I am a collaborator, I mostly focus on backend stuff. I want to wait for @hathach to be less busy so he can give guidance on "sometimes no OS needs a delay" problem.

You're already expected to instantiate an interrupt handler yourself and place a call into tud_int_handler in your application. I'm not against adding a function like e.g. tud_delay t...

fallow birchBOT
#

Sorry, I did not see that all the details are already in this issue when I asked for them in #1985.

So, I just checked out the latest master branch and built the video_capture example (in isochronous mode at first). Since I don't have an STM32 I tested it on a Pi Pico and ran your command:

    dicon@camelot:~$ v4l2-ctl --device=/dev/video4 --set-fmt-video=width=128,height=96,pixelformat=YUYV --stream-mmap --stream-to=file.raw
    <<<<<< 7.35 fps, dropped buffers: 3
    <<<...
fallow birchBOT
#

Thank you so much for the split test
I pull up the latest code, commit: f1e006d09bd32088ab421d0b519eb89c531eda4e
Using full speed
wMaxPacketSize set to 64 B (default)
git diff:
// video streaming endpoint size
-#define CFG_TUD_VIDEO_STREAMING_EP_BUFSIZE 256
+#define CFG_TUD_VIDEO_STREAMING_EP_BUFSIZE 64

// use bulk endpoint for streaming interface
-#define CFG_TUD_VIDEO_STREAMING_BULK 0
+#define CFG_TUD_VIDEO_STREAMING_BULK 1

make cmd:
make BOARD=stm32f746disco DEBUG=1 LO...

fallow birchBOT
fallow birchBOT
#

Really strange. You Pi Pico results and comparing those should be interesting.

There is one thing that I am wondering about, though: If I am not mistaken, CFG_TUD_VIDEO_STREAMING_EP_BUFSIZE only has an impact on internal buffering in the examples, because the actual endpoint size is hard-coded in the example:
https://github.com/hathach/tinyusb/blob/f1e006d09bd32088ab421d0b519eb89c531eda4e/examples/device/video_capture/src/usb_descriptors.c#L120
and
https://github.com/hathach/tinyusb/...

fallow birchBOT
fallow birchBOT
fallow birchBOT
#

No, sorry, I understood that. I meant that I am curious if the Pi Pico will work for you. And if it does, what would be the difference to the STM32 in Full Speed mode.

The other thing I was wondering about is that if I read the code correctly, the example should have set a 64B endpoint unless you changed lines 120 and 130. (Still, even if this was a problem, it should also be a problem in Windows.)

fallow birchBOT
fallow birchBOT
fallow birchBOT
#

Related area

Teensy 4.1

Hardware specification

Imxrt

Is your feature request related to a problem?

Example of usb host high speed support for one wifi dongle..
Thanks

Describe the solution you'd like

Example code with reference

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
#

I actually needed to use the high speed mode of DWC2, which is the IP most common in STM32

Unfortunately, current UVC implementation only supports Full Speed but High Speed.

Packet format of UVC is difference between FS and HS. Current implementation makes packets for FS format.
If I had a HS device, I would try to add support for HS.

fallow birchBOT
#

I actually needed to use the high speed mode of DWC2, which is the IP most common in STM32

Unfortunately, current UVC implementation only supports Full Speed but High Speed.

Packet format of UVC is difference between FS and HS. Current implementation makes packets for FS format. If I had a HS device, I would try to add support for HS.

Thank you very much for your support. After two different USB IP tests, it is determined that the stm32 UVC bulk transmission problem has n...

fallow birchBOT
#
[hathach/tinyusb] New branch created: imxrt-bsp
fallow birchBOT
fallow birchBOT
#
[hathach/tinyusb] New branch created: fix-etm-trace-h7
fallow birchBOT
#
  • include_guard requires GLOBAL as family.cmake is included in multiple non child places
  • the following recently rp2040 added check is sueprfluous (family_configure_host_example on rp2040 should do this already), and breaks if pico_pio_usb is not avaialble, so i have removed the rp2040 check
    family_configure_host_example(${PROJECT} noos)
    # Add pico-pio-usb for rp2040 since user can choose to run on bit-banging host
    if(FAMILY STREQUAL "rp2040")
        family_add_pico_pio_us...
fallow birchBOT
fallow birchBOT
fallow birchBOT
robust walrus
#

@jolly scroll nice! that sounds really interesting!

jolly scroll
#

let me make a thread, so i dont spam this up too much...

#

ah, no thread perms

#
] lan_run 0
] irq: raw 0x25000039 respecting mask 0x21000000
980.220600 [DWC2:dwc_check_interrupt]: masked HPRT: 0x8
980.234152 [DWC2:dwc_check_interrupt]: Port Enable/Disable Change
USB_HPRT:        0x1008
980.258991 [DWC2:dwc_check_interrupt]: port disabled
USB_HPRT:        0x1000
980.282697 [DWC2:dwc_check_interrupt]: Disconnect Detected Interrupt
980.296322 [DWC2:dwc_irq]: irq time: 88544

] irq: raw 0x4000035 respecting mask 0x4
981.219814 [DWC2:dwc_check_interrupt]: USB_GOTGINT: 0x40000
981.233683 [DWC2:dwc_check_interrupt]: A-Device Timeout Change
981.246713 [DWC2:dwc_irq]: irq time: 38933

#

so here for example, i pulled the reset pin of the onboard hub/nic low, and it dropped off the bus

robust walrus
#

it's all good

jolly scroll
#
] lan_run 1
] irq: raw 0x5000031 respecting mask 0x1000000
1062.745095 [DWC2:dwc_check_interrupt]: masked HPRT: 0x2
1062.758677 [DWC2:dwc_check_interrupt]: Port Connect Detected
1062.771711 [DWC2:dwc_check_interrupt]: a device is connected
1062.786042 [DWC2:dwc_irq]: irq time: 53376

] 
] 
#

i then pull reset high, and now the device connected irq fires

#
] 
] dwc_root_reset
] irq: raw 0x5000031 respecting mask 0x1000000
1088.602327 [DWC2:dwc_check_interrupt]: masked HPRT: 0xc
1088.615952 [DWC2:dwc_check_interrupt]: Port Enable/Disable Change
USB_HPRT:        0x100d
1088.641013 [DWC2:dwc_check_interrupt]: port enabled
USB_HPRT:        0x1005
1088.664636 [DWC2:dwc_check_interrupt]: a device is connected
1088.677651 [DWC2:dwc_irq]: irq time: 87775
#

if i then assert the usb reset signal for 50ms, the port transitions to the enabled state

#
] addr0_get
...
  bLength: 128
  bDescriptorType: 0
  bcdUSB: 0x5
  class: 18 1
  protocol: 0
  max-packet-size: 2
#

oh, it seems to be totally corrupt on doing it a second time

#
  bLength: 18
  bDescriptorType: 1
  bcdUSB: 0x200
  class: 9 0
  protocol: 2
  max-packet-size: 64
#

if i reboot, and repeat, i now get a valid looking usb hub device descriptor

robust walrus
#

are you able to capture the usb bus? are you managing any caches between usb memory and cpu memory?

jolly scroll
#

i'm on a pi2, so the usb bus is just a diff-pair between the SoC and the onboard usb hub

#

so capturing it would be difficult

#

dwc2 dma mode doesnt work currently, so everything has to be done thru FIFO's by the cpu

#

and when running on the VPU, the cache control is managed by bit 30/31 of the addr

#

currently, everything is going thru the C-alias, raw uncached ram

robust walrus
#

(I've been wanting to add host support for the pcie connected xhci chip on the rpi sbcs)

jolly scroll
#

the pi4/pi400 has 2 xhci controllers

robust walrus
#

its the pi400 in particular I want since I just added usb host support to circuitpython

jolly scroll
#

the bcm2711 SoC, has both the old dwc2 controller, and a broadcom xhci

both dwc2 and xhci, share a single phy, and only one must be enabled at once

that phy is wired to the usb-c port, so it can only do usb1/usb2

#

otg_mode=1 routes the PHY to the xhci, and adds it to DT automatically

#

otg_mode=0 (the default) and the usual dwc2 overlays (like on the pi0) routes it to the dwc, and can do host or device

#

in addition to all of that, you have the vl805 pcie<->usb xhci controller, for the main 3/4 usb-a ports

jolly scroll
robust walrus
#

the pi400's keyboard is connected to the vl805 right?

jolly scroll
#

yep

robust walrus
#

👍 sorry to sidetrack you

jolly scroll
#

the holtek still scans the keyboard while "off"

#

and deals with the mosfet that turns the main 5v rail on/off

jolly scroll
#

there it is, bit 4 of GINTSTS, RxFIFO Non-Empty (RxFLvl)

#
irq: raw 0x4000039 respecting mask 0x10
 19.347122 [DWC2:dwc_irq]: irq time: 12106
irq: raw 0x4000039 respecting mask 0x10
 19.371715 [DWC2:dwc_irq]: irq time: 12149
#

yep, when i control-in EP0, it gets stuck in the irq handler, need to ack it and receive data

robust walrus
#

so you figured it out?

jolly scroll
#

ive at least found the rx irq

#

i suspect there is a packet i didnt pop right

#

and with the rx irq wired up, i can detect them immediately and pop right away

#
211   if (interrupt_status & BIT(4)) {
212     ack |= BIT(4);
213     logf("RX irq\n");
214   }
#

at first, i just ack it, so its not stuck in the irq handler

#

(and print, so i know)

#

ah, fail

#

bit 4 is read-only, you cant clear the irq like normal

#

it clears on its own, once you read the fifo fully

#

so, i must read the fifo in the irq handler...

robust walrus
#

generally tinyusb reads state and queues it into its own fifo in the irq handler so that should be fine

jolly scroll
#
 35.198403 [DWC2:dwc_check_interrupt]: RX irq
USB_GRXSTSP:     0x50080
  channel: 0
  byte count: 8
  PID: 2
  packet status: 2
#

so now, i need to pop 8 bytes from the hw FIFO, move it to a software FIFO on channel 0, and then wake the thread

jolly scroll
#

hmmm, what was the aligned malloc func again...

#

ah, memalign()

#

so, i memalign() an 8 byte buffer for the device-descriptor, 32bit aligned
because i'm popping 32bits from the dwc fifo, and just writing them to ram, and 32bit writes must be 32bit aligned

#

i pass that buffer to control_in(), which stores the buffer in a channel-0 struct

jolly scroll
jolly scroll
#

@robust walrus for some more context, every model of rpi has a VPU processor in it

the VPU is a dual-core processor, with 32 x 32bit scalar registers
and 64x64x8bit vector registers

#

its mostly RISC in design, but the vector opcodes are fairly complex, and the instructions are variable length

#

pi2 and up runs the VPU at 500mhz
pi0/pi1 i think run the VPU at 250mhz

#

and functionally, the arm is more of an optional compute co-processor hanging off the side of the SoC design

robust walrus
#

How deep is the fifo from dwc?

#

I know the vpu starts first. That was convenient for me with getting cp going bare metal

jolly scroll
#

there is a large bank of internal ram on the dwc

robust walrus
#

So it should be able to hold any low level packet

jolly scroll
#

in device mode, that manages 17 fifo's, 16 IN fifo's (one per ep) and a single shared OUT fifo (all host->device traffic)

#

so you can queue up traffic on any IN endpoint, and the dwc can answer anything the host asks for

#

and the dwc can buffer OUT's from the host

#

in host mode, it only has 3 fifo's

#

the rx fifo, which is now the IN direction

#

and the periodic and non-periodic TX fifo's

#

so the same ram, now gets split across fewer fifo's

#

GRXFSIZ tells you the size of the rx fifo...

#

USB_GRXFSIZ: 0x306

#

which is 0x306 x 32bit

#

3096 bytes

#
USB_GNPTXFSIZ:   0x1000306
USB_GNPTXSTS:    0x80100

this is the non-periodic, and periodic tx fifo's, the lower 16bits is the starting addr within the ram
the upper 16bits is the depth, x 32bit

#

so periodic is 32 bytes??
and non-periodic is 1024 bytes

#

ah no, USB_GNPTXSTS is the status

#

HPTXFSIZ is periodic size

#

USB_HPTXFSIZ: 0x2000406

#

2048 bytes

jolly scroll
# robust walrus How deep is the fifo from dwc?

so i can see, that the rx fifo starts at 0, and is 0x306 * 32bit in size
the non-periodic fifo starts at 0x306, and is 0x100 * 32bit in size
and the periodic fifo starts at 0x406, and is 0x200 * 32bit in size

#

these registers are also RW, so you can re-allocate space, based on your needs

#

and that covers ~6168 bytes of FIFO space

#

oh, right, and something funky the dwc does

#

the "push/pop" addr for each fifo, is a whole 4kb wide

#

so you can use a 32bit load/store based memcpy, and not care about it incrementing the fifo addr

#

or use external dma bursts, and not care about the addr incrementing

#

and i think in host mode, reading anything in that whole 4kb*16 block, counts as a POP against the single rx fifo

#

there is also a 128kb addr range, to let you just read/write the fifo ram directly

#

bypassing the push/pop regs

#

its not clear how much ram is actually implemented

jolly scroll
#
  bLength: 0
  bDescriptorType: 112
  bcdUSB: 0x5f75
  class: 118 112
  protocol: 117
  max-packet-size: 95
#

that aint right!

#
 37.038617 [DWC2:dwc_check_interrupt]: RX irq
USB_GRXSTSP:     0x50080
  channel: 0
  byte count: 8
  PID: 2
  packet status: 2
...
 37.232129 [DWC2:dwc_check_interrupt]: RX irq
USB_GRXSTSP:     0x70080
  channel: 0
  byte count: 8
  PID: 2
  packet status: 3
#

status 2, in packet received
status 3, in transfer completed

#

i wasnt checking that, and was just popping data twice

#

had similar problems with device mode before

#

still corrupt, but all 0's now

#

and i think it wants me to pop on status 2, its corrupt if i pop on 3

#
 16.173940 [DWC2:dwc_check_interrupt]: RX irq
USB_GRXSTSP:     0x50080
  channel: 0
  byte count: 8
  PID: 2
  packet status: 2
IN complete, popping
popped 0x2000112 0xc4110150 0
popped 0x40020009 0xc4110154 4
#
  bLength: 0
  bDescriptorType: 1
  bcdUSB: 0x200
  class: 9 0
  protocol: 2
  max-packet-size: 64
#

the values it popped look right
but the values it then printf'd are corrupt, the length is wrong

#

because i printf'd the wrong buffer

robust walrus
jolly scroll
#
  bLength: 18
  bDescriptorType: 1
  bcdUSB: 0x200
  class: 9 0
  protocol: 2
  max-packet-size: 64
#

i now get this same reply, every time i fire a control-in to get the dev-descriptor!

#

progress!

robust walrus
#

you are very much in the "hcd" layer of tinyusb

jolly scroll
#

and i havent even added tinyusb to the project yet!

#

but i now have a working control-in function, that i can just point tinyusb at

#

along with a decent handling of most of the irq events

#

is it reasonable to assume, that the IN size will always be wLength bytes, when doing control-in?

robust walrus
#

I think so

#

but I haven't really implemented any low level stuff myself. just debugged in there

jolly scroll
#

the dwc2 controller is also nasty, in many areas

#

for example, there are a lot of race-proof interrupt registers, where bits will set themselves, and you must write 1 to clear it

#

so you can just write BIT(4) to ack event 4, and not risk clearing other events

#

except, there are 2 or 3 control bits in the same register, that control things like port power

#

so if you just blindly write BIT(4) to the register, you turn power off, and kill the port!

robust walrus
#

oops!

jolly scroll
#

and if you blindly |= BIT(4), you ack interrupts you where not aware of

#

also, the main device vs host mode flag, is in bit 0 of the interrupt status register

#

but it doesnt trigger an irq

#

in device mode, you program a packet-count, and byte-count for an endpoint, and then it does the transfers for you

#

except surprise, EP0 only supports a 1 bit packet-count

#

if your EP0 data doesnt fit in 1 packet, you must want for the completion irq, and queue the next one in software

#

and some datasheets dont mention this

#

so you are left going in circles for a week 😛

#

also, if the integrated PHY is mis-configured, then usb will 99% work, but silently corrupt all tcp packets

#

@robust walrus how bald do you think youll be, by the end of such a thing? 😄

robust walrus
#

I only do it sparingly

#

so only a small bald spot

jolly scroll
#

yeah, i go months without touching this, then get the urge to work on it

#

so, now to turn off some irq debug logging

#

i get nearly an entire screen full of logs, for a single control-in

#
] 
] addr0_get
USB_GNPTXSTS:    0x80100
USB_GNPTXSTS:    0x10700fe
 28.257143 [DWC2:control_in]: SETUP done
 28.268389 [DWC2:dwc_check_interrupt]: RX irq
USB_GRXSTSP:     0x50080
  channel: 0
  byte count: 8
  PID: 2
  packet status: 2
IN complete, popping
popped 0x2000112 0xc4110130 0
popped 0x40020009 0xc4110134 4
 28.366786 [DWC2:dwc_irq]: irq time: 98398
 28.379136 [DWC2:dwc_check_interrupt]: RX irq
USB_GRXSTSP:     0x70080
  channel: 0
  byte count: 8
  PID: 2
  packet status: 3
 28.443297 [DWC2:dwc_irq]: irq time: 64162
 28.455761 [DWC2:control_in]: IN done
  bLength: 18
  bDescriptorType: 1
  bcdUSB: 0x200
  class: 9 0
  protocol: 2
  max-packet-size: 64
 28.629317 [DWC2:dwc_addr0_get_desc]: 100ms later
dumping channel 0
  HCCHAR0: 0x108008
  HCSPLT0: 0x0
  HCINT0: 0x0
  HCINTMSK0: 0x7ff
  HCTSIZ0: 0x80000000
  HCDMA0: 0xc4189a88
] 
#

thats better, but can still be shrunk more

#

@robust walrus a control-in, involves a setup token, a data token with 8 bytes
an in token from the host, and a data token with the descriptor from the device

and then an ack, a 0 length packet, is that in or out?

robust walrus
#

I don't remember off the top of my head. I'd check tinyusb 🙂

jolly scroll
#

so control-in ack's with out

and control-out acks with in

#

and distractions are back!

#

also, right now, all of these actions are manual, via a command line

#

ideally, things like the usb reset, and get-descriptor, should be event driven

jolly scroll
#
 14.579706 [DWC2:control_in]: IN done
channel 0 wants attention
dumping channel 0
  HCCHAR0: 0x100008
  HCSPLT0: 0x0
  HCINT0: 0x21
    xfer complete
    ack
  HCINTMSK0: 0x7ff
  HCTSIZ0: 0x20000000
  HCDMA0: 0xc4189a88
 14.695551 [DWC2:dwc_irq]: irq time: 104640
 14.590909 [DWC2:control_in]: 0-length OUT done
  bLength: 18
  bDescriptorType: 1
  bcdUSB: 0x200
  class: 9 0
  protocol: 2
  max-packet-size: 64
#

the 0-length data-out, immediately gets an ack and xfer-complete irq

#

so, i have control-in fully implemented, and in theory, i can just switch to set-addr

#

@robust walrus oh, and you mentioned circuitpython on the pi400, thats baremetal right? are you interested in gfx accel?

#

i can do this with 0% cpu usage, and only writing about 400 bytes/frame

robust walrus
jolly scroll
#

at the most basic level, the 2d core on the rpi is basically a sprite-only gpu

#

you give it a list of sprites
for each sprite, you give:

  • the pixel format *rgb/yuv, and bit depth
  • the screen XY
  • the source wh
  • the dest wh (if scaling)
  • the addr of the image data in ram (1 to 3 pointers, depending on if its planar)
  • the stride (1 to 3 again)
  • some misc flags, like alpha, and mirroring
#

write that entire list to a dedicated chunk of memory

#

and then write the index for the start, to a main control reg

#

if you do the control-reg mid-frame, youll get a tear, but thats it

#

if you modify part of the control-list thats in use, it can malfunction harder, and spit out 1 or 2 junk frames

#

a vsync irq is available, so you can modify the main control-reg during the blanking period

#

in my current driver, i do all of the list updating out of irq

#

and write the index to a global var

#

the vsync irq handler then copies it to the control reg, on every vsync

#

and the 2d core can do this for up to 3 displays at once, depending on scene complexity

#

each display has its own control reg, and they share the display-list memory

#

for the pi0-pi3 lineup, there are only 3 pixel valves, each hard-wired to a channel on the 2d core

#

and each hard-wired to 2 output ports, only one from each PV can be active

#

SMI isnt documented, DSI0 isnt routed to pins

#

so your only choice is DPI, DSI1, and then HDMI or VEC(ntsc/pal)

#

bcm2711 is more complex, it has 5 PV's, but only 3 can be in use at once

#

i think next, i should take my control-in function, and break it up into smaller pieces

#

in, out, setup

#

then i can reuse the in/out code, for regular in/out stuff

#
static void control_in(dwc_host_state_t *state, int channel, int addr, int endpoint, setupData *setup, uint32_t *buffer) {
  dwc_send_setup(state, channel, addr, endpoint, setup);

  dwc_host_in(state, channel, addr, endpoint, buffer, setup->wLength);

  dwc_host_out(state, channel, addr, endpoint, NULL, 0);
}
#

@robust walrus does this look much better?

#

now i just need to flesh things out more, multi-packet transfers, and it should be ready for tinyusb

#

oh, and split transactions are entirely unhandled

#

and all of the state to keep track of max packet sizes and what device is at each addr

robust walrus
jolly scroll
# robust walrus I'd suggest looking at the existing tinyusb hcd API: https://github.com/hathach/...

ah:

// Submit a transfer, when complete hcd_event_xfer_complete() must be invoked
bool hcd_edpt_xfer(uint8_t rhport, uint8_t dev_addr, uint8_t ep_addr, uint8_t * buffer, uint16_t buflen);

// Submit a special transfer to send 8-byte Setup Packet, when complete hcd_event_xfer_complete() must be invoked
bool hcd_setup_send(uint8_t rhport, uint8_t dev_addr, uint8_t const setup_packet[8]);

looks like i could just map hcd_setup_send to my dwc_send_setup
and then hcd_edpt_xfer to either dwc_host_in or dwc_host_out

then i just have to handle the callbacks, and the basic attach/detatch events?

#

and thats basically 80-90% of it?

#

but then how are split transactions handled? i would need to know what speed a device is, and where in the path the speed drops

#

hcd_devtree_info_t seems to have the relevant info

#

extern void hcd_devtree_get_info(uint8_t dev_addr, hcd_devtree_info_t* devtree_info);

#

so, i could maybe cache that when hcd_edpt_open() is called, and also reserve a channel in the dwc

#

if i do reserve a channel, then i'm limited to 16 endpoints open at once

jolly scroll
#

that all looks fairly simple, and easy to tie in to what ive already got

#

i'll have to give that a stab tomorrow

jolly scroll
#

tossed src/tusb.c into my build, and set CFG_TUSB_MCU=OPT_MCU_BCM2835

#

and it at least compiles and links

#

but nothing uses it, so linker gc just deleted it all

#
 53 #if CFG_TUH_ENABLED && defined(TUH_OPT_RHPORT)
 54   // init host stack CFG_TUSB_RHPORTx_MODE must be defined
 55   TU_ASSERT( tuh_init(TUH_OPT_RHPORT) );
 56 #endif
#

but i think TUH_OPT_RHPORT is missing

jolly scroll
#

@robust walrus getting into tusb_os_custom.h now, and having some confusing compile errors

jolly scroll
#
typedef struct mutex {
    uint32_t magic;
    thread_t *holder;
    int count;
    wait_queue_t wait;
} mutex_t;
#

this is the mutex i have

#
void mutex_init(mutex_t *);
void mutex_destroy(mutex_t *);
status_t mutex_acquire_timeout(mutex_t *, lk_time_t); /* try to acquire the mutex with a timeout value */
status_t mutex_release(mutex_t *);
#

and all functions act on a pointer to it

#

typedef mutex_t* osal_mutex_t; is this then the right typedef?

robust walrus
#

sorry, I'm not sure

#

I haven't done osal stuff

jolly scroll
#
lib/tinyusb/upstream/src/osal/osal.h:50:33: error: unknown type name ‘osal_mutex_def_t’
   #define OSAL_MUTEX_DEF(_name) osal_mutex_def_t _name
#

and there seems to be 2 types for mutex

#

typedef struct mutex osal_mutex_def_t, *osal_mutex_t
reading the pico one as an example, there is a , in there that ive not seen before

#

i'm guessing osal_mutex_def_t is the non-pointer version?

#

that seems to have made that layer happy

#
lib/tinyusb/upstream/src/host/usbh.c:41:33: error: expected ‘)’ before numeric constant
 #define CFG_TUH_TASK_QUEUE_SZ   16
                                 ^
lib/tinyusb/upstream/src/host/usbh.c:222:42: note: in expansion of macro ‘CFG_TUH_TASK_QUEUE_SZ’
 OSAL_QUEUE_DEF(usbh_int_set, _usbh_qdef, CFG_TUH_TASK_QUEUE_SZ, hcd_event_t);
                                          ^~~~~~~~~~~~~~~~~~~~~
lib/tinyusb/upstream/src/host/usbh.c:223:8: error: unknown type name ‘osal_queue_t’
 static osal_queue_t _usbh_q;
#

now it seems to want a queue

#

@robust walrus should the queue be a stream of bytes, or a stream of pointers?

robust walrus
#

I think its bytes

jolly scroll
#

ah, rewrite time then

#

ah, but it seems tinyusb provides the fifo for me

#

i just need to protect it with a spinlock

jolly scroll
#
./build-vc4-stage2/lib/tinyusb.mod.o: In function `usbh_driver_set_config_complete':
/home/clever/apps/rpi/lk-overlay/lib/tinyusb/upstream/src/host/usbh.c:1080:(.text.usbh_driver_set_config_complete+0x52): relocation truncated to fit: R_VC4_PCREL27_MUL2 against undefined symbol `tuh_mount_cb'
./build-vc4-stage2/lib/tinyusb.mod.o: In function `process_removing_device':
/home/clever/apps/rpi/lk-overlay/lib/tinyusb/upstream/src/host/usbh.c:1080:(.text.tuh_task_ext+0x1ea): relocation truncated to fit: R_VC4_PCREL27_MUL2 against undefined symbol `tuh_umount_cb'
make[1]: *** [make/build.mk:27: build-vc4-stage2/lk.elf] Error 1
make[1]: Leaving directory '/home/clever/apps/rpi/lk-overlay'
make: *** [makefile:34: _top] Error 2
#

progress!

#

down to just 1 undefined function

#

it links!

#
cpu 0 LOAD: 100.00%, cs 0, pmpts 97, ints 159, tmr ints 99, tmrs 99
cpu 0 LOAD: 100.00%, cs 0, pmpts 99, ints 160, tmr ints 100, tmrs 101
cpu 0 LOAD: 100.00%, cs 0, pmpts 99, ints 161, tmr ints 101, tmrs 101
#

it is pegging the cpu

#
  4 static void auto_host_entry(const struct app_descriptor *app, void *args) {
  5   tusb_init();
  6   while (true) {
  7     tuh_task();
  8   }
  9 }
#

likely because this isnt blocking

#

@robust walrus i'm guessing its doing nothing, because i dont run any event callbacks, and tinyusb thinks no connect event has occured?

robust walrus
#

yup, that'd be my guess

#

irq queues something and then the task runs it

jolly scroll
#
191 // Called by HCD to notify stack
192 extern void hcd_event_handler(hcd_event_t const* event, bool in_isr);
#
] lan_run 0
] irq: raw 0x25000029 respecting mask 0x21000000
 17.040448 [DWC2:dwc_check_interrupt]: masked HPRT: 0x8
 17.054051 [DWC2:dwc_check_interrupt]: Port Enable/Disable Change
USB_HPRT:        0x1008
 17.078968 [DWC2:dwc_check_interrupt]: port disabled
USB_HPRT:        0x1000
 17.102769 [DWC2:dwc_check_interrupt]: Disconnect Detected Interrupt
ST_CLO: 17116407
Fatal VPU Exception: Misaligned
#

and kernel panic!

#
VPU registers:
     r0: 0x75757454  r1: 0xffffffff  r2: 0x00000000  r3: 0x00000258
     r4: 0x0000000c  r5: 0x00000000  r6: 0x55557555  r7: 0xffffffff
     r8: 0x00001008  r9: 0xc418f3dc r10: 0xc4014190 r11: 0x00000000
    r12: 0x0103d1e3 r13: 0x00000000 r14: 0x00001008 r15: 0x7e980440
     pc: 0xc4001c1e  lr: 0xc400442c  sr: 0x20000000
robust walrus
#

there is a setting for aligning the transmit buffers if you need to

jolly scroll
#

pc is inside mutex_acquire_timeout()

#

lr is inside tu_fifo_write()

#
static uint16_t _tu_fifo_write_n(tu_fifo_t* f, const void * data, uint16_t n, tu_fifo_copy_mode_t copy_mode)
{
  if ( n == 0 ) return 0;

  _ff_lock(f->mutex_wr);
#

so this mutex was probably not aligned correctly

#
c400441a <tu_fifo_write>:
c400441a:       a3 03                   stm r6-r9,lr,(--sp)
c400441c:       06 40                   mov r6,r0 
c400441e:       19 40                   mov r9,r1 
c4004420:       00 23                   ld r0,(r0+0xc)
c4004422:       00 80 05 c0             beq r0,0x0,c400442c <tu_fifo_write+0x12>
c4004426:       01 68                   not r1,0x0
c4004428:       ff 9f f1 eb             bl c4001c0a <mutex_acquire_timeout>
#

f was initially in r0
the value in r0+0xc was loaded into r0

#

ah wait, wrong fifo write

#
bool tu_fifo_write(tu_fifo_t* f, const void * data)
{
  _ff_lock(f->mutex_wr);
#
TU_ATTR_ALWAYS_INLINE static inline void _ff_lock(osal_mutex_t mutex)
{ 
  if (mutex) osal_mutex_lock(mutex, OSAL_TIMEOUT_WAIT_FOREVER);
}
#

ah, that explains the beq

#

so if the mutex pointer was null, it just doesnt lock

#
c4001c0a <mutex_acquire_timeout>:
c4001c0a:       a1 03                   stm r6-r7,lr,(--sp)
c4001c0c:       59 c0 7c cf             add sp,sp,-4
c4001c10:       06 40                   mov r6,r0
c4001c12:       17 40                   mov r7,r1
c4001c14:       00 08                   ld r0,(r0)                                                        
c4001c16:       40 e9 78 74 75 6d       cmp r0,0x6d757478
c4001c1c:       0b 18                   beq c4001c32 <mutex_acquire_timeout+0x28>
c4001c1e:       02 e8 d4 ea 00 c4       mov r2,0xc400ead4

so, r0 would be the raw pointer to the mutex

#
#define MUTEX_MAGIC (0x6D757478)  // 'mutx' 

typedef struct mutex {
    uint32_t magic;
#
status_t mutex_acquire_timeout(mutex_t *m, lk_time_t timeout) {
    DEBUG_ASSERT(m->magic == MUTEX_MAGIC);
#

and first thing it does, is load the magic# at the start

#

r0: 0x75757454

#

r0 was also preserved into r6...

#

r6: 0x55557555

#

wut

#
 10.353948 [DWC2:dwc_check_interrupt]: Disconnect Detected Interrupt
osal_mutex_lock(0x55557555, -1)
ST_CLO: 10380314
Fatal VPU Exception: Misaligned
#

yep, confirmed

#
bool tu_fifo_write(tu_fifo_t* f, const void * data)
{
  _ff_lock(f->mutex_wr);

@robust walrus so, what is responsible for allocating the memory that mutex_wr points to?

#
TU_ATTR_ALWAYS_INLINE static inline
void tu_fifo_config_mutex(tu_fifo_t *f, osal_mutex_t wr_mutex, osal_mutex_t rd_mutex)
{ 
  f->mutex_wr = wr_mutex;
  f->mutex_rd = rd_mutex;
}
#

this func

#
bool tu_edpt_stream_init(tu_edpt_stream_t* s, bool is_host, bool is_tx, bool overwritable,
                         void* ff_buf, uint16_t ff_bufsize, uint8_t* ep_buf, uint16_t ep_bufsize)
{
  osal_mutex_t new_mutex = osal_mutex_create(&s->ff_mutex); 
#

and its just using a mutex in the stream

robust walrus
#

@jolly scroll I'm not quite following. generally everything tinyusb uses itself is statically allocated

jolly scroll
#

so the fifo never went thru tu_edpt_stream_init()

#

is it illegal to send HCD_EVENT_DEVICE_REMOVE when tinyusb believes nothing was attached?

#
] lan_run 1
] irq: raw 0x5000021 respecting mask 0x1000000
 16.472800 [DWC2:dwc_check_interrupt]: masked HPRT: 0x2
 16.486334 [DWC2:dwc_check_interrupt]: Port Connect Detected
osal_mutex_lock(0x55557555, -1)
ST_CLO: 16511970
Fatal VPU Exception: Misaligned
#

i temporarily commented out the removable event, and bumped it, same thing on insertion event

#
] lan_run 1
] irq: raw 0x5000021 respecting mask 0x1000000
 72.801677 [DWC2:dwc_check_interrupt]: masked HPRT: 0x2
 72.815220 [DWC2:dwc_check_interrupt]: Port Connect Detected
tu_fifo_write(0x0, 0xc418f5bc)
osal_mutex_lock(0x55557555, -1)
ST_CLO: 72852147
Fatal VPU Exception: Misaligned
#

aha, because the fifo was null!

#

tu_fifo_write(0x0, 0xc418f5dc), lr=0xc4003870

#
c4003862 <hcd_event_handler>:
c4003862:       ef 03                   stm lr,(--sp)
c4003864:       01 40                   mov r1,r0
c4003866:       00 e7 4e 06 01 f8       ld r0,c4013eb4 <_usbh_q>
c400386c:       80 90 15 06             bl c4004496 <tu_fifo_write>
c4003870:       6f 03                   ldm pc,(sp++)
jolly scroll
#

ah, and tuh_init() should init it

#
static void auto_host_entry(const struct app_descriptor *app, void *args) {
  puts("doing init");
  tusb_init();
#

uhhhh

#

it no longer panics
but it also doesnt issue a reset to the port

jolly scroll
#

if ( !osal_queue_receive(_usbh_q, &event, timeout_ms) ) return;

#

that is aborting out of tuh_task_ext()

#

so it never processes any events

jolly scroll
#

oh, my OSAL_QUEUE_DEF is missing things

#

yep, that did it!

#
] lan_run 1
 39.782533 [DWC2:dwc_check_interrupt]: a device is connected
osal_mutex_lock(0irq: raw 0x5000021 respecting mask 0x1000000
 40.418429 [DWC2:dwc_irq]: irq time: 88754
xc401417c, -1)
 40.603467 [DWC2:dwc_send_setup]: SETUP done
#

@robust walrus so, upon connecting a device, tusb now initiates the bus reset for me, and then sends the setup to enumerate
but i'm not firing the HCD_EVENT_XFER_COMPLETE, so it hangs

robust walrus
#

sounds like its working so far then

jolly scroll
#

yep

#

.ff = TU_FIFO_INIT(_name##_buf, _depth, _type, false) \

#

the problem, was i was missing this line

#

i had deleted it, when i thought i had to implement my own queue

#

then i realized, tusb provides its own fifo, and only wants you to wrap it with spinlocks

#

and i didnt undelete it

#

so all fifo's in tusb where broken

#
499   channel_wait_irq(state, channel);
500   logf("SETUP done\n");
#

so currently, the setup-done message, is printed by this

#

hmmm, and i dont actually need to ack it from the irq handler

#

or rather...

#

@robust walrus should hcd_setup_send() be blocking or async?

robust walrus
#

I don't know off the top of my head

jolly scroll
#

currently, its a blocking call, and the thread sleeps, and the irq wakes it

#

i feel like blocking is bad, because the entire tuh_task hangs

#

so it cant do anything else, and is stuck with 1 transaction inflight at any time

#

and the whole fifo stuff, is to not need the ability to wake threads

#

oh, nice

#

the 4bit endpointnr, and the 1bit in/out flag, are right next to eachother in the control reg

#

so the 5bit form that descriptors and tusb use, is already there

#

hmmm, or not, the shift is wrong, nvm

robust walrus
jolly scroll
#

not currently

#

i have done baremetal dwc device mode before, with an entirely custom stack

#

that was somewhat easier, because wireshark+usbmon on the host could snoop

#
] lan_run 1
channel 0 wants attention
    xfer complete
tu_fifo_write(0xc4013450, 0xc418f758), lr=0xc4003962
 18.795649 [DWC2:dwc_check_interrupt]: RX irq
USB_GRXSTSP:     0x50080
  channel: 0
  byte count: 8
  PID: 2
  packet status: 2
IN packet, popping
 19.003013 [DWC2:dwc_check_interrupt]: RX irq
USB_GRXSTSP:     0x70080
  channel: 0
  byte count: 8
  PID: 2
  packet status: 3
#

the SETUP completed, and then there was an 8 byte IN, for the partial dev desc

#
USB_GRXSTSP:     0x50000
  channel: 0
  byte count: 0
  PID: 2
  packet status: 2
USB_GRXSTSP:     0x70000
  channel: 0
  byte count: 0
  PID: 2
  packet status: 3
 19.950546 [DWC2:dwc_check_interrupt]: IN complete

something moved 0 bytes that time

#

need to adjust the logging, now that its getting a lot more chatty

#
] lan_run 1
 43.524700 [DWC2:hcd_edpt_open]: 
 43.755486 [DWC2:hcd_edpt_xfer]: 
 44.252193 [DWC2:hcd_edpt_xfer]: 
 44.670280 [DWC2:hcd_edpt_xfer]: 
 45.166930 [DWC2:hcd_device_close]: 
 45.178700 [DWC2:hcd_edpt_open]: 
 45.201919 [DWC2:hcd_setup_send]: 
 45.409544 [DWC2:hcd_edpt_xfer]: 
 45.587326 [DWC2:hcd_edpt_xfer]: 
 45.655293 [DWC2:hcd_setup_send]: 
 46.074043 [DWC2:hcd_edpt_xfer]: 
 46.251873 [DWC2:hcd_edpt_xfer]: 
#

thats definitely something, need to improve that more

#
 12.934628 [DWC2:hcd_setup_send]: 
 12.957237 [DWC2:dwc_check_interrupt]: hcd_event_xfer_complete(0, 0x0, 8, success, true)

 12.997064 [DWC2:hcd_edpt_xfer]: (0, 0, IN 0x80, 0xc4013fb4, 8)
 13.085732 [DWC2:dwc_check_interrupt]: hcd_event_xfer_complete(0, 0x80, 0, success, true)
 13.204515 [DWC2:dwc_check_interrupt]: hcd_event_xfer_complete(0, 0x80, 0, success, true)

 13.244830 [DWC2:hcd_edpt_xfer]: (0, 0, OUT 0x0, 0x0, 0)
 13.259181 [DWC2:dwc_check_interrupt]: hcd_event_xfer_complete(0, 0x0, 0, success, true)
 13.323812 [DWC2:dwc_check_interrupt]: hcd_event_xfer_complete(0, 0x0, 8, success, true)

 13.363653 [DWC2:hcd_edpt_xfer]: (0, 0, IN 0x80, 0x0, 0)
 13.451725 [DWC2:dwc_check_interrupt]: hcd_event_xfer_complete(0, 0x80, 0, success, true)
 13.570521 [DWC2:dwc_check_interrupt]: hcd_event_xfer_complete(0, 0x80, 0, success, true)
#

aha, i'm ack'ing transfers twice

#
 16.126109 [DWC2:hcd_edpt_xfer:298]: (0, 0, IN 0x80, 0xc40141b4, 8)
 16.215694 [DWC2:dwc_check_interrupt:427]: hcd_event_xfer_complete(0, 0x80, 0, success, true)
 16.336404 [DWC2:dwc_check_interrupt:427]: hcd_event_xfer_complete(0, 0x80, 0, success, true)
#
[0:] USBH DEVICE ATTACH
[0:0] Open EP0 with Size = 8
Get 8 byte of Device Descriptor
[0:0] Get Descriptor: 80 06 00 01 00 00 08 00 
 27.718375 [DWC2:hcd_setup_send:268]: 
 27.730255 [DWC2:dwc_check_interrupt:427]: hcd_event_xfer_complete(0, 0x0, 8, success, true)
on EP 00 with 8 bytes: OK
#

ah, thats much better

#
 27.781177 [DWC2:hcd_edpt_xfer:298]: (0, 0, IN 0x80, 0xc40153b4, 8)
  packet status: 2
 27.880904 [DWC2:dwc_check_interrupt:427]: hcd_event_xfer_complete(0, 0x80, 0, success, true)
  packet status: 3
 28.001404 [DWC2:dwc_check_interrupt:427]: hcd_event_xfer_complete(0, 0x80, 0, success, true)
on EP 80 with 0 bytes: OK
#

and thats not right

#

HUB address = 5 is mounted

#

😮

#

@robust walrus other then some features/bugs, i think i'm ready to start working towards the next stage...

i would like to have keyboard, mouse, MSD(storage), ethernet(lan9514) all working
and i would like some kind of lsusb like interface, just to be able to debug things

any tips on all that?

jolly scroll
#

HUB Get Port Status: addr = 5 port = 1
fixed some issues with alignment and int ep's not having the int type

#
[0:0] Control data:
  0000:  12 01 00 02 FF 00 01 40                          |.......@|
 11.770494 [DWC2:hcd_edpt_xfer:305]: (0, 0, OUT 0x0, 0x0, 0)
  
 11.794516 [DWC2:dwc_host_out:585]: size=0
on EP 00 with 0 bytes: OK
  
Set Address = 1
[0:0] Set Address: 00 05 01 00 00 00 00 00 
unhandled packet status on rx fifo
  channel: 0
  byte count: 0
  PID: 2
  packet status: 7
 11.944175 [DWC2:dwc_irq:494]: irq time: 52795
on EP 00 with 8 bytes: OK
#

it is now getting the dev descriptor of the ethernet part of the lan9514

#

but then set-addr fails with an unexpected error code

jolly scroll
jolly scroll
#

having trouble fixing that, with a 2nd usb device active, its trying to IN the hub interrupt, at the same time as control-in the new addr-0

#

so it has 2 pending transfers, and using another channel isnt working

#
USB_GHWCFG2:     0x228ddd50
  OtgMode: 0
  OtgArch: 2
  NumHstChnl: 7
#

ah, minor surprise there, the hw only supports 8 channels, not 16

#

but i'm failing on channel 1 and 5...

jolly scroll
#

aha, i mis-understood how the fifo's work

robust walrus
fallow birchBOT
fallow birchBOT
#
[hathach/tinyusb] New branch created: usbh-xfer-user-callback
#

Describe the PR
Per @tannewt request for CircuitPython full control over built-in driver

  • When a transfer is complete on an endpoint, USBH will prefer application callback over built-in driver. This occurs when application uses tuh_edpt_xfer() on enabled driver e.g HID endpoint.
  • When using built-in driver API, callback is set to NULL
  • Take chance to add fine-grained debug support. CFG_TUD_LOG_LEVEL and CFG_TUD_MSC_LOG_LEVEL can be defined to requires higher level, can be useful wh...
fallow birchBOT
#

Operating System

Windows 11

Board

Raspberry Pi Pico

Firmware

examples/device/msc is the base of this.

I can incorporate msc/cdc/hid into a composite device using the examples provided and it works perfectly.

I can use MIDI as a standalone device using the example provided and it works perfectly.

I cannot, using any permutation or combination of settings, make MIDI work concurrently with any other device or devices. Windows rejects the device with a (not very useful) ...

jolly scroll
fallow birchBOT
#

Operating System

Others

Board

Customized RA4M2 board

Firmware

Custom Firmware.
RA
Host
Mass storage
No OSAL

What happened ?

The issue occurs during the enumeration of some MSC devices. The USB device report a stall, when I did some troubleshooting, I could notice that the first out token after enumeration is 32 and it is not 31.
I found a way to fix it, but I am not fixing it from the root cause.

I attached the Beagle files, before the fix and after t...

robust walrus
jolly scroll
#

yeah

#

i'll need to read all of them, find what is useful, and mix them together

#

and then for a lsusb style debug...

robust walrus
#

bare api prints the device descriptor

#

cdc_msc_hid does three different classes at once

jolly scroll
#
[0:0:0] USBH DEVICE REMOVED
[0:] USBH DEVICE ATTACH
High Speed
[0:0] Open EP0 with Size = 8
Get 8 byte of Device Descriptor
[0:0] Get Descriptor: 80 06 00 01 00 00 08 00 
on EP 00 with 56 bytes: OK
popped 0x2000112 0xc40155b4 0/8
popped 0x40020009 0xc40155b8 4/8
on EP 80 with 8 bytes: OK
[0:0] Control data:
  0000:  12 01 00 02 09 00 02 40                          |.......@|
on EP 00 with 0 bytes: OK
#

ok, so i believe that was tusb, finding the hub

#
Set Address = 5
[0:0] Set Address: 00 05 05 00 00 00 00 00 
on EP 00 with 56 bytes: OK
on EP 80 with 0 bytes: OK
[0:5] Open EP0 with Size = 64
Get Device Descriptor
[0:5] Get Descriptor: 80 06 00 01 00 00 12 00 
on EP 00 with 56 bytes: OK
popped 0x2000112 0xc40155b4 0/18
popped 0x40020009 0xc40155b8 4/18
popped 0x95140424 0xc40155bc 8/18
popped 0x200 0xc40155c0 12/18
popped 0x71520100 0xc40155c4 16/18
 10.785808 [DWC2:dwc_check_interrupt:384]: i 0, bytes_rem 2, word 0x71520100
on EP 80 with 18 bytes: OK
[0:5] Control data:
  0000:  12 01 00 02 09 00 02 40 24 04 14 95 00 02 00 00  |.......@$.......|
  0010:  00 00                                            |..|
#

then is made the hub device 5, and fetched the dev descriptor again

robust walrus
#

hubs get numbered after the device numbers. so 1-4 for device and then 5+ for hubs by default

jolly scroll
#

that descriptor, was 4+4+4+4+2 bytes in size

#

so 0x71520100 contains 2 bytes of the end

#

and if the buffer was not a multiple of 32bits, i need to write to it 8bits at a time, to finish it off

#

you mentioned something about alignment?

#

yeah, looking at those hexdumps, i have a bug there

#

and i corrupted the bNumberConfigurations

#

@robust walrus would it be possible, to enforce that all buffers are 32bit aligned, and a multiple of 32bits? then i can just drop this buggy code

#
for (int i=0; i<bytes_rem; i++) {
  bytes_rem--;
}
#

doh, thats why its buggy, lol

robust walrus
#

it is 4 byte aligned by default

#

(but maybe the example doesn't do it)

jolly scroll
#

bare_api and i think hub, have both given me mis-aligned buffers

robust walrus
#

could be the example code

jolly scroll
#
popped 0x2000112 0xc40155b4 0/18
popped 0x40020009 0xc40155b8 4/18
popped 0x95140424 0xc40155bc 8/18
popped 0x200 0xc40155c0 12/18
popped 0x71520100 0xc40155c4 16/18
 10.913708 [DWC2:dwc_check_interrupt:384]: i 0, bytes_rem 2, word 0x71520100
 10.929047 [DWC2:dwc_check_interrupt:384]: i 1, bytes_rem 2, word 0x715201
#

this time, it wrote the last 2 bytes correctly

#
[0:5] Control data:
  0000:  12 01 00 02 09 00 02 40 24 04 14 95 00 02 00 00  |.......@$.......|
  0010:  00 01                                            |..|
#

and bNumberConfigurations is no longer a lie!

#
Get Configuration[0] Descriptor (9 bytes)
[0:5] Get Descriptor: 80 06 00 02 00 00 09 00 
on EP 00 with 56 bytes: OK
on EP 80 with 9 bytes: OK
[0:5] Control data:
  0000:  09 02 29 00 01 01 00 E0 01                       |..)......|
#

yeah, that looks like a config desc

#
Get Configuration[0] Descriptor
[0:5] Get Descriptor: 80 06 00 02 00 00 29 00 
on EP 00 with 56 bytes: OK
on EP 80 with 41 bytes: OK
[0:5] Control data:
  0000:  09 02 29 00 01 01 00 E0 01 09 04 00 00 01 09 00  |..).............|
  0010:  01 00 07 05 81 03 01 00 0C 09 04 00 01 01 09 00  |................|
  0020:  02 00 07 05 81 03 01 00 0C                       |.........|
#
[0:5] Set Configuration: 00 09 01 00 00 00 00 00 
on EP 00 with 56 bytes: OK
on EP 80 with 0 bytes: OK

Device configured
HUB set config: itf = 0
[0:5] Class Request: A0 06 00 00 00 00 09 00 
on EP 00 with 56 bytes: OK
#

the hub appears to be configured

#
HUB Set Feature: PORT_POWER, addr = 5 port = 1
HUB Set Feature: PORT_POWER, addr = 5 port = 2

and its bringing all ports online

#
HUB address = 5 is mounted
on EP 81 with 1 bytes: OK
HUB xfer callback
  Hub Status Change = 0x02
HUB Get Port Status: addr = 5 port = 1
[0:5] Class Request: A3 00 00 00 01 00 04 00 
on EP 00 with 56 bytes: OK
#

and the interrupt endpoint seems to be working

#

the lan9514 claims a NIC was plugged into port 1

#
HUB Set Feature: PORT_RESET, addr = 5 port = 1
[0:5] Class Request: 23 03 04 00 01 00 00 00 
on EP 00 with 56 bytes: OK
#

and now the hub should send a reset pulse

#
on EP 80 with 8 bytes: OK
[0:0] Control data:
  0000:  12 01 00 02 FF 00 01 40                          |.......@|
 28.740650 [DWC2:dwc_check_interrupt:467]: transaction error on channel 0
#

@robust walrus and now i'm not calling the right callback for this event

jolly scroll
#

@robust walrus and i'm getting confusing interrupt patterns
tusb asks to send a setup packet
i then get transfer complete + ack
ack
transfer complete
in 3 different interrupts!

#

oh, wait...
setup
data + 8 bytes?

robust walrus
#

¯_(ツ)_/¯

jolly scroll
#

i'm also getting a NAK from the NIC i think

#

ah no, that looks like the hub

#
on EP 00 with 0 bytes: OK

Device configured
  Queue EP 81 with 1 bytes ... 
 36.091324 [DWC2:hcd_edpt_xfer:315]: (0, dev 5, IN 0x1, 0xc4015b47, 1)
 36.117668 [DWC2:dwc_host_in:603]: type 3, mps 64, addr 5, pid 2, buffer 0xc4015b47
channel 0 wants attention after 2 uSec
dumping channel 0
  HCCHAR0: 0xc15c8840
  HCSPLT0: 0x0
  HCINT0: 0x10
    NAK
  HCINTMSK0: 0x7ff
  HCTSIZ0: 0x80001
  HCDMA0: 0x0
 36.229418 [DWC2:dwc_check_interrupt:471]: NAK on chan 0
#

oh, i think i know why

#

it tried to read an interrupt endpoint, and it had nothing to interrupt about

#

so it NAK'd

#

@robust walrus should i tell tinyusb about the NAK, or poll it again after some interval myself?

robust walrus
jolly scroll
#

and the pico datasheet mentioned the hw can poll for you

#

so the software never even gets the NAK

#

so i would guess tusb is expecting that level of inteligence

#

and the driver should hide the stupid

robust walrus
#

makes sense to me

jolly scroll
#

for the moment, i dont care about interrupt endpoints NAK'ing (so no hub hotplug, no key/mouse), so i'll just detect that, not flag the transfer as complete, and slap a // TODO on it

#

because this error is causing it to panic, and cant enumerate the rest of the bus

jolly scroll
#
Get Device Descriptor
[0:1] Get Descriptor: 80 06 00 01 00 00 12 00 
on EP 80 with 18 bytes: OK
[0:1] Control data:
  0000:  12 01 00 02 FF 00 01 40 24 04 00 EC 00 02 00 00  |.......@$.......|
  0010:  00 01                                            |..|
#

class ff
subclass 00
protocol 1
max-packet 64

#

24 04 00 EC, vid/pid, bit odd

#

drivers/net/usb/smsc95xx.c: USB_DEVICE(0x0424, 0xec00),

#

but the drivers say its right

robust walrus
#

👍

jolly scroll
#
 32.565864 [DWC2:hcd_edpt_xfer:322]: (0, dev 1, OUT 0x0, 0x0, 0) chan=1
dumping channel 1
  HCCHAR1: 0xc0500008
  HCSPLT1: 0x0
  HCINT1: 0x80
    transaction error
  HCINTMSK1: 0x7ff
  HCTSIZ1: 0x60080000
  HCDMA1: 0x0
 32.762071 [DWC2:dwc_check_interrupt:488]: transaction error on channel 1
#

so, if the max-packet size is 64, why did i get an error on control?

#

i think this is a 0-length out, to ack the control-in

#
1387       // Get full device descriptor
1388       TU_LOG_USBH("Get Device Descriptor\r\n");
1389       TU_ASSERT(tuh_descriptor_get_device(new_addr, _usbh_ctrl_buf, sizeof(tusb_desc_device_t), process_enumeration, ENUM_GET_9BYTE_CONFIG_DESC), );
1390     }
#

process_enumeration 1397: ASSERT FAILED

#

ah, wrong lines

#
1393     case ENUM_GET_9BYTE_CONFIG_DESC:
1394     {
1395       tusb_desc_device_t const * desc_device = (tusb_desc_device_t const*) _usbh_ctrl_buf;
1396       usbh_device_t* dev = get_device(daddr);
1397       TU_ASSERT(dev, );
jolly scroll
#
process_enumeration() daddr=0 state=3
Get 8 byte of Device Descriptor
process_enumeration() daddr=0 state=7
Set Address = 5
process_enumeration() daddr=0 state=8
Get Device Descriptor
process_enumeration() daddr=5 state=9
#

after a set-addr call, the callback is still ran with addr 0, as expected

#

so, state 8(ENUM_GET_DEVICE_DESC) is kinda ran with the wrong daddr, because it just changed

#

but it all works out

#

then with the 2nd device that fails...

#
process_enumeration() daddr=5 state=2
process_enumeration() daddr=5 state=3
Get 8 byte of Device Descriptor
[0:0] Get Descriptor: 80 06 00 01 00 00 08 00 
 29.161900 [DWC2:hcd_edpt_xfer:322]: (0, dev 0, OUT 0x0, 0x0, 0) chan=0
 29.177310 [DWC2:dwc_check_interrupt:488]: transaction error on channel 0
 29.192878 [DWC2:dwc_irq:541]: irq time: 15569
on EP 00 with 0 bytes: OK
  
process_enumeration() daddr=0 state=7
Set Address = 1
#

wut

#

ah, ENUM_HUB_CLEAR_RESET_1=2

#

and while it claims daddr=5 in the triggering xfer, ENUM_ADDR0_DEVICE_DESC then switches to addr 0

#

then transitions to ENUM_SET_ADDR

jolly scroll
#

ok, so the hub port has been reset, and it has queried the dev-desc on port 1

#
Set Address = 1
[0:0] Set Address: 00 05 01 00 00 00 00 00 
 29.801776 [DWC2:hcd_setup_send:284]: port 0, addr 0
 30.314873 [DWC2:dwc_send_setup:584]: dwc_send_setup(0xc4015e6c, 1, 0, 0, 0xc401579c)
process_enumeration() daddr=0 state=8
#

and set-address completed successfully

#

so it should now be in ENUM_GET_DEVICE_DESC state

#
Get Device Descriptor
[0:1] Get Descriptor: 80 06 00 01 00 00 12 00 
 31.498097 [DWC2:hcd_setup_send:284]: port 0, addr 1
 32.011272 [DWC2:dwc_send_setup:584]: dwc_send_setup(0xc4015e6c, 1, 1, 0, 0xc401579c)
on EP 80 with 18 bytes: OK
[0:1] Control data:
  0000:  12 01 00 02 FF 00 01 40 24 04 00 EC 00 02 00 00  |.......@$.......|
  0010:  00 01                                            |..|
#

and it responds with the dev desc, all good

#
 32.643439 [DWC2:hcd_edpt_xfer:322]: (0, dev 1, OUT 0x0, 0x0, 0) chan=1
 32.658816 [DWC2:dwc_host_out:646]: size=0
dumping channel 1
  HCCHAR1: 0x508040
  HCSPLT1: 0x0
  HCINT1: 0x0
  HCINTMSK1: 0x7ff
  HCTSIZ1: 0x80000000
  HCDMA1: 0x0
channel 1 wants attention after 4 uSec
dumping channel 1
  HCCHAR1: 0xc0500008
  HCSPLT1: 0x0
  HCINT1: 0x80
    transaction error
  HCINTMSK1: 0x7ff
  HCTSIZ1: 0x60080000
  HCDMA1: 0x0
 32.839686 [DWC2:dwc_check_interrupt:488]: transaction error on channel 1
 32.854701 [DWC2:dwc_irq:541]: irq time: 110840
on EP 00 with 0 bytes: OK
#

and it ends, with a transaction error

jolly scroll
#

facepalm

#

when changing an 8->64, to increase the max packet size

#

i changed the wrong 8, the size of a setup packet

#

so every SETUP packet was configured to be 64 bytes in size

#
 18.994410 [DWC2:hcd_edpt_open:299]: dev 0 EP00 opened
 19.007343 [DWC2:hcd_setup_send:283]:   HOST0 SETUP 0.00 0xc401499c/8
 19.023054 [DWC2:dwc_check_interrupt:502]: hcd_event_xfer_complete(0, 0x0, 8, success, true)
 19.039029 [DWC2:dwc_irq:538]: irq time: 15976
 19.053048 [DWC2:hcd_edpt_xfer:315]:    HOST0  <-   0.80 0xc40149b4/8
 19.068046 [DWC2:dwc_check_interrupt:418]: hcd_event_xfer_complete(0, 0x80, 8, success, true)
 19.084122 [DWC2:dwc_irq:538]: irq time: 16077
 19.098233 [DWC2:hcd_edpt_xfer:318]:    HOST0  ->   0.00 0x0/0
 19.112703 [DWC2:dwc_check_interrupt:497]: transaction error on channel 0
 19.128289 [DWC2:dwc_check_interrupt:499]: hcd_event_xfer_complete(0, 0x0, 0, fail, true)
 19.143825 [DWC2:dwc_irq:538]: irq time: 31123
[0:0] Control FAILED, xferred_bytes = 0
80 06 00 01 00 00 08 00 
Enumeration attempt 1
#

so, its detecting a device on port 1 of the hub, turning that on, sending a reset, and then begining to query the dev desc

#

it successfully got a 8 byte reply, then tried to ACK it with an OUT, and failed

#

and on every retry, it failed again

robust walrus
#

making progress!

jolly scroll
#

@robust walrus do you know if accessing a HS device behind a HS hub (technically, all one chip), is special, or do you just set the addr and it works?

jolly scroll
#

one thing i notice, i was getting a vid/pid for the ethernet

#

but now i'm not getting that far

#

what changed...

fallow birchBOT
#

midi work just fine with other class, try out arduino example here

Arduino always keep the cdc therefore this is cdc + midi. You probably get the descriptor incorrectly. You can troubleshoot this by enabling debug log and/or dumping configuration and use online parse tool to spot any error.

Btw your how-to-reproduce is not reproducible, it is best to post a link to your example repo.

robust walrus
jolly scroll
#

i can try there tomorrow

#

only other hack i can think of right now, is to modify tinyusb, so it doesnt enable port 1 of the hub

#

then it would enable an externally facing port, and i could at least probe it with a device i control (pico/scope)

#

but my code is using MDATA

#

@robust walrus bam! lol

Device 1: ID 0424:ec00
Device Descriptor:
  bLength             18
  bDescriptorType     1
  bcdUSB              0200
  bDeviceClass        255
  bDeviceSubClass     0
  bDeviceProtocol     1
  bMaxPacketSize0     64
  idVendor            0x0424
  idProduct           0xec00
  bcdDevice           0200
  iManufacturer       0     
  iProduct            0     
  iSerialNumber       0     
  bNumConfigurations  1
#

a single bit in just one place, lol

#

so, the weird part, is how the hub half of the chip, allowed this invalid ack

#

but the ethernet part of the same chip, didnt!!

#

i also noticed, i need to keep track of the PID toggling, with the hub interrupt endpoint

#

so i'll need proper state, per endpoint

robust walrus
#

could be a tinyusb issue too. host support is pretty new

jolly scroll
#

with no devices connected (just the internal ethernet), i get 1 reply on the hub status port, and then a NAK

#

with a webcam on an external port, i get a second reply on the status port, but i messed up the data toggling

#

so it comes up with a dedicated error for that

#

i assume EP0 is special, and the SETUP token keeps resetting the toggle order

#

so ive been able to get away with hard-coding the PID's

#

but thats all good progress, and i can put more time in tomorrow

robust walrus
#

nice work!

fallow birchBOT
#

Related area

Host Driver (HCD)

Hardware specification

pi400

Is your feature request related to a problem?

Support xHCI host controller.

motivation

pi400 has an keyboard connected to xHCI controller via Holtek MCU. It would be nice to have ported so that we can have circuitpython as a PC. Note: xHCI is connected to bcm cpu via pci xpress which can be a bit of challange, we will see.

$ lsusb
Bus 002 Device 001: ID 1d6b:0003 Linux Foundation 3.0 root hub
Bu...
fallow birchBOT
#
[hathach/tinyusb] New branch created: hcd-abort-xfer
fallow birchBOT
#

Hello Mr Thach and thank you very much for your quick reply!

I'm going to attempt to put my code on here, but I've never used GitHub except for looking at code, so bear with me.

I've solved my problem by having two different code sets which I will use one at a time, as I don't actually really need composite (I just need the same port to be either MIDI or CDC depending on a switch).

fallow birchBOT
#

Operating System

Linux

Board

Raspberry Pi Pico

Firmware

examples/host/cdc_msc_hid

(With an extra printf to tuh_hid_report_received_cb to confirm that I was getting no reports)

What happened ?

This device is a bit weird in that it enumerates as a Nintendo Switch controller, then resets itself and enumerates as a generic xinput or HID controller.

With TinyUSB it fails in various different ways depending on the log level and other factors (timing issues?). Though...

fallow birchBOT
#

Operating System

Windows 10

Board

custom nrf52840

Firmware

Arduino n-able core

  • raw tinyUSB, master branch
    (I am NOT using their built in tinyusb)

I have made simple example repo with all the code necessary including test app (in nodejs, but anything that can send data to hid usb will do the trick)
https://github.com/kaminaris/tinyusb-nrf52

What happened ?

USB halts after a completely random period of time, causing it...

fallow birchBOT
#

After some further testing with modified write function to this:

void USB::write(uint8_t* data, int len) {
	while (!tud_hid_ready()) {
		delay(1);
	}

	// Serial.printf("sending usb data\n");
	// for (int i = 0; i < len; i++) Serial.print(data[i], HEX);
	// Serial.println();

	if (tud_hid_report(0, data, len)) {
		//Serial.println("SENT!");
	}
	else {
		Serial.println("FAILED TO SEND!");
	}
}```

I am getting absolutely spammed with `USBD Func Call` for about 1-2 s...
jolly scroll
#
Device 1: ID 0424:ec00
Device Descriptor:
  bLength             18
  bDescriptorType     1
  bcdUSB              0200
  bDeviceClass        255
  bDeviceSubClass     0
  bDeviceProtocol     1
  bMaxPacketSize0     64
  idVendor            0x0424
  idProduct           0xec00
  bcdDevice           0200
  iManufacturer       0     
  iProduct            0     
  iSerialNumber       0     
  bNumConfigurations  1
config descriptor
  bLength: 9
  bDescriptorType: 2
  wTotalLength: 39
  bNumInterfaces: 1
  bConfigurationValue: 1
  iConfiguration: 0
  bmAttributes: 0xe0
  bMaxPower: 1
  interface
    bLength: 9
    bDescriptorType: 4
    bInterfaceNumber: 0
    bAlternateSetting: 0
    bNumEndpoints: 3
    bInterfaceClass: 255
    bInterfaceSubClass: 0
    bInterfaceProtocol: 255
    iInterface: 0
    endpoint 0
      bLength: 7
      bDescriptorType: 5
      bEndpointAddress: 129
      wMaxPacketSize: 512
      bInterval: 0
    endpoint 1
      bLength: 7
      bDescriptorType: 5
      bEndpointAddress: 2
      wMaxPacketSize: 512
      bInterval: 0
    endpoint 2
      bLength: 7
      bDescriptorType: 5
      bEndpointAddress: 131
      wMaxPacketSize: 16
      bInterval: 4
#

@robust walrus and with this, i can now see the full descriptors for all devices, as they attach

jolly scroll
#
      bmAttributes: 2
      bmAttributes: 2
      bmAttributes: 3
#

a bit more casting, and i can see the endpoint attributes

#

lower 2bits is type
bulk, bulk, interrupt

#

makes sense, bulk in each direction for actual packets, interrupt for interrupts

#

looks like youll need to detect an incoming packet with interrupt, and then pull it with bulk

#

ah, interesting, linux is using usb_control_msg() to access various control regs

#

cmd=USB_VENDOR_REQUEST_WRITE_REGISTER
reqtype=USB_DIR_OUT|USB_TYPE_VENDOR|USB_RECIP_DEVICE

#

i think i just need to load up usbmon, and spy on things, to get a good idea

fallow birchBOT
#

Operating System

Linux

Board

iMX RT 1060 evk with usb drive

Firmware

On this branch: https://github.com/tannewt/circuitpython/tree/three_small

CP code.py is:

import usb.core
import storage
import struct
import time

device = None
while device is None:
    print("searching for devices")
    for device in usb.core.find(find_all=True):
        print("pid", hex(device.idProduct))
        print("vid", hex(device.idVendor))
        print("man", device.manu...
jolly scroll
#
 17.265495 [DWC2:hcd_edpt_open:299]: dev 0 EP00 opened root port: 0 hub_addr: 0 hub_port: 0 speed: 2
 17.292891 [DWC2:hcd_setup_send:283]:   HOST0 SETUP 0.00 0xc401459c/8
 17.308015 [DWC2:hcd_edpt_xfer:321]:    HOST0  <-   0.80 0xc40145b4/8
 17.323505 [DWC2:hcd_edpt_xfer:324]:    HOST0  ->   0.00 0x0/0
 19.457994 [DWC2:hcd_edpt_xfer:324]:    HOST1  ->   1.00 0x0/0
#

~2.1 seconds, to enumerate, with some of the logging still enabled

#

and fail if i disable the logging

#

hub doesnt fully enumerate, if i remove logging

#

added a 10ms sleep on every transfer, now it works

#
 17.394355 [DWC2:hcd_edpt_open:299]: dev 0 EP00 opened root port: 0 hub_addr: 0 hub_port: 0 speed: 2
 18.588454 [DWC2:tuh_mount_cb:21]: Device attached, address = 1
#

~1.1 sec now

jolly scroll
#

oops, forgot about my uart refclk, when i tried cranking it to 1,000,000 baud!

#

the refclk is too slow, need to adjust more divisors

jolly scroll
#

doh, i had the gfxconsole on the whole time, so prints where extra slow

#

but they still slow things down enough, to not cause that bug

jolly scroll
#
 17.028167 [DWC2:hcd_edpt_open:305]: dev 5 EP81 opened       bLength: 7
      bDescriptorType: 5
      bEndpointAddress: 0x81
      bmAttributes: 3
      wMaxPacketSize: 1
      bInterval: 12
#

and with better debug, i can now report this, and now i can see what i have access to, to keep track thats its an interrupt ep

jolly scroll
#
 16.188543 [DWC2:hcd_edpt_xfer:351]:    HOST0  <-   5.81 0xc401411b/1 pid:0
 16.960768 [DWC2:hcd_edpt_xfer:351]:    HOST0  <-   5.81 0xc401411b/1 pid:1
  packet status: 5
#

hmmm, pid handling isnt working right

#
 16.122613 [DWC2:hcd_edpt_xfer:354]:    HOST0  <-   5.81 0xc401411b/1 pid:0
  channel: 0
  byte count: 1
  PID: 0
  packet status: 2
#

so first, i start the interrupt IN with DATA0

#

then i get an event that 1 byte has been transfered, and its still DATA0

#
  HCCHAR0: 0x15c8840
    mps:64 ep:1 dir1 type:3 mc:1 addr:5
  HCSPLT0: 0x0
  HCINT0: 0x20
    ack
  HCINTMSK0: 0x7ff
  HCTSIZ0: 0xc0000000
    size:0 packets:0 pid:2 ping:1
  HCDMA0: 0x0
#

but now the channel is in DATA1 mode

#
  channel: 0
  byte count: 1
  PID: 0
  packet status: 3
#

i also get a transfer complete event, that still has DATA0 on it

#

18.705305 [DWC2:hcd_edpt_xfer:354]: HOST0 <- 5.81 0xc401411b/1 pid:1

#

and a while later, it tries to read the EP again, but with DATA2?!

jolly scroll
#
 16.161292 [DWC2:hcd_edpt_xfer:354]:    HOST0  <-   5.81 0xc4013f1b/1 pid:0
 16.936092 [DWC2:hcd_edpt_xfer:354]:    HOST0  <-   5.81 0xc4013f1b/1 pid:2
 16.983842 [DWC2:hcd_edpt_xfer:354]:    HOST0  <-   5.81 0xc4013f1b/1 pid:0
 17.014021 [DWC2:hcd_edpt_xfer:354]:    HOST0  <-   5.81 0xc4013f1b/1 pid:2
 17.063989 [DWC2:hcd_edpt_xfer:354]:    HOST0  <-   5.81 0xc4013f1b/1 pid:0
 17.144614 [DWC2:hcd_edpt_xfer:354]:    HOST0  <-   5.81 0xc4013f1b/1 pid:2
#

that looks like its workin!!

#

20.476780 [DWC2:hcd_edpt_open:297]: dev 0 EP00 opened root port: 0 hub_addr: 5 hub_port: 4 speed: 0

#

i can confirm, my mouse usb dongle, is full-speed (both tusb and linux say so)
and with split transactions entirely unhandled, it just
20.504802 [DWC2:dwc_check_interrupt:550]: transaction error on channel 0
fails hard, as expected

#

if i have a high-speed webcam plugged into port4, i get this:

 18.745683 [DWC2:hcd_edpt_open:298]: dev 0 EP00 opened root port: 0 hub_addr: 5 hub_port: 4 speed: 2
 18.774829 [DWC2:hcd_setup_send:339]:   HOST0 SETUP 0.00 0xc4014b70/8
 18.794200 [DWC2:hcd_edpt_xfer:355]:    HOST0  <-   0.80 0xc4014b88/8 pid:153
 18.800272 [DWC2:dwc_check_interrupt:547]: TODO, NAK
#

it tries to query the dev descriptor, but fails with NAK

#

or a NAK packet indicating to the host that the endpoint is working, but temporarily has no data to send.

#

so i think i just need to try the IN again

#

same happens even with a 1 second sleep (but only 1 IN attempt), on 2 diff HS devices

jolly scroll
#

after some trial&error, i found a usb<->sd adapter, that doesnt NAK the first descriptor read

#
Device 2: ID 14cd:121c
Device Descriptor:
  bLength             18
  bDescriptorType     1
  bcdUSB              0200
  bDeviceClass        0
  bDeviceSubClass     0
  bDeviceProtocol     0
  bMaxPacketSize0     64
  idVendor            0x14cd
  idProduct           0x121c
  bcdDevice           0200
jolly scroll
#
 54.544764 [DWC2:hcd_setup_send:344]:   HOST2 SETUP 2.00 0xc4013b70/8
 55.561734 [DWC2:hcd_edpt_xfer:361]:    HOST2  <-   2.80 0xc4013b88/18 type:0
 55.568501 [DWC2:dwc_check_interrupt:567]: TODO, NAK
 55.624272 [DWC2:dwc_in_retry:383]:     HOST3  <-   2.80 0xc4013b88/18 type:0 RETRY
 55.641496 [DWC2:hcd_edpt_xfer:367]:    HOST3  ->   2.00 0x0/0
#

looks like this is working

#
 55.649651 [DWC2:hcd_setup_send:344]:   HOST3 SETUP 2.00 0xc4013b70/8
 56.666622 [DWC2:hcd_edpt_xfer:361]:    HOST3  <-   2.80 0xc4013b88/9 type:0 pid:153
 56.673302 [DWC2:dwc_check_interrupt:567]: TODO, NAK
 56.728988 [DWC2:dwc_in_retry:383]:     HOST4  <-   2.80 0xc4013b88/9 type:0 pid:153 RETRY
 56.746127 [DWC2:hcd_edpt_xfer:367]:    HOST4  ->   2.00 0x0/0
#

@robust walrus found a possible bug for upstream
TU_ASSERT(total_len <= CFG_TUH_ENUMERATION_BUFSIZE, );

if any configuration descriptor is over 256 bytes, the enumeration halts, and it doesnt try any other device on the bus

a simple usb webcam was enough to break it

#

but that is in the tusb_config.h, so the user can increase it

#

plus, that is over the max-packet-size, so my code also cant read it

jolly scroll
#

@orchid cobalt ive also been working on rpi dwc host mode over here

#

ive nearly got interrupt endpoints working, but i dont have split transactions currently, so HS only

orchid cobalt
jolly scroll
#

if i get dwc host mode working fully, then the open firmware can boot from usb

orchid cobalt
#

I actually don't know much about it.

jolly scroll
#

the stock firmware is closed-source, and is required for the dram and arm to even start

orchid cobalt
#

Yeah, that much I know.

jolly scroll
#

so if you get rid of the closed-source blobs, the rpi cant even blink an LED

orchid cobalt
#

The same is true for virtually all x86 systems, despite some vendor claims to the contrary.

jolly scroll
#

(maskrom isnt being counted, read-only)

orchid cobalt
#

Interesting

jolly scroll
#

but currently, hdmi/camera/h264/mpeg2/vc1 dont work

#

and usb/network boot arent working, but will be possible

orchid cobalt
#

Just arriving at the theater to watch Oppenheimer though, so I'll have to look another time.

jolly scroll
#

usb-host works once linux has booted, and ssh/keyboard/mouse are all good

jolly scroll
#
Device 2: ID 054c:0243
Device Descriptor:
  bLength             18
  bDescriptorType     1
  bcdUSB              0200
  bDeviceClass        0
  bDeviceSubClass     0
  bDeviceProtocol     0
  bMaxPacketSize0     64
  idVendor            0x054c
  idProduct           0x0243
  bcdDevice           0100
#

after working at it all night, i can now detect a usb-stick being hotplugged

#

interrupt endpoints are semi working, and the NAK bugs are fixed

#

but interrupt just randomly stopped polling on its own

fallow birchBOT
#

Here I am working with a FRDM-K64F board and try to get the TinyUSB up and running.
It takes some time, but I could found the problem why it is not working at first.

In case of the K64 the USB clock will be set with e.g.

CLOCK_EnableUsbfs0Clock(kCLOCK_UsbSrcIrc48M, 48000000U);

This function will set inside some registers which are needed for the USB clock recovery:

if (kCLOCK_UsbSrcIrc48M == src)
{
    USB0->CLK_RECOVER_IRC_EN = 0x03U;
    USB0->CLK_RECOVER_CTRL |= USB_...
fallow birchBOT
#

Operating System

Others

Board

PIC0 RP2040

Firmware

https://github.com/hathach/tinyusb/tree/master/examples/host/bare_api

What happened ?

Invoking control transfer now has issue with mounting hub with multiple devices attached. Only one device will invoke mount callback. We need to remove the hub, remove all device from it. Then plug the hub without device and connect the devices one by one.

Do you still plan to fix this issue as stated in the tiny usb host bare examp...

fallow birchBOT
#
[hathach/tinyusb] New branch created: cmake-4088
#

I use a USB setup with multiple USB hubs. I have a laptop where a screen is connected via USB-C and that has a built-in hub. A USB switch is connected to that, to that there is an active USB hub connected because the switch don't have enough ports and and can't provide enough power.

With that setup I noticed that my Wooting sometimes remains lit after I unplug the screen from the laptop. So I checked out the TinyUSB example and was able to reproduce the issue on a GD32 dev kit which uses t...

fallow birchBOT
fallow birchBOT
#
[hathach/tinyusb] New branch created: imxrt-dcache-align
fallow birchBOT
#

Operating System

Others

Board

Renesas RA

Firmware

custom firmware, Host, MSC , no OS , one device.

What happened ?

The system is becoming unresponsive or freezes the application (stuck in tuh_task). I am assuming the immature removing of the USB stick is causing this, however, I will say maybe there is a better way

How to reproduce ?

You must run into a situation where you write or read to the USB stick and then unplug it during the operation. Also during the enu...

robust walrus
fallow birchBOT
#

Hi @hathach , sorry for disappearing but other releases + some vacation made my response running a bit late :slightly_smiling_face:
I'm answering in line with the issues you raised; some of them were workarounds for peculiar behaviours we experienced and might not be needed after all. We are willing to adopt your rebased branch and continue development there while testing for regressions on our side.
In particular, usb host enumeration was problematic and lead to most of them, but probably...

#

You are right, that hardcoded value is very strange; I asked a colleague and it was introduced to fix mass storage emulation by copying it from fsp sources (where it was hardcoded at the time but since I can't find it anymore probably Renesas could have fixed the surrounding code :slightly_smiling_face: )
To test if it doesn't regress we could use some of the MSC examples in the arduino core

fallow birchBOT
fallow birchBOT
#

Operating System

Linux

Board

rpi2

Firmware

custom https://github.com/librerpi/lk-overlay/tree/master/platform/bcm28xx/dwc2 + https://github.com/librerpi/lk-overlay/tree/master/lib/tinyusb

What happened ?

TU_ASSERT(total_len <= CFG_TUH_ENUMERATION_BUFSIZE, );
during enumeration, tinyusb will check if a config descriptor fits into the available buffer space
a usb webcam has a config descriptor over 1024 bytes, but the buffer is only 512 bytes

due to this assert, ti...

fallow birchBOT
#

The issue is triggered on my system by USB switch which is in-between the host and the active USB hub.
The hub shuts all its ports down if it's up facing port isn't active but the switch provides the idling J state to it's down facing ports even if the selected host isn't present. Every time the host is toggled on the switch the UFP are reset and then J state of the plugged in device is present again.

To be clear, this setup only revealed the reset issue and shows that TinyUSB don't seem...

fallow birchBOT
jolly scroll
#

@robust walrus ive also got enumeration of HS devices and int endpoints stable

i can plug/unplug a HS device repeatedly, and it enumerates each time

#

but if i connect a LS device, the lack of split transactions causes failures, and a lack of cleanup causes it to run out of channels and the whole stack crashes

robust walrus
#

interesting! so thats due to the high speed hub in the middle?

jolly scroll
#

so the dwc is always operating in HS mode (enless you force it to FS only)

#

so i would have to cripple the entire bus, to avoid split transactions

robust walrus
#

I wonder how that impacts imx hs

jolly scroll
#

imx?

robust walrus
#

imx rt 10xxx

jolly scroll
#

another mcu/board?

#

i also need to figure out the whole init sequence

#

because i'm cheating, and relying on the closed firmware

#

if i run the PHY init i already have, it just breaks entirely

robust walrus
#

yup, mcu

#

@jolly scroll do you know anything about ehci qhd/qtd?

jolly scroll
#

nope

robust walrus
#

kk

jolly scroll
#

just a bit about xhci

fallow birchBOT
#

This is still happening for me. The drive is labeled DT101 G2 16GB. Here is a screenshot of the beagle capture:
image

The OUT transactions to EP 02 are failing but CP is continuing. The IN transactions to EP 81 also fail and when they do, TinyUSB is finding the EP 02 failures a second time. The overlay isn't reset out of the failure state when the error is handled. I think there needs to be a check th...

fallow birchBOT
fallow birchBOT
#
  • Looks like there must be a note that the fall through is wanted. Not sure if [[fallthrough]], /* FALLTHROUGH */ or may __attribute__((__fallthrough__)) does the trick.

you should use TU_ATTR_FALLTHROUGH; like https://github.com/hathach/tinyusb/blob/master/src/host/usbh.c#L664

  • I cross checked the signal state (SE0) via a USB power tester (AVHzY CT3+).
  • The problem to reproduce the issue is likely to trigger a reset without an enumeration attempt afterwards. It should ...
jolly scroll
#

reading some more, in slave mode (no dma), the high-speed ping protocol isnt very automated (likely due to low fifo space)

#

software has to manually send ping's, wait for a good reply, then send the true OUT data

#

but if in dma mode, you can queue up the data, and enable the ping protocol

#

and the dwc will ping the endpoint until it gets an ack, then fill its own fifo with dma and move the data

fallow birchBOT
#
[hathach/tinyusb] New branch created: enhance-ehci
fallow birchBOT
#

Describe the PR

  • Fix issue with hub status_change is not aligned
  • EHCI use standard USB complete interrupt instead of custom chipidea async/period interrupt to be more compatible with other ehci implementation
  • refactor usb complete & error isr processing, merge, update. Should probably fix #2166 . @tannewt please try it out when you have time.
fallow birchBOT
fallow birchBOT
fallow birchBOT
#

Huh? I don't get why this matters. Sounds ridicules to me to use:

That's definitely is not non-sense

I don't get why a compiler should throw a warning here, the order shouldn't be defined by C either and the compiler is free to reorder instructions anyway. The order which register is read first here also don't matter.

The order of register access is important in some cases, register read has side effects such as clear/set bits.

![image](https://github.com/hathach/tinyusb/a...

fallow birchBOT
fallow birchBOT
fallow birchBOT
#

@hathach
As a warming, Wooting sent me a dev build with the changes of this PR for testing. So far I was only able to test it on a dev board. It seems I now that device get stuck in sleep every time I disconnect my host. This behavior depends on the MCU specific implementation. For the GD32 this should be addressed by the optimizations in the PR #2178. So it can be that fixing the bug causes the same issue for other MCUs as well which likely don't have the Start of Frame fallback to leave t...

fallow birchBOT
#

I think this is needed to write the detach values back to RAM:

// Remove an attached TD from queue head
static void qhd_remove_qtd(ehci_qhd_t *qhd) {
  ehci_qtd_t * volatile qtd = qhd->attached_qtd;

  qhd->attached_qtd = NULL;
  qhd->attached_buffer = 0;
  hcd_dcache_clean(qhd, sizeof(ehci_qhd_t));

  qtd->used = 0; // free QTD
  hcd_dcache_clean(qtd, sizeof(ehci_qtd_t));
}
fallow birchBOT
fallow birchBOT
fallow birchBOT
#

Hi hathach, ive added in the SOF callback to the HID driver specifically for fast mouse response and minimum latency.

I've put it here since I would like to use tinyUSB to follow the current fastest open-source mouse firmware on the market (after razer)

https://github.com/zaunkoenig-firmware/m2k-firmware/blob/main/mouse/Src/main.c

you can see here they wait for a SOF interrupt before starting the routine and getting data from the sensor/buttons then send it out. Since there is only ...

fallow birchBOT
#
[hathach/tinyusb] New branch created: correct-hcd_edpt_clear_stall-API
#

I don't see the reason to add sof callback to hid driver ? Could you explain why this is needed.

I'll chime in, as I've worked on high performance firmware for input devices before. I do see usefulness in a SOF interrupt, we can use it to assemble the HID packets at the very last second to minimize latency (Yes it is a very small latency gain, but the latency is there nonetheless), that said the vast majority of use cases will not need this so I think it might make sense to gate it behin...

fallow birchBOT
#

I think this is needed to write the detach values back to RAM:

It may not be needed, since these are all software only field for managing driver accessed by CPU only. EHCI controller does know/need to access these values at all. Let me know ifthis PR help with your issue

They are software only but you invalidate the cache for QHD and QTD because there is data on the same cache line that the EHCI controller needs. That drops any values written to the cache but not RAM. So, you ...

low kindle
#

Hey guys. I am using adafruit TinyUSB along with fastled. When I am using argb 10 outputs, I do not get any flickering. However, if I add two more outputs which totals out to 12 outputs, I get issues. Interestingly enough this issue is only on the first led on the first pin

#

For context, I am using rp2040 with 6 20 led strips and 6 27 led strips.

jolly scroll
#
    bInterfaceClass: 8
    bInterfaceSubClass: 6
    bInterfaceProtocol: 80
    iInterface: 0
    endpoint 0
      bLength: 7
      bDescriptorType: 5
      bEndpointAddress: 0x81
      bmAttributes: 2
      wMaxPacketSize: 512
      bInterval: 255
    endpoint 1
      bLength: 7
      bDescriptorType: 5
      bEndpointAddress: 0x2
      bmAttributes: 2
      wMaxPacketSize: 512
      bInterval: 255
#

i flipped on the MSC/MSD driver in tinyusb, and then things promptly crashed

#

i forgot to implement OUT transfers with a non-zero packet size, lol

#

49.274193 [DWC2:hcd_edpt_xfer:382]: HOST0 -> 2.02 0xc4014cec/31 opep:0xc4113bcc

#

tinyusb tries to do a 31 byte transfer to EP2

jolly scroll
#
SCSI Test Unit Ready
 36.811522 [DWC2:hcd_edpt_xfer:384]:    HOST0  ->   2.02 0xc4015b0c/31 opep:0xc411490c
MSC xfer callback
 36.879207 [DWC2:hcd_edpt_xfer:377]:    HOST0  <-   2.81 0xc4015b2c/13 opep:0xc41148c8 type:2 pid:153
    NAK
 37.910083 [DWC2:dwc_in_retry:402]:     HOST0  <-   2.81 0xc4015b2c/13 type:2 pid:153 opep:0xc41148c8 RETRY
    NAK
#
 37.875216 [DWC2:hcd_edpt_xfer:384]:    HOST0  ->   2.02 0xc4015b0c/31 opep:0xc411490c
0x43425355
0x54555342
0x0
0x60000
0x0
0x0
0x0
0x0
#

the 31 bytes send OUT, before it hung

#

0x43425355, the MSD signature
0x54555342, a tag on the request?
0x0, transfer size?
0x60000, flags=0, CDB length=6

#

LUN 0, command 0(test unit ready)

#

looks valid

#

cbw->tag = 0x54555342; // TUSB

#

yep, that looks all right

jolly scroll
#

same NAK issue on a 2nd drive

fallow birchBOT
#

an added complication to beware of

the vl805 pcie<->usb3 controller, normally has its own firmware in dedicated SPI flash, and once you configure the xhci scratch space, it will (ab)use the scratch space like swap, to store its own firmware/state

but RPF later found a way to save costs, if that SPI chip is omitted, thats 1 less part on the board

the 0x00030058/RPI_FIRMWARE_NOTIFY_XHCI_RESET mailbox call must be sent from the arm kernel to the VPU firmware, i think any time the pcie b...

fallow birchBOT
fallow birchBOT
#

Operating System

Windows 11

Board

Raspberry Pi Pico

Firmware

uint8_t msg[2]={ 0x0A, // Pan MSB
0x60, // value 60
}
tud_midi_n_stream_write(0, 0, msg, 2);

What happened ?

This results in Reaper seeing a Pan MSB Value 0x00 followed by a Data Button Inc (96) message.

I suspect there is a problem in tud_midi_n_stream_write.

How to reproduce ?

as above.

I cannot find an example with a Control Change message. Program Change works, as do note on/off etc.
...

fallow birchBOT
#

Describe the PR
Host Library:
The unplugging process of the USB device might lead to an infinite loop. It is easy to run into this situation if unplugging occurs during the enumeration process. Also, it happens when unplugging while the host and the USB device are doing something.

The issue is really big. As the stack enters an infinite loop when this is happening.

Additional context
I am testing with the RA4M2 family, with no OS. I know this fix is not meant if you are host...

fallow birchBOT
jolly scroll
#
/* Submitted by Ren Bigcren <bigcren.ren@sonymobile.com> */
UNUSUAL_DEV(  0x054c, 0x02a5, 0x0100, 0x0100,
        "Sony Corp.",
        "MicroVault Flash Drive",
        USB_SC_DEVICE, USB_PR_DEVICE, NULL,
        US_FL_NO_READ_CAPACITY_16 ),

ack!

robust walrus
jolly scroll
#

but i notice, the PID differs, so i have a different problem

robust walrus
#

👍

jolly scroll
#

asking on another discord server, if i had sent an invalid scsi command, it would have reported STALL

#

NAK implies the command was valid, and the device just isnt ready yet

#

but its never ready, and stays in that state

fallow birchBOT
jolly scroll
#

after fiddling with the dwc core reset bit, and banging my head into interrupt problems, i now have dwc enumerating with just a custom bootcode.bin and nothing else

#

all closed-source blobs that could have been helping me, are out of the picture

jolly scroll
#

@robust walrus something i should get your help with later on
i can give you an rpi binary, and you can snoop what it does to an MSD with the 480, just to double-check if its doing what i we expect it to

jolly scroll
#

@robust walrus whenever your free, drop this onto a (u)SD card, and boot it on a pi0/pi1/pi2/pi3/pi02

it will print a bunch of debug on both the uart (115200) and the composite/ntsc output

when it hits the end, it will have printed the usb descriptors for the usb-nic, if present

then plug in a MSD device with the 480, and see what the capture caught

#

ive done most of my debug on a pi2, and confirmed it also works on a pi1, so the whole model range should work

robust walrus
#

I don't have the time for that unfortunately

jolly scroll
#

@robust walrus about your circuitpython pio/usb stuff
are the only changes youve done for debug? where you working from the main branch from github?

jolly scroll
#

ive got a pico and a cut up usb extension, so i'm considering wiring the pio-usb up

jolly scroll
#

ah, and some more good news

#

i put the above bootcode.bin onto my usb stick, and OTG'd it into a zero2 (rom is host capable)

#
SCSI Test Unit Ready
  Queue EP 02 with 31 bytes ... 
0x43425355
0x54555342
0x0
0x60000
0x0
0x0
0x0
0x0
OK
on EP 02 with 31 bytes: OK
MSC xfer callback
  Queue EP 81 with 13 bytes ... 
OK
#

it enumerates and hangs at the same place

#

so the hub isnt to blame, and i can take over after the rom used dwc

#

16.239077 [DWC2:dwc_check_interrupt:571]: port enabled at FS

#

if i plug a pico in BOOTSEL mode in, i get this

#

and enumeration proceeds all the way down to failing at the same place

robust walrus
jolly scroll
#

so, if i connect my severed usb cable to the right pins, and build it, it should just work?

robust walrus
#

I fixed one issue with checking that host is active when looking for devices but that shouldn't be related

jolly scroll
#

as much as it worked for you?

robust walrus
#

I added host usb init to board_init

#

you can copy that code from the usb_host feather

#

and I uncommented the console uart config too

jolly scroll
#

whats the main command, to build circuitpython for the rp2040?

#

looks like no cmake

robust walrus
#

make -j 16 BOARD=<board name>

jolly scroll
#

pico, i assume?

robust walrus
#

same as the folder name inside the board/ dir

jolly scroll
#
[clever@amd-nixos:~/apps/rpi/circuitpython]$ ls board
ls: cannot access 'board': No such file or directory
#

ah, found em

ports/raspberrypi/boards/sparkfun_pro_micro_rp2040
ports/raspberrypi/boards/raspberry_pi_pico
#

ive got both of those

#

waiting on my cross-compiler to build now

#

i just had a crazy idea
you mentioned on stream, having co-processors attached over i2c

what if you ran circuitpython on the VPU, and then used the 4 arm cores as a co-processor, as the design originally intended! lol

jolly scroll
#
[nix-shell:~/apps/rpi/circuitpython/ports/raspberrypi]$ make -j 16 BOARD=raspberry_pi_pico
Use make V=1, make V=2 or set BUILD_VERBOSE similarly in your environment to increase build verbosity.
make: *** No rule to make target 'lib/PicoDVI/software/libdvi/dvi.c', needed by 'build-raspberry_pi_pico/genhdr/qstr.split'.  Stop.
#

seems i'm still missing some submodules, despite init'ing them all

#

fixed that

#
[nix-shell:~/apps/rpi/circuitpython/ports/raspberrypi]$ make -j 16 BOARD=raspberry_pi_pico
Use make V=1, make V=2 or set BUILD_VERBOSE similarly in your environment to increase build verbosity.
Traceback (most recent call last):
  File "../../py/maketranslationdata.py", line 30, in <module>
    import huffman
ModuleNotFoundError: No module named 'huffman'
#

python isnt playing nicely, even after installing everything, its missing things

fallow birchBOT
glacial stratus
fallow birchBOT
#

Related area

Currently I maintain my own branch of TinyUSB with an XInput driver implemented. It would be really nice if I could simply define these within my application though.

Hardware specification

rp2040

Is your feature request related to a problem?

Rather than having to maintain a unique branch of TinyUSB with my XInput driver, it would be really nice to have a mechanism to add it through the config within my application. I dug around but there doesnt seem to be a way t...

jolly scroll
fallow birchBOT
#

the general solution i see in other projects, is some linker trickery

basically, every driver that defines a struct usbh_class_driver_t object, has to put it into a special section with __attribute__ ((section(".data.usb_class_drivers")))

the linker script will then put all of those objects into one block of memory, and generate start/end symbols

usbh.c can then convert that back into the old style array
the major benefit of this method, is that you dont need to #ifdef every...

glacial stratus
jolly scroll
#
Changes not staged for commit:
  (use "git add <file>..." to update what will be committed)
  (use "git restore <file>..." to discard changes in working directory)
  (commit or discard the untracked or modified content in submodules)
        modified:   ../espressif/esp-idf (modified content)
        modified:   ../espressif/esp32-camera (modified content)
        modified:   ../silabs/tools/slc_cli_linux (modified content)
        modified:   ../stm/st_driver/stm32f4xx_hal_driver (modified content)
        modified:   ../../shared-module/displayio/Bitmap.c
#

and interrupting the submodule thing to kill that firmware repo, caused several dirs to be "modified" and empty

#

have to deinit and init each to fix em

#

huffman was one of those

jolly scroll
#

going backwards some, to add dma support

#
 17.335374 [DWC2:hcd_setup_send:372]:   HOST0 SETUP 0.00 0xc4015190/8 opep:0xc4114300
dumping channel 0
  HCCHAR0: 0x100008
    mps:8 ep:0 dir0 type:0 mc:1 addr:0
  HCSPLT0: 0x0
  HCINT0: 0x0
  HCINTMSK0: 0x7ff
  HCTSIZ0: 0x20000008
    size:8 packets:0 pid:1 ping:0
  HCDMA0: 0xc4015198
#

dma has advanced by 9 bytes

#

packets is 0, but bytes is still 8

#

but i had programmed it for 8 bytes and 1 packet

#
dumping channel 0
  HCCHAR0: 0x100008
    mps:8 ep:0 dir0 type:0 mc:1 addr:0
  HCSPLT0: 0x0
  HCINT0: 0x0
  HCINTMSK0: 0x7ff
  HCTSIZ0: 0x60080008
    size:8 packets:1 pid:3 ping:0
  HCDMA0: 0xc4015190

vs

dumping channel 0
  HCCHAR0: 0x100008
    mps:8 ep:0 dir0 type:0 mc:1 addr:0
  HCSPLT0: 0x0
  HCINT0: 0x0
  HCINTMSK0: 0x7ff
  HCTSIZ0: 0x20000008
    size:8 packets:0 pid:1 ping:0
  HCDMA0: 0xc4015198
#

before and after the enable flag

#

PID went from SETUP to DATA2, likely to prepare for the next packet
packets 1->0, implying it transmitted one
dma went up by 8, implying it read some

#

ah, an irq is firing, but its not proceeding to the next stage right

#
  HCINT0: 0x23
    xfer complete
    halted
    ack
#

yep, perfect, so why did my code not do the right thing

#

ah, my big else-if block

#

the halted irq has priority, and does nothing, and blocks all others

#

ok, SETUP appears to complete
tinyusb then does an 8-byte IN...

#

it would help if i set the dma dest, lol

#

and same as before, the interrupts firing differ, so i need to handle that

#

dma seems implemented, and enumeration works once more

#
  Queue EP 81 with 1 bytes ... 
 20.461786 [DWC2:hcd_edpt_xfer:393]:    HOST0  <-   5.81 0xc4015c3b/1 opep:0xc4114784 type:3 pid:0
  Hub Status Change = 0x02
HUB Get Port Status: addr = 5 port = 1

the hub reported a change on a port...

#
Device configured
  Queue EP C1 with 1 bytes ... 
 24.332040 [DWC2:hcd_edpt_xfer:393]:    HOST0  <-   5.c1 0xc4015c3b/1 opep:0xc4114784 type:3 pid:0
#

and then config was done, so it grabbed an invalid endpoint and resumed querying!!

#

ah, i think i see the problem

#
 43 typedef struct
 44 {
 45   uint8_t itf_num;
 46   uint8_t ep_in;
 47   uint8_t port_count;
 48   uint8_t status_change; // data from status change interrupt endpoint
 49 
 50   CFG_TUH_MEM_ALIGN hub_port_status_response_t port_status;
 51   CFG_TUH_MEM_ALIGN hub_status_response_t hub_status;
 52 } hub_interface_t;
#

its doing a dma write, directly into line 48

#

it might round down, to the next 32bit

#

so, dma splats all over lines 45-48

#

@robust walrus now what?

jolly scroll
jolly scroll
#

on EP 00 with 1431655765 bytes: OK

#

overflow time! 😄

#
> (1431655765).toString(16)
'55555555'
#

oh, not even overflow, just undefined

#

fixed

jolly scroll
#
Device found: type = Mass storage, addr = 6
Trying booting from MSD device addr 6
Retrieving the config descriptor
Found ep_in = 00000001, ep_out = 00000002
GetMaxLun returned 0, max_lun = 0
Sending and retrying TEST_UNIT_READY
Sending SCSI_COMMAND_INQUIRY
Sending READ_CAPACITY
init_msd returned 0
#

oh, and i found this in the firmware logs

jolly scroll
#

confirmed why interrupt endpoints are broken

#

in PIO mode, each IN turns up in the rx-fifo, and thats where i toggle the PID

#

in DMA mode, the rx-fifo is dead-silent

fallow birchBOT
#

https://github.com/littlekernel/lk/blob/30dc320054f70910e1c1ee40a6948ee99672acec/platform/pc/lapic.c#L59
https://github.com/littlekernel/lk/blob/master/top/include/lk/init.h#L72

/*
 * Copyright (c) 2013 Travis Geiselbrecht
 *
 * Use of this source code is governed by a MIT-style
 * license that can be found in the LICENSE file or at
 * https://opensource.org/licenses/MIT
 */
#define LK_INIT_HOOK_FLAGS(_name, _hook, _level, _flags) \
    const struct lk_init_struct _init_struct...
fallow birchBOT
fallow birchBOT
#

Related area

DMA

Hardware specification

synopsys dwc2

Is your feature request related to a problem?

How can tinyusb support dma features when its operation seems to be all fifo based? It is recommended to add the implementation of dma to improve the transfer rate of usb

Describe the solution you'd like

It's difficult when I want to use the dma function with the tinyusb.I hope tinyusb can support dma feature.And I would be happy to port synopsys's dma to tinyusb.

I ...

fallow birchBOT
fallow birchBOT
frosty abyss
#

Is tinyusb supported on UART programmers, such as CP2102?

fallow birchBOT
#

Describe the PR

Supersede #2052 (once this Pr is merged, the other will be marked as merged as well). Thank you @facchinm for original PR to add support for renesas highspeed USB. This PR rebased, merged with latest changes also add following changes to renesas port

  • better multiple ports support, the port and speed support is dynamic instead of depending on CFG_TUSB_RHPORT0/1_MODE. This make otg support and switching role support easier in the future.
  • move module start to part of...
fallow birchBOT
#

Sure thing! I'm testing it right now inside the core with our test suite 🙂 A couple of things I already spotted: UNO R4 Minima doesn't work because the internal LDO must be enabled via

#define USB_VDCEN 0x80
RUSB2->USBMC = (uint16_t) (RUSB2->USBMC | (USB_VDCEN));

I agree that this in not to be part of the actual driver but a configuration at board level, so we'll add the call in the core

oh really, let me test it out, maybe there is an BSP macro that give o...

fallow birchBOT
#

This is no longer working for MicroPython/RA6M5 (the device just doesn't enumerate) is the following config still valid ?

CFLAGS += -DCFG_TUH_RHPORT=0 \
          -DCFG_TUD_RHPORT=1 \
          -DCFG_TUH_MAX_SPEED=OPT_MODE_FULL_SPEED \
          -DCFG_TUD_MAX_SPEED=OPT_MODE_HIGH_SPEED \
          -DCFG_TUSB_RHPORT0_MODE=0\
          -DCFG_TUSB_RHPORT1_MODE=OPT_MODE_DEVICE

Let me pull out the https://github.com/micropython/micropython/pull/11405 to test...

fallow birchBOT
#

one area ive seen makes the fifo/dma stuff a bit more obvious, in dwc host mode

the high-speed ping protocol is manual when in non-dma mode
so you dont write to the fifo, you just enable sending pings
and when the ping gets an ACK, then you write to the fifo, and send the actual OUT

but in dma mode, you configure the DMA addr and enable pinging
it will ping, but not do dma
once it gets an ACK from the device, it will fill its own FIFO with DMA, and then perform the OUT

so at the ...

fallow birchBOT
#

Related area

HITL test

Hardware specification

DCD only for the moment

Is your feature request related to a problem?

I'm going to add more boards into the loop, currently planned:

  • LPCXpresso LPC54608 OM13092 (HS port)
  • STM32F746DISCO (both HS & FS port)
  • NUCLEO-L412KB (like now)

Meanwhile maybe a good idea to wait #1970 to avoid mixing boards.

I'm also open to sponsorship if anyone wants other boards to be added.

PS: Made a tiny hub as I can't find one :)
![I...

fallow birchBOT
#

Dual host would be nice, but that can be solved using a standard hub.

but that wont cover a case like the rpi4(00), where it has 2 host controllers, routed to different places

there is the pcie/vl805/xhci controller, going to the main 4 usb-a ports
and there is either dwc or xhci, going to the usb-c port

if you limit yourself to one xhci controller, you have to choose which physical ports work
if you limit yourself to an xhci driver that can handle 2 controllers, you cant use dev...

robust walrus
#

@jolly scroll I'm back now (was weekending)

jolly scroll
#

ah, wb

#

@robust walrus after enabling dma, i had a range of new problems, mostly fixed

  • status_change in the hub state was not aligned, so a 32bit write trashed the hub state, fixed
  • interrupts fire in a totally different order, and my handler stopped calling complete callbacks in tinyusb
  • my code for IN DATA0/DATA1 toggling relies on the rx-fifo, but DMA just bypasses the rx-fifo entirely, so i have to replace that
#

also, while reading tinyusb tickets, i had a theory for why MSD is broken

#

somebody mentioned a 16bit fifo, and the 31 byte commands, and how the final byte isnt written right

#

and with my 32bit fifo, the same thing might be happening

#

but with dma, i would expect the hw to deal with that for me

robust walrus
#

my next step was to use the saleae to sniff the bus

jolly scroll
#

i also had an idea, on how to better test your PIO usb stack, just take tinyusb out of the picture temporarily

#

keep the hcd, but disable tinyusb itself

then manually call something like hcd_setup_send()
verify it sent the right packet on the beagle480
verify the remote rp2040 received the packet

then move to hcd_edpt_xfer() and test IN and OUT the same way

#

if all 3 functions work in isolation, they should also work together

#

and test edge cases, like one byte above/below max-packet-size

#

i can see how you might even tie that into python

robust walrus
#

I'm not sure I have the patience to get that working in isolation. good idea though

jolly scroll
#

just dont link tinyusb

provide FFI code in python, to call hcd_setup_send() and hcd_edpt_xfer(), and make hcd_event_xfer_complete() run a python function

#

with just those ~3 bits, you can then implement the usb stack in python

#

but rather then implement a proper one, just call them with chunks of hex, from your existing REPL

#

it could be a good debug tool, for any future usb-host work, on any platform

#

next thing on my todo list, is to try and fix DATA0/DATA1 toggling, then maybe i'll take another stab at getting circuitpython to build

#
 19.216291 [DWC2:hcd_edpt_xfer:393]: ->>HOST0  <-   5.81 0xc4015e3c/1 opep:0xc4114988 type:3 pid:0
 19.224187 [DWC2:dwc_check_interrupt:626]: bytes 0, buflen 1
 19.229561 [DWC2:dwc_check_interrupt:627]: hcd_event_xfer_complete(5, 0x81, 1, success, true)
fallow birchBOT
#

Operating System

Linux

Board

RP2040 Pico

Firmware

examples/host/cdc_msc_hid/src

With tusb_config.h:
#define CFG_TUH_HUB 2 // number of supported hubs

Compiled with
cmake -DFAMILY=rp2040 .. -DPICO_SDK_FETCH_FROM_GIT=1 -DLOGGER=RTT -DCMAKE_BUILD_TYPE=Debug

What happened ?

Output on RTT:
assertion "!ep->active" failed: file "/home/andre/GIT/tinyusb/src/portable/raspberrypi/rp2040/hcd_rp2040.c", line 602, function: hcd_setup_send

How to ...

jolly scroll
#

so currently, i start with a DATA0 expected, for the hub interrupt

#

22.379937 [DWC2:hcd_edpt_xfer:393]: HOST0 <- 5.81 0xc4015e3c/1 opep:0xc4114988 type:3 pid:0

#

then i expect a DATA0 again, on the next read! ❌

#

and because the hub responds with NAK, that doesnt fail asap

#
]  26.309054 [DWC2:dwc_check_interrupt:634]: HOST0 data toggle error
 26.313477 [DWC2:dwc_irq:702]: irq time: 4423
#

but upon inserting another device, it responds with DATA1, and fails

#

oh.....

#

i just realized, i'm entirely ignoring the toggling for OUT's

#

what happens if my MSD host sends the wrong DATAn for an OUT?

#

that might be my problem!

fallow birchBOT
robust walrus
#

¯_(ツ)_/¯

jolly scroll
#

i can see 3 ways to confirm that
1: just implement it right (logs would show i'm doing the wrong thing)
2: beagle480
3: rp2040 msd, and it should have its own data-toggle exception

#
ST_CLO: 91245210
Fatal VPU Exception: Zero
VPU registers:
     r0: 0x00000001  r1: 0x2000000a  r2: 0x2000000a  r3: 0xc71fff74
     r4: 0xb9c00000  r5: 0xfa000000  r6: 0xc401558c  r7: 0xc0080000
     r8: 0x00000300  r9: 0x00000001 r10: 0x8000cb60 r11: 0xc0100000
    r12: 0x8000cbc0 r13: 0x00c00000 r14: 0xc0020000 r15: 0x00000080
     pc: 0xc40025b6  lr: 0xc40025b6  sr: 0x60000000
Exception info (IC0):
   src0: 0x00000200 src1: 0x00000000 vaddr: 0x00000000
      C: 0x00000000    S: 0x07490740
Exception info (IC1):
   src0: 0x00000201 src1: 0x00000000 vaddr: 0x00000000
      C: 0x00000000    S: 0x00000000
dump_thread: t 0xc401558c (idle)
        state run, priority 0, remaining quantum 5
        stack 0x0, stack_size 0, stack_used 0
        entry 0x0, arg 0x0, flags 0x11
        wait queue 0x0, wait queue ret 0
We are hanging here ...
#

ive also noticed, this is firing randomly

#

PC is pointing to the middle of an infinite loop, that just calls arch_idle()
which just calls sleep and returns

#

i doubt this is a cpu exception, this hw has system and cpu exceptions mixed into the same table

#

i'll just ignore that for now, and finish the IN toggling

robust walrus
#

you may get more insight if you have a tinyusb device with logging on

jolly scroll
#

yeah

#

but i lack split transaction support, so i cant talk to a rp2040 on the pi2

#

and the pi0 cant network boot, so i have to swap an SD card on every compile

robust walrus
#

ah, you need split to do full speed from a high speed hub?

jolly scroll
#

yep

robust walrus
#

👍

jolly scroll
#

but, i suppose i could cheat

#

i can disable HS in the dwc

#

then the hub runs at FS

#

just to iron out the bugs, i'll disable MSC first
then see what it looks like, if i (un)plug devices repeatedly

#
 20.891483 [DWC2:hcd_edpt_xfer:394]:    HOST0  <-   5.81 0xc401301c/1 opep:0xc41119b0 type:3 pid:0
 20.926699 [DWC2:dwc_check_interrupt:629]: hcd_event_xfer_complete(5, 0x81, 1, success, true)
#

so we have a DATA0 on the int

#
 24.336893 [DWC2:hcd_edpt_xfer:394]:    HOST0  <-   5.81 0xc401301c/1 opep:0xc41119b0 type:3 pid:2
#

the ethernet has enumerated, so it waits for a DATA1 on the int

#
 59.510570 [DWC2:dwc_check_interrupt:628]: bytes 0, buflen 1, packets: 1, old next_pid: 2
 59.518463 [DWC2:dwc_check_interrupt:629]: hcd_event_xfer_complete(5, 0x81, 1, success, true)
#

and then it gets one

#
 61.627101 [DWC2:hcd_edpt_open:325]: dev 0 EP00 opened root port: 0 hub_addr: 5 hub_port: 2 speed: 2(HS) opep: 0xc4111a88
      bLength: 7
      bDescriptorType: 5
      bEndpointAddress: 0x0
      bmAttributes: 0
      wMaxPacketSize: 8
      bInterval: 0
Get 8 byte of Device Descriptor
[0:0] Get Descriptor: 80 06 00 01 00 00 08 00 
on EP 00 with 0 bytes: OK
panic (caller 0xc4002e6e): timer 0xc4111a98 already in list
PM_WDOG: 0x7e100024
HALT: spinning forever... (reason = 9)
#

but then it panic's trying to open the MSC

#

for plain enumeration

jolly scroll
#

@robust walrus figured out the latest bug

in PIO mode, NAK kills the transaction, i was having to reset the channel, and retry on a timer

IN DMA mode, NAK isnt fatal, and it retries on its own!

jolly scroll
#
 27.470447 [DWC2:hcd_edpt_open:326]: dev 2 EP02 opened root port: 0 hub_addr: 5 hub_port: 3 speed: 2(HS) opep: 0xc4114d50
SCSI Test Unit Ready
 28.209798 [DWC2:hcd_edpt_xfer:403]:    HOST0  ->   2.02 0xc4016118/31 opep:0xc4114d50 type:2
 28.259239 [DWC2:dwc_check_interrupt:635]: bytes 31, buflen 31, packets: -1717986919, old next_pid: 153
 28.268347 [DWC2:dwc_check_interrupt:636]: hcd_event_xfer_complete(2, 0x2, 0, success, true)
msch_xfer_cb 331: ASSERT FAILED
#

its incorrectly reporting that 0 bytes have been transfered

#

fixed that

#
 26.432308 [DWC2:hcd_edpt_open:326]: dev 2 EP81 opened root port: 0 hub_addr: 5 hub_port: 3 speed: 2(HS) opep: 0xc4114d08
 27.333284 [DWC2:hcd_edpt_xfer:396]:    HOST0  <-   2.81 0xc4016138/13 opep:0xc4114d08 type:2 pid:153
  HCTSIZ0: 0xd
    size:13 packets:0 pid:0 ping:0
acking 0x10 (nak)
jolly scroll
#

aha, my 31 byte OUT, was DATA1
even after i fixed the toggle tracking, the out function ignored it, was hard-coded!

#

changing it to DATA0, i now get a reply

jolly scroll
#

i think i did it

#
] bio list
block devices:
        usb2_0, size 4009754624, bsize 512, ref 1 (no erase geometry)
#

i think thats it

#
] bio dump usb2_0 0 512
0x00000100: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................
0x00000110: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................
0x00000120: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................
0x00000130: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................
0x00000140: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................
0x00000150: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................
0x00000160: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................
0x00000170: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................
0x00000180: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................
0x00000190: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................
0x000001a0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................
0x000001b0: 00 00 00 00 00 00 00 00 38 c1 43 18 00 00 00 21 |........8.C....!
0x000001c0: 03 00 0c 39 12 44 00 08 00 00 00 00 08 00 00 00 |...9.D..........
0x000001d0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................
0x000001e0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................
0x000001f0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 55 aa |..............U.
] 

that looks like an MBR!

#
[root@amd-nixos:~]# hexdump -C /dev/sdc --length 512
00000000  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
*
000001b0  00 00 00 00 00 00 00 00  38 c1 43 18 00 00 00 21  |........8.C....!|
000001c0  03 00 0c 39 12 44 00 08  00 00 00 00 08 00 00 00  |...9.D..........|
000001d0  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
*
000001f0  00 00 00 00 00 00 00 00  00 00 00 00 00 00 55 aa  |..............U.|
00000200
fallow birchBOT
#

So, I've searched through my project folder and also checked my backup of this project, but I couldn't find any symbol related to tinyusb. I also looked through the old commits of that project, but I only found that tinyusb was added as a submodule. However, my porting part for the MSC Host was not there. I believe it was probably in some branch which got deleted after the successful implementation of another library.

jolly scroll
#
bio list
block devices:
        usb2_0, size 4009754624, bsize 512, ref 2 (no erase geometry)

        usb2_0p0, size 268435456, bsize 512, ref 1 (no erase geometry)

] 
#

and primary MBR partitions are now supported

jolly scroll
#
  iManufacturer       1     acked 0x20
ASSERT FAILED at (platform/bcm28xx/dwc2/dwc2.c:690): 0

i have a blue MSD, that i think has a 0 byte manufacturer string

#

my HCD isnt properly handling a zero-length packet on get-string-descriptor

#
] bio list
block devices:
        usb2_0, size 4009754624, bsize 512, ref 2 (no erase geometry)

        usb2_0p0, size 268435456, bsize 512, ref 1 (no erase geometry)

        usb3_0, size 2002747392, bsize 512, ref 3 (no erase geometry)

        usb3_0p0, size 31457280, bsize 512, ref 1 (no erase geometry)

        usb3_0p1, size 1817088000, bsize 512, ref 1 (no erase geometry)
#

if i comment out fetching that, then things do work

fallow birchBOT
fallow birchBOT
fallow birchBOT
#

@iabdalkader just pull and tested, you need update to correctly pass rhport to interrupt handler (1 instead of 0). It previously works, since the device stack is fixed to either port0 or port1 with CFG_TUSB_RHPORT0/1_MODE, but this rebased update to get it work dynnamically.

void usbhs_interrupt_handler(void) {
    IRQn_Type irq = R_FSP_CurrentIrqGet();
    R_BSP_IrqStatusClear(irq);

    #if CFG_TUSB_RHPORT1_MODE & OPT_MODE_HOST
    tuh_int_handler(1);
    #endif

    #if CF...
fallow birchBOT
#

@abakosh unfortunately, I have to switch to other works and don't have the time to test/improve this now. This is added as part of #2052, arduino may need to to work with their board/setup. Merging this as it is wil allow them to have an working commit in upstream and easier to base their repo/release while waiting for a better solution. we will definitely need to change this, but with follow-up PRs.

#

@hathach Thanks for the insight, it now works again!

If you use tud_init(rhport) (initialize port as device) instead of tusb_init(void), you could actually remove CFG_TUSB_RHPORT0/1_MODE

Is there a way to know/query if a port is configured as host or device, if I use tud_init(rhport) and remove CFG_TUSB_RHPORTx_MODE ? Or a common irq handler that knows which mode the port is configured for and calls either tuh_int_handler or tud_int_handler ?

#

thank you, that is great to hear, I can implement #1970 soon enough, your current list of board is great, it already cover 3 different usb ips. I have an Pi4 with pico rp2040 running tests and plan to add more boards (since I have several devkit laying around), since these aren't computing heavy as compiling IAR :).

We will probably need to spend more time to write more actual hardware tesing script :) . Only tested cdc, msc, dfu so far. Haven't tried testing with audio.

PS: what's up ...

#

@hathach Thanks for the insight, it now works again!

If you use tud_init(rhport) (initialize port as device) instead of tusb_init(void), you could actually remove CFG_TUSB_RHPORT0/1_MODE

Is there a way to know/query if a port is configured as host or device, if I use tud_init(rhport) and remove CFG_TUSB_RHPORTx_MODE ? Or a common irq handler that knows which mode the port is configured for and calls either tuh_int_handler or tud_int_handler ?

tud_init(rhport) ...

#

@hathach I spotted one issue in the dynamic IRQ handling; since rusb2_controller_t rusb2_controller[] is static in a .h you get a different copy every time and tud_rusb2_set_irqnum() doesn't really work for multiple ports. Where should I put the fix? The WIP core branch is https://github.com/facchinm/ArduinoCore-renesas/pull/new/tinyusb_mainline

ah, you are right, hcd and dcd will have different copies of the controllers. I think we shoud add an common rusb2_common.c like rp2040 sin...

fallow birchBOT
#

@facchinm I just realized we are doing the same thing in different PR :smile: . I merged your commits from 2052, but also add some additional changes:

  • rename new file to rusb2_common.c since it maybe handy for other port. We will probably move some common code (pipe write/read) to this file as well
  • rename tud_rub2_set_irqnum to tusb_() since this function is called for both host and devie stack (sorry for more renaming)
  • add `#if defined(TUP_USBIP_RUSB2) && (CFG_TUH_ENABLED || CFG_TU...
fallow birchBOT
fallow birchBOT
fallow birchBOT
#

Describe the PR
Fix complaining of missing HAL PWR & DMA source file.

/Src/stm32g0xx_hal_rcc_ex.o: in function `??HAL_RCCEx_DisableLSCO_1':
/home/tusb/tinyusb/hw/mcu/st/stm32g0xx_hal_driver/Src/stm32g0xx_hal_rcc_ex.c:(.text+0xb2e): undefined reference to `HAL_PWR_DisableBkUpAccess'
/opt/arm-none-eabi-gcc/arm-gnu-toolchain-11.3.rel1-x86_64-arm-none-eabi/bin/../lib/gcc/arm-none-eabi/11.3.1/../../../../arm-none-eabi/bin/ld: _build/stm32g0b1nucleo/obj/hw/mcu/st/stm32g0xx_hal_driver...
fallow birchBOT
#

I've desperately tried several solutions to achieve sleep/ wake HID function but none work. I found out that I could use TinyUSB to make an RP2040 into HID USB device. I installed Adafruit TinyUSB. I selected TinyUSB under Tools > USB Stack. I ran verify/ compile and started to get a bunch of missing library file errors. I tried to manually copy and paste missing libraries to no avail. What do I need to do to get this to work?

In file included from C:\Users\null\AppData\Local\Arduino...
fallow birchBOT
#

I resolved my issue by getting the right kind of board for the task! I purchased a micro-Leonardo clone (32u4 controller) and it worked right out of the gate with Nicohoods HID-Project library! You need a microcontroller that supports USB HID protocol natively. Most boards communicate using SERIAL via USB which is not the same thing. TinyUSB is a bit of a hack, and as you can see, requires too much effort to perform a simple (SLEEP/ WAKE) function! I'd also like to add that worse than adafrui...

fallow birchBOT
fallow birchBOT
jolly scroll
#

adding in my existing ext2/4 stack now, and hard crash

fallow birchBOT
#
[hathach/tinyusb] New branch created: selective-log
jolly scroll
#

ooo

fallow birchBOT
jolly scroll
#
dumping channel 0: xfer comp
  HCCHAR0: 0x988a00
    mps:512 ep:1 dir1 type:2 mc:1 addr:2
  HCSPLT0: 0x0
  HCINT0: 0x0
  HCINTMSK0: 0x7ff
  HCTSIZ0: 0x80000000
    size:0 packets:0 pid:0 ping:1
  HCDMA0: 0x200
#

why does that say 200??

#
dumping channel 0: IN init
  HCCHAR0: 0x988a00
    mps:512 ep:1 dir1 type:2 mc:1 addr:2
  HCSPLT0: 0x0
  HCINT0: 0x0
  HCINTMSK0: 0x7ff
  HCTSIZ0: 0x40080200
    size:512 packets:1 pid:2 ping:0
  HCDMA0: 0xc4120220
#

so, the channel was in this state before being enabled

#
dumping channel 0: xfer comp
  HCCHAR0: 0x988a00
    mps:512 ep:1 dir1 type:2 mc:1 addr:2
  HCSPLT0: 0x0
  HCINT0: 0x0
  HCINTMSK0: 0x7ff
  HCTSIZ0: 0x80000000
    size:0 packets:0 pid:0 ping:1
  HCDMA0: 0x00000200