diff --git a/hw/bsp/fomu/family.mk b/hw/bsp/fomu/family.mk index 40cb5dd45..165535c6b 100644 --- a/hw/bsp/fomu/family.mk +++ b/hw/bsp/fomu/family.mk @@ -5,7 +5,7 @@ CFLAGS += \ -nostdlib \ -DCFG_TUSB_MCU=OPT_MCU_VALENTYUSB_EPTRI -# Cross Compiler for RISC-V +# Toolchain from https://github.com/xpack-dev-tools/riscv-none-embed-gcc-xpack CROSS_COMPILE = riscv-none-embed- # All source paths should be relative to the top level. diff --git a/hw/bsp/gd32vf103_longan_nano/nuclei_sdk_hal.h b/hw/bsp/gd32vf103/boards/sipeed_longan_nano/board.h similarity index 91% rename from hw/bsp/gd32vf103_longan_nano/nuclei_sdk_hal.h rename to hw/bsp/gd32vf103/boards/sipeed_longan_nano/board.h index 9b2a616a8..fae7c40b7 100644 --- a/hw/bsp/gd32vf103_longan_nano/nuclei_sdk_hal.h +++ b/hw/bsp/gd32vf103/boards/sipeed_longan_nano/board.h @@ -2,8 +2,6 @@ #define _NUCLEI_SDK_HAL_H #include "gd32vf103c_longan_nano.h" -#include "drv_usb_hw.h" -#include "drv_usb_dev.h" // 4 bits for interrupt level, 0 for priority. // level 0 = lowest priority, level 15 = highest priority. diff --git a/hw/bsp/gd32vf103/boards/sipeed_longan_nano/board.mk b/hw/bsp/gd32vf103/boards/sipeed_longan_nano/board.mk new file mode 100644 index 000000000..3b8944452 --- /dev/null +++ b/hw/bsp/gd32vf103/boards/sipeed_longan_nano/board.mk @@ -0,0 +1,13 @@ +LONGAN_NANO_SDK_BSP = $(GD32VF103_SDK_SOC)/Board/gd32vf103c_longan_nano +LINKER_SCRIPTS = $(LONGAN_NANO_SDK_BSP)/Source/GCC + +# All source paths should be relative to the top level. +LD_FILE = $(LINKER_SCRIPTS)/gcc_gd32vf103xb_flashxip.ld # Longan Nano 128k ROM 32k RAM +#LD_FILE = $(LINKER_SCRIPTS)/gcc_gd32vf103x8_flashxip.ld # Longan Nano Lite 64k ROM 20k RAM + +SRC_C += $(LONGAN_NANO_SDK_BSP)/Source/gd32vf103c_longan_nano.c +INC += $(TOP)/$(LONGAN_NANO_SDK_BSP)/Include + +# Longan Nano 128k ROM 32k RAM +JLINK_DEVICE = gd32vf103cbt6 +#JLINK_DEVICE = gd32vf103c8t6 # Longan Nano Lite 64k ROM 20k RAM diff --git a/hw/bsp/gd32vf103_longan_nano/gd32vf103_longan_nano.c b/hw/bsp/gd32vf103/family.c similarity index 98% rename from hw/bsp/gd32vf103_longan_nano/gd32vf103_longan_nano.c rename to hw/bsp/gd32vf103/family.c index 951ab844c..d76fb9a2a 100644 --- a/hw/bsp/gd32vf103_longan_nano/gd32vf103_longan_nano.c +++ b/hw/bsp/gd32vf103/family.c @@ -24,8 +24,11 @@ * This file is part of the TinyUSB stack. */ +#include "board.h" +#include "drv_usb_hw.h" +#include "drv_usb_dev.h" + #include "../board.h" -#include "nuclei_sdk_hal.h" //--------------------------------------------------------------------+ // Forward USB interrupt events to TinyUSB IRQ Handler diff --git a/hw/bsp/gd32vf103_longan_nano/board.mk b/hw/bsp/gd32vf103/family.mk similarity index 65% rename from hw/bsp/gd32vf103_longan_nano/board.mk rename to hw/bsp/gd32vf103/family.mk index 5ab275dbe..3479433e4 100644 --- a/hw/bsp/gd32vf103_longan_nano/board.mk +++ b/hw/bsp/gd32vf103/family.mk @@ -1,17 +1,24 @@ -CROSS_COMPILE = riscv32-unknown-elf- +# https://www.embecosm.com/resources/tool-chain-downloads/#riscv-stable +#CROSS_COMPILE ?= riscv32-unknown-elf- + +# Toolchain from https://nucleisys.com/download.php +CROSS_COMPILE ?= riscv-nuclei-elf- + +# Toolchain from https://github.com/xpack-dev-tools/riscv-none-embed-gcc-xpack +#CROSS_COMPILE ?= riscv-none-embed- # Submodules -DEPS_SUBMODULES += hw/mcu/gd/nuclei-sdk NUCLEI_SDK = hw/mcu/gd/nuclei-sdk +DEPS_SUBMODULES += $(NUCLEI_SDK) # Nuclei-SDK paths GD32VF103_SDK_SOC = $(NUCLEI_SDK)/SoC/gd32vf103 GD32VF103_SDK_DRIVER = $(GD32VF103_SDK_SOC)/Common/Source/Drivers -LONGAN_NANO_SDK_BSP = $(GD32VF103_SDK_SOC)/Board/gd32vf103c_longan_nano -LINKER_SCRIPTS = $(LONGAN_NANO_SDK_BSP)/Source/GCC LIBC_STUBS = $(GD32VF103_SDK_SOC)/Common/Source/Stubs STARTUP_ASM = $(GD32VF103_SDK_SOC)/Common/Source/GCC +include $(TOP)/$(BOARD_PATH)/board.mk + SKIP_NANOLIB = 1 CFLAGS += \ @@ -27,17 +34,12 @@ CFLAGS += \ # mcu driver cause following warnings CFLAGS += -Wno-error=unused-parameter -# All source paths should be relative to the top level. -LD_FILE = $(LINKER_SCRIPTS)/gcc_gd32vf103xb_flashxip.ld # Longan Nano 128k ROM 32k RAM -#LD_FILE = $(LINKER_SCRIPTS)/gcc_gd32vf103x8_flashxip.ld # Longan Nano Lite 64k ROM 20k RAM - SRC_C += \ src/portable/st/synopsys/dcd_synopsys.c \ $(GD32VF103_SDK_DRIVER)/gd32vf103_rcu.c \ $(GD32VF103_SDK_DRIVER)/gd32vf103_gpio.c \ $(GD32VF103_SDK_DRIVER)/Usb/gd32vf103_usb_hw.c \ $(GD32VF103_SDK_DRIVER)/gd32vf103_usart.c \ - $(LONGAN_NANO_SDK_BSP)/Source/gd32vf103c_longan_nano.c \ $(LIBC_STUBS)/sbrk.c \ $(LIBC_STUBS)/close.c \ $(LIBC_STUBS)/isatty.c \ @@ -50,19 +52,16 @@ SRC_S += \ $(STARTUP_ASM)/intexc_gd32vf103.S INC += \ - $(TOP)/hw/bsp/$(BOARD) \ + $(TOP)/$(BOARD_PATH) \ $(TOP)/$(NUCLEI_SDK)/NMSIS/Core/Include \ $(TOP)/$(GD32VF103_SDK_SOC)/Common/Include \ - $(TOP)/$(GD32VF103_SDK_SOC)/Common/Include/Usb \ - $(TOP)/$(LONGAN_NANO_SDK_BSP)/Include + $(TOP)/$(GD32VF103_SDK_SOC)/Common/Include/Usb # For freeRTOS port source FREERTOS_PORT = RISC-V # For flash-jlink target JLINK_IF = jtag -JLINK_DEVICE = gd32vf103cbt6 # Longan Nano 128k ROM 32k RAM -#JLINK_DEVICE = gd32vf103c8t6 # Longan Nano Lite 64k ROM 20k RAM # flash target ROM bootloader flash: $(BUILD)/$(PROJECT).bin diff --git a/hw/bsp/gd32vf103_longan_nano/system_gd32vf103.c b/hw/bsp/gd32vf103/system_gd32vf103.c similarity index 99% rename from hw/bsp/gd32vf103_longan_nano/system_gd32vf103.c rename to hw/bsp/gd32vf103/system_gd32vf103.c index 8019974d6..29518a54a 100644 --- a/hw/bsp/gd32vf103_longan_nano/system_gd32vf103.c +++ b/hw/bsp/gd32vf103/system_gd32vf103.c @@ -33,7 +33,7 @@ OF SUCH DAMAGE. */ /* This file refers the RISC-V standard, some adjustments are made according to GigaDevice chips */ -#include "nuclei_sdk_hal.h" +#include "board.h" /* system frequency define */ #define __IRC8M (IRC8M_VALUE) /* internal 8 MHz RC oscillator frequency */ diff --git a/src/portable/st/synopsys/dcd_synopsys.c b/src/portable/st/synopsys/dcd_synopsys.c index b8f6ceda2..ea19080ae 100644 --- a/src/portable/st/synopsys/dcd_synopsys.c +++ b/src/portable/st/synopsys/dcd_synopsys.c @@ -303,6 +303,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 ) @@ -646,6 +648,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);