temp code

This commit is contained in:
hathach 2024-05-17 16:13:59 +07:00
parent ab5f276877
commit 5fee292606
No known key found for this signature in database
GPG Key ID: 26FAB84F615C3C52
5 changed files with 50 additions and 13 deletions

View File

@ -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
//--------------------------------------------------------------------+
@ -72,6 +84,7 @@ 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);
@ -79,6 +92,18 @@ void board_init(void) {
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

View File

@ -1,5 +1,6 @@
include_guard()
set(CH32_FAMILY ch32v30x)
set(SDK_DIR ${TOP}/hw/mcu/wch/ch32v307/EVT/EXAM/SRC)
# include board specific
@ -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
#------------------------------------
@ -27,18 +30,18 @@ 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
@ -46,7 +49,8 @@ function(add_board_target BOARD_TARGET)
${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})
@ -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})

View File

@ -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

View File

@ -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

View File

@ -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"