Skip to content

Commit 75ae343

Browse files
authored
Merge pull request #3167 from Guozhanxin/usbd
完善stm32 usb 驱动,在驱动开启中断,不需要在cubemx里配置了
2 parents 186d7cf + d687c5f commit 75ae343

File tree

26 files changed

+372
-242
lines changed

26 files changed

+372
-242
lines changed

bsp/stm32/libraries/HAL_Drivers/config/f1/usbd_config.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,17 @@
1111
#ifndef __USBD_CONFIG_H__
1212
#define __USBD_CONFIG_H__
1313

14+
#define USBD_IRQ_TYPE USB_LP_CAN1_RX0_IRQn
1415
#define USBD_IRQ_HANDLER USB_LP_CAN1_RX0_IRQHandler
1516
#define USBD_INSTANCE USB
1617
#define USBD_PCD_SPEED PCD_SPEED_FULL
1718
#define USBD_PCD_PHY_MODULE PCD_PHY_EMBEDDED
19+
20+
#ifndef BSP_USB_CONNECT_PIN
1821
#define BSP_USB_CONNECT_PIN -1
22+
#endif
1923

24+
#ifndef BSP_USB_PULL_UP_STATUS
25+
#define BSP_USB_PULL_UP_STATUS 1
26+
#endif
2027
#endif

bsp/stm32/libraries/HAL_Drivers/config/f4/usbd_config.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,11 @@
1414
#include <rtconfig.h>
1515

1616
#ifdef BSP_USBD_TYPE_HS
17+
#define USBD_IRQ_TYPE OTG_HS_IRQn
1718
#define USBD_IRQ_HANDLER OTG_HS_IRQHandler
1819
#define USBD_INSTANCE USB_OTG_HS
19-
#else
20+
#else
21+
#define USBD_IRQ_TYPE OTG_FS_IRQn
2022
#define USBD_IRQ_HANDLER OTG_FS_IRQHandler
2123
#define USBD_INSTANCE USB_OTG_FS
2224
#endif

bsp/stm32/libraries/HAL_Drivers/config/g4/usbd_config.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,11 @@
1414
#include <rtconfig.h>
1515

1616
#ifdef BSP_USBD_TYPE_HS
17+
#define USBD_IRQ_TYPE OTG_HS_IRQn
1718
#define USBD_IRQ_HANDLER OTG_HS_IRQHandler
1819
#define USBD_INSTANCE USB_OTG_HS
1920
#else
21+
#define USBD_IRQ_TYPE OTG_FS_IRQn
2022
#define USBD_IRQ_HANDLER OTG_FS_IRQHandler
2123
#define USBD_INSTANCE USB_OTG_FS
2224
#endif

bsp/stm32/libraries/HAL_Drivers/config/h7/usbd_config.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,11 @@
1414
#include <rtconfig.h>
1515

1616
#ifdef BSP_USBD_TYPE_HS
17+
#define USBD_IRQ_TYPE OTG_HS_IRQn
1718
#define USBD_IRQ_HANDLER OTG_HS_IRQHandler
1819
#define USBD_INSTANCE USB_OTG_HS
19-
#else
20+
#else
21+
#define USBD_IRQ_TYPE OTG_FS_IRQn
2022
#define USBD_IRQ_HANDLER OTG_FS_IRQHandler
2123
#define USBD_INSTANCE USB_OTG_FS
2224
#endif

bsp/stm32/libraries/HAL_Drivers/config/l4/usbd_config.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,11 @@
1414
#include <rtconfig.h>
1515

1616
#ifdef BSP_USBD_TYPE_HS
17+
#define USBD_IRQ_TYPE OTG_HS_IRQn
1718
#define USBD_IRQ_HANDLER OTG_HS_IRQHandler
1819
#define USBD_INSTANCE USB_OTG_HS
1920
#else
21+
#define USBD_IRQ_TYPE OTG_FS_IRQn
2022
#define USBD_IRQ_HANDLER OTG_FS_IRQHandler
2123
#define USBD_INSTANCE USB_OTG_FS
2224
#endif

bsp/stm32/libraries/HAL_Drivers/drv_usbd.c

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,14 +99,14 @@ void HAL_PCDEx_SetConnectionState(PCD_HandleTypeDef *hpcd, uint8_t state)
9999
{
100100
#if defined(SOC_SERIES_STM32F1)
101101
rt_pin_mode(BSP_USB_CONNECT_PIN,PIN_MODE_OUTPUT);
102-
rt_pin_write(BSP_USB_CONNECT_PIN, PIN_HIGH);
102+
rt_pin_write(BSP_USB_CONNECT_PIN, BSP_USB_PULL_UP_STATUS);
103103
#endif
104104
}
105105
else
106106
{
107107
#if defined(SOC_SERIES_STM32F1)
108108
rt_pin_mode(BSP_USB_CONNECT_PIN,PIN_MODE_OUTPUT);
109-
rt_pin_write(BSP_USB_CONNECT_PIN, PIN_LOW);
109+
rt_pin_write(BSP_USB_CONNECT_PIN, !BSP_USB_PULL_UP_STATUS);
110110
#endif
111111
}
112112
}
@@ -201,6 +201,9 @@ static rt_err_t _init(rt_device_t device)
201201
#endif
202202
/* Initialize LL Driver */
203203
HAL_PCD_Init(pcd);
204+
/* USB interrupt Init */
205+
HAL_NVIC_SetPriority(USBD_IRQ_TYPE, 2, 0);
206+
HAL_NVIC_EnableIRQ(USBD_IRQ_TYPE);
204207
#if !defined(SOC_SERIES_STM32F1)
205208
HAL_PCDEx_SetRxFiFo(pcd, 0x80);
206209
HAL_PCDEx_SetTxFiFo(pcd, 0, 0x40);
@@ -246,6 +249,9 @@ int stm_usbd_register(void)
246249
/* Register endpoint infomation */
247250
_stm_udc.ep_pool = _ep_pool;
248251
_stm_udc.ep0.id = &_ep_pool[0];
252+
#ifdef BSP_USBD_SPEED_HS
253+
_stm_udc.device_is_hs = RT_TRUE;
254+
#endif
249255
rt_device_register((rt_device_t)&_stm_udc, "usbd", 0);
250256
rt_usb_device_init();
251257
return RT_EOK;

bsp/stm32/stm32f103-fire-arbitrary/README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@
4444
| SPI Flash | 支持 | W25Q64 |
4545
| 以太网 | 支持 | W5500 |
4646
| 电位器 | 支持 | 使用 ADC1 |
47-
| SD卡 | 即将支持 | |
47+
| SD卡 | 支持 | |
4848
| CAN | 支持 | |
4949
| SDRAM | 即将支持 | |
5050
| WIFI ESP8266 | 即将支持 | |
@@ -57,9 +57,9 @@
5757
| RTC | 支持 | 支持外部晶振和内部低速时钟 |
5858
| WDT | 支持 | |
5959
| FLASH | 支持 | 已适配 [FAL](https://github.com/RT-Thread-packages/fal) |
60-
| SDIO | 暂不支持 | 即将支持 |
61-
| PWM | 暂不支持 | 即将支持 |
62-
| USB Device | 暂不支持 | 即将支持 |
60+
| SDIO | 支持 | |
61+
| PWM | 支持 | |
62+
| USB Device | 支持 | |
6363
| USB Host | 暂不支持 | 即将支持 |
6464
| **扩展模块** | **支持情况** | **备注** |
6565
| 暂无 | 暂不支持 | 暂不支持 |

bsp/stm32/stm32f103-fire-arbitrary/board/CubeMX_Config/.mxproject

Lines changed: 8 additions & 4 deletions
Large diffs are not rendered by default.

0 commit comments

Comments
 (0)