summaryrefslogtreecommitdiff
path: root/src/portable/st/synopsys/dcd_synopsys.c
diff options
context:
space:
mode:
authorHa Thach <[email protected]>2021-08-15 18:50:00 +0700
committerGitHub <[email protected]>2021-08-15 18:50:00 +0700
commit2bb63406e997189a329f223136b183084f90fa7d (patch)
treee3a86832926448a8afb4d93f1009b8a0a7e3bd69 /src/portable/st/synopsys/dcd_synopsys.c
parent48f17efa77b84ed7c977b3655b7a067385fffcc1 (diff)
parentc4a6a5ccb710828111eda25b98704ae489fc63ab (diff)
Merge pull request #959 from KarlK90/gd32vf103-support-tiny-usb
[PORT] Add GD32VF103 support and Sipeed Longan Nano Board support
Diffstat (limited to 'src/portable/st/synopsys/dcd_synopsys.c')
-rw-r--r--src/portable/st/synopsys/dcd_synopsys.c31
1 files changed, 30 insertions, 1 deletions
diff --git a/src/portable/st/synopsys/dcd_synopsys.c b/src/portable/st/synopsys/dcd_synopsys.c
index 5a5645dd4..8a998aa3a 100644
--- a/src/portable/st/synopsys/dcd_synopsys.c
+++ b/src/portable/st/synopsys/dcd_synopsys.c
@@ -51,7 +51,8 @@
CFG_TUSB_MCU == OPT_MCU_STM32F4 || \
CFG_TUSB_MCU == OPT_MCU_STM32F7 || \
CFG_TUSB_MCU == OPT_MCU_STM32H7 || \
- (CFG_TUSB_MCU == OPT_MCU_STM32L4 && defined(STM32L4_SYNOPSYS)) \
+ (CFG_TUSB_MCU == OPT_MCU_STM32L4 && defined(STM32L4_SYNOPSYS) || \
+ CFG_TUSB_MCU == OPT_MCU_GD32VF103 ) \
)
// EP_MAX : Max number of bi-directional endpoints including EP0
@@ -92,6 +93,30 @@
#define EP_MAX_FS 6
#define EP_FIFO_SIZE_FS 1280
+#elif CFG_TUSB_MCU == OPT_MCU_GD32VF103
+#include "synopsys_common.h"
+
+// These numbers are the same for the whole GD32VF103 family.
+#define OTG_FS_IRQn 86
+#define EP_MAX_FS 4
+#define EP_FIFO_SIZE_FS 1280
+
+// The GD32VF103 is a RISC-V MCU, which implements the ECLIC Core-Local
+// Interrupt Controller by Nuclei. It is nearly API compatible to the
+// NVIC used by ARM MCUs.
+#define ECLIC_INTERRUPT_ENABLE_BASE 0xD2001001UL
+
+#define NVIC_EnableIRQ __eclic_enable_interrupt
+#define NVIC_DisableIRQ __eclic_disable_interrupt
+
+static inline void __eclic_enable_interrupt (uint32_t irq) {
+ *(volatile uint8_t*)(ECLIC_INTERRUPT_ENABLE_BASE + (irq * 4)) = 1;
+}
+
+static inline void __eclic_disable_interrupt (uint32_t irq){
+ *(volatile uint8_t*)(ECLIC_INTERRUPT_ENABLE_BASE + (irq * 4)) = 0;
+}
+
#else
#error "Unsupported MCUs"
#endif
@@ -282,6 +307,8 @@ static void set_turnaround(USB_OTG_GlobalTypeDef * usb_otg, tusb_speed_t speed)
// Turnaround timeout depends on the MCU clock
uint32_t turnaround;
+ TU_LOG_INT(2, SystemCoreClock);
+
if ( SystemCoreClock >= 32000000U )
turnaround = 0x6U;
else if ( SystemCoreClock >= 27500000U )
@@ -625,6 +652,8 @@ bool dcd_edpt_open (uint8_t rhport, tusb_desc_endpoint_t const * desc_edpt)
_allocated_fifo_words_tx += fifo_size;
+ TU_LOG(2, " Allocated %u bytes at offset %u", fifo_size*4, EP_FIFO_SIZE-_allocated_fifo_words_tx*4);
+
// DIEPTXF starts at FIFO #1.
// Both TXFD and TXSA are in unit of 32-bit words.
usb_otg->DIEPTXF[epnum - 1] = (fifo_size << USB_OTG_DIEPTXF_INEPTXFD_Pos) | (EP_FIFO_SIZE/4 - _allocated_fifo_words_tx);