Merge branch 'master' into fork/Maerdl/master
This commit is contained in:
@@ -31,6 +31,9 @@
|
||||
|
||||
#if CFG_TUD_ENABLED && defined(TUP_USBIP_DWC2)
|
||||
|
||||
// Debug level for DWC2
|
||||
#define DWC2_DEBUG 2
|
||||
|
||||
#include "device/dcd.h"
|
||||
#include "dwc2_type.h"
|
||||
|
||||
@@ -57,29 +60,26 @@
|
||||
#error "Unsupported MCUs"
|
||||
#endif
|
||||
|
||||
enum {
|
||||
DWC2_CONTROLLER_COUNT = TU_ARRAY_SIZE(_dwc2_controller)
|
||||
};
|
||||
|
||||
// DWC2 registers
|
||||
//#define DWC2_REG(_port) ((dwc2_regs_t*) _dwc2_controller[_port].reg_base)
|
||||
|
||||
TU_ATTR_ALWAYS_INLINE static inline dwc2_regs_t* DWC2_REG(uint8_t rhport) {
|
||||
if (rhport >= DWC2_CONTROLLER_COUNT) {
|
||||
// user mis-configured, ignore and use first controller
|
||||
rhport = 0;
|
||||
}
|
||||
return (dwc2_regs_t*) _dwc2_controller[rhport].reg_base;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------+
|
||||
// MACRO TYPEDEF CONSTANT ENUM
|
||||
//--------------------------------------------------------------------+
|
||||
|
||||
// DWC2 registers
|
||||
#define DWC2_REG(_port) ((dwc2_regs_t*) _dwc2_controller[_port].reg_base)
|
||||
|
||||
// Debug level for DWC2
|
||||
#define DWC2_DEBUG 2
|
||||
|
||||
#ifndef dcache_clean
|
||||
#define dcache_clean(_addr, _size)
|
||||
#endif
|
||||
|
||||
#ifndef dcache_invalidate
|
||||
#define dcache_invalidate(_addr, _size)
|
||||
#endif
|
||||
|
||||
#ifndef dcache_clean_invalidate
|
||||
#define dcache_clean_invalidate(_addr, _size)
|
||||
#endif
|
||||
|
||||
static TU_ATTR_ALIGNED(4) uint32_t _setup_packet[2];
|
||||
static CFG_TUD_MEM_SECTION TU_ATTR_ALIGNED(4) uint32_t _setup_packet[2];
|
||||
|
||||
typedef struct {
|
||||
uint8_t* buffer;
|
||||
@@ -93,99 +93,230 @@ static xfer_ctl_t xfer_status[DWC2_EP_MAX][2];
|
||||
#define XFER_CTL_BASE(_ep, _dir) (&xfer_status[_ep][_dir])
|
||||
|
||||
// EP0 transfers are limited to 1 packet - larger sizes has to be split
|
||||
static uint16_t ep0_pending[2]; // Index determines direction as tusb_dir_t type
|
||||
static uint16_t ep0_pending[2]; // Index determines direction as tusb_dir_t type
|
||||
static uint16_t _dfifo_top; // top free location in FIFO RAM
|
||||
|
||||
// TX FIFO RAM allocation so far in words - RX FIFO size is readily available from dwc2->grxfsiz
|
||||
static uint16_t _allocated_fifo_words_tx; // TX FIFO size in words (IN EPs)
|
||||
// Number of IN endpoints active
|
||||
static uint8_t _allocated_ep_in_count;
|
||||
|
||||
// SOF enabling flag - required for SOF to not get disabled in ISR when SOF was enabled by
|
||||
static bool _sof_en;
|
||||
|
||||
// Calculate the RX FIFO size according to minimum recommendations from reference manual
|
||||
// RxFIFO = (5 * number of control endpoints + 8) +
|
||||
// ((largest USB packet used / 4) + 1 for status information) +
|
||||
// (2 * number of OUT endpoints) + 1 for Global NAK
|
||||
// with number of control endpoints = 1 we have
|
||||
// RxFIFO = 15 + (largest USB packet used / 4) + 2 * number of OUT endpoints
|
||||
// we double the largest USB packet size to be able to hold up to 2 packets
|
||||
static inline uint16_t calc_grxfsiz(uint16_t max_ep_size, uint8_t ep_count) {
|
||||
return 15 + 2 * (max_ep_size / 4) + 2 * ep_count;
|
||||
//--------------------------------------------------------------------
|
||||
// DMA
|
||||
//--------------------------------------------------------------------
|
||||
|
||||
TU_ATTR_ALWAYS_INLINE static inline bool dma_enabled(const dwc2_regs_t* dwc2) {
|
||||
#if !CFG_TUD_DWC2_DMA
|
||||
(void) dwc2;
|
||||
return false;
|
||||
#else
|
||||
// Internal DMA only
|
||||
return (dwc2->ghwcfg2_bm.arch == GHWCFG2_ARCH_INTERNAL_DMA);
|
||||
#endif
|
||||
}
|
||||
|
||||
TU_ATTR_ALWAYS_INLINE static inline void fifo_flush_tx(dwc2_regs_t* dwc2, uint8_t epnum) {
|
||||
TU_ATTR_ALWAYS_INLINE static inline uint16_t dma_cal_epfifo_base(uint8_t rhport) {
|
||||
// Scatter/Gather DMA mode is not yet supported. Buffer DMA only need 1 words per endpoint direction
|
||||
const dwc2_controller_t* dwc2_controller = &_dwc2_controller[rhport];
|
||||
return dwc2_controller->ep_fifo_size/4 - 2*dwc2_controller->ep_count;
|
||||
}
|
||||
|
||||
static void dma_setup_prepare(uint8_t rhport) {
|
||||
dwc2_regs_t* dwc2 = DWC2_REG(rhport);
|
||||
|
||||
if (dwc2->gsnpsid >= DWC2_CORE_REV_3_00a) {
|
||||
if(dwc2->epout[0].doepctl & DOEPCTL_EPENA) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
// Receive only 1 packet
|
||||
dwc2->epout[0].doeptsiz = (1 << DOEPTSIZ_STUPCNT_Pos) | (1 << DOEPTSIZ_PKTCNT_Pos) | (8 << DOEPTSIZ_XFRSIZ_Pos);
|
||||
dwc2->epout[0].doepdma = (uintptr_t)_setup_packet;
|
||||
dwc2->epout[0].doepctl |= DOEPCTL_EPENA | DOEPCTL_USBAEP;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------+
|
||||
// Data FIFO
|
||||
//--------------------------------------------------------------------+
|
||||
|
||||
TU_ATTR_ALWAYS_INLINE static inline void dfifo_flush_tx(dwc2_regs_t* dwc2, uint8_t epnum) {
|
||||
// flush TX fifo and wait for it cleared
|
||||
dwc2->grstctl = GRSTCTL_TXFFLSH | (epnum << GRSTCTL_TXFNUM_Pos);
|
||||
while (dwc2->grstctl & GRSTCTL_TXFFLSH_Msk) {}
|
||||
}
|
||||
TU_ATTR_ALWAYS_INLINE static inline void fifo_flush_rx(dwc2_regs_t* dwc2) {
|
||||
TU_ATTR_ALWAYS_INLINE static inline void dfifo_flush_rx(dwc2_regs_t* dwc2) {
|
||||
// flush RX fifo and wait for it cleared
|
||||
dwc2->grstctl = GRSTCTL_RXFFLSH;
|
||||
while (dwc2->grstctl & GRSTCTL_RXFFLSH_Msk) {}
|
||||
}
|
||||
|
||||
static bool fifo_alloc(uint8_t rhport, uint8_t ep_addr, uint16_t packet_size) {
|
||||
/* USB Data FIFO Layout
|
||||
|
||||
The FIFO is split up into
|
||||
- EPInfo: for storing DMA metadata, only required when use DMA. Maximum size is called
|
||||
EP_LOC_CNT = ep_fifo_size - ghwcfg3.dfifo_depth. For value less than EP_LOC_CNT, gdfifocfg must be configured before
|
||||
gahbcfg.dmaen is set
|
||||
- Buffer mode: 1 word per endpoint direction
|
||||
- Scatter/Gather DMA: 4 words per endpoint direction
|
||||
- TX FIFO: one fifo for each IN endpoint. Size is dynamic depending on packet size, starting from top with EP0 IN.
|
||||
- Shared RX FIFO: a shared fifo for all OUT endpoints. Typically, can hold up to 2 packets of the largest EP size.
|
||||
|
||||
We allocated TX FIFO from top to bottom (using top pointer), this to allow the RX FIFO to grow dynamically which is
|
||||
possible since the free space is located between the RX and TX FIFOs.
|
||||
|
||||
---------------- ep_fifo_size
|
||||
| EPInfo |
|
||||
| for DMA |
|
||||
|-------------|-- gdfifocfg.EPINFOBASE (max is ghwcfg3.dfifo_depth)
|
||||
| IN FIFO 0 |
|
||||
| control |
|
||||
|-------------|
|
||||
| IN FIFO 1 |
|
||||
|-------------|
|
||||
| . . . . |
|
||||
|-------------|
|
||||
| IN FIFO n |
|
||||
|-------------|
|
||||
| FREE |
|
||||
|-------------|-- GRXFSIZ (expandable)
|
||||
| OUT FIFO |
|
||||
| ( Shared ) |
|
||||
--------------- 0
|
||||
|
||||
According to "FIFO RAM allocation" section in RM, FIFO RAM are allocated as follows (each word 32-bits):
|
||||
- Each EP IN needs at least max packet size
|
||||
- All EP OUT shared a unique OUT FIFO which uses (for Slave or Buffer DMA, Scatt/Gather DMA use different formula):
|
||||
- 13 for setup packets + control words (up to 3 setup packets).
|
||||
- 1 for global NAK (not required/used here).
|
||||
- Largest-EPsize / 4 + 1. ( FS: 64 bytes, HS: 512 bytes). Recommended is "2 x (Largest-EPsize/4) + 1"
|
||||
- 2 for each used OUT endpoint
|
||||
|
||||
Therefore GRXFSIZ = 13 + 1 + 2 x (Largest-EPsize/4 + 1) + 2 x EPOUTnum
|
||||
*/
|
||||
|
||||
TU_ATTR_ALWAYS_INLINE static inline uint16_t calc_grxfsiz(uint16_t largest_ep_size, uint8_t ep_count) {
|
||||
return 13 + 1 + 2 * ((largest_ep_size / 4) + 1) + 2 * ep_count;
|
||||
}
|
||||
|
||||
static bool dfifo_alloc(uint8_t rhport, uint8_t ep_addr, uint16_t packet_size) {
|
||||
dwc2_regs_t* dwc2 = DWC2_REG(rhport);
|
||||
uint8_t const ep_count = _dwc2_controller[rhport].ep_count;
|
||||
const dwc2_controller_t* dwc2_controller = &_dwc2_controller[rhport];
|
||||
uint8_t const ep_count = dwc2_controller->ep_count;
|
||||
uint8_t const epnum = tu_edpt_number(ep_addr);
|
||||
uint8_t const dir = tu_edpt_dir(ep_addr);
|
||||
|
||||
TU_ASSERT(epnum < ep_count);
|
||||
|
||||
uint16_t fifo_size = tu_div_ceil(packet_size, 4);
|
||||
|
||||
// "USB Data FIFOs" section in reference manual
|
||||
// Peripheral FIFO architecture
|
||||
//
|
||||
// --------------- 320 or 1024 ( 1280 or 4096 bytes )
|
||||
// | IN FIFO 0 |
|
||||
// --------------- (320 or 1024) - 16
|
||||
// | IN FIFO 1 |
|
||||
// --------------- (320 or 1024) - 16 - x
|
||||
// | . . . . |
|
||||
// --------------- (320 or 1024) - 16 - x - y - ... - z
|
||||
// | IN FIFO MAX |
|
||||
// ---------------
|
||||
// | FREE |
|
||||
// --------------- GRXFSIZ
|
||||
// | OUT FIFO |
|
||||
// | ( Shared ) |
|
||||
// --------------- 0
|
||||
//
|
||||
// In FIFO is allocated by following rules:
|
||||
// - IN EP 1 gets FIFO 1, IN EP "n" gets FIFO "n".
|
||||
if (dir == TUSB_DIR_OUT) {
|
||||
// Calculate required size of RX FIFO
|
||||
uint16_t const sz = calc_grxfsiz(4 * fifo_size, ep_count);
|
||||
uint16_t const new_sz = calc_grxfsiz(4 * fifo_size, ep_count);
|
||||
|
||||
// If size_rx needs to be extended check if possible and if so enlarge it
|
||||
if (dwc2->grxfsiz < sz) {
|
||||
TU_ASSERT(sz + _allocated_fifo_words_tx <= _dwc2_controller[rhport].ep_fifo_size / 4);
|
||||
|
||||
// Enlarge RX FIFO
|
||||
dwc2->grxfsiz = sz;
|
||||
// If size_rx needs to be extended check if there is enough free space
|
||||
if (dwc2->grxfsiz < new_sz) {
|
||||
TU_ASSERT(new_sz <= _dfifo_top);
|
||||
dwc2->grxfsiz = new_sz; // Enlarge RX FIFO
|
||||
}
|
||||
} else {
|
||||
// Note if The TXFELVL is configured as half empty. In order
|
||||
// to be able to write a packet at that point, the fifo must be twice the max_size.
|
||||
// Check IN endpoints concurrently active limit
|
||||
if(_dwc2_controller->ep_in_count) {
|
||||
TU_ASSERT(_allocated_ep_in_count < _dwc2_controller->ep_in_count);
|
||||
_allocated_ep_in_count++;
|
||||
}
|
||||
|
||||
// If The TXFELVL is configured as half empty, the fifo must be twice the max_size.
|
||||
if ((dwc2->gahbcfg & GAHBCFG_TXFELVL) == 0) {
|
||||
fifo_size *= 2;
|
||||
}
|
||||
|
||||
// Check if free space is available
|
||||
TU_ASSERT(_allocated_fifo_words_tx + fifo_size + dwc2->grxfsiz <= _dwc2_controller[rhport].ep_fifo_size / 4);
|
||||
_allocated_fifo_words_tx += fifo_size;
|
||||
TU_LOG(DWC2_DEBUG, " Allocated %u bytes at offset %" PRIu32, fifo_size * 4,
|
||||
_dwc2_controller[rhport].ep_fifo_size - _allocated_fifo_words_tx * 4);
|
||||
TU_ASSERT(_dfifo_top >= fifo_size + dwc2->grxfsiz);
|
||||
_dfifo_top -= fifo_size;
|
||||
TU_LOG(DWC2_DEBUG, " TX FIFO %u: allocated %u words at offset %u\r\n", epnum, fifo_size, _dfifo_top);
|
||||
|
||||
// DIEPTXF starts at FIFO #1.
|
||||
// Both TXFD and TXSA are in unit of 32-bit words.
|
||||
dwc2->dieptxf[epnum - 1] = (fifo_size << DIEPTXF_INEPTXFD_Pos) |
|
||||
(_dwc2_controller[rhport].ep_fifo_size / 4 - _allocated_fifo_words_tx);
|
||||
if (epnum == 0) {
|
||||
dwc2->dieptxf0 = (fifo_size << DIEPTXF0_TX0FD_Pos) | _dfifo_top;
|
||||
} else {
|
||||
// DIEPTXF starts at FIFO #1.
|
||||
dwc2->dieptxf[epnum - 1] = (fifo_size << DIEPTXF_INEPTXFD_Pos) | _dfifo_top;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
static void dfifo_init(uint8_t rhport) {
|
||||
const dwc2_controller_t* dwc2_controller = &_dwc2_controller[rhport];
|
||||
dwc2_regs_t* dwc2 = DWC2_REG(rhport);
|
||||
dwc2->grxfsiz = calc_grxfsiz(CFG_TUD_ENDPOINT0_SIZE, dwc2_controller->ep_count);
|
||||
|
||||
if(dma_enabled(dwc2)) {
|
||||
// DMA use last DFIFO to store metadata
|
||||
_dfifo_top = dma_cal_epfifo_base(rhport);
|
||||
}else {
|
||||
_dfifo_top = dwc2_controller->ep_fifo_size / 4;
|
||||
}
|
||||
|
||||
// Allocate FIFO for EP0 IN
|
||||
dfifo_alloc(rhport, 0x80, CFG_TUD_ENDPOINT0_SIZE);
|
||||
}
|
||||
|
||||
// Read a single data packet from receive FIFO
|
||||
static void dfifo_read_packet(uint8_t rhport, uint8_t* dst, uint16_t len) {
|
||||
(void) rhport;
|
||||
|
||||
dwc2_regs_t* dwc2 = DWC2_REG(rhport);
|
||||
volatile const uint32_t* rx_fifo = dwc2->fifo[0];
|
||||
|
||||
// Reading full available 32 bit words from fifo
|
||||
uint16_t full_words = len >> 2;
|
||||
while (full_words--) {
|
||||
tu_unaligned_write32(dst, *rx_fifo);
|
||||
dst += 4;
|
||||
}
|
||||
|
||||
// Read the remaining 1-3 bytes from fifo
|
||||
uint8_t const bytes_rem = len & 0x03;
|
||||
if (bytes_rem != 0) {
|
||||
uint32_t const tmp = *rx_fifo;
|
||||
dst[0] = tu_u32_byte0(tmp);
|
||||
if (bytes_rem > 1) dst[1] = tu_u32_byte1(tmp);
|
||||
if (bytes_rem > 2) dst[2] = tu_u32_byte2(tmp);
|
||||
}
|
||||
}
|
||||
|
||||
// Write a single data packet to EPIN FIFO
|
||||
static void dfifo_write_packet(uint8_t rhport, uint8_t fifo_num, uint8_t const* src, uint16_t len) {
|
||||
(void) rhport;
|
||||
|
||||
dwc2_regs_t* dwc2 = DWC2_REG(rhport);
|
||||
volatile uint32_t* tx_fifo = dwc2->fifo[fifo_num];
|
||||
|
||||
// Pushing full available 32 bit words to fifo
|
||||
uint16_t full_words = len >> 2;
|
||||
while (full_words--) {
|
||||
*tx_fifo = tu_unaligned_read32(src);
|
||||
src += 4;
|
||||
}
|
||||
|
||||
// Write the remaining 1-3 bytes into fifo
|
||||
uint8_t const bytes_rem = len & 0x03;
|
||||
if (bytes_rem) {
|
||||
uint32_t tmp_word = src[0];
|
||||
if (bytes_rem > 1) tmp_word |= (src[1] << 8);
|
||||
if (bytes_rem > 2) tmp_word |= (src[2] << 16);
|
||||
|
||||
*tx_fifo = tmp_word;
|
||||
}
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------
|
||||
// Endpoint
|
||||
//--------------------------------------------------------------------
|
||||
|
||||
static void edpt_activate(uint8_t rhport, tusb_desc_endpoint_t const * p_endpoint_desc) {
|
||||
dwc2_regs_t* dwc2 = DWC2_REG(rhport);
|
||||
uint8_t const epnum = tu_edpt_number(p_endpoint_desc->bEndpointAddress);
|
||||
@@ -206,7 +337,7 @@ static void edpt_activate(uint8_t rhport, tusb_desc_endpoint_t const * p_endpoin
|
||||
dwc2->daintmsk |= TU_BIT(DAINTMSK_OEPM_Pos + epnum);
|
||||
} else {
|
||||
dwc2->epin[epnum].diepctl = dxepctl | (epnum << DIEPCTL_TXFNUM_Pos);
|
||||
dwc2->daintmsk |= (1 << (DAINTMSK_IEPM_Pos + epnum));
|
||||
dwc2->daintmsk |= TU_BIT(DAINTMSK_IEPM_Pos + epnum);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -236,7 +367,7 @@ static void edpt_disable(uint8_t rhport, uint8_t ep_addr, bool stall) {
|
||||
}
|
||||
|
||||
// Flush the FIFO, and wait until we have confirmed it cleared.
|
||||
fifo_flush_tx(dwc2, epnum);
|
||||
dfifo_flush_tx(dwc2, epnum);
|
||||
} else {
|
||||
dwc2_epout_t* epout = dwc2->epout;
|
||||
|
||||
@@ -272,6 +403,8 @@ static void bus_reset(uint8_t rhport) {
|
||||
|
||||
_sof_en = false;
|
||||
|
||||
_allocated_ep_in_count = 1;
|
||||
|
||||
// clear device address
|
||||
dwc2->dcfg &= ~DCFG_DAD_Msk;
|
||||
|
||||
@@ -287,79 +420,28 @@ static void bus_reset(uint8_t rhport) {
|
||||
}
|
||||
}
|
||||
|
||||
fifo_flush_tx(dwc2, 0x10); // all tx fifo
|
||||
fifo_flush_rx(dwc2);
|
||||
dfifo_flush_tx(dwc2, 0x10); // all tx fifo
|
||||
dfifo_flush_rx(dwc2);
|
||||
|
||||
// 3. Set up interrupt mask
|
||||
dwc2->daintmsk = TU_BIT(DAINTMSK_OEPM_Pos) | TU_BIT(DAINTMSK_IEPM_Pos);
|
||||
dwc2->doepmsk = DOEPMSK_STUPM | DOEPMSK_XFRCM;
|
||||
dwc2->diepmsk = DIEPMSK_TOM | DIEPMSK_XFRCM;
|
||||
|
||||
// "USB Data FIFOs" section in reference manual
|
||||
// Peripheral FIFO architecture
|
||||
//
|
||||
// The FIFO is split up in a lower part where the RX FIFO is located and an upper part where the TX FIFOs start.
|
||||
// We do this to allow the RX FIFO to grow dynamically which is possible since the free space is located
|
||||
// between the RX and TX FIFOs. This is required by ISO OUT EPs which need a bigger FIFO than the standard
|
||||
// configuration done below.
|
||||
//
|
||||
// Dynamically FIFO sizes are of interest only for ISO EPs since all others are usually not opened and closed.
|
||||
// All EPs other than ISO are opened as soon as the driver starts up i.e. when the host sends a
|
||||
// configure interface command. Hence, all IN EPs other the ISO will be located at the top. IN ISO EPs are usually
|
||||
// opened when the host sends an additional command: setInterface. At this point in time
|
||||
// the ISO EP will be located next to the free space and can change its size. In case more IN EPs change its size
|
||||
// an additional memory
|
||||
//
|
||||
// --------------- 320 or 1024 ( 1280 or 4096 bytes )
|
||||
// | IN FIFO 0 |
|
||||
// --------------- (320 or 1024) - 16
|
||||
// | IN FIFO 1 |
|
||||
// --------------- (320 or 1024) - 16 - x
|
||||
// | . . . . |
|
||||
// --------------- (320 or 1024) - 16 - x - y - ... - z
|
||||
// | IN FIFO MAX |
|
||||
// ---------------
|
||||
// | FREE |
|
||||
// --------------- GRXFSIZ
|
||||
// | OUT FIFO |
|
||||
// | ( Shared ) |
|
||||
// --------------- 0
|
||||
//
|
||||
// According to "FIFO RAM allocation" section in RM, FIFO RAM are allocated as follows (each word 32-bits):
|
||||
// - Each EP IN needs at least max packet size, 16 words is sufficient for EP0 IN
|
||||
//
|
||||
// - All EP OUT shared a unique OUT FIFO which uses
|
||||
// - 13 for setup packets + control words (up to 3 setup packets).
|
||||
// - 1 for global NAK (not required/used here).
|
||||
// - Largest-EPsize / 4 + 1. ( FS: 64 bytes, HS: 512 bytes). Recommended is "2 x (Largest-EPsize/4) + 1"
|
||||
// - 2 for each used OUT endpoint
|
||||
//
|
||||
// Therefore GRXFSIZ = 13 + 1 + 1 + 2 x (Largest-EPsize/4) + 2 x EPOUTnum
|
||||
// - FullSpeed (64 Bytes ): GRXFSIZ = 15 + 2 x 16 + 2 x ep_count = 47 + 2 x ep_count
|
||||
// - Highspeed (512 bytes): GRXFSIZ = 15 + 2 x 128 + 2 x ep_count = 271 + 2 x ep_count
|
||||
//
|
||||
// NOTE: Largest-EPsize & EPOUTnum is actual used endpoints in configuration. Since DCD has no knowledge
|
||||
// of the overall picture yet. We will use the worst scenario: largest possible + ep_count
|
||||
//
|
||||
// For Isochronous, largest EP size can be 1023/1024 for FS/HS respectively. In addition if multiple ISO
|
||||
// are enabled at least "2 x (Largest-EPsize/4) + 1" are recommended. Maybe provide a macro for application to
|
||||
// overwrite this.
|
||||
|
||||
// EP0 out max is 64
|
||||
dwc2->grxfsiz = calc_grxfsiz(64, ep_count);
|
||||
|
||||
// Setup the control endpoint 0
|
||||
_allocated_fifo_words_tx = 16;
|
||||
|
||||
// Control IN uses FIFO 0 with 64 bytes ( 16 32-bit word )
|
||||
dwc2->dieptxf0 = (16 << DIEPTXF0_TX0FD_Pos) | (_dwc2_controller[rhport].ep_fifo_size / 4 - _allocated_fifo_words_tx);
|
||||
dfifo_init(rhport);
|
||||
|
||||
// Fixed control EP0 size to 64 bytes
|
||||
dwc2->epin[0].diepctl &= ~(0x03 << DIEPCTL_MPSIZ_Pos);
|
||||
dwc2->epout[0].doepctl &= ~(0x03 << DOEPCTL_MPSIZ_Pos);
|
||||
|
||||
xfer_status[0][TUSB_DIR_OUT].max_size = 64;
|
||||
xfer_status[0][TUSB_DIR_IN].max_size = 64;
|
||||
|
||||
dwc2->epout[0].doeptsiz |= (3 << DOEPTSIZ_STUPCNT_Pos);
|
||||
if(dma_enabled(dwc2)) {
|
||||
dma_setup_prepare(rhport);
|
||||
} else {
|
||||
dwc2->epout[0].doeptsiz |= (3 << DOEPTSIZ_STUPCNT_Pos);
|
||||
}
|
||||
|
||||
dwc2->gintmsk |= GINTMSK_OEPINT | GINTMSK_IEPINT;
|
||||
}
|
||||
@@ -369,11 +451,11 @@ static void edpt_schedule_packets(uint8_t rhport, uint8_t const epnum, uint8_t c
|
||||
(void) rhport;
|
||||
|
||||
dwc2_regs_t* dwc2 = DWC2_REG(rhport);
|
||||
xfer_ctl_t* const xfer = XFER_CTL_BASE(epnum, dir);
|
||||
|
||||
// EP0 is limited to one packet each xfer
|
||||
// We use multiple transaction of xfer->max_size length to get a whole transfer done
|
||||
if (epnum == 0) {
|
||||
xfer_ctl_t* const xfer = XFER_CTL_BASE(epnum, dir);
|
||||
total_bytes = tu_min16(ep0_pending[dir], xfer->max_size);
|
||||
ep0_pending[dir] -= total_bytes;
|
||||
}
|
||||
@@ -386,17 +468,31 @@ static void edpt_schedule_packets(uint8_t rhport, uint8_t const epnum, uint8_t c
|
||||
epin[epnum].dieptsiz = (num_packets << DIEPTSIZ_PKTCNT_Pos) |
|
||||
((total_bytes << DIEPTSIZ_XFRSIZ_Pos) & DIEPTSIZ_XFRSIZ_Msk);
|
||||
|
||||
epin[epnum].diepctl |= DIEPCTL_EPENA | DIEPCTL_CNAK;
|
||||
if(dma_enabled(dwc2)) {
|
||||
epin[epnum].diepdma = (uintptr_t)xfer->buffer;
|
||||
|
||||
// For ISO endpoint set correct odd/even bit for next frame.
|
||||
if ((epin[epnum].diepctl & DIEPCTL_EPTYP) == DIEPCTL_EPTYP_0 && (XFER_CTL_BASE(epnum, dir))->interval == 1) {
|
||||
// Take odd/even bit from frame counter.
|
||||
uint32_t const odd_frame_now = (dwc2->dsts & (1u << DSTS_FNSOF_Pos));
|
||||
epin[epnum].diepctl |= (odd_frame_now ? DIEPCTL_SD0PID_SEVNFRM_Msk : DIEPCTL_SODDFRM_Msk);
|
||||
}
|
||||
// Enable fifo empty interrupt only if there are something to put in the fifo.
|
||||
if (total_bytes != 0) {
|
||||
dwc2->diepempmsk |= (1 << epnum);
|
||||
// For ISO endpoint set correct odd/even bit for next frame.
|
||||
if ((epin[epnum].diepctl & DIEPCTL_EPTYP) == DIEPCTL_EPTYP_0 && (XFER_CTL_BASE(epnum, dir))->interval == 1) {
|
||||
// Take odd/even bit from frame counter.
|
||||
uint32_t const odd_frame_now = (dwc2->dsts & (1u << DSTS_FNSOF_Pos));
|
||||
epin[epnum].diepctl |= (odd_frame_now ? DIEPCTL_SD0PID_SEVNFRM_Msk : DIEPCTL_SODDFRM_Msk);
|
||||
}
|
||||
|
||||
epin[epnum].diepctl |= DIEPCTL_EPENA | DIEPCTL_CNAK;
|
||||
} else {
|
||||
|
||||
epin[epnum].diepctl |= DIEPCTL_EPENA | DIEPCTL_CNAK;
|
||||
|
||||
// For ISO endpoint set correct odd/even bit for next frame.
|
||||
if ((epin[epnum].diepctl & DIEPCTL_EPTYP) == DIEPCTL_EPTYP_0 && (XFER_CTL_BASE(epnum, dir))->interval == 1) {
|
||||
// Take odd/even bit from frame counter.
|
||||
uint32_t const odd_frame_now = (dwc2->dsts & (1u << DSTS_FNSOF_Pos));
|
||||
epin[epnum].diepctl |= (odd_frame_now ? DIEPCTL_SD0PID_SEVNFRM_Msk : DIEPCTL_SODDFRM_Msk);
|
||||
}
|
||||
// Enable fifo empty interrupt only if there are something to put in the fifo.
|
||||
if (total_bytes != 0) {
|
||||
dwc2->diepempmsk |= (1 << epnum);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
dwc2_epout_t* epout = dwc2->epout;
|
||||
@@ -406,31 +502,24 @@ static void edpt_schedule_packets(uint8_t rhport, uint8_t const epnum, uint8_t c
|
||||
epout[epnum].doeptsiz |= (num_packets << DOEPTSIZ_PKTCNT_Pos) |
|
||||
((total_bytes << DOEPTSIZ_XFRSIZ_Pos) & DOEPTSIZ_XFRSIZ_Msk);
|
||||
|
||||
epout[epnum].doepctl |= DOEPCTL_EPENA | DOEPCTL_CNAK;
|
||||
if ((epout[epnum].doepctl & DOEPCTL_EPTYP) == DOEPCTL_EPTYP_0 &&
|
||||
XFER_CTL_BASE(epnum, dir)->interval == 1) {
|
||||
// Take odd/even bit from frame counter.
|
||||
uint32_t const odd_frame_now = (dwc2->dsts & (1u << DSTS_FNSOF_Pos));
|
||||
epout[epnum].doepctl |= (odd_frame_now ? DOEPCTL_SD0PID_SEVNFRM_Msk : DOEPCTL_SODDFRM_Msk);
|
||||
}
|
||||
|
||||
if(dma_enabled(dwc2)) {
|
||||
epout[epnum].doepdma = (uintptr_t)xfer->buffer;
|
||||
}
|
||||
|
||||
epout[epnum].doepctl |= DOEPCTL_EPENA | DOEPCTL_CNAK;
|
||||
}
|
||||
}
|
||||
|
||||
/*------------------------------------------------------------------*/
|
||||
/* Controller API
|
||||
*------------------------------------------------------------------*/
|
||||
#if CFG_TUSB_DEBUG >= DWC2_DEBUG
|
||||
void print_dwc2_info(dwc2_regs_t* dwc2) {
|
||||
// print guid, gsnpsid, ghwcfg1, ghwcfg2, ghwcfg3, ghwcfg4
|
||||
// use dwc2_info.py/md for bit-field value and comparison with other ports
|
||||
volatile uint32_t const* p = (volatile uint32_t const*) &dwc2->guid;
|
||||
TU_LOG(DWC2_DEBUG, "guid, gsnpsid, ghwcfg1, ghwcfg2, ghwcfg3, ghwcfg4\r\n");
|
||||
for (size_t i = 0; i < 5; i++) {
|
||||
TU_LOG(DWC2_DEBUG, "0x%08" PRIX32 ", ", p[i]);
|
||||
}
|
||||
TU_LOG(DWC2_DEBUG, "0x%08" PRIX32 "\r\n", p[5]);
|
||||
}
|
||||
#endif
|
||||
|
||||
static void reset_core(dwc2_regs_t* dwc2) {
|
||||
// reset core
|
||||
@@ -449,13 +538,10 @@ static void reset_core(dwc2_regs_t* dwc2) {
|
||||
static bool phy_hs_supported(dwc2_regs_t* dwc2) {
|
||||
(void) dwc2;
|
||||
|
||||
#if TU_CHECK_MCU(OPT_MCU_ESP32S2, OPT_MCU_ESP32S3)
|
||||
// note: esp32 incorrect report its hs_phy_type as utmi
|
||||
return false;
|
||||
#elif !TUD_OPT_HIGH_SPEED
|
||||
#if !TUD_OPT_HIGH_SPEED
|
||||
return false;
|
||||
#else
|
||||
return dwc2->ghwcfg2_bm.hs_phy_type != HS_PHY_TYPE_NONE;
|
||||
return dwc2->ghwcfg2_bm.hs_phy_type != GHWCFG2_HSPHY_NOT_SUPPORTED;
|
||||
#endif
|
||||
}
|
||||
|
||||
@@ -466,7 +552,7 @@ static void phy_fs_init(dwc2_regs_t* dwc2) {
|
||||
dwc2->gusbcfg |= GUSBCFG_PHYSEL;
|
||||
|
||||
// MCU specific PHY init before reset
|
||||
dwc2_phy_init(dwc2, HS_PHY_TYPE_NONE);
|
||||
dwc2_phy_init(dwc2, GHWCFG2_HSPHY_NOT_SUPPORTED);
|
||||
|
||||
// Reset core after selecting PHY
|
||||
reset_core(dwc2);
|
||||
@@ -477,7 +563,7 @@ static void phy_fs_init(dwc2_regs_t* dwc2) {
|
||||
dwc2->gusbcfg = (dwc2->gusbcfg & ~GUSBCFG_TRDT_Msk) | (5u << GUSBCFG_TRDT_Pos);
|
||||
|
||||
// MCU specific PHY update post reset
|
||||
dwc2_phy_update(dwc2, HS_PHY_TYPE_NONE);
|
||||
dwc2_phy_update(dwc2, GHWCFG2_HSPHY_NOT_SUPPORTED);
|
||||
|
||||
// set max speed
|
||||
dwc2->dcfg = (dwc2->dcfg & ~DCFG_DSPD_Msk) | (DCFG_DSPD_FS << DCFG_DSPD_Pos);
|
||||
@@ -489,7 +575,7 @@ static void phy_hs_init(dwc2_regs_t* dwc2) {
|
||||
// De-select FS PHY
|
||||
gusbcfg &= ~GUSBCFG_PHYSEL;
|
||||
|
||||
if (dwc2->ghwcfg2_bm.hs_phy_type == HS_PHY_TYPE_ULPI) {
|
||||
if (dwc2->ghwcfg2_bm.hs_phy_type == GHWCFG2_HSPHY_ULPI) {
|
||||
TU_LOG(DWC2_DEBUG, "Highspeed ULPI PHY init\r\n");
|
||||
|
||||
// Select ULPI
|
||||
@@ -510,7 +596,9 @@ static void phy_hs_init(dwc2_regs_t* dwc2) {
|
||||
gusbcfg &= ~(GUSBCFG_ULPI_UTMI_SEL | GUSBCFG_PHYIF16);
|
||||
|
||||
// Set 16-bit interface if supported
|
||||
if (dwc2->ghwcfg4_bm.utmi_phy_data_width) gusbcfg |= GUSBCFG_PHYIF16;
|
||||
if (dwc2->ghwcfg4_bm.phy_data_width) {
|
||||
gusbcfg |= GUSBCFG_PHYIF16;
|
||||
}
|
||||
}
|
||||
|
||||
// Apply config
|
||||
@@ -526,7 +614,7 @@ static void phy_hs_init(dwc2_regs_t* dwc2) {
|
||||
// - 9 if using 8-bit PHY interface
|
||||
// - 5 if using 16-bit PHY interface
|
||||
gusbcfg &= ~GUSBCFG_TRDT_Msk;
|
||||
gusbcfg |= (dwc2->ghwcfg4_bm.utmi_phy_data_width ? 5u : 9u) << GUSBCFG_TRDT_Pos;
|
||||
gusbcfg |= (dwc2->ghwcfg4_bm.phy_data_width ? 5u : 9u) << GUSBCFG_TRDT_Pos;
|
||||
dwc2->gusbcfg = gusbcfg;
|
||||
|
||||
// MCU specific PHY update post reset
|
||||
@@ -539,17 +627,26 @@ static void phy_hs_init(dwc2_regs_t* dwc2) {
|
||||
|
||||
// XCVRDLY: transceiver delay between xcvr_sel and txvalid during device chirp is required
|
||||
// when using with some PHYs such as USB334x (USB3341, USB3343, USB3346, USB3347)
|
||||
if (dwc2->ghwcfg2_bm.hs_phy_type == HS_PHY_TYPE_ULPI) dcfg |= DCFG_XCVRDLY;
|
||||
if (dwc2->ghwcfg2_bm.hs_phy_type == GHWCFG2_HSPHY_ULPI) {
|
||||
dcfg |= DCFG_XCVRDLY;
|
||||
}
|
||||
|
||||
dwc2->dcfg = dcfg;
|
||||
}
|
||||
|
||||
static bool check_dwc2(dwc2_regs_t* dwc2) {
|
||||
#if CFG_TUSB_DEBUG >= DWC2_DEBUG
|
||||
print_dwc2_info(dwc2);
|
||||
// print guid, gsnpsid, ghwcfg1, ghwcfg2, ghwcfg3, ghwcfg4
|
||||
// Run 'dwc2_info.py render-md' and check dwc2_info.md for bit-field value and comparison with other ports
|
||||
volatile uint32_t const* p = (volatile uint32_t const*) &dwc2->guid;
|
||||
TU_LOG1("guid, gsnpsid, ghwcfg1, ghwcfg2, ghwcfg3, ghwcfg4\r\n");
|
||||
for (size_t i = 0; i < 5; i++) {
|
||||
TU_LOG1("0x%08" PRIX32 ", ", p[i]);
|
||||
}
|
||||
TU_LOG1("0x%08" PRIX32 "\r\n", p[5]);
|
||||
#endif
|
||||
|
||||
// For some reasons: GD32VF103 snpsid and all hwcfg register are always zero (skip it)
|
||||
// For some reason: GD32VF103 snpsid and all hwcfg register are always zero (skip it)
|
||||
(void) dwc2;
|
||||
#if !TU_CHECK_MCU(OPT_MCU_GD32VF103)
|
||||
uint32_t const gsnpsid = dwc2->gsnpsid & GSNPSID_ID_MASK;
|
||||
@@ -565,12 +662,9 @@ void dcd_init(uint8_t rhport) {
|
||||
dwc2_regs_t* dwc2 = DWC2_REG(rhport);
|
||||
|
||||
// Check Synopsys ID register, failed if controller clock/power is not enabled
|
||||
if (!check_dwc2(dwc2)) return;
|
||||
TU_ASSERT(check_dwc2(dwc2), );
|
||||
dcd_disconnect(rhport);
|
||||
|
||||
// max number of endpoints & total_fifo_size are:
|
||||
// hw_cfg2->num_dev_ep, hw_cfg2->total_fifo_size
|
||||
|
||||
if (phy_hs_supported(dwc2)) {
|
||||
phy_hs_init(dwc2); // Highspeed
|
||||
} else {
|
||||
@@ -600,8 +694,8 @@ void dcd_init(uint8_t rhport) {
|
||||
// (non zero-length packet), send STALL back and discard.
|
||||
dwc2->dcfg |= DCFG_NZLSOHSK;
|
||||
|
||||
fifo_flush_tx(dwc2, 0x10); // all tx fifo
|
||||
fifo_flush_rx(dwc2);
|
||||
dfifo_flush_tx(dwc2, 0x10); // all tx fifo
|
||||
dfifo_flush_rx(dwc2);
|
||||
|
||||
// Clear all interrupts
|
||||
uint32_t int_mask = dwc2->gintsts;
|
||||
@@ -610,12 +704,21 @@ void dcd_init(uint8_t rhport) {
|
||||
dwc2->gotgint |= int_mask;
|
||||
|
||||
// Required as part of core initialization.
|
||||
dwc2->gintmsk = GINTMSK_OTGINT | GINTMSK_RXFLVLM |
|
||||
GINTMSK_USBSUSPM | GINTMSK_USBRST | GINTMSK_ENUMDNEM | GINTMSK_WUIM;
|
||||
dwc2->gintmsk = GINTMSK_OTGINT | GINTMSK_USBSUSPM | GINTMSK_USBRST | GINTMSK_ENUMDNEM | GINTMSK_WUIM;
|
||||
|
||||
// Configure TX FIFO empty level for interrupt. Default is complete empty
|
||||
dwc2->gahbcfg |= GAHBCFG_TXFELVL;
|
||||
|
||||
if (dma_enabled(dwc2)) {
|
||||
const uint16_t epinfo_base = dma_cal_epfifo_base(rhport);
|
||||
dwc2->gdfifocfg = (epinfo_base << GDFIFOCFG_EPINFOBASE_SHIFT) | epinfo_base;
|
||||
|
||||
// DMA seems to be only settable after a core reset
|
||||
dwc2->gahbcfg |= GAHBCFG_DMAEN | GAHBCFG_HBSTLEN_2;
|
||||
}else {
|
||||
dwc2->gintmsk |= GINTMSK_RXFLVLM;
|
||||
}
|
||||
|
||||
// Enable global interrupt
|
||||
dwc2->gahbcfg |= GAHBCFG_GINT;
|
||||
|
||||
@@ -718,7 +821,7 @@ void dcd_sof_enable(uint8_t rhport, bool en) {
|
||||
*------------------------------------------------------------------*/
|
||||
|
||||
bool dcd_edpt_open(uint8_t rhport, tusb_desc_endpoint_t const* desc_edpt) {
|
||||
TU_ASSERT(fifo_alloc(rhport, desc_edpt->bEndpointAddress, tu_edpt_packet_size(desc_edpt)));
|
||||
TU_ASSERT(dfifo_alloc(rhport, desc_edpt->bEndpointAddress, tu_edpt_packet_size(desc_edpt)));
|
||||
edpt_activate(rhport, desc_edpt);
|
||||
return true;
|
||||
}
|
||||
@@ -728,6 +831,8 @@ void dcd_edpt_close_all(uint8_t rhport) {
|
||||
dwc2_regs_t* dwc2 = DWC2_REG(rhport);
|
||||
uint8_t const ep_count = _dwc2_controller[rhport].ep_count;
|
||||
|
||||
_allocated_ep_in_count = 1;
|
||||
|
||||
// Disable non-control interrupt
|
||||
dwc2->daintmsk = (1 << DAINTMSK_OEPM_Pos) | (1 << DAINTMSK_IEPM_Pos);
|
||||
|
||||
@@ -745,26 +850,21 @@ void dcd_edpt_close_all(uint8_t rhport) {
|
||||
xfer_status[n][TUSB_DIR_IN].max_size = 0;
|
||||
}
|
||||
|
||||
// reset allocated fifo OUT
|
||||
dwc2->grxfsiz = calc_grxfsiz(64, ep_count);
|
||||
// reset allocated fifo IN
|
||||
_allocated_fifo_words_tx = 16;
|
||||
dfifo_flush_tx(dwc2, 0x10); // all tx fifo
|
||||
dfifo_flush_rx(dwc2);
|
||||
|
||||
fifo_flush_tx(dwc2, 0x10); // all tx fifo
|
||||
fifo_flush_rx(dwc2);
|
||||
dfifo_init(rhport); // re-init dfifo
|
||||
}
|
||||
|
||||
bool dcd_edpt_iso_alloc(uint8_t rhport, uint8_t ep_addr, uint16_t largest_packet_size) {
|
||||
TU_ASSERT(fifo_alloc(rhport, ep_addr, largest_packet_size));
|
||||
TU_ASSERT(dfifo_alloc(rhport, ep_addr, largest_packet_size));
|
||||
return true;
|
||||
}
|
||||
|
||||
bool dcd_edpt_iso_activate(uint8_t rhport, tusb_desc_endpoint_t const * p_endpoint_desc) {
|
||||
// Disable EP to clear potential incomplete transfers
|
||||
edpt_disable(rhport, p_endpoint_desc->bEndpointAddress, false);
|
||||
|
||||
edpt_activate(rhport, p_endpoint_desc);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -831,6 +931,9 @@ void dcd_edpt_close(uint8_t rhport, uint8_t ep_addr) {
|
||||
|
||||
void dcd_edpt_stall(uint8_t rhport, uint8_t ep_addr) {
|
||||
edpt_disable(rhport, ep_addr, true);
|
||||
if((tu_edpt_number(ep_addr) == 0) && dma_enabled(DWC2_REG(rhport))) {
|
||||
dma_setup_prepare(rhport);
|
||||
}
|
||||
}
|
||||
|
||||
void dcd_edpt_clear_stall(uint8_t rhport, uint8_t ep_addr) {
|
||||
@@ -851,56 +954,9 @@ void dcd_edpt_clear_stall(uint8_t rhport, uint8_t ep_addr) {
|
||||
}
|
||||
}
|
||||
|
||||
/*------------------------------------------------------------------*/
|
||||
|
||||
// Read a single data packet from receive FIFO
|
||||
static void read_fifo_packet(uint8_t rhport, uint8_t* dst, uint16_t len) {
|
||||
(void) rhport;
|
||||
|
||||
dwc2_regs_t* dwc2 = DWC2_REG(rhport);
|
||||
volatile const uint32_t* rx_fifo = dwc2->fifo[0];
|
||||
|
||||
// Reading full available 32 bit words from fifo
|
||||
uint16_t full_words = len >> 2;
|
||||
while (full_words--) {
|
||||
tu_unaligned_write32(dst, *rx_fifo);
|
||||
dst += 4;
|
||||
}
|
||||
|
||||
// Read the remaining 1-3 bytes from fifo
|
||||
uint8_t const bytes_rem = len & 0x03;
|
||||
if (bytes_rem != 0) {
|
||||
uint32_t const tmp = *rx_fifo;
|
||||
dst[0] = tu_u32_byte0(tmp);
|
||||
if (bytes_rem > 1) dst[1] = tu_u32_byte1(tmp);
|
||||
if (bytes_rem > 2) dst[2] = tu_u32_byte2(tmp);
|
||||
}
|
||||
}
|
||||
|
||||
// Write a single data packet to EPIN FIFO
|
||||
static void write_fifo_packet(uint8_t rhport, uint8_t fifo_num, uint8_t const* src, uint16_t len) {
|
||||
(void) rhport;
|
||||
|
||||
dwc2_regs_t* dwc2 = DWC2_REG(rhport);
|
||||
volatile uint32_t* tx_fifo = dwc2->fifo[fifo_num];
|
||||
|
||||
// Pushing full available 32 bit words to fifo
|
||||
uint16_t full_words = len >> 2;
|
||||
while (full_words--) {
|
||||
*tx_fifo = tu_unaligned_read32(src);
|
||||
src += 4;
|
||||
}
|
||||
|
||||
// Write the remaining 1-3 bytes into fifo
|
||||
uint8_t const bytes_rem = len & 0x03;
|
||||
if (bytes_rem) {
|
||||
uint32_t tmp_word = src[0];
|
||||
if (bytes_rem > 1) tmp_word |= (src[1] << 8);
|
||||
if (bytes_rem > 2) tmp_word |= (src[2] << 16);
|
||||
|
||||
*tx_fifo = tmp_word;
|
||||
}
|
||||
}
|
||||
//--------------------------------------------------------------------
|
||||
// Interrupt Handler
|
||||
//--------------------------------------------------------------------
|
||||
|
||||
static void handle_rxflvl_irq(uint8_t rhport) {
|
||||
dwc2_regs_t* dwc2 = DWC2_REG(rhport);
|
||||
@@ -954,7 +1010,7 @@ static void handle_rxflvl_irq(uint8_t rhport) {
|
||||
tu_fifo_write_n_const_addr_full_words(xfer->ff, (const void*) (uintptr_t) rx_fifo, bcnt);
|
||||
} else {
|
||||
// Linear buffer
|
||||
read_fifo_packet(rhport, xfer->buffer, bcnt);
|
||||
dfifo_read_packet(rhport, xfer->buffer, bcnt);
|
||||
|
||||
// Increment pointer to xfer data
|
||||
xfer->buffer += bcnt;
|
||||
@@ -978,21 +1034,7 @@ static void handle_rxflvl_irq(uint8_t rhport) {
|
||||
// XFRC complete is additionally generated when
|
||||
// - setup packet is received
|
||||
// - complete the data stage of control write is complete
|
||||
if ((epnum == 0) && (bcnt == 0) && (dwc2->gsnpsid >= DWC2_CORE_REV_3_00a)) {
|
||||
uint32_t doepint = epout->doepint;
|
||||
|
||||
if (doepint & (DOEPINT_STPKTRX | DOEPINT_OTEPSPR)) {
|
||||
// skip this "no-data" transfer complete event
|
||||
// Note: STPKTRX will be clear later by setup received handler
|
||||
uint32_t clear_flags = DOEPINT_XFRC;
|
||||
|
||||
if (doepint & DOEPINT_OTEPSPR) clear_flags |= DOEPINT_OTEPSPR;
|
||||
|
||||
epout->doepint = clear_flags;
|
||||
|
||||
// TU_LOG(DWC2_DEBUG, " FIX extra transfer complete on setup/data compete\r\n");
|
||||
}
|
||||
}
|
||||
// It will be handled in handle_epout_irq()
|
||||
break;
|
||||
|
||||
default: // Invalid
|
||||
@@ -1013,18 +1055,7 @@ static void handle_epout_irq(uint8_t rhport) {
|
||||
|
||||
uint32_t const doepint = epout->doepint;
|
||||
|
||||
// SETUP packet Setup Phase done.
|
||||
if (doepint & DOEPINT_STUP) {
|
||||
uint32_t clear_flag = DOEPINT_STUP;
|
||||
|
||||
// STPKTRX is only available for version from 3_00a
|
||||
if ((doepint & DOEPINT_STPKTRX) && (dwc2->gsnpsid >= DWC2_CORE_REV_3_00a)) {
|
||||
clear_flag |= DOEPINT_STPKTRX;
|
||||
}
|
||||
|
||||
epout->doepint = clear_flag;
|
||||
dcd_event_setup_received(rhport, (uint8_t*) _setup_packet, true);
|
||||
}
|
||||
TU_ASSERT((epout->doepint & DOEPINT_AHBERR) == 0, );
|
||||
|
||||
// OUT XFER complete
|
||||
if (epout->doepint & DOEPINT_XFRC) {
|
||||
@@ -1032,14 +1063,66 @@ static void handle_epout_irq(uint8_t rhport) {
|
||||
|
||||
xfer_ctl_t* xfer = XFER_CTL_BASE(n, TUSB_DIR_OUT);
|
||||
|
||||
// EP0 can only handle one packet
|
||||
if ((n == 0) && ep0_pending[TUSB_DIR_OUT]) {
|
||||
// Schedule another packet to be received.
|
||||
edpt_schedule_packets(rhport, n, TUSB_DIR_OUT, 1, ep0_pending[TUSB_DIR_OUT]);
|
||||
if(dma_enabled(dwc2)) {
|
||||
if (doepint & DOEPINT_STUP) {
|
||||
// STPKTRX is only available for version from 3_00a
|
||||
if ((doepint & DOEPINT_STPKTRX) && (dwc2->gsnpsid > DWC2_CORE_REV_3_00a)) {
|
||||
epout->doepint = DOEPINT_STPKTRX;
|
||||
}
|
||||
} else if (doepint & DOEPINT_OTEPSPR) {
|
||||
epout->doepint = DOEPINT_OTEPSPR;
|
||||
} else {
|
||||
if ((doepint & DOEPINT_STPKTRX) && (dwc2->gsnpsid > DWC2_CORE_REV_3_00a)) {
|
||||
epout->doepint = DOEPINT_STPKTRX;
|
||||
} else {
|
||||
// EP0 can only handle one packet
|
||||
if ((n == 0) && ep0_pending[TUSB_DIR_OUT]) {
|
||||
// Schedule another packet to be received.
|
||||
edpt_schedule_packets(rhport, n, TUSB_DIR_OUT, 1, ep0_pending[TUSB_DIR_OUT]);
|
||||
} else {
|
||||
// Fix packet length
|
||||
uint16_t remain = (epout->doeptsiz & DOEPTSIZ_XFRSIZ_Msk) >> DOEPTSIZ_XFRSIZ_Pos;
|
||||
xfer->total_len -= remain;
|
||||
// this is ZLP, so prepare EP0 for next setup
|
||||
if(n == 0 && xfer->total_len == 0) {
|
||||
dma_setup_prepare(rhport);
|
||||
}
|
||||
|
||||
dcd_event_xfer_complete(rhport, n, xfer->total_len, XFER_RESULT_SUCCESS, true);
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
dcd_event_xfer_complete(rhport, n, xfer->total_len, XFER_RESULT_SUCCESS, true);
|
||||
if ((doepint & DOEPINT_STPKTRX) && (dwc2->gsnpsid == DWC2_CORE_REV_3_10a)) {
|
||||
epout->doepint = DOEPINT_STPKTRX;
|
||||
} else {
|
||||
if ((doepint & DOEPINT_OTEPSPR) && (dwc2->gsnpsid == DWC2_CORE_REV_3_10a)) {
|
||||
epout->doepint = DOEPINT_OTEPSPR;
|
||||
}
|
||||
|
||||
// EP0 can only handle one packet
|
||||
if ((n == 0) && ep0_pending[TUSB_DIR_OUT]) {
|
||||
// Schedule another packet to be received.
|
||||
edpt_schedule_packets(rhport, n, TUSB_DIR_OUT, 1, ep0_pending[TUSB_DIR_OUT]);
|
||||
} else {
|
||||
dcd_event_xfer_complete(rhport, n, xfer->total_len, XFER_RESULT_SUCCESS, true);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// SETUP packet Setup Phase done.
|
||||
if (doepint & DOEPINT_STUP) {
|
||||
epout->doepint = DOEPINT_STUP;
|
||||
if ((doepint & DOEPINT_STPKTRX) && (dwc2->gsnpsid > DWC2_CORE_REV_3_00a)) {
|
||||
epout->doepint = DOEPINT_STPKTRX;
|
||||
}
|
||||
if(dma_enabled(dwc2) && (dwc2->gsnpsid > DWC2_CORE_REV_3_00a)) {
|
||||
dma_setup_prepare(rhport);
|
||||
}
|
||||
|
||||
dcd_event_setup_received(rhport, (uint8_t*) _setup_packet, true);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1064,6 +1147,9 @@ static void handle_epin_irq(uint8_t rhport) {
|
||||
// Schedule another packet to be transmitted.
|
||||
edpt_schedule_packets(rhport, n, TUSB_DIR_IN, 1, ep0_pending[TUSB_DIR_IN]);
|
||||
} else {
|
||||
if((n == 0) && dma_enabled(dwc2)) {
|
||||
dma_setup_prepare(rhport);
|
||||
}
|
||||
dcd_event_xfer_complete(rhport, n | TUSB_DIR_IN_MASK, xfer->total_len, XFER_RESULT_SUCCESS, true);
|
||||
}
|
||||
}
|
||||
@@ -1093,7 +1179,7 @@ static void handle_epin_irq(uint8_t rhport) {
|
||||
volatile uint32_t* tx_fifo = dwc2->fifo[n];
|
||||
tu_fifo_read_n_const_addr_full_words(xfer->ff, (void*) (uintptr_t) tx_fifo, packet_size);
|
||||
} else {
|
||||
write_fifo_packet(rhport, n, xfer->buffer, packet_size);
|
||||
dfifo_write_packet(rhport, n, xfer->buffer, packet_size);
|
||||
|
||||
// Increment pointer to xfer data
|
||||
xfer->buffer += packet_size;
|
||||
|
||||
@@ -39,7 +39,7 @@
|
||||
|
||||
static const dwc2_controller_t _dwc2_controller[] =
|
||||
{
|
||||
{ .reg_base = USB_OTG_GLOBAL_BASE, .irqnum = USB_IRQn, .ep_count = DWC2_EP_MAX, .ep_fifo_size = 4096 }
|
||||
{ .reg_base = USB_OTG_GLOBAL_BASE, .irqnum = USB_IRQn, .ep_count = DWC2_EP_MAX, .ep_fifo_size = 16384 }
|
||||
};
|
||||
|
||||
#define dcache_clean(_addr, _size) data_clean(_addr, _size)
|
||||
|
||||
@@ -38,28 +38,41 @@
|
||||
#include "soc/periph_defs.h"
|
||||
#include "soc/usb_wrap_struct.h"
|
||||
|
||||
#define DWC2_REG_BASE 0x60080000UL
|
||||
#define DWC2_EP_MAX 6 // USB_OUT_EP_NUM. TODO ESP32Sx only has 5 tx fifo (5 endpoint IN)
|
||||
#if TU_CHECK_MCU(OPT_MCU_ESP32S2, OPT_MCU_ESP32S3)
|
||||
#define DWC2_FS_REG_BASE 0x60080000UL
|
||||
#define DWC2_EP_MAX 7
|
||||
|
||||
static const dwc2_controller_t _dwc2_controller[] = {
|
||||
{ .reg_base = DWC2_REG_BASE, .irqnum = 0, .ep_count = DWC2_EP_MAX, .ep_fifo_size = 1024 }
|
||||
{ .reg_base = DWC2_FS_REG_BASE, .irqnum = ETS_USB_INTR_SOURCE, .ep_count = 7, .ep_in_count = 5, .ep_fifo_size = 1024 }
|
||||
};
|
||||
|
||||
static intr_handle_t usb_ih;
|
||||
#elif TU_CHECK_MCU(OPT_MCU_ESP32P4)
|
||||
#define DWC2_FS_REG_BASE 0x50040000UL
|
||||
#define DWC2_HS_REG_BASE 0x50000000UL
|
||||
#define DWC2_EP_MAX 16
|
||||
|
||||
// On ESP32 for consistency we associate
|
||||
// - Port0 to OTG_FS, and Port1 to OTG_HS
|
||||
static const dwc2_controller_t _dwc2_controller[] = {
|
||||
{ .reg_base = DWC2_FS_REG_BASE, .irqnum = ETS_USB_OTG11_CH0_INTR_SOURCE, .ep_count = 7, .ep_in_count = 5, .ep_fifo_size = 1024 },
|
||||
{ .reg_base = DWC2_HS_REG_BASE, .irqnum = ETS_USB_OTG_INTR_SOURCE, .ep_count = 16, .ep_in_count = 8, .ep_fifo_size = 4096 }
|
||||
};
|
||||
#endif
|
||||
|
||||
static intr_handle_t usb_ih[TU_ARRAY_SIZE(_dwc2_controller)];
|
||||
|
||||
static void dcd_int_handler_wrap(void* arg) {
|
||||
(void)arg;
|
||||
dcd_int_handler(0);
|
||||
const uint8_t rhport = (uint8_t)(uintptr_t) arg;
|
||||
dcd_int_handler(rhport);
|
||||
}
|
||||
|
||||
TU_ATTR_ALWAYS_INLINE static inline void dwc2_dcd_int_enable(uint8_t rhport) {
|
||||
(void)rhport;
|
||||
esp_intr_alloc(ETS_USB_INTR_SOURCE, ESP_INTR_FLAG_LOWMED, dcd_int_handler_wrap, NULL, &usb_ih);
|
||||
esp_intr_alloc(_dwc2_controller[rhport].irqnum, ESP_INTR_FLAG_LOWMED,
|
||||
dcd_int_handler_wrap, (void*)(uintptr_t) rhport, &usb_ih[rhport]);
|
||||
}
|
||||
|
||||
TU_ATTR_ALWAYS_INLINE static inline void dwc2_dcd_int_disable(uint8_t rhport) {
|
||||
(void)rhport;
|
||||
esp_intr_free(usb_ih);
|
||||
esp_intr_free(usb_ih[rhport]);
|
||||
}
|
||||
|
||||
TU_ATTR_ALWAYS_INLINE static inline void dwc2_remote_wakeup_delay(void) {
|
||||
@@ -70,7 +83,6 @@ TU_ATTR_ALWAYS_INLINE static inline void dwc2_remote_wakeup_delay(void) {
|
||||
TU_ATTR_ALWAYS_INLINE static inline void dwc2_phy_init(dwc2_regs_t* dwc2, uint8_t hs_phy_type) {
|
||||
(void)dwc2;
|
||||
(void)hs_phy_type;
|
||||
|
||||
// nothing to do
|
||||
}
|
||||
|
||||
@@ -78,7 +90,6 @@ TU_ATTR_ALWAYS_INLINE static inline void dwc2_phy_init(dwc2_regs_t* dwc2, uint8_
|
||||
TU_ATTR_ALWAYS_INLINE static inline void dwc2_phy_update(dwc2_regs_t* dwc2, uint8_t hs_phy_type) {
|
||||
(void)dwc2;
|
||||
(void)hs_phy_type;
|
||||
|
||||
// nothing to do
|
||||
}
|
||||
|
||||
|
||||
@@ -1,55 +1,58 @@
|
||||
| | BCM2711 (Pi4) | EFM32GG FullSpeed | ESP32-S2 | STM32F407 Fullspeed | STM32F407 Highspeed | STM32F411 Fullspeed | STM32F412 Fullspeed | STM32F429 Fullspeed | STM32F429 Highspeed | STM32F723 Fullspeed | STM32F723 HighSpeed | STM32F767 Fullspeed | STM32H743 Highspeed | STM32L476 Fullspeed | STM32U5A5 Highspeed | GD32VF103 Fullspeed | XMC4500 |
|
||||
|:----------------------------|:----------------|:--------------------|:-----------|:----------------------|:----------------------|:----------------------|:----------------------|:----------------------|:----------------------|:----------------------|:----------------------|:----------------------|:----------------------|:----------------------|:----------------------|:----------------------|:-----------|
|
||||
| guid | 0x2708A000 | 0x00000000 | 0x00000000 | 0x00001200 | 0x00001100 | 0x00001200 | 0x00002000 | 0x00001200 | 0x00001100 | 0x00003000 | 0x00003100 | 0x00002000 | 0x00002300 | 0x00002000 | 0x00005000 | 0x00001000 | 0x00AEC000 |
|
||||
| gsnpsid | 0x4F54280A | 0x4F54330A | 0x4F54400A | 0x4F54281A | 0x4F54281A | 0x4F54281A | 0x4F54320A | 0x4F54281A | 0x4F54281A | 0x4F54330A | 0x4F54330A | 0x4F54320A | 0x4F54330A | 0x4F54310A | 0x4F54411A | 0x00000000 | 0x4F54292A |
|
||||
| - specs version | 2.80a | 3.30a | 4.00a | 2.81a | 2.81a | 2.81a | 3.20a | 2.81a | 2.81a | 3.30a | 3.30a | 3.20a | 3.30a | 3.10a | 4.11a | 0.00W | 2.92a |
|
||||
| ghwcfg1 | 0x00000000 | 0x00000000 | 0x00000000 | 0x00000000 | 0x00000000 | 0x00000000 | 0x00000000 | 0x00000000 | 0x00000000 | 0x00000000 | 0x00000000 | 0x00000000 | 0x00000000 | 0x00000000 | 0x00000000 | 0x00000000 | 0x00000000 |
|
||||
| ghwcfg2 | 0x228DDD50 | 0x228F5910 | 0x224DD930 | 0x229DCD20 | 0x229ED590 | 0x229DCD20 | 0x229ED520 | 0x229DCD20 | 0x229ED590 | 0x229ED520 | 0x229FE1D0 | 0x229ED520 | 0x229FE190 | 0x229ED520 | 0x228FE052 | 0x00000000 | 0x228F5930 |
|
||||
| - op_mode | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 2 | 0 | 0 |
|
||||
| - arch | 2 | 2 | 2 | 0 | 2 | 0 | 0 | 0 | 2 | 0 | 2 | 0 | 2 | 0 | 2 | 0 | 2 |
|
||||
| - point2point | 0 | 0 | 1 | 1 | 0 | 1 | 1 | 1 | 0 | 1 | 0 | 1 | 0 | 1 | 0 | 0 | 1 |
|
||||
| - hs_phy_type | 1 | 0 | 0 | 0 | 2 | 0 | 0 | 0 | 2 | 0 | 3 | 0 | 2 | 0 | 1 | 0 | 0 |
|
||||
| - fs_phy_type | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 0 | 0 | 1 |
|
||||
| - num_dev_ep | 7 | 6 | 6 | 3 | 5 | 3 | 5 | 3 | 5 | 5 | 8 | 5 | 8 | 5 | 8 | 0 | 6 |
|
||||
| - num_host_ch | 7 | 13 | 7 | 7 | 11 | 7 | 11 | 7 | 11 | 11 | 15 | 11 | 15 | 11 | 15 | 0 | 13 |
|
||||
| - period_channel_support | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 0 | 1 |
|
||||
| - enable_dynamic_fifo | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 0 | 1 |
|
||||
| - mul_cpu_int | 0 | 0 | 0 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 0 | 0 | 0 |
|
||||
| - reserved21 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 |
|
||||
| - nperiod_tx_q_depth | 2 | 2 | 1 | 2 | 2 | 2 | 2 | 2 | 2 | 2 | 2 | 2 | 2 | 2 | 2 | 0 | 2 |
|
||||
| - host_period_tx_q_depth | 2 | 2 | 2 | 2 | 2 | 2 | 2 | 2 | 2 | 2 | 2 | 2 | 2 | 2 | 2 | 0 | 2 |
|
||||
| - dev_token_q_depth | 8 | 8 | 8 | 8 | 8 | 8 | 8 | 8 | 8 | 8 | 8 | 8 | 8 | 8 | 8 | 0 | 8 |
|
||||
| - otg_enable_ic_usb | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 |
|
||||
| ghwcfg3 | 0x0FF000E8 | 0x01F204E8 | 0x00C804B5 | 0x020001E8 | 0x03F403E8 | 0x020001E8 | 0x0200D1E8 | 0x020001E8 | 0x03F403E8 | 0x0200D1E8 | 0x03EED2E8 | 0x0200D1E8 | 0x03B8D2E8 | 0x0200D1E8 | 0x03B882E8 | 0x00000000 | 0x027A01E5 |
|
||||
| - xfer_size_width | 8 | 8 | 5 | 8 | 8 | 8 | 8 | 8 | 8 | 8 | 8 | 8 | 8 | 8 | 8 | 0 | 5 |
|
||||
| - packet_size_width | 6 | 6 | 3 | 6 | 6 | 6 | 6 | 6 | 6 | 6 | 6 | 6 | 6 | 6 | 6 | 0 | 6 |
|
||||
| - otg_enable | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 0 | 1 |
|
||||
| - i2c_enable | 0 | 0 | 0 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 0 | 1 | 0 | 1 | 0 | 0 | 1 |
|
||||
| - vendor_ctrl_itf | 0 | 0 | 0 | 0 | 1 | 0 | 0 | 0 | 1 | 0 | 1 | 0 | 1 | 0 | 1 | 0 | 0 |
|
||||
| - optional_feature_removed | 0 | 1 | 1 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 |
|
||||
| - synch_reset | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 |
|
||||
| - otg_adp_support | 0 | 0 | 0 | 0 | 0 | 0 | 1 | 0 | 0 | 1 | 1 | 1 | 1 | 1 | 0 | 0 | 0 |
|
||||
| - otg_enable_hsic | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 |
|
||||
| - battery_charger_support | 0 | 0 | 0 | 0 | 0 | 0 | 1 | 0 | 0 | 1 | 1 | 1 | 1 | 1 | 0 | 0 | 0 |
|
||||
| - lpm_mode | 0 | 0 | 0 | 0 | 0 | 0 | 1 | 0 | 0 | 1 | 1 | 1 | 1 | 1 | 1 | 0 | 0 |
|
||||
| - total_fifo_size | 4080 | 498 | 200 | 512 | 1012 | 512 | 512 | 512 | 1012 | 512 | 1006 | 512 | 952 | 512 | 952 | 0 | 634 |
|
||||
| ghwcfg4 | 0x1FF00020 | 0x1BF08030 | 0xD3F0A030 | 0x0FF08030 | 0x17F00030 | 0x0FF08030 | 0x17F08030 | 0x0FF08030 | 0x17F00030 | 0x17F08030 | 0x23F00030 | 0x17F08030 | 0xE3F00030 | 0x17F08030 | 0xE2103E30 | 0x00000000 | 0xDBF08030 |
|
||||
| - num_dev_period_in_ep | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 |
|
||||
| - power_optimized | 0 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 0 | 1 |
|
||||
| - ahb_freq_min | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 0 | 1 |
|
||||
| - hibernation | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 |
|
||||
| - reserved7 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 4 | 0 | 0 |
|
||||
| - service_interval_mode | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 1 | 0 | 0 |
|
||||
| - ipg_isoc_en | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 1 | 0 | 0 |
|
||||
| - acg_enable | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 1 | 0 | 0 |
|
||||
| - reserved13 | 0 | 0 | 1 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 1 | 0 | 0 |
|
||||
| - utmi_phy_data_width | 0 | 2 | 2 | 2 | 0 | 2 | 2 | 2 | 0 | 2 | 0 | 2 | 0 | 2 | 0 | 0 | 2 |
|
||||
| - dev_ctrl_ep_num | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 |
|
||||
| - iddg_filter_enabled | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 0 | 1 |
|
||||
| - vbus_valid_filter_enabled | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 0 | 0 | 1 |
|
||||
| - a_valid_filter_enabled | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 0 | 0 | 1 |
|
||||
| - b_valid_filter_enabled | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 0 | 0 | 1 |
|
||||
| - dedicated_fifos | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 0 | 0 | 1 |
|
||||
| - num_dev_in_eps | 15 | 13 | 9 | 7 | 11 | 7 | 11 | 7 | 11 | 11 | 1 | 11 | 1 | 11 | 1 | 0 | 13 |
|
||||
| - dma_desc_enable | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 1 | 0 | 1 | 0 | 1 | 0 | 0 |
|
||||
| - dma_dynamic | 0 | 0 | 1 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 1 | 0 | 1 | 0 | 1 |
|
||||
| | BCM2711 (Pi4) | EFM32GG FS | ESP32-S2/S3 | ESP32-P4 | STM32F 407/411/429 FS | STM32F 407/429 HS | STM32F 412/767 FS | STM32F723 FS | STM32F723 HS | STM32H743 HS | STM32L476 FS | STM32U5A5 HS | GD32VF103 FS | XMC4500 |
|
||||
|:---------------------------|:----------------|:-------------|:--------------|:-----------|:------------------------|:--------------------|:--------------------|:---------------|:---------------|:---------------|:---------------|:---------------|:---------------|:-----------|
|
||||
| guid | 0x2708A000 | 0x00000000 | 0x00000000 | 0x00000000 | 0x00001200 | 0x00001100 | 0x00002000 | 0x00003000 | 0x00003100 | 0x00002300 | 0x00002000 | 0x00005000 | 0x00001000 | 0x00AEC000 |
|
||||
| gsnpsid | 0x4F54280A | 0x4F54330A | 0x4F54400A | 0x4F54400A | 0x4F54281A | 0x4F54281A | 0x4F54320A | 0x4F54330A | 0x4F54330A | 0x4F54330A | 0x4F54310A | 0x4F54411A | 0x00000000 | 0x4F54292A |
|
||||
| - specs version | 2.80a | 3.30a | 4.00a | 4.00a | 2.81a | 2.81a | 3.20a | 3.30a | 3.30a | 3.30a | 3.10a | 4.11a | 0.00W | 2.92a |
|
||||
| ghwcfg1 | 0x00000000 | 0x00000000 | 0x00000000 | 0x00000000 | 0x00000000 | 0x00000000 | 0x00000000 | 0x00000000 | 0x00000000 | 0x00000000 | 0x00000000 | 0x00000000 | 0x00000000 | 0x00000000 |
|
||||
| ghwcfg2 | 0x228DDD50 | 0x228F5910 | 0x224DD930 | 0x215FFFD0 | 0x229DCD20 | 0x229ED590 | 0x229ED520 | 0x229ED520 | 0x229FE1D0 | 0x229FE190 | 0x229ED520 | 0x228FE052 | 0x00000000 | 0x228F5930 |
|
||||
| - op_mode | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 2 | 0 | 0 |
|
||||
| - arch | 2 | 2 | 2 | 2 | 0 | 2 | 0 | 0 | 2 | 2 | 0 | 2 | 0 | 2 |
|
||||
| - point2point | 0 | 0 | 1 | 0 | 1 | 0 | 1 | 1 | 0 | 0 | 1 | 0 | 0 | 1 |
|
||||
| - hs_phy_type | 1 | 0 | 0 | 3 | 0 | 2 | 0 | 0 | 3 | 2 | 0 | 1 | 0 | 0 |
|
||||
| - fs_phy_type | 1 | 1 | 1 | 3 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 0 | 0 | 1 |
|
||||
| - num_dev_ep | 7 | 6 | 6 | 15 | 3 | 5 | 5 | 5 | 8 | 8 | 5 | 8 | 0 | 6 |
|
||||
| - num_host_ch | 7 | 13 | 7 | 15 | 7 | 11 | 11 | 11 | 15 | 15 | 11 | 15 | 0 | 13 |
|
||||
| - period_channel_support | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 0 | 1 |
|
||||
| - enable_dynamic_fifo | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 0 | 1 |
|
||||
| - mul_cpu_int | 0 | 0 | 0 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 0 | 0 | 0 |
|
||||
| - reserved21 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 |
|
||||
| - nptx_q_depth | 2 | 2 | 1 | 1 | 2 | 2 | 2 | 2 | 2 | 2 | 2 | 2 | 0 | 2 |
|
||||
| - ptx_q_depth | 2 | 2 | 2 | 1 | 2 | 2 | 2 | 2 | 2 | 2 | 2 | 2 | 0 | 2 |
|
||||
| - token_q_depth | 8 | 8 | 8 | 8 | 8 | 8 | 8 | 8 | 8 | 8 | 8 | 8 | 0 | 8 |
|
||||
| - otg_enable_ic_usb | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 |
|
||||
| ghwcfg3 | 0x0FF000E8 | 0x01F204E8 | 0x00C804B5 | 0x03805EB5 | 0x020001E8 | 0x03F403E8 | 0x0200D1E8 | 0x0200D1E8 | 0x03EED2E8 | 0x03B8D2E8 | 0x0200D1E8 | 0x03B882E8 | 0x00000000 | 0x027A01E5 |
|
||||
| - xfer_size_width | 8 | 8 | 5 | 5 | 8 | 8 | 8 | 8 | 8 | 8 | 8 | 8 | 0 | 5 |
|
||||
| - packet_size_width | 6 | 6 | 3 | 3 | 6 | 6 | 6 | 6 | 6 | 6 | 6 | 6 | 0 | 6 |
|
||||
| - otg_enable | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 0 | 1 |
|
||||
| - i2c_enable | 0 | 0 | 0 | 0 | 1 | 1 | 1 | 1 | 0 | 0 | 1 | 0 | 0 | 1 |
|
||||
| - vendor_ctrl_itf | 0 | 0 | 0 | 1 | 0 | 1 | 0 | 0 | 1 | 1 | 0 | 1 | 0 | 0 |
|
||||
| - optional_feature_removed | 0 | 1 | 1 | 1 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 |
|
||||
| - synch_reset | 0 | 0 | 0 | 1 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 |
|
||||
| - otg_adp_support | 0 | 0 | 0 | 1 | 0 | 0 | 1 | 1 | 1 | 1 | 1 | 0 | 0 | 0 |
|
||||
| - otg_enable_hsic | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 |
|
||||
| - battery_charger_support | 0 | 0 | 0 | 1 | 0 | 0 | 1 | 1 | 1 | 1 | 1 | 0 | 0 | 0 |
|
||||
| - lpm_mode | 0 | 0 | 0 | 0 | 0 | 0 | 1 | 1 | 1 | 1 | 1 | 1 | 0 | 0 |
|
||||
| - dfifo_depth | 4080 | 498 | 200 | 896 | 512 | 1012 | 512 | 512 | 1006 | 952 | 512 | 952 | 0 | 634 |
|
||||
| ghwcfg4 | 0x1FF00020 | 0x1BF08030 | 0xD3F0A030 | 0xDFF1A030 | 0x0FF08030 | 0x17F00030 | 0x17F08030 | 0x17F08030 | 0x23F00030 | 0xE3F00030 | 0x17F08030 | 0xE2103E30 | 0x00000000 | 0xDBF08030 |
|
||||
| - num_dev_period_in_ep | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 |
|
||||
| - partial_powerdown | 0 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 0 | 1 |
|
||||
| - ahb_freq_min | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 0 | 1 |
|
||||
| - hibernation | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 |
|
||||
| - extended_hibernation | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 |
|
||||
| - reserved8 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 |
|
||||
| - enhanced_lpm_support1 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 1 | 0 | 0 |
|
||||
| - service_interval_flow | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 1 | 0 | 0 |
|
||||
| - ipg_isoc_support | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 1 | 0 | 0 |
|
||||
| - acg_support | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 1 | 0 | 0 |
|
||||
| - enhanced_lpm_support | 0 | 0 | 1 | 1 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 1 | 0 | 0 |
|
||||
| - phy_data_width | 0 | 2 | 2 | 2 | 2 | 0 | 2 | 2 | 0 | 0 | 2 | 0 | 0 | 2 |
|
||||
| - ctrl_ep_num | 0 | 0 | 0 | 1 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 |
|
||||
| - iddg_filter | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 0 | 1 |
|
||||
| - vbus_valid_filter | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 0 | 0 | 1 |
|
||||
| - a_valid_filter | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 0 | 0 | 1 |
|
||||
| - b_valid_filter | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 0 | 0 | 1 |
|
||||
| - session_end_filter | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 0 | 0 | 1 |
|
||||
| - dedicated_fifos | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 0 | 1 |
|
||||
| - num_dev_in_eps | 7 | 6 | 4 | 7 | 3 | 5 | 5 | 5 | 8 | 8 | 5 | 8 | 0 | 6 |
|
||||
| - dma_desc_enable | 0 | 0 | 1 | 1 | 0 | 0 | 0 | 0 | 0 | 1 | 0 | 1 | 0 | 1 |
|
||||
| - dma_desc_dynamic | 0 | 0 | 1 | 1 | 0 | 0 | 0 | 0 | 0 | 1 | 0 | 1 | 0 | 1 |
|
||||
|
||||
@@ -3,24 +3,22 @@ import ctypes
|
||||
import pandas as pd
|
||||
|
||||
# hex value for register: guid, gsnpsid, ghwcfg1, ghwcfg2, ghwcfg3, ghwcfg4
|
||||
# Note: FS is FullSpeed, HS is HighSpeed
|
||||
dwc2_reg_list = ['guid', 'gsnpsid', 'ghwcfg1', 'ghwcfg2', 'ghwcfg3', 'ghwcfg4']
|
||||
dwc2_reg_value = {
|
||||
'BCM2711 (Pi4)': [0x2708A000, 0x4F54280A, 0, 0x228DDD50, 0xFF000E8, 0x1FF00020],
|
||||
'EFM32GG FullSpeed': [0, 0x4F54330A, 0, 0x228F5910, 0x1F204E8, 0x1BF08030],
|
||||
'ESP32-S2': [0, 0x4F54400A, 0, 0x224DD930, 0xC804B5, 0xD3F0A030],
|
||||
'STM32F407 Fullspeed': [0x1200, 0x4F54281A, 0, 0x229DCD20, 0x20001E8, 0xFF08030],
|
||||
'STM32F407 Highspeed': [0x1100, 0x4F54281A, 0, 0x229ED590, 0x3F403E8, 0x17F00030],
|
||||
'STM32F411 Fullspeed': [0x1200, 0x4F54281A, 0, 0x229DCD20, 0x20001E8, 0xFF08030],
|
||||
'STM32F412 Fullspeed': [0x2000, 0x4F54320A, 0, 0x229ED520, 0x200D1E8, 0x17F08030],
|
||||
'STM32F429 Fullspeed': [0x1200, 0x4F54281A, 0, 0x229DCD20, 0x20001E8, 0xFF08030],
|
||||
'STM32F429 Highspeed': [0x1100, 0x4F54281A, 0, 0x229ED590, 0x3F403E8, 0x17F00030],
|
||||
'STM32F723 Fullspeed': [0x3000, 0x4F54330A, 0, 0x229ED520, 0x200D1E8, 0x17F08030],
|
||||
'STM32F723 HighSpeed': [0x3100, 0x4F54330A, 0, 0x229FE1D0, 0x3EED2E8, 0x23F00030],
|
||||
'STM32F767 Fullspeed': [0x2000, 0x4F54320A, 0, 0x229ED520, 0x200D1E8, 0x17F08030],
|
||||
'STM32H743 Highspeed': [0x2300, 0x4F54330A, 0, 0x229FE190, 0x3B8D2E8, 0xE3F00030], # both HS cores
|
||||
'STM32L476 Fullspeed': [0x2000, 0x4F54310A, 0, 0x229ED520, 0x200D1E8, 0x17F08030],
|
||||
'STM32U5A5 Highspeed': [0x00005000, 0x4F54411A, 0x00000000, 0x228FE052, 0x03B882E8, 0xE2103E30],
|
||||
'GD32VF103 Fullspeed': [0x1000, 0, 0, 0, 0, 0],
|
||||
'EFM32GG FS': [0, 0x4F54330A, 0, 0x228F5910, 0x1F204E8, 0x1BF08030],
|
||||
'ESP32-S2/S3': [0, 0x4F54400A, 0, 0x224DD930, 0xC804B5, 0xD3F0A030],
|
||||
'ESP32-P4': [0, 0x4F54400A, 0, 0x215FFFD0, 0x03805EB5, 0xDFF1A030],
|
||||
'STM32F 407/411/429 FS': [0x1200, 0x4F54281A, 0, 0x229DCD20, 0x20001E8, 0xFF08030],
|
||||
'STM32F 407/429 HS': [0x1100, 0x4F54281A, 0, 0x229ED590, 0x3F403E8, 0x17F00030],
|
||||
'STM32F 412/767 FS': [0x2000, 0x4F54320A, 0, 0x229ED520, 0x200D1E8, 0x17F08030],
|
||||
'STM32F723 FS': [0x3000, 0x4F54330A, 0, 0x229ED520, 0x200D1E8, 0x17F08030],
|
||||
'STM32F723 HS': [0x3100, 0x4F54330A, 0, 0x229FE1D0, 0x3EED2E8, 0x23F00030],
|
||||
'STM32H743 HS': [0x2300, 0x4F54330A, 0, 0x229FE190, 0x3B8D2E8, 0xE3F00030], # both HS cores
|
||||
'STM32L476 FS': [0x2000, 0x4F54310A, 0, 0x229ED520, 0x200D1E8, 0x17F08030],
|
||||
'STM32U5A5 HS': [0x5000, 0x4F54411A, 0, 0x228FE052, 0x03B882E8, 0xE2103E30],
|
||||
'GD32VF103 FS': [0x1000, 0, 0, 0, 0, 0],
|
||||
'XMC4500': [0xAEC000, 0x4F54292A, 0, 0x228F5930, 0x27A01E5, 0xDBF08030]
|
||||
}
|
||||
|
||||
@@ -50,9 +48,9 @@ class GHWCFG2(ctypes.LittleEndianStructure):
|
||||
("enable_dynamic_fifo", ctypes.c_uint32, 1),
|
||||
("mul_cpu_int", ctypes.c_uint32, 1),
|
||||
("reserved21", ctypes.c_uint32, 1),
|
||||
("nperiod_tx_q_depth", ctypes.c_uint32, 2),
|
||||
("host_period_tx_q_depth", ctypes.c_uint32, 2),
|
||||
("dev_token_q_depth", ctypes.c_uint32, 5),
|
||||
("nptx_q_depth", ctypes.c_uint32, 2),
|
||||
("ptx_q_depth", ctypes.c_uint32, 2),
|
||||
("token_q_depth", ctypes.c_uint32, 5),
|
||||
("otg_enable_ic_usb", ctypes.c_uint32, 1)
|
||||
]
|
||||
|
||||
@@ -70,31 +68,34 @@ class GHWCFG3(ctypes.LittleEndianStructure):
|
||||
("otg_enable_hsic", ctypes.c_uint32, 1),
|
||||
("battery_charger_support", ctypes.c_uint32, 1),
|
||||
("lpm_mode", ctypes.c_uint32, 1),
|
||||
("total_fifo_size", ctypes.c_uint32, 16)
|
||||
("dfifo_depth", ctypes.c_uint32, 16)
|
||||
]
|
||||
|
||||
|
||||
class GHWCFG4(ctypes.LittleEndianStructure):
|
||||
_fields_ = [
|
||||
("num_dev_period_in_ep", ctypes.c_uint32, 4),
|
||||
("power_optimized", ctypes.c_uint32, 1),
|
||||
("partial_powerdown", ctypes.c_uint32, 1),
|
||||
("ahb_freq_min", ctypes.c_uint32, 1),
|
||||
("hibernation", ctypes.c_uint32, 1),
|
||||
("reserved7", ctypes.c_uint32, 3),
|
||||
("service_interval_mode", ctypes.c_uint32, 1),
|
||||
("ipg_isoc_en", ctypes.c_uint32, 1),
|
||||
("acg_enable", ctypes.c_uint32, 1),
|
||||
("reserved13", ctypes.c_uint32, 1),
|
||||
("utmi_phy_data_width", ctypes.c_uint32, 2),
|
||||
("dev_ctrl_ep_num", ctypes.c_uint32, 4),
|
||||
("iddg_filter_enabled", ctypes.c_uint32, 1),
|
||||
("vbus_valid_filter_enabled", ctypes.c_uint32, 1),
|
||||
("a_valid_filter_enabled", ctypes.c_uint32, 1),
|
||||
("b_valid_filter_enabled", ctypes.c_uint32, 1),
|
||||
("extended_hibernation", ctypes.c_uint32, 1),
|
||||
("reserved8", ctypes.c_uint32, 1),
|
||||
("enhanced_lpm_support1", ctypes.c_uint32, 1),
|
||||
("service_interval_flow", ctypes.c_uint32, 1),
|
||||
("ipg_isoc_support", ctypes.c_uint32, 1),
|
||||
("acg_support", ctypes.c_uint32, 1),
|
||||
("enhanced_lpm_support", ctypes.c_uint32, 1),
|
||||
("phy_data_width", ctypes.c_uint32, 2),
|
||||
("ctrl_ep_num", ctypes.c_uint32, 4),
|
||||
("iddg_filter", ctypes.c_uint32, 1),
|
||||
("vbus_valid_filter", ctypes.c_uint32, 1),
|
||||
("a_valid_filter", ctypes.c_uint32, 1),
|
||||
("b_valid_filter", ctypes.c_uint32, 1),
|
||||
("session_end_filter", ctypes.c_uint32, 1),
|
||||
("dedicated_fifos", ctypes.c_uint32, 1),
|
||||
("num_dev_in_eps", ctypes.c_uint32, 4),
|
||||
("dma_desc_enable", ctypes.c_uint32, 1),
|
||||
("dma_dynamic", ctypes.c_uint32, 1)
|
||||
("dma_desc_dynamic", ctypes.c_uint32, 1)
|
||||
]
|
||||
|
||||
|
||||
|
||||
@@ -149,7 +149,7 @@ TU_ATTR_ALWAYS_INLINE static inline void dwc2_remote_wakeup_delay(void) {
|
||||
// - dwc2 3.30a (H5) use USB_HS_PHYC
|
||||
// - dwc2 4.11a (U5) use femtoPHY
|
||||
static inline void dwc2_phy_init(dwc2_regs_t* dwc2, uint8_t hs_phy_type) {
|
||||
if (hs_phy_type == HS_PHY_TYPE_NONE) {
|
||||
if (hs_phy_type == GHWCFG2_HSPHY_NOT_SUPPORTED) {
|
||||
// Enable on-chip FS PHY
|
||||
dwc2->stm32_gccfg |= STM32_GCCFG_PWRDWN;
|
||||
|
||||
@@ -182,7 +182,7 @@ static inline void dwc2_phy_init(dwc2_regs_t* dwc2, uint8_t hs_phy_type) {
|
||||
#endif
|
||||
|
||||
// Enable on-chip HS PHY
|
||||
if (hs_phy_type == HS_PHY_TYPE_UTMI || hs_phy_type == HS_PHY_TYPE_UTMI_ULPI) {
|
||||
if (hs_phy_type == GHWCFG2_HSPHY_UTMI || hs_phy_type == GHWCFG2_HSPHY_UTMI_ULPI) {
|
||||
#ifdef USB_HS_PHYC
|
||||
// Enable UTMI HS PHY
|
||||
dwc2->stm32_gccfg |= STM32_GCCFG_PHYHSEN;
|
||||
@@ -225,7 +225,7 @@ static inline void dwc2_phy_init(dwc2_regs_t* dwc2, uint8_t hs_phy_type) {
|
||||
// MCU specific PHY update, it is called AFTER init() and core reset
|
||||
static inline void dwc2_phy_update(dwc2_regs_t* dwc2, uint8_t hs_phy_type) {
|
||||
// used to set turnaround time for fullspeed, nothing to do in highspeed mode
|
||||
if (hs_phy_type == HS_PHY_TYPE_NONE) {
|
||||
if (hs_phy_type == GHWCFG2_HSPHY_NOT_SUPPORTED) {
|
||||
// Turnaround timeout depends on the AHB clock dictated by STM32 Reference Manual
|
||||
uint32_t turnaround;
|
||||
|
||||
|
||||
@@ -46,6 +46,7 @@ typedef struct
|
||||
uintptr_t reg_base;
|
||||
uint32_t irqnum;
|
||||
uint8_t ep_count;
|
||||
uint8_t ep_in_count;
|
||||
uint32_t ep_fifo_size;
|
||||
}dwc2_controller_t;
|
||||
|
||||
@@ -86,86 +87,222 @@ typedef struct
|
||||
#endif
|
||||
|
||||
enum {
|
||||
HS_PHY_TYPE_NONE = 0 , // not supported
|
||||
HS_PHY_TYPE_UTMI , // internal PHY (mostly)
|
||||
HS_PHY_TYPE_ULPI , // external PHY
|
||||
HS_PHY_TYPE_UTMI_ULPI ,
|
||||
GHWCFG2_OPMODE_HNP_SRP = 0,
|
||||
GHWCFG2_OPMODE_SRP = 1,
|
||||
GHWCFG2_OPMODE_NON_HNP_NON_SRP = 2,
|
||||
GHWCFG2_OPMODE_SRP_DEVICE = 3,
|
||||
GHWCFFG2_OPMODE_NON_OTG_DEVICE = 4,
|
||||
GHWCFG2_OPMODE_SRP_HOST = 5,
|
||||
GHWCFG2_OPMODE_NON_OTG_HOST = 6,
|
||||
};
|
||||
enum {
|
||||
GHWCFG2_ARCH_SLAVE_ONLY = 0,
|
||||
GHWCFG2_ARCH_EXTERNAL_DMA = 1,
|
||||
GHWCFG2_ARCH_INTERNAL_DMA = 2,
|
||||
};
|
||||
|
||||
enum {
|
||||
FS_PHY_TYPE_NONE = 0, // not supported
|
||||
FS_PHY_TYPE_DEDICATED,
|
||||
FS_PHY_TYPE_UTMI,
|
||||
FS_PHY_TYPE_ULPI,
|
||||
GHWCFG2_HSPHY_NOT_SUPPORTED = 0,
|
||||
GHWCFG2_HSPHY_UTMI = 1, // internal PHY (mostly)
|
||||
GHWCFG2_HSPHY_ULPI = 2, // external PHY (mostly)
|
||||
GHWCFG2_HSPHY_UTMI_ULPI = 3, // both
|
||||
|
||||
};
|
||||
|
||||
typedef struct TU_ATTR_PACKED
|
||||
{
|
||||
uint32_t op_mode : 3; // 0: HNP and SRP | 1: SRP | 2: non-HNP, non-SRP
|
||||
uint32_t arch : 2; // 0: slave-only | 1: External DMA | 2: Internal DMA | 3: others
|
||||
uint32_t point2point : 1; // 0: support hub and split | 1: no hub, no split
|
||||
uint32_t hs_phy_type : 2; // 0: not supported | 1: UTMI+ | 2: ULPI | 3: UTMI+ and ULPI
|
||||
uint32_t fs_phy_type : 2; // 0: not supported | 1: dedicated | 2: UTMI+ | 3: ULPI
|
||||
uint32_t num_dev_ep : 4; // Number of device endpoints (not including EP0)
|
||||
uint32_t num_host_ch : 4; // Number of host channel
|
||||
uint32_t period_channel_support : 1; // Support Periodic OUT Host Channel
|
||||
uint32_t enable_dynamic_fifo : 1; // Dynamic FIFO Sizing Enabled
|
||||
uint32_t mul_cpu_int : 1; // Multi-Processor Interrupt Enabled
|
||||
uint32_t reserved21 : 1;
|
||||
uint32_t nperiod_tx_q_depth : 2; // Non-periodic request queue depth: 0 = 2. 1 = 4, 2 = 8
|
||||
uint32_t host_period_tx_q_depth : 2; // Host periodic request queue depth: 0 = 2. 1 = 4, 2 = 8
|
||||
uint32_t dev_token_q_depth : 5; // Device IN token sequence learning queue depth: 0-30
|
||||
uint32_t otg_enable_ic_usb : 1; // IC_USB mode specified for mode of operation
|
||||
} dwc2_ghwcfg2_t;
|
||||
enum {
|
||||
GHWCFG2_FSPHY_NOT_SUPPORTED = 0,
|
||||
GHWCFG2_FSPHY_DEDICATED = 1, // have dedicated FS PHY
|
||||
GHWCFG2_FSPHY_UTMI = 2, // shared with UTMI+
|
||||
GHWCFG2_FSPHY_ULPI = 3, // shared with ULPI
|
||||
};
|
||||
|
||||
enum {
|
||||
GHWCFFG4_PHY_DATA_WIDTH_8 = 0,
|
||||
GHWCFFG4_PHY_DATA_WIDTH_16 = 1,
|
||||
GHWCFFG4_PHY_DATA_WIDTH_8_16 = 2, // software selectable
|
||||
};
|
||||
|
||||
//--------------------------------------------------------------------
|
||||
// Register bitfield definitions
|
||||
//--------------------------------------------------------------------
|
||||
typedef struct TU_ATTR_PACKED {
|
||||
uint32_t ses_req_scs : 1; // 0 Session request success
|
||||
uint32_t ses_req : 1; // 1 Session request
|
||||
uint32_t vbval_ov_en : 1; // 2 VBUS valid override enable
|
||||
uint32_t vbval_ov_val : 1; // 3 VBUS valid override value
|
||||
uint32_t aval_ov_en : 1; // 4 A-peripheral session valid override enable
|
||||
uint32_t aval_ov_al : 1; // 5 A-peripheral session valid override value
|
||||
uint32_t bval_ov_en : 1; // 6 B-peripheral session valid override enable
|
||||
uint32_t bval_ov_val : 1; // 7 B-peripheral session valid override value
|
||||
uint32_t hng_scs : 1; // 8 Host negotiation success
|
||||
uint32_t hnp_rq : 1; // 9 HNP (host negotiation protocol) request
|
||||
uint32_t host_set_hnp_en : 1; // 10 Host set HNP enable
|
||||
uint32_t dev_hnp_en : 1; // 11 Device HNP enabled
|
||||
uint32_t embedded_host_en : 1; // 12 Embedded host enable
|
||||
uint32_t rsv13_14 : 2; // 13.14 Reserved
|
||||
uint32_t dbnc_filter_bypass : 1; // 15 Debounce filter bypass
|
||||
uint32_t cid_status : 1; // 16 Connector ID status
|
||||
uint32_t dbnc_done : 1; // 17 Debounce done
|
||||
uint32_t ases_valid : 1; // 18 A-session valid
|
||||
uint32_t bses_valid : 1; // 19 B-session valid
|
||||
uint32_t otg_ver : 1; // 20 OTG version 0: v1.3, 1: v2.0
|
||||
uint32_t current_mode : 1; // 21 Current mode of operation 0: device, 1: host
|
||||
uint32_t mult_val_id_bc : 5; // 22..26 Multi-valued input pin ID battery charger
|
||||
uint32_t chirp_en : 1; // 27 Chirp detection enable
|
||||
uint32_t rsv28_30 : 3; // 28.30: Reserved
|
||||
uint32_t test_mode_corr_eusb2 : 1; // 31 Test mode control for eUSB2 PHY
|
||||
} dwc2_gotgctl_t;
|
||||
TU_VERIFY_STATIC(sizeof(dwc2_gotgctl_t) == 4, "incorrect size");
|
||||
|
||||
typedef struct TU_ATTR_PACKED {
|
||||
uint32_t rsv0_1 : 2; // 0..1 Reserved
|
||||
uint32_t ses_end_det : 1; // 2 Session end detected
|
||||
uint32_t rsv3_7 : 5; // 3..7 Reserved
|
||||
uint32_t srs_status_change : 1; // 8 Session request success status change
|
||||
uint32_t hns_status_change : 1; // 9 Host negotiation success status change
|
||||
uint32_t rsv10_16 : 7; // 10..16 Reserved
|
||||
uint32_t hng_det : 1; // 17 Host negotiation detected
|
||||
uint32_t adev_timeout_change : 1; // 18 A-device timeout change
|
||||
uint32_t dbnc_done : 1; // 19 Debounce done
|
||||
uint32_t mult_val_lp_change : 1; // 20 Multi-valued input pin change
|
||||
uint32_t rsv21_31 :11; // 21..31 Reserved
|
||||
} dwc2_gotgint_t;
|
||||
TU_VERIFY_STATIC(sizeof(dwc2_gotgint_t) == 4, "incorrect size");
|
||||
|
||||
typedef struct TU_ATTR_PACKED {
|
||||
uint32_t gintmask : 1; // 0 Global interrupt mask
|
||||
uint32_t hbst_len : 4; // 1..4 Burst length/type
|
||||
uint32_t dma_en : 1; // 5 DMA enable
|
||||
uint32_t rsv6 : 1; // 6 Reserved
|
||||
uint32_t nptxf_empty_lvl : 1; // 7 Non-periodic Tx FIFO empty level
|
||||
uint32_t ptxf_empty_lvl : 1; // 8 Periodic Tx FIFO empty level
|
||||
uint32_t rsv9_20 : 12; // 9.20: Reserved
|
||||
uint32_t remote_mem_support : 1; // 21 Remote memory support
|
||||
uint32_t notify_all_dma_write : 1; // 22 Notify all DMA writes
|
||||
uint32_t ahb_single : 1; // 23 AHB single
|
||||
uint32_t inv_desc_endian : 1; // 24 Inverse descriptor endian
|
||||
uint32_t rsv25_31 : 7; // 25..31 Reserved
|
||||
} dwc2_gahbcfg_t;
|
||||
TU_VERIFY_STATIC(sizeof(dwc2_gahbcfg_t) == 4, "incorrect size");
|
||||
|
||||
typedef struct TU_ATTR_PACKED {
|
||||
uint32_t timeout_cal : 3; /* 0..2 Timeout calibration.
|
||||
The USB standard timeout value for high-speed operation is 736 to 816 (inclusive) bit times. The USB standard
|
||||
timeout value for full- speed operation is 16 to 18 (inclusive) bit times. The application must program this field
|
||||
based on the speed of enumeration. The number of bit times added per PHY clock are as follows:
|
||||
- High-speed: PHY clock One 30-MHz = 16 bit times, One 60-MHz = 8 bit times
|
||||
- Full-speed: PHY clock One 30-MHz = 0.4 bit times, One 60-MHz = 0.2 bit times, One 48-MHz = 0.25 bit times */
|
||||
uint32_t phy_if : 1; // 3 PHY interface. 0: 8 bits, 1: 16 bits
|
||||
uint32_t ulpi_utmi_sel : 1; // 4 ULPI/UTMI select. 0: UTMI+, 1: ULPI
|
||||
uint32_t fs_intf_sel : 1; // 5 Fullspeed serial interface select. 0: 6-pin, 1: 3-pin
|
||||
uint32_t phy_sel : 1; // 6 HS/FS PHY selection. 0: HS UTMI+ or ULPI, 1: FS serial transceiver
|
||||
uint32_t ddr_sel : 1; // 7 ULPI DDR select. 0: Single data rate 8-bit, 1: Double data rate 4-bit
|
||||
uint32_t srp_capable : 1; // 8 SRP-capable
|
||||
uint32_t hnp_capable : 1; // 9 HNP-capable
|
||||
uint32_t turnaround_time : 4; // 10..13 Turnaround time. 9: 8-bit UTMI+, 5: 16-bit UTMI+
|
||||
uint32_t rsv14 : 1; // 14 Reserved
|
||||
uint32_t phy_low_power_clk_sel : 1; /* 15 PHY low-power clock select either 480-MHz or 48-MHz (low-power) PHY mode.
|
||||
In FS/LS modes, the PHY can usually operate on a 48-MHz clock to save power. This bit is valid only for UTMI+ PHYs.
|
||||
- 0: 480 Mhz internal PLL: the UTMI interface operates at either 60 MHz (8 bit) or 30 MHz (16-bit)
|
||||
- 1 48 Mhz external clock: the UTMI interface operates at 48 MHz in FS mode and at either 48 or 6 MHz in LS mode */
|
||||
uint32_t otg_i2c_sel : 1; // 16 OTG I2C interface select. 0: UTMI-FS, 1: I2C for OTG signals
|
||||
uint32_t ulpi_fsls : 1; /* 17 ULPI FS/LS select. 0: ULPI, 1: ULPI FS/LS.
|
||||
valid only when the FS serial transceiver is selected on the ULPI PHY. */
|
||||
uint32_t ulpi_auto_resume : 1; // 18 ULPI Auto-resume
|
||||
uint32_t ulpi_clk_sus_m : 1; // 19 ULPI Clock SuspendM
|
||||
uint32_t ulpi_ext_vbus_drv : 1; // 20 ULPI External VBUS Drive
|
||||
uint32_t ulpi_int_vbus_indicator : 1; // 21 ULPI Internal VBUS Indicator
|
||||
uint32_t term_sel_dl_pulse : 1; // 22 TermSel DLine pulsing
|
||||
uint32_t indicator_complement : 1; // 23 Indicator complement
|
||||
uint32_t indicator_pass_through : 1; // 24 Indicator pass through
|
||||
uint32_t ulpi_if_protect_disable : 1; // 25 ULPI interface protect disable
|
||||
uint32_t ic_usb_capable : 1; // 26 IC_USB Capable
|
||||
uint32_t ic_usb_traf_ctl : 1; // 27 IC_USB Traffic Control
|
||||
uint32_t tx_end_delay : 1; // 28 TX end delay
|
||||
uint32_t force_host_mode : 1; // 29 Force host mode
|
||||
uint32_t force_dev_mode : 1; // 30 Force device mode
|
||||
uint32_t corrupt_tx_pkt : 1; // 31 Corrupt Tx packet. 0: normal, 1: debug
|
||||
} dwc2_gusbcfg_t;
|
||||
TU_VERIFY_STATIC(sizeof(dwc2_gusbcfg_t) == 4, "incorrect size");
|
||||
|
||||
typedef struct TU_ATTR_PACKED {
|
||||
uint32_t core_soft_rst : 1; // 0 Core Soft Reset
|
||||
uint32_t piufs_soft_rst : 1; // 1 PIU FS Dedicated Controller Soft Reset
|
||||
uint32_t frame_counter_rst : 1; // 2 Frame Counter Reset (host)
|
||||
uint32_t intoken_q_flush : 1; // 3 IN Token Queue Flush
|
||||
uint32_t rx_fifo_flush : 1; // 4 RX FIFO Flush
|
||||
uint32_t tx_fifo_flush : 1; // 5 TX FIFO Flush
|
||||
uint32_t tx_fifo_num : 5; // 6..10 TX FIFO Number
|
||||
uint32_t rsv11_28 :18; // 11..28 Reserved
|
||||
uint32_t core_soft_rst_done : 1; // 29 Core Soft Reset Done, from v4.20a
|
||||
uint32_t dma_req : 1; // 30 DMA Request
|
||||
uint32_t ahb_idle : 1; // 31 AHB Idle
|
||||
} dwc2_grstctl_t;
|
||||
TU_VERIFY_STATIC(sizeof(dwc2_grstctl_t) == 4, "incorrect size");
|
||||
|
||||
typedef struct TU_ATTR_PACKED {
|
||||
uint32_t op_mode : 3; // 0..2 HNP/SRP Host/Device/OTG mode
|
||||
uint32_t arch : 2; // 3..4 Slave/External/Internal DMA
|
||||
uint32_t point2point : 1; // 5 0: support hub and split | 1: no hub, no split
|
||||
uint32_t hs_phy_type : 2; // 6..7 0: not supported | 1: UTMI+ | 2: ULPI | 3: UTMI+ and ULPI
|
||||
uint32_t fs_phy_type : 2; // 8..9 0: not supported | 1: dedicated | 2: UTMI+ | 3: ULPI
|
||||
uint32_t num_dev_ep : 4; // 10..13 Number of device endpoints (excluding EP0)
|
||||
uint32_t num_host_ch : 4; // 14..17 Number of host channel (excluding control)
|
||||
uint32_t period_channel_support : 1; // 18 Support Periodic OUT Host Channel
|
||||
uint32_t enable_dynamic_fifo : 1; // 19 Dynamic FIFO Sizing Enabled
|
||||
uint32_t mul_cpu_int : 1; // 20 Multi-Processor Interrupt Enabled
|
||||
uint32_t reserved21 : 1; // 21 reserved
|
||||
uint32_t nptx_q_depth : 2; // 22..23 Non-periodic request queue depth: 0 = 2. 1 = 4, 2 = 8
|
||||
uint32_t ptx_q_depth : 2; // 24..25 Host periodic request queue depth: 0 = 2. 1 = 4, 2 = 8
|
||||
uint32_t token_q_depth : 5; // 26..30 Device IN token sequence learning queue depth: 0-30
|
||||
uint32_t otg_enable_ic_usb : 1; // 31 IC_USB mode specified for mode of operation
|
||||
} dwc2_ghwcfg2_t;
|
||||
TU_VERIFY_STATIC(sizeof(dwc2_ghwcfg2_t) == 4, "incorrect size");
|
||||
|
||||
typedef struct TU_ATTR_PACKED
|
||||
{
|
||||
uint32_t xfer_size_width : 4; // Transfer size counter in bits = 11 + n (max 19 bits)
|
||||
uint32_t packet_size_width : 3; // Packet size counter in bits = 4 + n (max 10 bits)
|
||||
uint32_t otg_enable : 1; // 1 is OTG capable
|
||||
uint32_t i2c_enable : 1; // I2C interface is available
|
||||
uint32_t vendor_ctrl_itf : 1; // Vendor control interface is available
|
||||
uint32_t optional_feature_removed : 1; // remove User ID, GPIO, SOF toggle & counter
|
||||
uint32_t synch_reset : 1; // 0: async reset | 1: synch reset
|
||||
uint32_t otg_adp_support : 1; // ADP logic is present along with HSOTG controller
|
||||
uint32_t otg_enable_hsic : 1; // 1: HSIC-capable with shared UTMI PHY interface | 0: non-HSIC
|
||||
uint32_t battery_charger_support : 1; // support battery charger
|
||||
uint32_t lpm_mode : 1; // LPC mode
|
||||
uint32_t total_fifo_size : 16; // DFIFO depth value in terms of 32-bit words
|
||||
typedef struct TU_ATTR_PACKED {
|
||||
uint32_t xfer_size_width : 4; // 0..3 Transfer size counter in bits = 11 + n (max 19 bits)
|
||||
uint32_t packet_size_width : 3; // 4..6 Packet size counter in bits = 4 + n (max 10 bits)
|
||||
uint32_t otg_enable : 1; // 7 OTG capable
|
||||
uint32_t i2c_enable : 1; // 8 I2C interface is available
|
||||
uint32_t vendor_ctrl_itf : 1; // 9 Vendor control interface is available
|
||||
uint32_t optional_feature_removed : 1; // 10 remove User ID, GPIO, SOF toggle & counter to save gate count
|
||||
uint32_t synch_reset : 1; // 11 0: async reset | 1: synch reset
|
||||
uint32_t otg_adp_support : 1; // 12 ADP logic is present along with HSOTG controller
|
||||
uint32_t otg_enable_hsic : 1; // 13 1: HSIC-capable with shared UTMI PHY interface | 0: non-HSIC
|
||||
uint32_t battery_charger_support : 1; // s14 upport battery charger
|
||||
uint32_t lpm_mode : 1; // 15 LPM mode
|
||||
uint32_t dfifo_depth : 16; // DFIFO depth - EP_LOC_CNT in terms of 32-bit words
|
||||
}dwc2_ghwcfg3_t;
|
||||
|
||||
TU_VERIFY_STATIC(sizeof(dwc2_ghwcfg3_t) == 4, "incorrect size");
|
||||
|
||||
typedef struct TU_ATTR_PACKED
|
||||
{
|
||||
uint32_t num_dev_period_in_ep : 4; // Number of Device Periodic IN Endpoints
|
||||
uint32_t power_optimized : 1; // Partial Power Down Enabled
|
||||
uint32_t ahb_freq_min : 1; // 1: minimum of AHB frequency is less than 60 MHz
|
||||
uint32_t hibernation : 1; // Hibernation feature is enabled
|
||||
uint32_t reserved7 : 3;
|
||||
uint32_t service_interval_mode : 1; // Service Interval supported
|
||||
uint32_t ipg_isoc_en : 1; // IPG ISOC supported
|
||||
uint32_t acg_enable : 1; // ACG enabled
|
||||
uint32_t reserved13 : 1;
|
||||
uint32_t utmi_phy_data_width : 2; // 0: 8 bits | 1: 16 bits | 2: 8/16 software selectable
|
||||
uint32_t dev_ctrl_ep_num : 4; // Number of Device control endpoints in addition to EP0
|
||||
uint32_t iddg_filter_enabled : 1;
|
||||
uint32_t vbus_valid_filter_enabled : 1;
|
||||
uint32_t a_valid_filter_enabled : 1;
|
||||
uint32_t b_valid_filter_enabled : 1;
|
||||
uint32_t dedicated_fifos : 1; // Dedicated tx fifo for device IN Endpoint is enabled
|
||||
uint32_t num_dev_in_eps : 4; // Number of Device IN Endpoints including EP0
|
||||
uint32_t dma_desc_enable : 1; // scatter/gather DMA configuration
|
||||
uint32_t dma_dynamic : 1; // Dynamic scatter/gather DMA
|
||||
typedef struct TU_ATTR_PACKED {
|
||||
uint32_t num_dev_period_in_ep : 4; // 0..3 Number of Device Periodic IN Endpoints
|
||||
uint32_t partial_powerdown : 1; // 4 Partial Power Down Enabled
|
||||
uint32_t ahb_freq_min : 1; // 5 1: minimum of AHB frequency is less than 60 MHz
|
||||
uint32_t hibernation : 1; // 6 Hibernation feature is enabled
|
||||
uint32_t extended_hibernation : 1; // 7 Extended Hibernation feature is enabled
|
||||
uint32_t reserved8 : 1; // 8 Reserved
|
||||
uint32_t enhanced_lpm_support1 : 1; // 9 Enhanced LPM Support1
|
||||
uint32_t service_interval_flow : 1; // 10 Service Interval flow is supported
|
||||
uint32_t ipg_isoc_support : 1; // 11 Interpacket GAP ISO OUT worst-case is supported
|
||||
uint32_t acg_support : 1; // 12 Active clock gating is supported
|
||||
uint32_t enhanced_lpm_support : 1; // 13 Enhanced LPM Support
|
||||
uint32_t phy_data_width : 2; // 14..15 0: 8 bits | 1: 16 bits | 2: 8/16 software selectable
|
||||
uint32_t ctrl_ep_num : 4; // 16..19 Number of Device control endpoints in addition to EP0
|
||||
uint32_t iddg_filter : 1; // 20 IDDG Filter Enabled
|
||||
uint32_t vbus_valid_filter : 1; // 21 VBUS Valid Filter Enabled
|
||||
uint32_t a_valid_filter : 1; // 22 A Valid Filter Enabled
|
||||
uint32_t b_valid_filter : 1; // 23 B Valid Filter Enabled
|
||||
uint32_t session_end_filter : 1; // 24 Session End Filter Enabled
|
||||
uint32_t dedicated_fifos : 1; // 25 Dedicated tx fifo for device IN Endpoint
|
||||
uint32_t num_dev_in_eps : 4; // 26..29 Number of Device IN Endpoints including EP0
|
||||
uint32_t dma_desc_enabled : 1; // scatter/gather DMA configuration enabled
|
||||
uint32_t dma_desc_dynamic : 1; // Dynamic scatter/gather DMA
|
||||
}dwc2_ghwcfg4_t;
|
||||
|
||||
TU_VERIFY_STATIC(sizeof(dwc2_ghwcfg4_t) == 4, "incorrect size");
|
||||
|
||||
// Host Channel
|
||||
typedef struct
|
||||
{
|
||||
typedef struct {
|
||||
volatile uint32_t hcchar; // 500 + 20*ch Host Channel Characteristics
|
||||
volatile uint32_t hcsplt; // 504 + 20*ch Host Channel Split Control
|
||||
volatile uint32_t hcint; // 508 + 20*ch Host Channel Interrupt
|
||||
@@ -177,8 +314,7 @@ typedef struct
|
||||
} dwc2_channel_t;
|
||||
|
||||
// Endpoint IN
|
||||
typedef struct
|
||||
{
|
||||
typedef struct {
|
||||
volatile uint32_t diepctl; // 900 + 20*ep Device IN Endpoint Control
|
||||
uint32_t reserved04; // 904
|
||||
volatile uint32_t diepint; // 908 + 20*ep Device IN Endpoint Interrupt
|
||||
@@ -190,8 +326,7 @@ typedef struct
|
||||
} dwc2_epin_t;
|
||||
|
||||
// Endpoint OUT
|
||||
typedef struct
|
||||
{
|
||||
typedef struct {
|
||||
volatile uint32_t doepctl; // B00 + 20*ep Device OUT Endpoint Control
|
||||
uint32_t reserved04; // B04
|
||||
volatile uint32_t doepint; // B08 + 20*ep Device OUT Endpoint Interrupt
|
||||
@@ -201,105 +336,107 @@ typedef struct
|
||||
uint32_t reserved18[2]; // B18..B1C
|
||||
} dwc2_epout_t;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
//------------- Core Global -------------//
|
||||
volatile uint32_t gotgctl; // 000 OTG Control and Status
|
||||
volatile uint32_t gotgint; // 004 OTG Interrupt
|
||||
volatile uint32_t gahbcfg; // 008 AHB Configuration
|
||||
volatile uint32_t gusbcfg; // 00c USB Configuration
|
||||
volatile uint32_t grstctl; // 010 Reset
|
||||
volatile uint32_t gintsts; // 014 Interrupt
|
||||
volatile uint32_t gintmsk; // 018 Interrupt Mask
|
||||
volatile uint32_t grxstsr; // 01c Receive Status Debug Read
|
||||
volatile uint32_t grxstsp; // 020 Receive Status Read/Pop
|
||||
volatile uint32_t grxfsiz; // 024 Receive FIFO Size
|
||||
union {
|
||||
volatile uint32_t dieptxf0; // 028 EP0 Tx FIFO Size
|
||||
volatile uint32_t gnptxfsiz; // 028 Non-periodic Transmit FIFO Size
|
||||
};
|
||||
volatile uint32_t gnptxsts; // 02c Non-periodic Transmit FIFO/Queue Status
|
||||
volatile uint32_t gi2cctl; // 030 I2C Address
|
||||
volatile uint32_t gpvndctl; // 034 PHY Vendor Control
|
||||
union {
|
||||
volatile uint32_t ggpio; // 038 General Purpose IO
|
||||
volatile uint32_t stm32_gccfg; // 038 STM32 General Core Configuration
|
||||
};
|
||||
volatile uint32_t guid; // 03C User (Application programmable) ID
|
||||
volatile uint32_t gsnpsid; // 040 Synopsys ID + Release version
|
||||
volatile uint32_t ghwcfg1; // 044 User Hardware Configuration1: endpoint dir (2 bit per ep)
|
||||
union {
|
||||
volatile uint32_t ghwcfg2; // 048 User Hardware Configuration2
|
||||
dwc2_ghwcfg2_t ghwcfg2_bm;
|
||||
};
|
||||
union {
|
||||
volatile uint32_t ghwcfg3; // 04C User Hardware Configuration3
|
||||
dwc2_ghwcfg3_t ghwcfg3_bm;
|
||||
};
|
||||
union {
|
||||
volatile uint32_t ghwcfg4; // 050 User Hardware Configuration4
|
||||
dwc2_ghwcfg4_t ghwcfg4_bm;
|
||||
};
|
||||
volatile uint32_t glpmcfg; // 054 Core LPM Configuration
|
||||
volatile uint32_t gpwrdn; // 058 Power Down
|
||||
volatile uint32_t gdfifocfg; // 05C DFIFO Software Configuration
|
||||
volatile uint32_t gadpctl; // 060 ADP Timer, Control and Status
|
||||
uint32_t reserved64[39]; // 064..0FF
|
||||
volatile uint32_t hptxfsiz; // 100 Host Periodic Tx FIFO Size
|
||||
volatile uint32_t dieptxf[15]; // 104..13C Device Periodic Transmit FIFO Size
|
||||
uint32_t reserved140[176]; // 140..3FF
|
||||
//--------------------------------------------------------------------
|
||||
// CSR Register Map
|
||||
//--------------------------------------------------------------------
|
||||
typedef struct {
|
||||
//------------- Core Global -------------//
|
||||
volatile uint32_t gotgctl; // 000 OTG Control and Status
|
||||
volatile uint32_t gotgint; // 004 OTG Interrupt
|
||||
volatile uint32_t gahbcfg; // 008 AHB Configuration
|
||||
volatile uint32_t gusbcfg; // 00c USB Configuration
|
||||
volatile uint32_t grstctl; // 010 Reset
|
||||
volatile uint32_t gintsts; // 014 Interrupt
|
||||
volatile uint32_t gintmsk; // 018 Interrupt Mask
|
||||
volatile uint32_t grxstsr; // 01c Receive Status Debug Read
|
||||
volatile uint32_t grxstsp; // 020 Receive Status Read/Pop
|
||||
volatile uint32_t grxfsiz; // 024 Receive FIFO Size
|
||||
union {
|
||||
volatile uint32_t dieptxf0; // 028 EP0 Tx FIFO Size
|
||||
volatile uint32_t gnptxfsiz; // 028 Non-periodic Transmit FIFO Size
|
||||
};
|
||||
volatile uint32_t gnptxsts; // 02c Non-periodic Transmit FIFO/Queue Status
|
||||
volatile uint32_t gi2cctl; // 030 I2C Address
|
||||
volatile uint32_t gpvndctl; // 034 PHY Vendor Control
|
||||
union {
|
||||
volatile uint32_t ggpio; // 038 General Purpose IO
|
||||
volatile uint32_t stm32_gccfg; // 038 STM32 General Core Configuration
|
||||
};
|
||||
volatile uint32_t guid; // 03C User (Application programmable) ID
|
||||
volatile uint32_t gsnpsid; // 040 Synopsys ID + Release version
|
||||
volatile uint32_t ghwcfg1; // 044 User Hardware Configuration1: endpoint dir (2 bit per ep)
|
||||
union {
|
||||
volatile uint32_t ghwcfg2; // 048 User Hardware Configuration2
|
||||
volatile dwc2_ghwcfg2_t ghwcfg2_bm;
|
||||
};
|
||||
union {
|
||||
volatile uint32_t ghwcfg3; // 04C User Hardware Configuration3
|
||||
volatile dwc2_ghwcfg3_t ghwcfg3_bm;
|
||||
};
|
||||
union {
|
||||
volatile uint32_t ghwcfg4; // 050 User Hardware Configuration4
|
||||
volatile dwc2_ghwcfg4_t ghwcfg4_bm;
|
||||
};
|
||||
volatile uint32_t glpmcfg; // 054 Core LPM Configuration
|
||||
volatile uint32_t gpwrdn; // 058 Power Down
|
||||
volatile uint32_t gdfifocfg; // 05C DFIFO Software Configuration
|
||||
volatile uint32_t gadpctl; // 060 ADP Timer, Control and Status
|
||||
uint32_t reserved64[39]; // 064..0FF
|
||||
volatile uint32_t hptxfsiz; // 100 Host Periodic Tx FIFO Size
|
||||
volatile uint32_t dieptxf[15]; // 104..13C Device Periodic Transmit FIFO Size
|
||||
uint32_t reserved140[176]; // 140..3FF
|
||||
|
||||
//------------- Host -------------//
|
||||
volatile uint32_t hcfg; // 400 Host Configuration
|
||||
volatile uint32_t hfir; // 404 Host Frame Interval
|
||||
volatile uint32_t hfnum; // 408 Host Frame Number / Frame Remaining
|
||||
uint32_t reserved40c; // 40C
|
||||
volatile uint32_t hptxsts; // 410 Host Periodic TX FIFO / Queue Status
|
||||
volatile uint32_t haint; // 414 Host All Channels Interrupt
|
||||
volatile uint32_t haintmsk; // 418 Host All Channels Interrupt Mask
|
||||
volatile uint32_t hflbaddr; // 41C Host Frame List Base Address
|
||||
uint32_t reserved420[8]; // 420..43F
|
||||
volatile uint32_t hprt; // 440 Host Port Control and Status
|
||||
uint32_t reserved444[47]; // 444..4FF
|
||||
//------------ Host -------------//
|
||||
volatile uint32_t hcfg; // 400 Host Configuration
|
||||
volatile uint32_t hfir; // 404 Host Frame Interval
|
||||
volatile uint32_t hfnum; // 408 Host Frame Number / Frame Remaining
|
||||
uint32_t reserved40c; // 40C
|
||||
volatile uint32_t hptxsts; // 410 Host Periodic TX FIFO / Queue Status
|
||||
volatile uint32_t haint; // 414 Host All Channels Interrupt
|
||||
volatile uint32_t haintmsk; // 418 Host All Channels Interrupt Mask
|
||||
volatile uint32_t hflbaddr; // 41C Host Frame List Base Address
|
||||
uint32_t reserved420[8]; // 420..43F
|
||||
volatile uint32_t hprt; // 440 Host Port Control and Status
|
||||
uint32_t reserved444[47]; // 444..4FF
|
||||
|
||||
//------------- Host Channel -------------//
|
||||
dwc2_channel_t channel[16]; // 500..6FF Host Channels 0-15
|
||||
uint32_t reserved700[64]; // 700..7FF
|
||||
//------------- Host Channel -------------//
|
||||
dwc2_channel_t channel[16]; // 500..6FF Host Channels 0-15
|
||||
uint32_t reserved700[64]; // 700..7FF
|
||||
|
||||
//------------- Device -------------//
|
||||
volatile uint32_t dcfg; // 800 Device Configuration
|
||||
volatile uint32_t dctl; // 804 Device Control
|
||||
volatile uint32_t dsts; // 808 Device Status (RO)
|
||||
uint32_t reserved80c; // 80C
|
||||
volatile uint32_t diepmsk; // 810 Device IN Endpoint Interrupt Mask
|
||||
volatile uint32_t doepmsk; // 814 Device OUT Endpoint Interrupt Mask
|
||||
volatile uint32_t daint; // 818 Device All Endpoints Interrupt
|
||||
volatile uint32_t daintmsk; // 81C Device All Endpoints Interrupt Mask
|
||||
volatile uint32_t dtknqr1; // 820 Device IN token sequence learning queue read1
|
||||
volatile uint32_t dtknqr2; // 824 Device IN token sequence learning queue read2
|
||||
volatile uint32_t dvbusdis; // 828 Device VBUS Discharge Time
|
||||
volatile uint32_t dvbuspulse; // 82C Device VBUS Pulsing Time
|
||||
volatile uint32_t dthrctl; // 830 Device threshold Control
|
||||
volatile uint32_t diepempmsk; // 834 Device IN Endpoint FIFO Empty Interrupt Mask
|
||||
volatile uint32_t deachint; // 838 Device Each Endpoint Interrupt
|
||||
volatile uint32_t deachmsk; // 83C Device Each Endpoint Interrupt msk
|
||||
volatile uint32_t diepeachmsk[16]; // 840..87C Device Each IN Endpoint mask
|
||||
volatile uint32_t doepeachmsk[16]; // 880..8BF Device Each OUT Endpoint mask
|
||||
uint32_t reserved8c0[16]; // 8C0..8FF
|
||||
//------------- Device -----------//
|
||||
volatile uint32_t dcfg; // 800 Device Configuration
|
||||
volatile uint32_t dctl; // 804 Device Control
|
||||
volatile uint32_t dsts; // 808 Device Status (RO)
|
||||
uint32_t reserved80c; // 80C
|
||||
volatile uint32_t diepmsk; // 810 Device IN Endpoint Interrupt Mask
|
||||
volatile uint32_t doepmsk; // 814 Device OUT Endpoint Interrupt Mask
|
||||
volatile uint32_t daint; // 818 Device All Endpoints Interrupt
|
||||
volatile uint32_t daintmsk; // 81C Device All Endpoints Interrupt Mask
|
||||
volatile uint32_t dtknqr1; // 820 Device IN token sequence learning queue read1
|
||||
volatile uint32_t dtknqr2; // 824 Device IN token sequence learning queue read2
|
||||
volatile uint32_t dvbusdis; // 828 Device VBUS Discharge Time
|
||||
volatile uint32_t dvbuspulse; // 82C Device VBUS Pulsing Time
|
||||
volatile uint32_t dthrctl; // 830 Device threshold Control
|
||||
volatile uint32_t diepempmsk; // 834 Device IN Endpoint FIFO Empty Interrupt Mask
|
||||
volatile uint32_t deachint; // 838 Device Each Endpoint Interrupt
|
||||
volatile uint32_t deachmsk; // 83C Device Each Endpoint Interrupt msk
|
||||
volatile uint32_t diepeachmsk[16]; // 840..87C Device Each IN Endpoint mask
|
||||
volatile uint32_t doepeachmsk[16]; // 880..8BF Device Each OUT Endpoint mask
|
||||
uint32_t reserved8c0[16]; // 8C0..8FF
|
||||
|
||||
//------------- Device Endpoint -------------//
|
||||
dwc2_epin_t epin[16]; // 900..AFF IN Endpoints
|
||||
dwc2_epout_t epout[16]; // B00..CFF OUT Endpoints
|
||||
uint32_t reservedd00[64]; // D00..DFF
|
||||
//------------- Device Endpoint -------------//
|
||||
dwc2_epin_t epin[16]; // 900..AFF IN Endpoints
|
||||
dwc2_epout_t epout[16]; // B00..CFF OUT Endpoints
|
||||
uint32_t reservedd00[64]; // D00..DFF
|
||||
|
||||
//------------- Power Clock -------------//
|
||||
volatile uint32_t pcgctl; // E00 Power and Clock Gating Control
|
||||
volatile uint32_t pcgctl1; // E04
|
||||
uint32_t reservede08[126]; // E08..FFF
|
||||
//------------- Power Clock -------------//
|
||||
volatile uint32_t pcgctl; // E00 Power and Clock Gating Control
|
||||
volatile uint32_t pcgctl1; // E04
|
||||
uint32_t reservede08[126]; // E08..FFF
|
||||
|
||||
//------------- FIFOs -------------//
|
||||
// Word-accessed only using first pointer since it auto shift
|
||||
volatile uint32_t fifo[16][0x400]; // 1000..FFFF Endpoint FIFO
|
||||
//------------- FIFOs -------------//
|
||||
// Word-accessed only using first pointer since it auto shift
|
||||
volatile uint32_t fifo[16][0x400]; // 1000..FFFF Endpoint FIFO
|
||||
} dwc2_regs_t;
|
||||
|
||||
TU_VERIFY_STATIC(offsetof(dwc2_regs_t, hcfg ) == 0x0400, "incorrect size");
|
||||
@@ -1239,6 +1376,12 @@ TU_VERIFY_STATIC(offsetof(dwc2_regs_t, fifo ) == 0x1000, "incorrect size");
|
||||
#define GLPMCFG_ENBESL_Msk (0x1UL << GLPMCFG_ENBESL_Pos) // 0x10000000
|
||||
#define GLPMCFG_ENBESL GLPMCFG_ENBESL_Msk // Enable best effort service latency
|
||||
|
||||
// GDFIFOCFG
|
||||
#define GDFIFOCFG_EPINFOBASE_MASK (0xffff << 16)
|
||||
#define GDFIFOCFG_EPINFOBASE_SHIFT 16
|
||||
#define GDFIFOCFG_GDFIFOCFG_MASK (0xffff << 0)
|
||||
#define GDFIFOCFG_GDFIFOCFG_SHIFT 0
|
||||
|
||||
/******************** Bit definition for DIEPEACHMSK1 register ********************/
|
||||
#define DIEPEACHMSK1_XFRCM_Pos (0U)
|
||||
#define DIEPEACHMSK1_XFRCM_Msk (0x1UL << DIEPEACHMSK1_XFRCM_Pos) // 0x00000001
|
||||
|
||||
Reference in New Issue
Block a user