Skip to content

Commit

Permalink
temp code
Browse files Browse the repository at this point in the history
  • Loading branch information
hathach committed May 17, 2024
1 parent 2a67ce7 commit c7c2daa
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 13 deletions.
25 changes: 25 additions & 0 deletions hw/bsp/ch32v307/family.c
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,18 @@ __attribute__ ((used)) void USBHS_IRQHandler_impl (void)
tud_int_handler(0);
}


void OTG_FS_IRQHandler (void) __attribute__((naked));
void OTG_FS_IRQHandler (void)
{
__asm volatile ("call OTG_FS_IRQHandler_impl; mret");
}

__attribute__ ((used)) void OTG_FS_IRQHandler_impl (void)
{
tud_int_handler(0);
}

//--------------------------------------------------------------------+
// MACRO TYPEDEF CONSTANT ENUM
//--------------------------------------------------------------------+
Expand All @@ -72,13 +84,26 @@ void board_init(void) {

usart_printf_init(115200);

#if 0
RCC_USBCLK48MConfig(RCC_USBCLK48MCLKSource_USBPHY);
RCC_USBHSPLLCLKConfig(RCC_HSBHSPLLCLKSource_HSE);
RCC_USBHSConfig(RCC_USBPLL_Div2);
RCC_USBHSPLLCKREFCLKConfig(RCC_USBHSPLLCKREFCLK_4M);
RCC_USBHSPHYPLLALIVEcmd(ENABLE);
RCC_AHBPeriphClockCmd(RCC_AHBPeriph_USBHS, ENABLE);

#else
uint8_t otg_div;
switch (SystemCoreClock) {
case 48000000: otg_div = RCC_OTGFSCLKSource_PLLCLK_Div1; break;
case 96000000: otg_div = RCC_OTGFSCLKSource_PLLCLK_Div2; break;
case 144000000: otg_div = RCC_OTGFSCLKSource_PLLCLK_Div3; break;
default: TU_ASSERT(0,); break;
}
RCC_OTGFSCLKConfig(otg_div);
RCC_AHBPeriphClockCmd(RCC_AHBPeriph_OTG_FS, ENABLE);
#endif

GPIO_InitTypeDef GPIO_InitStructure = {0};

// LED
Expand Down
23 changes: 14 additions & 9 deletions hw/bsp/ch32v307/family.cmake
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
include_guard()

set(CH32_FAMILY ch32v30x)
set(SDK_DIR ${TOP}/hw/mcu/wch/ch32v307/EVT/EXAM/SRC)

# include board specific
Expand All @@ -12,6 +13,8 @@ set(CMAKE_TOOLCHAIN_FILE ${TOP}/examples/build_system/cmake/toolchain/riscv_${TO
set(FAMILY_MCUS CH32V307 CACHE INTERNAL "")
set(OPENOCD_OPTION "-f ${CMAKE_CURRENT_LIST_DIR}/wch-riscv.cfg")

# Port0 Fullspeed, Port1 Highspeed

#------------------------------------
# BOARD_TARGET
#------------------------------------
Expand All @@ -27,26 +30,27 @@ function(add_board_target BOARD_TARGET)
set(LD_FILE_Clang ${LD_FILE_GNU})

if (NOT DEFINED STARTUP_FILE_GNU)
set(STARTUP_FILE_GNU ${SDK_DIR}/Startup/startup_ch32v30x_D8C.S)
set(STARTUP_FILE_GNU ${SDK_DIR}/Startup/startup_${CH32_FAMILY}_D8C.S)
endif ()
set(STARTUP_FILE_Clang ${STARTUP_FILE_GNU})

add_library(${BOARD_TARGET} STATIC
${SDK_DIR}/Core/core_riscv.c
${SDK_DIR}/Peripheral/src/ch32v30x_gpio.c
${SDK_DIR}/Peripheral/src/ch32v30x_misc.c
${SDK_DIR}/Peripheral/src/ch32v30x_rcc.c
${SDK_DIR}/Peripheral/src/ch32v30x_usart.c
${CMAKE_CURRENT_FUNCTION_LIST_DIR}/ch32v30x_it.c
${CMAKE_CURRENT_FUNCTION_LIST_DIR}/system_ch32v30x.c
${SDK_DIR}/Peripheral/src/${CH32_FAMILY}_gpio.c
${SDK_DIR}/Peripheral/src/${CH32_FAMILY}_misc.c
${SDK_DIR}/Peripheral/src/${CH32_FAMILY}_rcc.c
${SDK_DIR}/Peripheral/src/${CH32_FAMILY}_usart.c
${CMAKE_CURRENT_FUNCTION_LIST_DIR}/${CH32_FAMILY}_it.c
${CMAKE_CURRENT_FUNCTION_LIST_DIR}/system_${CH32_FAMILY}.c
${STARTUP_FILE_${CMAKE_C_COMPILER_ID}}
)
target_include_directories(${BOARD_TARGET} PUBLIC
${SDK_DIR}/Peripheral/inc
${CMAKE_CURRENT_FUNCTION_LIST_DIR}
)
target_compile_definitions(${BOARD_TARGET} PUBLIC
BOARD_TUD_MAX_SPEED=OPT_MODE_HIGH_SPEED
#BOARD_TUD_MAX_SPEED=OPT_MODE_HIGH_SPEED
BOARD_TUD_MAX_SPEED=OPT_MODE_FULL_SPEED
)

update_board(${BOARD_TARGET})
Expand Down Expand Up @@ -100,7 +104,8 @@ function(family_configure_example TARGET RTOS)
# Add TinyUSB target and port source
family_add_tinyusb(${TARGET} OPT_MCU_CH32V307 ${RTOS})
target_sources(${TARGET}-tinyusb PUBLIC
${TOP}/src/portable/wch/dcd_ch32_usbhs.c
#${TOP}/src/portable/wch/dcd_ch32_usbhs.c
${TOP}/src/portable/wch/dcd_ch32_usbfs.c
)
target_link_libraries(${TARGET}-tinyusb PUBLIC board_${BOARD})

Expand Down
4 changes: 2 additions & 2 deletions src/common/tusb_mcu.h
Original file line number Diff line number Diff line change
Expand Up @@ -404,8 +404,8 @@

//------------- WCH -------------//
#elif TU_CHECK_MCU(OPT_MCU_CH32V307)
#define TUP_DCD_ENDPOINT_MAX 16
#define TUP_RHPORT_HIGHSPEED 1
#define TUP_DCD_ENDPOINT_MAX 8
// #define TUP_RHPORT_HIGHSPEED 1

#elif TU_CHECK_MCU(OPT_MCU_CH32F20X)
#define TUP_DCD_ENDPOINT_MAX 16
Expand Down
9 changes: 8 additions & 1 deletion src/portable/wch/ch32_usbfs_reg.h
Original file line number Diff line number Diff line change
@@ -1,8 +1,15 @@
#ifndef USB_CH32_USBFS_REG_H
#define USB_CH32_USBFS_REG_H

#if (CFG_TUSB_MCU == OPT_MCU_CH32V20X)
#if (CFG_TUSB_MCU == OPT_MCU_CH32V307)
#include <ch32v30x.h>
#define USBHD_IRQn OTG_FS_IRQn

#elif (CFG_TUSB_MCU == OPT_MCU_CH32V20X)
#include <ch32v20x.h>

#elif (CFG_TUSB_MCU == OPT_MCU_CH32F20X)
#include <ch32f20x.h>
#endif

// CTRL
Expand Down
2 changes: 1 addition & 1 deletion src/portable/wch/dcd_ch32_usbfs.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#include "tusb_option.h"

#if CFG_TUD_ENABLED && (CFG_TUSB_MCU == OPT_MCU_CH32V20X)
#if CFG_TUD_ENABLED && (CFG_TUSB_MCU == OPT_MCU_CH32V20X || CFG_TUSB_MCU == OPT_MCU_CH32V307)

#include <stdio.h>
#include "device/dcd.h"
Expand Down

0 comments on commit c7c2daa

Please sign in to comment.