Skip to content

Commit b32a735

Browse files
committed
refactor(soc/host): Update USB OTG struct fields
This commit updates the "*_struct.h" files for the USB OTG peripheral: - Added/removed some missing/non-existing register fields - Added "reserved" place holders for registers that are missing due to IP configuration. - Added "usb_dwc_cfg.h" listing the USB OTG IP configuration for each target. - Updated LL/HAL according to register field updates. Also tidied up the include directives in those headers.
1 parent 177eb9f commit b32a735

File tree

7 files changed

+865
-603
lines changed

7 files changed

+865
-603
lines changed

components/hal/include/hal/usb_dwc_hal.h

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,21 +6,22 @@
66

77
#pragma once
88

9-
#ifdef __cplusplus
10-
extern "C" {
11-
#endif
12-
9+
#include "soc/soc_caps.h"
1310
/*
14-
NOTE: Thread safety is the responsibility fo the HAL user. All USB Host HAL
15-
functions must be called from critical sections unless specified otherwise
11+
This header is shared across all targets. Resolve to an empty header for targets
12+
that don't support USB OTG.
1613
*/
17-
18-
#include <stdlib.h>
19-
#include <stddef.h>
20-
#include "soc/usb_dwc_struct.h"
14+
#if SOC_USB_OTG_SUPPORTED
15+
#include <stdint.h>
16+
#include <stdbool.h>
2117
#include "hal/usb_dwc_ll.h"
2218
#include "hal/usb_dwc_types.h"
2319
#include "hal/assert.h"
20+
#endif // SOC_USB_OTG_SUPPORTED
21+
22+
#ifdef __cplusplus
23+
extern "C" {
24+
#endif
2425

2526
#if SOC_USB_OTG_SUPPORTED
2627

components/hal/include/hal/usb_dwc_ll.h

Lines changed: 43 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,25 @@
66

77
#pragma once
88

9-
#ifdef __cplusplus
10-
extern "C" {
11-
#endif
12-
9+
#include "soc/soc_caps.h"
10+
/*
11+
This header is shared across all targets. Resolve to an empty header for targets
12+
that don't support USB OTG.
13+
*/
14+
#if SOC_USB_OTG_SUPPORTED
1315
#include <stdint.h>
1416
#include <stdbool.h>
1517
#include "soc/usb_dwc_struct.h"
18+
#include "soc/usb_dwc_cfg.h"
1619
#include "hal/usb_dwc_types.h"
1720
#include "hal/misc.h"
21+
#endif // SOC_USB_OTG_SUPPORTED
22+
23+
#ifdef __cplusplus
24+
extern "C" {
25+
#endif
1826

27+
#if SOC_USB_OTG_SUPPORTED
1928

2029
/* -----------------------------------------------------------------------------
2130
--------------------------------- DWC Constants --------------------------------
@@ -853,28 +862,48 @@ static inline uint32_t usb_dwc_ll_hctsiz_get_pid(volatile usb_dwc_host_chan_regs
853862

854863
static inline void usb_dwc_ll_hctsiz_set_qtd_list_len(volatile usb_dwc_host_chan_regs_t *chan, int qtd_list_len)
855864
{
856-
HAL_FORCE_MODIFY_U32_REG_FIELD(chan->hctsiz_reg, ntd, qtd_list_len - 1); //Set the length of the descriptor list
865+
usb_dwc_hctsiz_reg_t hctsiz;
866+
hctsiz.val = chan->hctsiz_reg.val;
867+
//Set the length of the descriptor list. NTD occupies xfersize[15:8]
868+
hctsiz.xfersize &= ~(0xFF << 8);
869+
hctsiz.xfersize |= ((qtd_list_len - 1) & 0xFF) << 8;
870+
chan->hctsiz_reg.val = hctsiz.val;
857871
}
858872

859873
static inline void usb_dwc_ll_hctsiz_init(volatile usb_dwc_host_chan_regs_t *chan)
860874
{
861-
chan->hctsiz_reg.dopng = 0; //Don't do ping
862-
HAL_FORCE_MODIFY_U32_REG_FIELD(chan->hctsiz_reg, sched_info, 0xFF); //Schedinfo is always 0xFF for fullspeed. Not used in Bulk/Ctrl channels
875+
usb_dwc_hctsiz_reg_t hctsiz;
876+
hctsiz.val = chan->hctsiz_reg.val;
877+
hctsiz.dopng = 0; //Don't do ping
878+
/*
879+
Set SCHED_INFO which occupies xfersize[7:0]
880+
It is always set to 0xFF for full speed and not used in Bulk/Ctrl channels
881+
*/
882+
hctsiz.xfersize |= 0xFF;
883+
chan->hctsiz_reg.val = hctsiz.val;
863884
}
864885

865886
// ---------------------------- HCDMAi Register --------------------------------
866887

867888
static inline void usb_dwc_ll_hcdma_set_qtd_list_addr(volatile usb_dwc_host_chan_regs_t *chan, void *dmaaddr, uint32_t qtd_idx)
868889
{
869-
//Set HCDMAi
870-
chan->hcdma_reg.val = 0;
871-
chan->hcdma_reg.non_iso.dmaaddr = (((uint32_t)dmaaddr) >> 9) & 0x7FFFFF; //MSB of 512 byte aligned address
872-
chan->hcdma_reg.non_iso.ctd = qtd_idx;
890+
usb_dwc_hcdma_reg_t hcdma;
891+
/*
892+
Set the base address portion of the field which is dmaaddr[31:9]. This is
893+
the based address of the QTD list and must be 512 bytes aligned
894+
*/
895+
hcdma.dmaaddr = ((uint32_t)dmaaddr) & 0xFFFFFE00;
896+
//Set the current QTD index in the QTD list which is dmaaddr[8:3]
897+
hcdma.dmaaddr |= (qtd_idx & 0x3F) << 3;
898+
//dmaaddr[2:0] is reserved thus doesn't not need to be set
899+
900+
chan->hcdma_reg.val = hcdma.val;
873901
}
874902

875903
static inline int usb_dwc_ll_hcdam_get_cur_qtd_idx(usb_dwc_host_chan_regs_t *chan)
876904
{
877-
return chan->hcdma_reg.non_iso.ctd;
905+
//The current QTD index is dmaaddr[8:3]
906+
return (chan->hcdma_reg.dmaaddr >> 3) & 0x3F;
878907
}
879908

880909
// ---------------------------- HCDMABi Register -------------------------------
@@ -994,6 +1023,8 @@ static inline void usb_dwc_ll_qtd_get_status(usb_dwc_ll_dma_qtd_t *qtd, int *rem
9941023
qtd->buffer_status_val = 0;
9951024
}
9961025

1026+
#endif // SOC_USB_OTG_SUPPORTED
1027+
9971028
#ifdef __cplusplus
9981029
}
9991030
#endif

components/hal/usb_dwc_hal.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@
99
#include <string.h>
1010
#include "sdkconfig.h"
1111
#include "soc/chip_revision.h"
12-
#include "hal/efuse_hal.h"
1312
#include "hal/usb_dwc_hal.h"
1413
#include "hal/usb_dwc_ll.h"
14+
#include "hal/efuse_hal.h"
1515
#include "hal/assert.h"
1616

1717
// ------------------------------------------------ Macros and Types ---------------------------------------------------
Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
/*
2+
* SPDX-FileCopyrightText: 2023 Espressif Systems (Shanghai) CO LTD
3+
*
4+
* SPDX-License-Identifier: Apache-2.0
5+
*/
6+
7+
#pragma once
8+
9+
#ifdef __cplusplus
10+
extern "C" {
11+
#endif
12+
13+
/*
14+
Configuration Set ID: 1
15+
*/
16+
17+
/* 3.1 Basic Config Parameters */
18+
#define OTG_MODE 0
19+
#define OTG_ARCHITECTURE 2
20+
#define OTG_SINGLE_POINT 1
21+
#define OTG_ENABLE_LPM 0
22+
#define OTG_EN_DED_TX_FIFO 1
23+
#define OTG_EN_DESC_DMA 1
24+
#define OTG_MULTI_PROC_INTRPT 0
25+
26+
/* 3.2 USB Physical Layer Interface Parameters */
27+
#define OTG_HSPHY_INTERFACE 0
28+
#define OTG_FSPHY_INTERFACE 1
29+
#define OTG_ENABLE_IC_USB 0
30+
#define OTG_I2C_INTERFACE 0
31+
#define OTG_ADP_SUPPORT 0
32+
#define OTG_BC_SUPPORT 0
33+
34+
/* 3.3 Device Endpoint Configuration Parameters */
35+
#define OTG_NUM_EPS 6
36+
#define OTG_NUM_IN_EPS 5
37+
#define OTG_NUM_CRL_EPS 0
38+
39+
/* 3.4 Host Endpoint Configuration Parameters */
40+
#define OTG_NUM_HOST_CHAN 8
41+
#define OTG_EN_PERIO_HOST 1
42+
43+
/* 3.5 Endpoint Channel FIFO Configuration Parameters */
44+
#define OTG_DFIFO_DEPTH 256
45+
#define OTG_DFIFO_DYNAMIC 1
46+
#define OTG_RX_DFIFO_DEPTH 256
47+
#define OTG_TX_HNPERIO_DFIFO_DEPTH 256
48+
#define OTG_TX_NPERIO_DFIFO_DEPTH 256
49+
#define OTG_TX_HPERIO_DFIFO_DEPTH 256
50+
#define OTG_NPERIO_TX_QUEUE_DEPTH 4
51+
#define OTG_PERIO_TX_QUEUE_DEPTH 8
52+
53+
/* 3.6 Additional Configuration Options Parameters */
54+
#define OTG_TRANS_COUNT_WIDTH 16
55+
#define OTG_PACKET_COUNT_WIDTH 7
56+
#define OTG_RM_OPT_FEATURES 1
57+
#define OTG_EN_PWROPT 1
58+
#define OTG_SYNC_RESET_TYPE 0
59+
#define OTG_EN_IDDIG_FILTER 1
60+
#define OTG_EN_VBUSVALID_FILTER 1
61+
#define OTG_EN_A_VALID_FILTER 1
62+
#define OTG_EN_B_VALID_FILTER 1
63+
#define OTG_EN_SESSIONEND_FILTER 1
64+
#define OTG_EXCP_CNTL_XFER_FLOW 1
65+
#define OTG_PWR_CLAMP 0
66+
#define OTG_PWR_SWITCH_POLARITY 0
67+
68+
/* 3.7 Endpoint Direction Parameters */
69+
#define OTG_EP_DIR_1 0
70+
#define OTG_EP_DIR_2 0
71+
#define OTG_EP_DIR_3 0
72+
#define OTG_EP_DIR_4 0
73+
#define OTG_EP_DIR_5 0
74+
#define OTG_EP_DIR_6 0
75+
76+
/* 3.8 Device Periodic FIFO Depth Parameters */
77+
78+
/* 3.9 Device IN Endpoint FIFO Depth Parameters */
79+
#define OTG_TX_DINEP_DFIFO_DEPTH_1 256
80+
#define OTG_TX_DINEP_DFIFO_DEPTH_2 256
81+
#define OTG_TX_DINEP_DFIFO_DEPTH_3 256
82+
#define OTG_TX_DINEP_DFIFO_DEPTH_4 256
83+
84+
/* 3.10 UTMI-To-UTMI Bridge Component Parameters */
85+
#define U2UB_EN 0
86+
87+
#ifdef __cplusplus
88+
}
89+
#endif

0 commit comments

Comments
 (0)