Skip to content

Commit d624454

Browse files
[bsp][stm]: add stm32g0 usbd fs support
1 parent 9ed6154 commit d624454

3 files changed

Lines changed: 53 additions & 1 deletion

File tree

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
/*
2+
* Copyright (c) 2006-2023, RT-Thread Development Team
3+
*
4+
* SPDX-License-Identifier: Apache-2.0
5+
*
6+
* Change Logs:
7+
* Date Author Notes
8+
* 2026-06-10 Luxianfan add FS USB support
9+
*/
10+
#ifndef __USBD_CONFIG_H__
11+
#define __USBD_CONFIG_H__
12+
13+
#include <rtconfig.h>
14+
15+
#ifdef BSP_USBD_TYPE_HS
16+
//#define USBD_IRQ_TYPE OTG_HS_IRQn
17+
//#define USBD_IRQ_HANDLER OTG_HS_IRQHandler
18+
//#define USBD_INSTANCE USB_OTG_HS
19+
#else
20+
#define USBD_IRQ_TYPE USB_UCPD1_2_IRQn
21+
#define USBD_IRQ_HANDLER USB_UCPD1_2_IRQHandler
22+
#define USBD_INSTANCE USB_DRD_FS
23+
#endif
24+
25+
#ifdef BSP_USBD_SPEED_HS
26+
//#define USBD_PCD_SPEED PCD_SPEED_HIGH
27+
//#elif BSP_USBD_SPEED_HSINFS
28+
//#define USBD_PCD_SPEED PCD_SPEED_HIGH_IN_FULL
29+
#else
30+
#define USBD_PCD_SPEED PCD_SPEED_FULL
31+
#endif
32+
33+
#ifdef BSP_USBD_PHY_ULPI
34+
//#define USBD_PCD_PHY_MODULE PCD_PHY_ULPI
35+
//#elif BSP_USBD_PHY_UTMI
36+
//#define USBD_PCD_PHY_MODULE PCD_PHY_UTMI
37+
#else
38+
#define USBD_PCD_PHY_MODULE PCD_PHY_EMBEDDED
39+
#endif
40+
41+
#endif

bsp/stm32/libraries/HAL_Drivers/drivers/drv_config.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,7 @@ extern "C" {
105105
#include "g0/adc_config.h"
106106
#include "g0/tim_config.h"
107107
#include "g0/pwm_config.h"
108+
#include "g0/usbd_config.h"
108109
#elif defined(SOC_SERIES_STM32G4)
109110
#include "g4/dma_config.h"
110111
#include "g4/uart_config.h"

bsp/stm32/libraries/HAL_Drivers/drivers/drv_usbd.c

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -213,13 +213,23 @@ static rt_err_t _init(rt_device_t device)
213213
pcd->Init.ep0_mps = EP_MPS_64;
214214
#if !defined(SOC_SERIES_STM32F1)
215215
pcd->Init.phy_itface = USBD_PCD_PHY_MODULE;
216+
#endif
217+
#if defined(SOC_SERIES_STM32G0)
218+
pcd->Init.Host_channels = 8;
219+
pcd->Init.Sof_enable = DISABLE;
220+
pcd->Init.low_power_enable = DISABLE;
221+
pcd->Init.lpm_enable = DISABLE;
222+
pcd->Init.battery_charging_enable = DISABLE;
223+
pcd->Init.vbus_sensing_enable = DISABLE;
224+
pcd->Init.bulk_doublebuffer_enable = DISABLE;
225+
pcd->Init.iso_singlebuffer_enable = DISABLE;
216226
#endif
217227
/* Initialize LL Driver */
218228
HAL_PCD_Init(pcd);
219229
/* USB interrupt Init */
220230
HAL_NVIC_SetPriority(USBD_IRQ_TYPE, 2, 0);
221231
HAL_NVIC_EnableIRQ(USBD_IRQ_TYPE);
222-
#if !defined(SOC_SERIES_STM32F1)
232+
#if !defined(SOC_SERIES_STM32F1) && !defined(SOC_SERIES_STM32G0)
223233
HAL_PCDEx_SetRxFiFo(pcd, 0x80);
224234
HAL_PCDEx_SetTxFiFo(pcd, 0, 0x40);
225235
HAL_PCDEx_SetTxFiFo(pcd, 1, 0x40);

0 commit comments

Comments
 (0)