Skip to content

Commit

Permalink
fix issues in esp32s2 and esp32s3 USB0 endpoint control registers (#213)
Browse files Browse the repository at this point in the history
* usb: group DIEPTXF registers into an array

* usb: cluster endpoint registers

This groups the USB endpoint registers into clusters.

Note that endpoint 0 is different from the other endpoints, so it
unfortunately must be put into a separate cluster of its own, for both
the in and out endpoints.  This does produce some ergonomic issues:
The `in_ep0()`, `in_ep1()`, ... `in_ep6()` functions behave as you would
expect.  However, there is also an `in_ep(n: usize)` function, but it's
behavior is slightly surprising, as it only returns data for endpoints
1-6, and the index it accepts is therefore off by one (`in_ep(1)`
returns the same result as `in_ep2()`).

* usb: fix bugs in the DIEPCTL, DOEPCTL, DIEPTSIZ, and DOEPTSIZ registers

These registers were defined incorrectly for endpoints 1 through 6.
This fixes the bid-widths and read-write access modes for several fields
which had their values copied from the endpoint 0 register definitions.

* usb: rename the endpoint 0 control register fields

Rename the register fields for endpoint 0 to match the fields in the
register cluster created for endpoints 1 through 6.

* usb: clean up remaining endpoint register field names

Update the register field names to be consistent between endpoint 0 and
the other endpoints.  This removes the endpoint number suffix, and drops
the `D_`, `DI_`, and `DO_` prefixes that were inconsistently applied to
the field names.

* usb: add registers to access the FIFOs

* usb: specify that the FIFOs allow writing any possible value

This allows users to write any value to the FIFOs without needing to use
the unsafe `bits()` method.

* Upgrade to svdtools 0.3.14

This release contains fixes for handling write constraints as
well as derived registers, which are needed for some of my USB0
peripheral fixes.

* usb: add write constraints to register fields

Add write constraints to individual register fields. This allows
svd2rust to generate safe accessors for these fields, rather than only
being able to access them through unsafe methods.

* usb: unify endpoint register types where possible

Endpoint 0 has different register definitions than the other endpoints
for some but not all of its registers.  For the registers that are the
same between all endpoints, use `deriveFrom` to make endpoints 1-6 share
the same register type as endpoint 0.  This makes it easier to write
code using these registers that doesn't care if it is operating on
endpoint 0 or not.

* usb: add write constraints for fields in the dcfg register

This allows svd2rust to make writes to these fields safe.
  • Loading branch information
simpkins authored Apr 6, 2024
1 parent a8a8340 commit 09ae7f0
Show file tree
Hide file tree
Showing 211 changed files with 4,834 additions and 20,102 deletions.
354 changes: 354 additions & 0 deletions common_patches/usb0.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,354 @@
_array:
DIEPTXF*: {}

DCFG:
_modify:
DEVADDR:
writeConstraint: [0, 0x7f]
PERFRLINT:
writeConstraint: [0, 3]


_cluster:
IN_EP0:
description: "Device IN endpoint 0"
DIEPCTL0:
name: DIEPCTL
_modify:
D_MPS0:
name: MPS
D_USBACTEP0:
name: USBACTEP
D_NAKSTS0:
name: NAKSTS
D_EPTYPE0:
name: EPTYPE
D_STALL0:
name: STALL
D_TXFNUM0:
name: TXFNUM
D_CNAK0:
name: CNAK
DI_SNAK0:
name: SNAK
D_EPDIS0:
name: EPDIS
D_EPENA0:
name: EPENA
DIEPINT0:
name: DIEPINT
_modify:
D_XFERCOMPL0:
name: XFERCOMPL
D_EPDISBLD0:
name: EPDISBLD
D_AHBERR0:
name: AHBERR
D_TIMEOUT0:
name: TIMEOUT
D_INTKNTXFEMP0:
name: INTKNTXFEMP
D_INTKNEPMIS0:
name: INTKNEPMIS
D_INEPNAKEFF0:
name: INEPNAKEFF
D_TXFEMP0:
name: TXFEMP
D_TXFIFOUNDRN0:
name: TXFIFOUNDRN
D_BNAINTR0:
name: BNAINTR
D_PKTDRPSTS0:
name: PKTDRPSTS
D_BBLEERR0:
name: BBLEERR
D_NAKINTRPT0:
name: NAKINTRPT
D_NYETINTRPT0:
name: NYETINTRPT
DIEPTSIZ0:
name: DIEPTSIZ
_modify:
D_XFERSIZE0:
name: XFERSIZE
writeConstraint: [0, 0x7f]
D_PKTCNT0:
name: PKTCNT
writeConstraint: [0, 3]
DIEPDMA0:
name: DIEPDMA
_modify:
D_DMAADDR0:
name: DMAADDR
DIEPDMAB0:
name: DIEPDMAB
_modify:
D_DMABUFFERADDR0:
name: DMABUFFERADDR
DTXFSTS0:
name: DTXFSTS
_modify:
D_INEPTXFSPCAVAIL0:
name: INEPTXFSPCAVAIL
IN_EP%s:
description: "Device IN endpoints 1-6"
DIEPCTL[1-6]:
name: DIEPCTL
DIEPINT[1-6]:
name: DIEPINT
DIEPTSIZ[1-6]:
name: DIEPTSIZ
DIEPDMA[1-6]:
name: DIEPDMA
DIEPDMAB[1-6]:
name: DIEPDMAB
DTXFSTS[1-6]:
name: DTXFSTS
_modify:
DIEPCTL:
fields:
MPS:
bitOffset: 0
bitWidth: 11
writeConstraint: [0, 0x7ff]
access: read-write
USBACTEP:
bitOffset: 15
bitWidth: 1
access: read-write
NAKSTS:
bitOffset: 17
bitWidth: 1
access: read-only
EPTYPE:
bitOffset: 18
bitWidth: 2
writeConstraint: [0, 3]
access: read-write
STALL:
bitOffset: 21
bitWidth: 1
access: read-write
TXFNUM:
bitOffset: 22
bitWidth: 4
access: read-write
CNAK:
bitOffset: 26
bitWidth: 1
access: write-only
SNAK:
bitOffset: 27
bitWidth: 1
access: write-only
SETD0PID:
bitOffset: 28
bitWidth: 1
access: write-only
SETD1PID:
bitOffset: 29
bitWidth: 1
access: write-only
EPDIS:
bitOffset: 30
bitWidth: 1
access: read-write
EPENA:
bitOffset: 31
bitWidth: 1
access: read-write
DIEPTSIZ:
fields:
XFERSIZE:
bitOffset: 0
bitWidth: 19
writeConstraint: [0, 0x7ffff]
access: read-write
PKTCNT:
bitOffset: 19
bitWidth: 10
writeConstraint: [0, 0x3ff]
access: read-write
_derive:
DIEPINT: USB0.IN_EP0.DIEPINT
DTXFSTS: USB0.IN_EP0.DTXFSTS
DIEPDMA: USB0.IN_EP0.DIEPDMA
DIEPDMAB: USB0.IN_EP0.DIEPDMAB
OUT_EP0:
description: "Device OUT endpoint 0"
DOEPCTL0:
name: DOEPCTL
_modify:
MPS0:
name: MPS
USBACTEP0:
name: USBACTEP
NAKSTS0:
name: NAKSTS
EPTYPE0:
name: EPTYPE
SNP0:
name: SNP
STALL0:
name: STALL
CNAK0:
name: CNAK
DO_SNAK0:
name: SNAK
EPDIS0:
name: EPDIS
EPENA0:
name: EPENA
DOEPINT0:
name: DOEPINT
_modify:
XFERCOMPL0:
name: XFERCOMPL
EPDISBLD0:
name: EPDISBLD
AHBERR0:
name: AHBERR
SETUP0:
name: SETUP
OUTTKNEPDIS0:
name: OUTTKNEPDIS
STSPHSERCVD0:
name: STSPHSERCVD
BACK2BACKSETUP0:
name: BACK2BACKSETUP
OUTPKTERR0:
name: OUTPKTERR
BNAINTR0:
name: BNAINTR
PKTDRPSTS0:
name: PKTDRPSTS
BBLEERR0:
name: BBLEERR
NAKINTRPT0:
name: NAKINTRPT
NYEPINTRPT0:
name: NYEPINTRPT
STUPPKTRCVD0:
name: STUPPKTRCVD
DOEPTSIZ0:
name: DOEPTSIZ
_modify:
XFERSIZE0:
name: XFERSIZE
writeConstraint: [0, 0x7f]
PKTCNT0:
name: PKTCNT
SUPCNT0:
name: SUPCNT
DOEPDMA0:
name: DOEPDMA
_modify:
DMAADDR0:
name: DMAADDR
DOEPDMAB0:
name: DOEPDMAB
_modify:
DMABUFFERADDR0:
name: DMABUFFERADDR
OUT_EP%s:
description: "Device OUT endpoints 1-6"
DOEPCTL[1-6]:
name: DOEPCTL
DOEPINT[1-6]:
name: DOEPINT
DOEPTSIZ[1-6]:
name: DOEPTSIZ
DOEPDMA[1-6]:
name: DOEPDMA
DOEPDMAB[1-6]:
name: DOEPDMAB
_modify:
DOEPCTL:
fields:
MPS:
bitOffset: 0
bitWidth: 11
access: read-write
writeConstraint: [0, 0x7ff]
USBACTEP:
bitOffset: 15
bitWidth: 1
access: read-write
NAKSTS:
bitOffset: 17
bitWidth: 1
access: read-only
EPTYPE:
bitOffset: 18
bitWidth: 2
access: read-write
writeConstraint: [0, 3]
SNP:
bitOffset: 20
bitWidth: 1
access: read-write
STALL:
bitOffset: 21
bitWidth: 1
access: read-write
CNAK:
bitOffset: 26
bitWidth: 1
access: write-only
SNAK:
bitOffset: 27
bitWidth: 1
access: write-only
SETD0PID:
bitOffset: 28
bitWidth: 1
access: write-only
SETD1PID:
bitOffset: 29
bitWidth: 1
access: write-only
EPDIS:
bitOffset: 30
bitWidth: 1
access: read-write
EPENA:
bitOffset: 31
bitWidth: 1
access: read-write
DOEPTSIZ:
fields:
XFERSIZE:
bitOffset: 0
bitWidth: 19
access: read-write
writeConstraint: [0, 0x7ffff]
PKTCNT:
bitOffset: 19
bitWidth: 10
access: read-write
writeConstraint: [0, 0x3ff]
SUPCNT:
bitOffset: 29
bitWidth: 2
access: read-write
writeConstraint: [0, 3]
_derive:
DOEPINT: USB0.OUT_EP0.DOEPINT
DOEPDMA: USB0.OUT_EP0.DOEPDMA
DOEPDMAB: USB0.OUT_EP0.DOEPDMAB

_add:
FIFO%s:
addressOffset: 0x1000
dim: 16
dimIncrement: 0x1000
dimIndex: 0-15
size: 32
description: "Read and write data to the USB FIFOs through this register."
writeConstraint: [0, 0xffffffff]
fields:
WORD:
bitOffset: 0
bitWidth: 32
writeConstraint: [0, 0xffffffff]
access: read-write
Loading

0 comments on commit 09ae7f0

Please sign in to comment.