summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorsakumisu <[email protected]>2025-07-10 21:52:58 +0800
committersakumisu <[email protected]>2025-07-10 21:52:58 +0800
commit78a802faa6a1eac710a2e48b7aa55c3458596604 (patch)
treecb1856ea7ef3a6b708d761d21611b93908b86683
parent811550ad255e32a6775449e663bbc4f9d1a629a2 (diff)
update(port/dwc2/usb_glue_at): update at glue with dwc2 param
Signed-off-by: sakumisu <[email protected]>
-rw-r--r--port/dwc2/usb_glue_at.c124
1 files changed, 85 insertions, 39 deletions
diff --git a/port/dwc2/usb_glue_at.c b/port/dwc2/usb_glue_at.c
index 636ce12c..a531fdb3 100644
--- a/port/dwc2/usb_glue_at.c
+++ b/port/dwc2/usb_glue_at.c
@@ -3,60 +3,106 @@
*
* SPDX-License-Identifier: Apache-2.0
*/
-#include "usb_config.h"
-#include "stdint.h"
-#include "usb_dwc2_reg.h"
+#include "usbd_core.h"
+#include "usbh_core.h"
+#include "usb_dwc2_param.h"
extern unsigned int system_core_clock;
uint32_t SystemCoreClock;
-/* you can find this config in function: usb_global_init, file:at32fxxx_usb.c, for example:
- *
- * usbx->gccfg_bit.pwrdown = TRUE;
- * usbx->gccfg_bit.avalidsesen = TRUE;
- * usbx->gccfg_bit.bvalidsesen = TRUE;
- *
-*/
-uint32_t usbd_get_dwc2_gccfg_conf(uint32_t reg_base)
-{
- SystemCoreClock = system_core_clock;
-#ifdef CONFIG_USB_HS
- return ((1 << 16) | (1 << 21));
-#else
- // AT32F415
-#if defined(AT32F415RCT7) || defined(AT32F415RCT7_7) || defined(AT32F415CCT7) || \
- defined(AT32F415CCU7) || defined(AT32F415KCU7_4) || defined(AT32F415RBT7) || \
- defined(AT32F415RBT7_7) || defined(AT32F415CBT7) || defined(AT32F415CBU7) || \
- defined(AT32F415KBU7_4) || defined(AT32F415R8T7) || defined(AT32F415R8T7_7) || \
- defined(AT32F415C8T7) || defined(AT32F415K8U7_4)
- return ((1 << 16) | (1 << 18) | (1 << 19) | (1 << 21));
+const struct dwc2_user_params param_pa11_pa12 = {
+ .phy_type = DWC2_PHY_TYPE_PARAM_FS,
+ .device_dma_enable = false,
+ .device_dma_desc_enable = false,
+ .device_rx_fifo_size = (320 - 16 - 16 - 16 - 16),
+ .device_tx_fifo_size = {
+ [0] = 16, // 64 byte
+ [1] = 16, // 64 byte
+ [2] = 16, // 64 byte
+ [3] = 16, // 64 byte
+ [4] = 0,
+ [5] = 0,
+ [6] = 0,
+ [7] = 0,
+ [8] = 0,
+ [9] = 0,
+ [10] = 0,
+ [11] = 0,
+ [12] = 0,
+ [13] = 0,
+ [14] = 0,
+ [15] = 0 },
+#ifdef AT32F415xx
+ .device_gccfg = ((1 << 16) | (1 << 18) | (1 << 19) | (1 << 21)),
#else
- return ((1 << 16) | (1 << 21));
+ .device_gccfg = ((1 << 16) | (1 << 21)),
#endif
+ .total_fifo_size = 320 // 1280 byte
+};
+
+#if __has_include("at32f402_405.h")
+#include "at32f402_405.h"
+
+const struct dwc2_user_params param_pb14_pb15 = {
+ .phy_type = DWC2_PHY_TYPE_PARAM_UTMI,
+ .device_dma_enable = true,
+ .device_dma_desc_enable = false,
+ .device_rx_fifo_size = (1008 - 16 - 256 - 128 - 128 - 128 - 128),
+ .device_tx_fifo_size = {
+ [0] = 16, // 64 byte
+ [1] = 256, // 1024 byte
+ [2] = 128, // 512 byte
+ [3] = 128, // 512 byte
+ [4] = 128, // 512 byte
+ [5] = 128, // 512 byte
+ [6] = 0,
+ [7] = 0,
+ [8] = 0,
+ [9] = 0,
+ [10] = 0,
+ [11] = 0,
+ [12] = 0,
+ [13] = 0,
+ [14] = 0,
+ [15] = 0 },
+
+ .host_dma_desc_enable = false,
+ .host_rx_fifo_size = 628,
+ .host_nperio_tx_fifo_size = 128, // 512 byte
+ .host_perio_tx_fifo_size = 256, // 1024 byte
+
+ .device_gccfg = ((1 << 16) | (1 << 21)),
+ .host_gccfg = ((1 << 16) | (1 << 21))
+};
#endif
-}
-uint32_t usbh_get_dwc2_gccfg_conf(uint32_t reg_base)
+#ifndef CONFIG_USB_DWC2_CUSTOM_PARAM
+void dwc2_get_user_params(uint32_t reg_base, struct dwc2_user_params *params)
{
SystemCoreClock = system_core_clock;
-#ifdef CONFIG_USB_HS
- return ((1 << 16) | (1 << 21));
-#else
- // AT32F415
-#if defined(AT32F415RCT7) || defined(AT32F415RCT7_7) || defined(AT32F415CCT7) || \
- defined(AT32F415CCU7) || defined(AT32F415KCU7_4) || defined(AT32F415RBT7) || \
- defined(AT32F415RBT7_7) || defined(AT32F415CBT7) || defined(AT32F415CBU7) || \
- defined(AT32F415KBU7_4) || defined(AT32F415R8T7) || defined(AT32F415R8T7_7) || \
- defined(AT32F415C8T7) || defined(AT32F415K8U7_4)
- return ((1 << 16) | (1 << 18) | (1 << 19) | (1 << 21));
+
+#if __has_include("at32f402_405.h")
+ if (reg_base == OTGHS_BASE) {
+ memcpy(params, &param_pb14_pb15, sizeof(struct dwc2_user_params));
+ } else {
+ memcpy(params, &param_pa11_pa12, sizeof(struct dwc2_user_params));
+ }
#else
- return ((1 << 16) | (1 << 21));
+ memcpy(params, &param_pa11_pa12, sizeof(struct dwc2_user_params));
#endif
+#ifdef CONFIG_USB_DWC2_CUSTOM_FIFO
+ struct usb_dwc2_user_fifo_config s_dwc2_fifo_config;
+
+ dwc2_get_user_fifo_config(reg_base, &s_dwc2_fifo_config);
+
+ params->device_rx_fifo_size = s_dwc2_fifo_config.device_rx_fifo_size;
+ for (uint8_t i = 0; i < MAX_EPS_CHANNELS; i++) {
+ params->device_tx_fifo_size[i] = s_dwc2_fifo_config.device_tx_fifo_size[i];
+ }
#endif
}
-
-extern uint32_t SystemCoreClock;
+#endif
void usbd_dwc2_delay_ms(uint8_t ms)
{