Skip to main content

Module usbhs

Module usbhs 

Source
Expand description

USB high-speed (kind: usbhs). H4 shares the v4x7 register map; v3 is its own layout. USBHS device mode peripheral driver Note that this currently only implements device mode

Every transfer completes in the interrupt handler: it reads the shared status (INT_ST, RX_LEN) and releases INT_FG at once – isochronous transactions ignore INT_BUSY and would overwrite them – then records the result per endpoint and wakes the task. Bulk / interrupt endpoints keep flow control by answering NAK until their task has taken the data (OUT) or loaded the next packet (IN).

Isochronous endpoints run without a task in the loop:

  • OUT: a ring of [ISO_OUT_SLOTS] packet buffers. The interrupt points the endpoint’s DMA at the next free slot after each packet; read drains the ring, or [iso_out_take] in place. A full ring drops the newest packet, and zero-length packets are not delivered (arrivals are detected by a marker in the slot).
  • IN: a ring of [ISO_IN_SLOTS] packets. After each IN transaction the interrupt loads the next queued packet, or a zero-length one when none is queued. write waits for a free slot, so a writer keeps the ring full and stays at most [ISO_IN_SLOTS] packets ahead; [iso_in_prime] queues from an interrupt (e.g. an explicit feedback value from the SOF callback), [iso_in_fill] in place.
  • Both work from the SOF callback, without a task: one packet each way per microframe.
  • Each slot is one endpoint buffer from the driver’s buffer array, so the array needs room for the rings: one buffer for EP0 and each bulk / interrupt endpoint, plus [ISO_OUT_SLOTS] per isochronous OUT and [ISO_IN_SLOTS] per isochronous IN.

[set_sof_callback] runs a function from the interrupt on every SOF (125 us at high speed).

An endpoint number can be used for both an IN and an OUT endpoint of the same type. Isochronous and bulk / interrupt endpoints must use different numbers: a PING to a bulk OUT whose number is isochronous on the IN side hangs the SIE.

Not supported: remote wakeup, high-bandwidth isochronous (more than one transaction per microframe), hardware double buffering, full-speed operation (the block is configured for high speed).

Modules§

control

Structs§

Bus
Driver
InterruptHandler
WakeupInterruptHandler

Constants§

ISO_IN_SLOTS
Packets queued per isochronous IN endpoint.
ISO_OUT_SLOTS
Packet buffers per isochronous OUT endpoint (15 packets can wait for the task).

Traits§

DmPin
DpPin
Instance
UsbHs peripheral instance

Functions§

endpoint_enabled
Whether the host enabled endpoint ep in direction (for an isochronous one: selected its interface’s streaming alternate setting).
iso_in_advance
A paced iso IN endpoint (iso_in_set_paced): the host took a packet in each microframe since the last call; they move on and the next queued packet is loaded. Call it at the USB interrupt’s priority (it shares the endpoint’s state with it), some way into the microframe: after the host’s IN, before the next microframe’s.
iso_in_fill
Build one packet on isochronous IN endpoint ep in place and queue it: f fills the next free slot (one endpoint buffer; keep to the endpoint’s max packet size) and returns the packet’s length. false: not queued and f not run (ring full, endpoint not enabled or not isochronous). Callable from interrupts.
iso_in_pending
Packets queued on isochronous IN endpoint ep and not yet taken by the host (including the one loaded in the endpoint).
iso_in_prime
Queue one packet on isochronous IN endpoint ep; callable from interrupts. false: not queued (ring full, endpoint not enabled or not isochronous, packet too long).
iso_in_register_waker
Wake waker when isochronous IN endpoint ep sends a packet (a slot frees up), to refill it from a task. One waiter per endpoint, shared with the endpoint’s write.
iso_in_set_paced
Pace isochronous IN endpoint ep (polled every microframe) from outside: the interrupt no longer moves it on after an IN; iso_in_advance, called once in each microframe after the host’s IN to it and well before the next, does.
iso_out_overruns
Packets dropped because isochronous OUT endpoint ep’s ring was full (the newest packet is dropped), since the driver was created. 0 for an endpoint that is not isochronous OUT.
iso_out_take
Take the oldest packet waiting on isochronous OUT endpoint ep, in place: f reads it, then its slot goes back to the ring. None: no packet waiting (or not an isochronous OUT endpoint). One reader per endpoint; callable from interrupts.
microframe
The current microframe number: 8 per frame, wrapping at 2^14. Read from the frame number register, so it also counts microframes whose SOF interrupt was missed.
set_sof_callback
Call f from the USB interrupt on every SOF (every 125 us microframe at high speed). Keep it short: it delays every other USB completion.