Skip to content

Commit c4b62a9

Browse files
authored
[bsp/stm32] add usbcdc for openmv (#5702)
1 parent cff3446 commit c4b62a9

File tree

11 files changed

+266
-84
lines changed

11 files changed

+266
-84
lines changed

bsp/stm32/stm32h743-openmv-h7plus/.config

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,7 @@ CONFIG_RT_MMCSD_THREAD_PREORITY=22
187187
CONFIG_RT_MMCSD_MAX_PARTITION=16
188188
# CONFIG_RT_SDIO_DEBUG is not set
189189
CONFIG_RT_USING_SPI=y
190+
# CONFIG_RT_USING_SPI_BITOPS is not set
190191
CONFIG_RT_USING_QSPI=y
191192
# CONFIG_RT_USING_SPI_MSD is not set
192193
CONFIG_RT_USING_SFUD=y
@@ -209,9 +210,26 @@ CONFIG_RT_SFUD_SPI_MAX_HZ=50000000
209210
#
210211
# Using USB
211212
#
212-
# CONFIG_RT_USING_USB is not set
213+
CONFIG_RT_USING_USB=y
213214
# CONFIG_RT_USING_USB_HOST is not set
214-
# CONFIG_RT_USING_USB_DEVICE is not set
215+
CONFIG_RT_USING_USB_DEVICE=y
216+
CONFIG_RT_USBD_THREAD_STACK_SZ=4096
217+
CONFIG_USB_VENDOR_ID=0x0FFE
218+
CONFIG_USB_PRODUCT_ID=0x0001
219+
# CONFIG_RT_USB_DEVICE_COMPOSITE is not set
220+
# CONFIG__RT_USB_DEVICE_NONE is not set
221+
CONFIG__RT_USB_DEVICE_CDC=y
222+
# CONFIG__RT_USB_DEVICE_MSTORAGE is not set
223+
# CONFIG__RT_USB_DEVICE_HID is not set
224+
# CONFIG__RT_USB_DEVICE_WINUSB is not set
225+
# CONFIG__RT_USB_DEVICE_AUDIO is not set
226+
CONFIG_RT_USB_DEVICE_CDC=y
227+
CONFIG_RT_VCOM_TASK_STK_SIZE=512
228+
CONFIG_RT_CDC_RX_BUFSIZE=128
229+
# CONFIG_RT_VCOM_TX_USE_DMA is not set
230+
CONFIG_RT_VCOM_SERNO="32021919830108"
231+
CONFIG_RT_VCOM_SER_LEN=14
232+
CONFIG_RT_VCOM_TX_TIMEOUT=1000
215233

216234
#
217235
# POSIX layer and C standard library
@@ -473,6 +491,7 @@ CONFIG_RT_USING_POSIX_FS=y
473491
# CONFIG_PKG_USING_SOLAR_TERMS is not set
474492
# CONFIG_PKG_USING_GAN_ZHI is not set
475493
# CONFIG_PKG_USING_FDT is not set
494+
# CONFIG_PKG_USING_CBOX is not set
476495

477496
#
478497
# system packages
@@ -719,7 +738,7 @@ CONFIG_BSP_USING_UART1=y
719738
# CONFIG_BSP_UART1_RX_USING_DMA is not set
720739
# CONFIG_BSP_USING_UART2 is not set
721740
# CONFIG_BSP_USING_LPUART1 is not set
722-
CONFIG_BSP_USING_QSPI=y
741+
# CONFIG_BSP_USING_QSPI is not set
723742
# CONFIG_BSP_USING_CRC is not set
724743
# CONFIG_BSP_USING_RNG is not set
725744
# CONFIG_BSP_USING_UDID is not set
@@ -730,3 +749,4 @@ CONFIG_BSP_USING_QSPI=y
730749
CONFIG_BSP_USING_SDRAM=y
731750
# CONFIG_BSP_USING_QSPI_FLASH is not set
732751
# CONFIG_BSP_USING_SDMMC is not set
752+
# CONFIG_BSP_USING_USBD is not set

bsp/stm32/stm32h743-openmv-h7plus/README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ OPENMV4-H7-PLUS 是 OPENMV公司推出的一款针对 STM32H7系列设计的 Cor
4242
| SDRAM | 支持 | IS42S32800 BANK1 |
4343
| QSPI FLASH | 支持 | W25Q256JV |
4444
| SDIO | 支持 | USD-1040310811 |
45+
| USBCDC | 支持 | |
4546

4647
## 使用说明
4748

@@ -99,7 +100,7 @@ msh >
99100

100101

101102

102-
5. USBD CDC使用,参考文章[STM32L496 USB CDC适配](https://club.rt-thread.org/ask/article/2959.html)
103+
5. USBD CDC使用,参考文章[STM32L496 USB CDC适配](https://club.rt-thread.org/ask/article/2959.html)(bsp已配置引脚和修改Kconfig)
103104

104105
## 注意事项
105106

bsp/stm32/stm32h743-openmv-h7plus/board/CubeMX_Config/.mxproject

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

bsp/stm32/stm32h743-openmv-h7plus/board/CubeMX_Config/Core/Inc/stm32h7xx_hal_conf.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@
8080
/* #define HAL_IRDA_MODULE_ENABLED */
8181
/* #define HAL_SMARTCARD_MODULE_ENABLED */
8282
/* #define HAL_WWDG_MODULE_ENABLED */
83-
/* #define HAL_PCD_MODULE_ENABLED */
83+
#define HAL_PCD_MODULE_ENABLED
8484
/* #define HAL_HCD_MODULE_ENABLED */
8585
/* #define HAL_DFSDM_MODULE_ENABLED */
8686
/* #define HAL_DSI_MODULE_ENABLED */

bsp/stm32/stm32h743-openmv-h7plus/board/CubeMX_Config/Core/Inc/stm32h7xx_it.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,8 @@ void DebugMon_Handler(void);
5656
void PendSV_Handler(void);
5757
void SysTick_Handler(void);
5858
void SDMMC1_IRQHandler(void);
59+
void OTG_FS_EP1_OUT_IRQHandler(void);
60+
void OTG_FS_EP1_IN_IRQHandler(void);
5961
/* USER CODE BEGIN EFP */
6062

6163
/* USER CODE END EFP */

bsp/stm32/stm32h743-openmv-h7plus/board/CubeMX_Config/Core/Src/main.c

Lines changed: 43 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,8 @@ SD_HandleTypeDef hsd1;
4646

4747
UART_HandleTypeDef huart1;
4848

49+
PCD_HandleTypeDef hpcd_USB_OTG_FS;
50+
4951
SDRAM_HandleTypeDef hsdram1;
5052

5153
/* USER CODE BEGIN PV */
@@ -59,6 +61,7 @@ static void MX_USART1_UART_Init(void);
5961
static void MX_FMC_Init(void);
6062
static void MX_QUADSPI_Init(void);
6163
static void MX_SDMMC1_SD_Init(void);
64+
static void MX_USB_OTG_FS_PCD_Init(void);
6265
/* USER CODE BEGIN PFP */
6366

6467
/* USER CODE END PFP */
@@ -106,6 +109,7 @@ int main(void)
106109
MX_FMC_Init();
107110
MX_QUADSPI_Init();
108111
MX_SDMMC1_SD_Init();
112+
MX_USB_OTG_FS_PCD_Init();
109113
/* USER CODE BEGIN 2 */
110114

111115
/* USER CODE END 2 */
@@ -141,8 +145,9 @@ void SystemClock_Config(void)
141145
/** Initializes the RCC Oscillators according to the specified parameters
142146
* in the RCC_OscInitTypeDef structure.
143147
*/
144-
RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSE;
148+
RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSI48|RCC_OSCILLATORTYPE_HSE;
145149
RCC_OscInitStruct.HSEState = RCC_HSE_ON;
150+
RCC_OscInitStruct.HSI48State = RCC_HSI48_ON;
146151
RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON;
147152
RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSE;
148153
RCC_OscInitStruct.PLL.PLLM = 3;
@@ -290,6 +295,42 @@ static void MX_USART1_UART_Init(void)
290295

291296
}
292297

298+
/**
299+
* @brief USB_OTG_FS Initialization Function
300+
* @param None
301+
* @retval None
302+
*/
303+
static void MX_USB_OTG_FS_PCD_Init(void)
304+
{
305+
306+
/* USER CODE BEGIN USB_OTG_FS_Init 0 */
307+
308+
/* USER CODE END USB_OTG_FS_Init 0 */
309+
310+
/* USER CODE BEGIN USB_OTG_FS_Init 1 */
311+
312+
/* USER CODE END USB_OTG_FS_Init 1 */
313+
hpcd_USB_OTG_FS.Instance = USB_OTG_FS;
314+
hpcd_USB_OTG_FS.Init.dev_endpoints = 9;
315+
hpcd_USB_OTG_FS.Init.speed = PCD_SPEED_FULL;
316+
hpcd_USB_OTG_FS.Init.dma_enable = DISABLE;
317+
hpcd_USB_OTG_FS.Init.phy_itface = PCD_PHY_EMBEDDED;
318+
hpcd_USB_OTG_FS.Init.Sof_enable = DISABLE;
319+
hpcd_USB_OTG_FS.Init.low_power_enable = DISABLE;
320+
hpcd_USB_OTG_FS.Init.lpm_enable = DISABLE;
321+
hpcd_USB_OTG_FS.Init.battery_charging_enable = DISABLE;
322+
hpcd_USB_OTG_FS.Init.vbus_sensing_enable = DISABLE;
323+
hpcd_USB_OTG_FS.Init.use_dedicated_ep1 = DISABLE;
324+
if (HAL_PCD_Init(&hpcd_USB_OTG_FS) != HAL_OK)
325+
{
326+
Error_Handler();
327+
}
328+
/* USER CODE BEGIN USB_OTG_FS_Init 2 */
329+
330+
/* USER CODE END USB_OTG_FS_Init 2 */
331+
332+
}
333+
293334
/* FMC initialization function */
294335
static void MX_FMC_Init(void)
295336
{
@@ -351,10 +392,10 @@ static void MX_GPIO_Init(void)
351392
__HAL_RCC_GPIOC_CLK_ENABLE();
352393
__HAL_RCC_GPIOG_CLK_ENABLE();
353394
__HAL_RCC_GPIOD_CLK_ENABLE();
395+
__HAL_RCC_GPIOA_CLK_ENABLE();
354396
__HAL_RCC_GPIOI_CLK_ENABLE();
355397
__HAL_RCC_GPIOH_CLK_ENABLE();
356398
__HAL_RCC_GPIOF_CLK_ENABLE();
357-
__HAL_RCC_GPIOA_CLK_ENABLE();
358399
__HAL_RCC_GPIOB_CLK_ENABLE();
359400

360401
/*Configure GPIO pin Output Level */

bsp/stm32/stm32h743-openmv-h7plus/board/CubeMX_Config/Core/Src/stm32h7xx_hal_msp.c

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -353,6 +353,91 @@ void HAL_UART_MspDeInit(UART_HandleTypeDef* huart)
353353

354354
}
355355

356+
/**
357+
* @brief PCD MSP Initialization
358+
* This function configures the hardware resources used in this example
359+
* @param hpcd: PCD handle pointer
360+
* @retval None
361+
*/
362+
void HAL_PCD_MspInit(PCD_HandleTypeDef* hpcd)
363+
{
364+
GPIO_InitTypeDef GPIO_InitStruct = {0};
365+
RCC_PeriphCLKInitTypeDef PeriphClkInitStruct = {0};
366+
if(hpcd->Instance==USB_OTG_FS)
367+
{
368+
/* USER CODE BEGIN USB_OTG_FS_MspInit 0 */
369+
370+
/* USER CODE END USB_OTG_FS_MspInit 0 */
371+
/** Initializes the peripherals clock
372+
*/
373+
PeriphClkInitStruct.PeriphClockSelection = RCC_PERIPHCLK_USB;
374+
PeriphClkInitStruct.UsbClockSelection = RCC_USBCLKSOURCE_HSI48;
375+
if (HAL_RCCEx_PeriphCLKConfig(&PeriphClkInitStruct) != HAL_OK)
376+
{
377+
Error_Handler();
378+
}
379+
/** Enable USB Voltage detector
380+
*/
381+
HAL_PWREx_EnableUSBVoltageDetector();
382+
383+
__HAL_RCC_GPIOA_CLK_ENABLE();
384+
/**USB_OTG_FS GPIO Configuration
385+
PA12 ------> USB_OTG_FS_DP
386+
PA11 ------> USB_OTG_FS_DM
387+
*/
388+
GPIO_InitStruct.Pin = GPIO_PIN_12|GPIO_PIN_11;
389+
GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
390+
GPIO_InitStruct.Pull = GPIO_NOPULL;
391+
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_HIGH;
392+
GPIO_InitStruct.Alternate = GPIO_AF10_OTG1_FS;
393+
HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
394+
395+
/* Peripheral clock enable */
396+
__HAL_RCC_USB_OTG_FS_CLK_ENABLE();
397+
/* USB_OTG_FS interrupt Init */
398+
HAL_NVIC_SetPriority(OTG_FS_EP1_OUT_IRQn, 0, 0);
399+
HAL_NVIC_EnableIRQ(OTG_FS_EP1_OUT_IRQn);
400+
HAL_NVIC_SetPriority(OTG_FS_EP1_IN_IRQn, 0, 0);
401+
HAL_NVIC_EnableIRQ(OTG_FS_EP1_IN_IRQn);
402+
/* USER CODE BEGIN USB_OTG_FS_MspInit 1 */
403+
404+
/* USER CODE END USB_OTG_FS_MspInit 1 */
405+
}
406+
407+
}
408+
409+
/**
410+
* @brief PCD MSP De-Initialization
411+
* This function freeze the hardware resources used in this example
412+
* @param hpcd: PCD handle pointer
413+
* @retval None
414+
*/
415+
void HAL_PCD_MspDeInit(PCD_HandleTypeDef* hpcd)
416+
{
417+
if(hpcd->Instance==USB_OTG_FS)
418+
{
419+
/* USER CODE BEGIN USB_OTG_FS_MspDeInit 0 */
420+
421+
/* USER CODE END USB_OTG_FS_MspDeInit 0 */
422+
/* Peripheral clock disable */
423+
__HAL_RCC_USB_OTG_FS_CLK_DISABLE();
424+
425+
/**USB_OTG_FS GPIO Configuration
426+
PA12 ------> USB_OTG_FS_DP
427+
PA11 ------> USB_OTG_FS_DM
428+
*/
429+
HAL_GPIO_DeInit(GPIOA, GPIO_PIN_12|GPIO_PIN_11);
430+
431+
/* USB_OTG_FS interrupt DeInit */
432+
HAL_NVIC_DisableIRQ(OTG_FS_EP1_OUT_IRQn);
433+
HAL_NVIC_DisableIRQ(OTG_FS_EP1_IN_IRQn);
434+
/* USER CODE BEGIN USB_OTG_FS_MspDeInit 1 */
435+
436+
/* USER CODE END USB_OTG_FS_MspDeInit 1 */
437+
}
438+
439+
}
440+
356441
static uint32_t FMC_Initialized = 0;
357442

358443
static void HAL_FMC_MspInit(void){

0 commit comments

Comments
 (0)