mirror of
https://github.com/sakumisu/CherryUSB.git
synced 2025-10-14 02:58:19 +08:00
feat: add nationstech support
Signed-off-by: sakumisu <1203593632@qq.com>
This commit is contained in:
4
Kconfig
4
Kconfig
@@ -40,6 +40,8 @@ if CHERRYUSB
|
||||
bool "dwc2_at"
|
||||
config CHERRYUSB_DEVICE_DWC2_HC
|
||||
bool "dwc2_hc"
|
||||
config CHERRYUSB_DEVICE_DWC2_NATION
|
||||
bool "dwc2_nation"
|
||||
config CHERRYUSB_DEVICE_DWC2_GD
|
||||
bool "dwc2_gd"
|
||||
config CHERRYUSB_DEVICE_DWC2_CUSTOM
|
||||
@@ -199,6 +201,8 @@ if CHERRYUSB
|
||||
bool "dwc2_kendryte"
|
||||
config CHERRYUSB_HOST_DWC2_HC
|
||||
bool "dwc2_hc"
|
||||
config CHERRYUSB_HOST_DWC2_NATION
|
||||
bool "dwc2_nation"
|
||||
config CHERRYUSB_HOST_DWC2_CUSTOM
|
||||
bool "dwc2_custom"
|
||||
config CHERRYUSB_HOST_MUSB_ES
|
||||
|
@@ -40,6 +40,8 @@ if RT_USING_CHERRYUSB
|
||||
bool "dwc2_at"
|
||||
config RT_CHERRYUSB_DEVICE_DWC2_HC
|
||||
bool "dwc2_hc"
|
||||
config RT_CHERRYUSB_DEVICE_DWC2_NATION
|
||||
bool "dwc2_nation"
|
||||
config RT_CHERRYUSB_DEVICE_DWC2_GD
|
||||
bool "dwc2_gd"
|
||||
config RT_CHERRYUSB_DEVICE_DWC2_CUSTOM
|
||||
@@ -203,6 +205,8 @@ if RT_USING_CHERRYUSB
|
||||
bool "dwc2_kendryte"
|
||||
config RT_CHERRYUSB_HOST_DWC2_HC
|
||||
bool "dwc2_hc"
|
||||
config RT_CHERRYUSB_HOST_DWC2_NATION
|
||||
bool "dwc2_nation"
|
||||
config RT_CHERRYUSB_HOST_DWC2_CUSTOM
|
||||
bool "dwc2_custom"
|
||||
config RT_CHERRYUSB_HOST_MUSB_ES
|
||||
|
@@ -41,6 +41,8 @@ if PKG_USING_CHERRYUSB
|
||||
bool "dwc2_at"
|
||||
config PKG_CHERRYUSB_DEVICE_DWC2_HC
|
||||
bool "dwc2_hc"
|
||||
config PKG_CHERRYUSB_DEVICE_DWC2_NATION
|
||||
bool "dwc2_nation"
|
||||
config PKG_CHERRYUSB_DEVICE_DWC2_GD
|
||||
bool "dwc2_gd"
|
||||
config PKG_CHERRYUSB_DEVICE_DWC2_CUSTOM
|
||||
@@ -202,6 +204,8 @@ if PKG_USING_CHERRYUSB
|
||||
bool "dwc2_kendryte"
|
||||
config PKG_CHERRYUSB_HOST_DWC2_HC
|
||||
bool "dwc2_hc"
|
||||
config PKG_CHERRYUSB_HOST_DWC2_NATION
|
||||
bool "dwc2_nation"
|
||||
config PKG_CHERRYUSB_HOST_DWC2_CUSTOM
|
||||
bool "dwc2_custom"
|
||||
config PKG_CHERRYUSB_HOST_MUSB_ES
|
||||
|
@@ -194,6 +194,7 @@ TODO
|
||||
|Espressif | esp32s2/esp32s3/esp32p4 | dwc2 |[esp32_repo](https://github.com/CherryUSB/cherryusb_esp32)|<= latest | Long-term |
|
||||
|NXP | mcx | kinetis/chipidea/ehci |[nxp_mcx_repo](https://github.com/CherryUSB/cherryusb_mcx)|<= latest | Long-term |
|
||||
|Kendryte | k230 | dwc2 |[k230_repo](https://github.com/CherryUSB/k230_sdk)|v1.2.0 | Long-term |
|
||||
|Nationstech | n32h4x | dwc2 |[nation_repo](https://github.com/CherryUSB/cherryusb_nation)|>=1.5.0 | Long-term |
|
||||
|Raspberry pi | rp2040/rp2350 | rp2040 |[pico-examples](https://github.com/CherryUSB/pico-examples)|<= latest | Long-term |
|
||||
|AllwinnerTech | F1C100S/F1C200S | musb |[cherryusb_rtt_f1c100s](https://github.com/CherryUSB/cherryusb_rtt_f1c100s)|<= latest | the same with musb |
|
||||
|Bekencorp | bk7256/bk7258 | musb |[bk_idk](https://github.com/CherryUSB/bk_idk)| v0.7.0 | the same with musb |
|
||||
@@ -221,3 +222,4 @@ CherryUSB discord: https://discord.com/invite/wFfvrSAey8.
|
||||
Thanks to the following companies for their support (in no particular order):
|
||||
|
||||
<img src="docs/assets/bouffalolab.jpg" width="100" height="80"/> <img src="docs/assets/hpmicro.jpg" width="100" height="80" /> <img src="docs/assets/eastsoft.jpg" width="100" height="80" /> <img src="docs/assets/rtthread.jpg" width="100" height="80" /> <img src="docs/assets/sophgo.jpg" width="100" height="80" /> <img src="docs/assets/phytium.jpg" width="100" height="80" /> <img src="docs/assets/thead.jpg" width="100" height="80" /> <img src="docs/assets/nuvoton.jpg" width="100" height="80" /> <img src="docs/assets/artinchip.jpg" width="100" height="80" /> <img src="docs/assets/bekencorp.jpg" width="100" height="80" /> <img src="docs/assets/nxp.png" width="100" height="80" /> <img src="docs/assets/espressif.png" width="100" height="80" /> <img src="docs/assets/canaan.jpg" width="100" height="80" />
|
||||
<img src="docs/assets/nationstech.jpg" width="100" height="80" />
|
||||
|
@@ -194,6 +194,7 @@ TODO
|
||||
|Espressif | esp32s2/esp32s3/esp32p4 | dwc2 |[esp32_repo](https://github.com/CherryUSB/cherryusb_esp32)|<= latest | Long-term |
|
||||
|NXP | mcx | kinetis/chipidea/ehci |[nxp_mcx_repo](https://github.com/CherryUSB/cherryusb_mcx)|<= latest | Long-term |
|
||||
|Kendryte | k230 | dwc2 |[k230_repo](https://github.com/CherryUSB/k230_sdk)|v1.2.0 | Long-term |
|
||||
|Nationstech | n32h4x | dwc2 |[nation_repo](https://github.com/CherryUSB/cherryusb_nation)|>=1.5.0 | Long-term |
|
||||
|Raspberry pi | rp2040/rp2350 | rp2040 |[pico-examples](https://github.com/CherryUSB/pico-examples)|<= latest | Long-term |
|
||||
|AllwinnerTech | F1C100S/F1C200S | musb |[cherryusb_rtt_f1c100s](https://github.com/CherryUSB/cherryusb_rtt_f1c100s)|<= latest | the same with musb |
|
||||
|Bekencorp | bk7256/bk7258 | musb |[bk_idk](https://github.com/CherryUSB/bk_idk)| v0.7.0 | the same with musb |
|
||||
@@ -223,3 +224,4 @@ CherryUSB 微信群:与我联系后邀请加入
|
||||
感谢以下企业支持(顺序不分先后):
|
||||
|
||||
<img src="docs/assets/bouffalolab.jpg" width="100" height="80"/> <img src="docs/assets/hpmicro.jpg" width="100" height="80" /> <img src="docs/assets/eastsoft.jpg" width="100" height="80" /> <img src="docs/assets/rtthread.jpg" width="100" height="80" /> <img src="docs/assets/sophgo.jpg" width="100" height="80" /> <img src="docs/assets/phytium.jpg" width="100" height="80" /> <img src="docs/assets/thead.jpg" width="100" height="80" /> <img src="docs/assets/nuvoton.jpg" width="100" height="80" /> <img src="docs/assets/artinchip.jpg" width="100" height="80" /> <img src="docs/assets/bekencorp.jpg" width="100" height="80" /> <img src="docs/assets/nxp.png" width="100" height="80" /> <img src="docs/assets/espressif.png" width="100" height="80" /> <img src="docs/assets/canaan.jpg" width="100" height="80" />
|
||||
<img src="docs/assets/nationstech.jpg" width="100" height="80" />
|
||||
|
@@ -53,6 +53,9 @@ if GetDepend(['PKG_CHERRYUSB_DEVICE']):
|
||||
if GetDepend(['PKG_CHERRYUSB_DEVICE_DWC2_HC']):
|
||||
src += Glob('port/dwc2/usb_dc_dwc2.c')
|
||||
src += Glob('port/dwc2/usb_glue_hc.c')
|
||||
if GetDepend(['PKG_CHERRYUSB_DEVICE_DWC2_NATION']):
|
||||
src += Glob('port/dwc2/usb_dc_dwc2.c')
|
||||
src += Glob('port/dwc2/usb_glue_nation.c')
|
||||
if GetDepend(['PKG_CHERRYUSB_DEVICE_DWC2_GD']):
|
||||
src += Glob('port/dwc2/usb_dc_dwc2.c')
|
||||
src += Glob('port/dwc2/usb_glue_gd.c')
|
||||
@@ -197,6 +200,9 @@ if GetDepend(['PKG_CHERRYUSB_HOST']):
|
||||
if GetDepend(['PKG_CHERRYUSB_HOST_DWC2_HC']):
|
||||
src += Glob('port/dwc2/usb_hc_dwc2.c')
|
||||
src += Glob('port/dwc2/usb_glue_hc.c')
|
||||
if GetDepend(['PKG_CHERRYUSB_HOST_DWC2_NATION']):
|
||||
src += Glob('port/dwc2/usb_hc_dwc2.c')
|
||||
src += Glob('port/dwc2/usb_glue_nation.c')
|
||||
if GetDepend(['PKG_CHERRYUSB_HOST_DWC2_CUSTOM']):
|
||||
src += Glob('port/dwc2/usb_hc_dwc2.c')
|
||||
if GetDepend(['PKG_CHERRYUSB_HOST_MUSB_STANDARD']):
|
||||
|
BIN
docs/assets/nationstech.jpg
Normal file
BIN
docs/assets/nationstech.jpg
Normal file
Binary file not shown.
After Width: | Height: | Size: 12 KiB |
@@ -44,3 +44,7 @@ CONFIG_USBDEV_EP_NUM 必须为4 或者 6,并删除 usb_dc_dwc2.c 中 while(1){
|
||||
## Kendryte
|
||||
|
||||
- K230
|
||||
|
||||
## Nationstech
|
||||
|
||||
- N32H4X
|
187
port/dwc2/usb_glue_nation.c
Normal file
187
port/dwc2/usb_glue_nation.c
Normal file
@@ -0,0 +1,187 @@
|
||||
/*
|
||||
* Copyright (c) 2025, sakumisu
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
#include "usbd_core.h"
|
||||
#include "usbh_core.h"
|
||||
|
||||
__WEAK void USBD_IRQHandler(uint8_t busid)
|
||||
{
|
||||
}
|
||||
|
||||
__WEAK void USBH_IRQHandler(uint8_t busid)
|
||||
{
|
||||
}
|
||||
|
||||
#if defined(N32H473) || defined(N32H474) || defined(N32H475) || defined(N32H482) || defined(N32H487)
|
||||
#include "n32h47x_48x_rcc.h"
|
||||
#include "n32h47x_48x_gpio.h"
|
||||
#include "n32h47x_48x_exti.h"
|
||||
#include "misc.h"
|
||||
|
||||
typedef void (*usb_dwc2_irq)(uint8_t busid);
|
||||
|
||||
static usb_dwc2_irq g_usb_dwc2_irq;
|
||||
static volatile uint8_t g_usb_dwc2_busid = 0;
|
||||
|
||||
static void usbhs_common_init(void)
|
||||
{
|
||||
RCC_EnableAHB1PeriphClk(RCC_AHB_PERIPHEN_GPIOA | RCC_AHB_PERIPHEN_GPIOB, ENABLE);
|
||||
RCC_EnableAPB2PeriphClk(RCC_APB2_PERIPH_AFIO, ENABLE);
|
||||
/* PLL= 240MHz */
|
||||
#if (HSE_VALUE == 8000000)
|
||||
/* Select PLL clock as USBHS clock source , clock 15 divisions = 16M */
|
||||
RCC_ConfigUSBPLLPresClk(RCC_USBPLLCLK_SRC_PLL, RCC_USBPLLCLK_DIV15);
|
||||
|
||||
/* Select the corresponding bandwidth and frequency*/
|
||||
RCC_ConfigUSBHSBandwidth(RCC_USBHS_BW_16M);
|
||||
|
||||
/* Select USBHS clock source frequency */
|
||||
RCC_ConfigUSBHSFrequency(RCC_USBHS_FREQ_16_OR_32M);
|
||||
|
||||
/* Select PLL as USBHS clock */
|
||||
RCC_ConfigUSBHSClk(RCC_USBHS_CLKSRC_PLLPRES);
|
||||
#else //HSE 16M
|
||||
RCC_ConfigUSBHSBandwidth(RCC_USBHS_BW_16M);
|
||||
RCC_ConfigUSBHSFrequency(RCC_USBHS_FREQ_16_OR_32M);
|
||||
RCC_ConfigUSBHSClk(RCC_USBHS_CLKSRC_HSE);
|
||||
#endif
|
||||
/* Reset the USBHS phy clock*/
|
||||
RCC_EnableAHBPeriphReset(RCC_AHBPRST_USBHSPHYRST);
|
||||
/* Enables the USBHS peripheral clock*/
|
||||
RCC_EnableAHBPeriphClk(RCC_AHB_PERIPHEN_USBHS, ENABLE);
|
||||
|
||||
NVIC_InitType NVIC_InitStructure;
|
||||
// EXTI_InitType EXTI_InitStructure;
|
||||
|
||||
// NVIC_InitStructure.NVIC_IRQChannel = USB_HS_WKUP_IRQn;
|
||||
// NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;
|
||||
// NVIC_InitStructure.NVIC_IRQChannelSubPriority = 1;
|
||||
// NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
|
||||
// NVIC_Init(&NVIC_InitStructure);
|
||||
|
||||
NVIC_InitStructure.NVIC_IRQChannel = USB_HS_IRQn;
|
||||
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 1;
|
||||
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 3;
|
||||
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
|
||||
NVIC_Init(&NVIC_InitStructure);
|
||||
|
||||
/* Configure the EXTI line 23 connected internally to the USBHS IP */
|
||||
// EXTI_ClrITPendBit(EXTI_LINE23);
|
||||
// EXTI_InitStructure.EXTI_Line = EXTI_LINE23;
|
||||
// EXTI_InitStructure.EXTI_Mode = EXTI_Mode_Interrupt;
|
||||
// EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Rising;
|
||||
// EXTI_InitStructure.EXTI_LineCmd = ENABLE;
|
||||
// EXTI_InitPeripheral(&EXTI_InitStructure);
|
||||
}
|
||||
|
||||
static void usbhs_gpio_init(void)
|
||||
{
|
||||
GPIO_InitType GPIO_InitStructure;
|
||||
|
||||
RCC_EnableAHB1PeriphClk(RCC_AHB_PERIPHEN_GPIOA | RCC_AHB_PERIPHEN_GPIOB | RCC_AHB_PERIPHEN_GPIOE, ENABLE);
|
||||
RCC_EnableAPB2PeriphClk(RCC_APB2_PERIPH_AFIO, ENABLE);
|
||||
GPIO_ConfigPinRemap(0, 0, GPIO_RMP_SWJ_SWD);
|
||||
|
||||
GPIO_InitStruct(&GPIO_InitStructure);
|
||||
#ifdef USBHS_HOST
|
||||
GPIO_InitStructure.Pin = GPIO_PIN_1;
|
||||
GPIO_InitStructure.GPIO_Mode = GPIO_MODE_OUTPUT_PP;
|
||||
GPIO_InitPeripheral(GPIOE, &GPIO_InitStructure);
|
||||
GPIO_ResetBits(GPIOE, GPIO_PIN_1);
|
||||
|
||||
GPIO_InitStructure.Pin = GPIO_PIN_3;
|
||||
GPIO_InitPeripheral(GPIOB, &GPIO_InitStructure);
|
||||
GPIO_ResetBits(GPIOB, GPIO_PIN_3);
|
||||
#endif
|
||||
// VBUS
|
||||
// GPIO_InitStructure.Pin = GPIO_PIN_13;
|
||||
// GPIO_InitStructure.GPIO_Mode = GPIO_MODE_INPUT;
|
||||
// GPIO_InitPeripheral(GPIOB, &GPIO_InitStructure);
|
||||
|
||||
// // SOF
|
||||
// GPIO_InitStructure.Pin = GPIO_PIN_4;
|
||||
// GPIO_InitStructure.GPIO_Mode = GPIO_MODE_AF_PP;
|
||||
// GPIO_InitStructure.GPIO_Alternate = 8; // SOF
|
||||
// GPIO_InitPeripheral(GPIOA, &GPIO_InitStructure);
|
||||
|
||||
// // ID
|
||||
// GPIO_InitStructure.Pin = GPIO_PIN_12;
|
||||
// GPIO_InitStructure.GPIO_Mode = GPIO_MODE_AF_PP;
|
||||
// GPIO_InitStructure.GPIO_Alternate = 14; // ID
|
||||
// GPIO_InitPeripheral(GPIOB, &GPIO_InitStructure);
|
||||
}
|
||||
|
||||
void usb_dc_low_level_init(uint8_t busid)
|
||||
{
|
||||
g_usb_dwc2_irq = USBD_IRQHandler;
|
||||
g_usb_dwc2_busid = busid;
|
||||
|
||||
usbhs_common_init();
|
||||
|
||||
RCC->USBHSCTRL2 |= (uint32_t)0x01 << 19;
|
||||
RCC->USBHSCTRL1 |= (uint32_t)0x01 << 31;
|
||||
}
|
||||
|
||||
void usb_dc_low_level_deinit(uint8_t busid)
|
||||
{
|
||||
NVIC_InitType NVIC_InitStructure;
|
||||
|
||||
NVIC_InitStructure.NVIC_IRQChannel = USB_HS_IRQn;
|
||||
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 1;
|
||||
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 3;
|
||||
NVIC_InitStructure.NVIC_IRQChannelCmd = DISABLE;
|
||||
NVIC_Init(&NVIC_InitStructure);
|
||||
|
||||
RCC_EnableAHBPeriphReset(RCC_AHBPRST_USBHSPHYRST);
|
||||
/* Enables the USBHS peripheral clock*/
|
||||
RCC_EnableAHBPeriphClk(RCC_AHB_PERIPHEN_USBHS, DISABLE);
|
||||
}
|
||||
|
||||
void usb_hc_low_level_init(struct usbh_bus *bus)
|
||||
{
|
||||
g_usb_dwc2_irq = USBH_IRQHandler;
|
||||
g_usb_dwc2_busid = 0;
|
||||
|
||||
usbhs_common_init();
|
||||
|
||||
RCC->USBHSCTRL2 &= ~(uint32_t)0x01 << 19;
|
||||
RCC->USBHSCTRL1 |= (uint32_t)0x01 << 31;
|
||||
}
|
||||
|
||||
void usb_hc_low_level_deinit(struct usbh_bus *bus)
|
||||
{
|
||||
NVIC_InitType NVIC_InitStructure;
|
||||
|
||||
NVIC_InitStructure.NVIC_IRQChannel = USB_HS_IRQn;
|
||||
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 1;
|
||||
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 3;
|
||||
NVIC_InitStructure.NVIC_IRQChannelCmd = DISABLE;
|
||||
NVIC_Init(&NVIC_InitStructure);
|
||||
|
||||
RCC_EnableAHBPeriphReset(RCC_AHBPRST_USBHSPHYRST);
|
||||
/* Enables the USBHS peripheral clock*/
|
||||
RCC_EnableAHBPeriphClk(RCC_AHB_PERIPHEN_USBHS, DISABLE);
|
||||
}
|
||||
|
||||
uint32_t usbd_get_dwc2_gccfg_conf(uint32_t reg_base)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
uint32_t usbh_get_dwc2_gccfg_conf(uint32_t reg_base)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
void USB_HS_IRQHandler(void)
|
||||
{
|
||||
g_usb_dwc2_irq(g_usb_dwc2_busid);
|
||||
}
|
||||
|
||||
void usbd_dwc2_delay_ms(uint8_t ms)
|
||||
{
|
||||
|
||||
}
|
||||
#endif
|
Reference in New Issue
Block a user