Skip to main content

Module otg_fs

Module otg_fs 

Source
Expand description

WCH USBFS + OTG (kind: otg / otg_v2) — v2fs device layout + OTG regs. USB_FS and OTG_FS device mode peripheral driver Note that this currently only implements device mode

Serves the register models of the FS device block: kind: otg (otg_v2, the V2/V3 OTG parts), kind: usbfs (usbfs_h4, CH32H417) and kind: usb (x0fs on CH32X035, v2fs on CH32V20x/V303). The field-name differences live in the private regs module.

§Bidirectional endpoints and buffer sizing

Non-control endpoint numbers 1..=7 (except EP4 on CH32X035, which shares EP0’s DMA buffer in hardware) can be allocated in both IN and OUT directions simultaneously (for example 0x81 and 0x01).

Each endpoint number has a single UEPn_DMA base register. With UEPn_BUF_MOD = 0, hardware places OUT data at [UEPn_DMA .. +64) and, when both UEPn_RX_EN and UEPn_TX_EN are enabled, offsets IN data to [UEPn_DMA + 64 .. +128). Because WCH USBFS has no per-endpoint max-RX length register (and writes two CRC16 bytes past received payloads up to 64 bytes), EP0 and any OUT endpoint always reserve 64 bytes in ep_buffer, and bidirectional endpoint pairs reserve 128 contiguous bytes regardless of the order in which alloc_endpoint_in and alloc_endpoint_out were called. Budget 64 bytes per allocated endpoint plus 64 bytes for EP0 (for example, one EndpointDataBuffer64 per allocated endpoint plus one for EP0).

There's a lot of TODOs and panics where things are not implemented

List of things that is tested Untested but expected to work items are noted as well

Control Pipe:

  • Receive SETUP packet (Host -> Dev)
  • Send IN packet (Dev -> Host).
  • Receive OUT packet (Host -> Dev).

Other Endpoints:

  • Interrupt Out
  • Interrupt In
  • Bulk Out (CDC-ACM echo on the CH32V203 USBFS)
  • Bulk In (same)

Other Features:

  • Set endpoint stall (bulk, on the CH32V203 USBFS)
  • Get endpoint stall status (same)
  • Remote wakeup

Modules§

endpoint

Structs§

Bus
Config
USB PHY configuration (X035 only).
Driver
InterruptHandler

Traits§

DmPin
DpPin
Instance
OTG_FS peripheral instance