feat(port/fsdev/usb_glue_st): implement low level api

Signed-off-by: sakumisu <1203593632@qq.com>
This commit is contained in:
sakumisu 2025-04-25 21:07:36 +08:00
parent 4edd86c872
commit 95d968bd57
4 changed files with 76 additions and 5 deletions

View File

@ -26,8 +26,10 @@ if CHERRYUSB
default CHERRYUSB_DEVICE_CUSTOM
config CHERRYUSB_DEVICE_CUSTOM
bool "CUSTOM (Implement it yourself)"
config CHERRYUSB_DEVICE_FSDEV
bool "fsdev"
config CHERRYUSB_DEVICE_FSDEV_ST
bool "fsdev_st"
config CHERRYUSB_DEVICE_FSDEV_CUSTOM
bool "fsdev_custom"
config CHERRYUSB_DEVICE_DWC2_ST
bool "dwc2_st"
config CHERRYUSB_DEVICE_DWC2_ESP

View File

@ -33,7 +33,10 @@ if GetDepend(['PKG_CHERRYUSB_DEVICE']):
if GetDepend(['PKG_CHERRYUSB_DEVICE_HS']):
CPPDEFINES+=['CONFIG_USB_HS']
if GetDepend(['PKG_CHERRYUSB_DEVICE_FSDEV']):
if GetDepend(['PKG_CHERRYUSB_DEVICE_FSDEV_ST']):
src += Glob('port/fsdev/usb_dc_fsdev.c')
src += Glob('port/fsdev/usb_glue_st.c')
if GetDepend(['PKG_CHERRYUSB_DEVICE_FSDEV_CUSTOM']):
src += Glob('port/fsdev/usb_dc_fsdev.c')
if GetDepend(['PKG_CHERRYUSB_DEVICE_DWC2_ST']):
src += Glob('port/dwc2/usb_dc_dwc2.c')

View File

@ -166,7 +166,7 @@ USB Device 移植要点
.. figure:: img/stm32_10.png
.. figure:: img/stm32_11.png
.. note :: 如果使用的是 dwc2以下两个步骤从 V1.4.4 开始不再需要,**usb_glue_st.c** 文件中已经实现
.. note :: 以下两个步骤从 V1.4.4 开始不再需要,**fsdev/usb_glue_st.c**, **dwc2/usb_glue_st.c** 文件中已经实现
- 拷贝 **xxx_msp.c** 中的 **HAL_PCD_MspInit** 函数中的内容到 **usb_dc_low_level_init** 函数中,屏蔽 st 生成的 usb 初始化
@ -208,7 +208,7 @@ USB Host 移植要点
#define CONFIG_USB_DWC2_PTX_FIFO_SIZE (1024 / 4)
#define CONFIG_USB_DWC2_RX_FIFO_SIZE ((1012 - CONFIG_USB_DWC2_NPTX_FIFO_SIZE - CONFIG_USB_DWC2_PTX_FIFO_SIZE) / 4)
.. note :: 如果使用的是 dwc2以下两个步骤从 V1.4.4 开始不再需要,**usb_glue_st.c** 文件中已经实现
.. note :: 以下两个步骤从 V1.4.4 开始不再需要,**fsdev/usb_glue_st.c**, **dwc2/usb_glue_st.c** 文件中已经实现
- 拷贝 **xxx_msp.c** 中的 `HAL_HCD_MspInit` 函数中的内容到 `usb_hc_low_level_init` 函数中,屏蔽 st 生成的 usb 初始化
- 在中断函数中调用 `USBH_IRQHandler`,并传入 `busid`

66
port/fsdev/usb_glue_st.c Normal file
View File

@ -0,0 +1,66 @@
/*
* Copyright (c) 2025, sakumisu
*
* SPDX-License-Identifier: Apache-2.0
*/
#include "usbd_core.h"
#if __has_include("stm32f0xx_hal.h")
#include "stm32f0xx_hal.h"
#elif __has_include("stm32f1xx_hal.h")
#include "stm32f1xx_hal.h"
#elif __has_include("stm32f3xx_hal.h")
#include "stm32f3xx_hal.h"
#elif __has_include("stm32g0xx_hal.h")
#include "stm32g0xx_hal.h"
#elif __has_include("stm32g4xx_hal.h")
#include "stm32g4xx_hal.h"
#elif __has_include("stm32l0xx_hal.h")
#include "stm32l0xx_hal.h"
#elif __has_include("stm32l1xx_hal.h")
#include "stm32l1xx_hal.h"
#elif __has_include("stm32l4xx_hal.h")
#include "stm32l4xx_hal.h"
#elif __has_include("stm32l5xx_hal.h")
#include "stm32l5xx_hal.h"
#endif
#if !defined(HAL_PCD_MODULE_ENABLED)
#error please define HAL_PCD_MODULE_ENABLED in stm32xxx_hal_conf.h
#endif
#ifndef CONFIG_USBDEV_FSDEV_PMA_ACCESS
#error "please define CONFIG_USBDEV_FSDEV_PMA_ACCESS in usb_config.h"
#endif
#if CONFIG_USBDEV_FSDEV_PMA_ACCESS != PMA_ACCESS
#error "CONFIG_USBDEV_FSDEV_PMA_ACCESS must be equal PMA_ACCESS"
#endif
struct fsdev_instance {
USB_TypeDef *Instance;
};
static struct fsdev_instance g_fsdev_instance;
void usb_dc_low_level_init(uint8_t busid)
{
g_fsdev_instance.Instance = (USB_TypeDef *)g_usbdev_bus[busid].reg_base;
HAL_PCD_MspInit((PCD_HandleTypeDef *)&g_fsdev_instance);
}
void usb_dc_low_level_deinit(uint8_t busid)
{
g_fsdev_instance.Instance = (USB_TypeDef *)g_usbdev_bus[busid].reg_base;
HAL_PCD_MspDeInit((PCD_HandleTypeDef *)&g_fsdev_instance);
}
void USB_IRQHandler(void)
{
USBD_IRQHandler(0);
}
void USB_LP_IRQHandler(void)
{
USBD_IRQHandler(0);
}