Skip to content

Commit e8f9310

Browse files
committed
dcd/dwc2: add IN fifo configure
Signed-off-by: HiFiPhile <[email protected]>
1 parent 3842980 commit e8f9310

File tree

2 files changed

+31
-3
lines changed

2 files changed

+31
-3
lines changed

src/device/usbd.h

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,20 @@
3333
extern "C" {
3434
#endif
3535

36+
// ConfigID for tuh_configure()
37+
enum {
38+
TUD_CFGID_INVALID = 0,
39+
TUD_CFGID_DWC2 = 100,
40+
};
41+
42+
typedef struct {
43+
uint16_t bm_double_buffered; // bitmap of IN endpoints to be double buffered, only effective for bulk endpoints
44+
} tud_configure_dwc2_t;
45+
46+
typedef union {
47+
tud_configure_dwc2_t dwc2;
48+
} tud_configure_param_t;
49+
3650
//--------------------------------------------------------------------+
3751
// Application API
3852
//--------------------------------------------------------------------+

src/portable/synopsys/dwc2/dcd_dwc2.c

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
#define DWC2_DEBUG 2
4040

4141
#include "device/dcd.h"
42+
#include "device/usbd.h"
4243
#include "device/usbd_pvt.h"
4344
#include "dwc2_common.h"
4445

@@ -76,6 +77,10 @@ CFG_TUD_MEM_SECTION static struct {
7677
TUD_EPBUF_DEF(setup_packet, 8);
7778
} _dcd_usbbuf;
7879

80+
static tud_configure_dwc2_t _tud_cfg = {
81+
.bm_double_buffered = 0
82+
};
83+
7984
TU_ATTR_ALWAYS_INLINE static inline uint8_t dwc2_ep_count(const dwc2_regs_t* dwc2) {
8085
#if TU_CHECK_MCU(OPT_MCU_GD32VF103)
8186
(void) dwc2;
@@ -212,8 +217,8 @@ static bool dfifo_alloc(uint8_t rhport, uint8_t ep_addr, uint16_t packet_size) {
212217
_dcd_data.allocated_epin_count++;
213218
}
214219

215-
// If The TXFELVL is configured as half empty, the fifo must be twice the max_size.
216-
if ((dwc2->gahbcfg & GAHBCFG_TX_FIFO_EPMTY_LVL) == 0) {
220+
// Enable double buffering if configured
221+
if (((_tud_cfg.bm_double_buffered & (1 << epnum)) != 0) && (epnum > 0)) {
217222
fifo_size *= 2;
218223
}
219224

@@ -446,6 +451,16 @@ static void edpt_schedule_packets(uint8_t rhport, const uint8_t epnum, const uin
446451
//--------------------------------------------------------------------
447452
// Controller API
448453
//--------------------------------------------------------------------
454+
// optional dcd configuration, called by tud_configure()
455+
bool dcd_configure(uint8_t rhport, uint32_t cfg_id, const void* cfg_param) {
456+
(void) rhport;
457+
TU_VERIFY(cfg_id == TUD_CFGID_DWC2 && cfg_param != NULL);
458+
459+
const tud_configure_param_t* const cfg = (const tud_configure_param_t*) cfg_param;
460+
_tud_cfg = cfg->dwc2;
461+
return true;
462+
}
463+
449464
bool dcd_init(uint8_t rhport, const tusb_rhport_init_t* rh_init) {
450465
(void) rh_init;
451466
dwc2_regs_t* dwc2 = DWC2_REG(rhport);
@@ -494,7 +509,6 @@ bool dcd_init(uint8_t rhport, const tusb_rhport_init_t* rh_init) {
494509

495510
// TX FIFO empty level for interrupt is complete empty
496511
uint32_t gahbcfg = dwc2->gahbcfg;
497-
gahbcfg |= GAHBCFG_TX_FIFO_EPMTY_LVL;
498512
gahbcfg |= GAHBCFG_GINT; // Enable global interrupt
499513
dwc2->gahbcfg = gahbcfg;
500514

0 commit comments

Comments
 (0)