Skip to content

Commit

Permalink
[bsp/stm32] add usbcdc for openmv
Browse files Browse the repository at this point in the history
  • Loading branch information
Miaowulue authored and Horimatic committed Mar 23, 2022
1 parent 2a1272e commit 34bdc3c
Show file tree
Hide file tree
Showing 11 changed files with 266 additions and 84 deletions.
26 changes: 23 additions & 3 deletions bsp/stm32/stm32h743-openmv-h7plus/.config
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,7 @@ CONFIG_RT_MMCSD_THREAD_PREORITY=22
CONFIG_RT_MMCSD_MAX_PARTITION=16
# CONFIG_RT_SDIO_DEBUG is not set
CONFIG_RT_USING_SPI=y
# CONFIG_RT_USING_SPI_BITOPS is not set
CONFIG_RT_USING_QSPI=y
# CONFIG_RT_USING_SPI_MSD is not set
CONFIG_RT_USING_SFUD=y
Expand All @@ -209,9 +210,26 @@ CONFIG_RT_SFUD_SPI_MAX_HZ=50000000
#
# Using USB
#
# CONFIG_RT_USING_USB is not set
CONFIG_RT_USING_USB=y
# CONFIG_RT_USING_USB_HOST is not set
# CONFIG_RT_USING_USB_DEVICE is not set
CONFIG_RT_USING_USB_DEVICE=y
CONFIG_RT_USBD_THREAD_STACK_SZ=4096
CONFIG_USB_VENDOR_ID=0x0FFE
CONFIG_USB_PRODUCT_ID=0x0001
# CONFIG_RT_USB_DEVICE_COMPOSITE is not set
# CONFIG__RT_USB_DEVICE_NONE is not set
CONFIG__RT_USB_DEVICE_CDC=y
# CONFIG__RT_USB_DEVICE_MSTORAGE is not set
# CONFIG__RT_USB_DEVICE_HID is not set
# CONFIG__RT_USB_DEVICE_WINUSB is not set
# CONFIG__RT_USB_DEVICE_AUDIO is not set
CONFIG_RT_USB_DEVICE_CDC=y
CONFIG_RT_VCOM_TASK_STK_SIZE=512
CONFIG_RT_CDC_RX_BUFSIZE=128
# CONFIG_RT_VCOM_TX_USE_DMA is not set
CONFIG_RT_VCOM_SERNO="32021919830108"
CONFIG_RT_VCOM_SER_LEN=14
CONFIG_RT_VCOM_TX_TIMEOUT=1000

#
# POSIX layer and C standard library
Expand Down Expand Up @@ -473,6 +491,7 @@ CONFIG_RT_USING_POSIX_FS=y
# CONFIG_PKG_USING_SOLAR_TERMS is not set
# CONFIG_PKG_USING_GAN_ZHI is not set
# CONFIG_PKG_USING_FDT is not set
# CONFIG_PKG_USING_CBOX is not set

#
# system packages
Expand Down Expand Up @@ -719,7 +738,7 @@ CONFIG_BSP_USING_UART1=y
# CONFIG_BSP_UART1_RX_USING_DMA is not set
# CONFIG_BSP_USING_UART2 is not set
# CONFIG_BSP_USING_LPUART1 is not set
CONFIG_BSP_USING_QSPI=y
# CONFIG_BSP_USING_QSPI is not set
# CONFIG_BSP_USING_CRC is not set
# CONFIG_BSP_USING_RNG is not set
# CONFIG_BSP_USING_UDID is not set
Expand All @@ -730,3 +749,4 @@ CONFIG_BSP_USING_QSPI=y
CONFIG_BSP_USING_SDRAM=y
# CONFIG_BSP_USING_QSPI_FLASH is not set
# CONFIG_BSP_USING_SDMMC is not set
# CONFIG_BSP_USING_USBD is not set
3 changes: 2 additions & 1 deletion bsp/stm32/stm32h743-openmv-h7plus/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ OPENMV4-H7-PLUS 是 OPENMV公司推出的一款针对 STM32H7系列设计的 Cor
| SDRAM | 支持 | IS42S32800 BANK1 |
| QSPI FLASH | 支持 | W25Q256JV |
| SDIO | 支持 | USD-1040310811 |
| USBCDC | 支持 | |

## 使用说明

Expand Down Expand Up @@ -99,7 +100,7 @@ msh >



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

## 注意事项

Expand Down

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@
/* #define HAL_IRDA_MODULE_ENABLED */
/* #define HAL_SMARTCARD_MODULE_ENABLED */
/* #define HAL_WWDG_MODULE_ENABLED */
/* #define HAL_PCD_MODULE_ENABLED */
#define HAL_PCD_MODULE_ENABLED
/* #define HAL_HCD_MODULE_ENABLED */
/* #define HAL_DFSDM_MODULE_ENABLED */
/* #define HAL_DSI_MODULE_ENABLED */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@ void DebugMon_Handler(void);
void PendSV_Handler(void);
void SysTick_Handler(void);
void SDMMC1_IRQHandler(void);
void OTG_FS_EP1_OUT_IRQHandler(void);
void OTG_FS_EP1_IN_IRQHandler(void);
/* USER CODE BEGIN EFP */

/* USER CODE END EFP */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ SD_HandleTypeDef hsd1;

UART_HandleTypeDef huart1;

PCD_HandleTypeDef hpcd_USB_OTG_FS;

SDRAM_HandleTypeDef hsdram1;

/* USER CODE BEGIN PV */
Expand All @@ -59,6 +61,7 @@ static void MX_USART1_UART_Init(void);
static void MX_FMC_Init(void);
static void MX_QUADSPI_Init(void);
static void MX_SDMMC1_SD_Init(void);
static void MX_USB_OTG_FS_PCD_Init(void);
/* USER CODE BEGIN PFP */

/* USER CODE END PFP */
Expand Down Expand Up @@ -106,6 +109,7 @@ int main(void)
MX_FMC_Init();
MX_QUADSPI_Init();
MX_SDMMC1_SD_Init();
MX_USB_OTG_FS_PCD_Init();
/* USER CODE BEGIN 2 */

/* USER CODE END 2 */
Expand Down Expand Up @@ -141,8 +145,9 @@ void SystemClock_Config(void)
/** Initializes the RCC Oscillators according to the specified parameters
* in the RCC_OscInitTypeDef structure.
*/
RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSE;
RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSI48|RCC_OSCILLATORTYPE_HSE;
RCC_OscInitStruct.HSEState = RCC_HSE_ON;
RCC_OscInitStruct.HSI48State = RCC_HSI48_ON;
RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON;
RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSE;
RCC_OscInitStruct.PLL.PLLM = 3;
Expand Down Expand Up @@ -290,6 +295,42 @@ static void MX_USART1_UART_Init(void)

}

/**
* @brief USB_OTG_FS Initialization Function
* @param None
* @retval None
*/
static void MX_USB_OTG_FS_PCD_Init(void)
{

/* USER CODE BEGIN USB_OTG_FS_Init 0 */

/* USER CODE END USB_OTG_FS_Init 0 */

/* USER CODE BEGIN USB_OTG_FS_Init 1 */

/* USER CODE END USB_OTG_FS_Init 1 */
hpcd_USB_OTG_FS.Instance = USB_OTG_FS;
hpcd_USB_OTG_FS.Init.dev_endpoints = 9;
hpcd_USB_OTG_FS.Init.speed = PCD_SPEED_FULL;
hpcd_USB_OTG_FS.Init.dma_enable = DISABLE;
hpcd_USB_OTG_FS.Init.phy_itface = PCD_PHY_EMBEDDED;
hpcd_USB_OTG_FS.Init.Sof_enable = DISABLE;
hpcd_USB_OTG_FS.Init.low_power_enable = DISABLE;
hpcd_USB_OTG_FS.Init.lpm_enable = DISABLE;
hpcd_USB_OTG_FS.Init.battery_charging_enable = DISABLE;
hpcd_USB_OTG_FS.Init.vbus_sensing_enable = DISABLE;
hpcd_USB_OTG_FS.Init.use_dedicated_ep1 = DISABLE;
if (HAL_PCD_Init(&hpcd_USB_OTG_FS) != HAL_OK)
{
Error_Handler();
}
/* USER CODE BEGIN USB_OTG_FS_Init 2 */

/* USER CODE END USB_OTG_FS_Init 2 */

}

/* FMC initialization function */
static void MX_FMC_Init(void)
{
Expand Down Expand Up @@ -351,10 +392,10 @@ static void MX_GPIO_Init(void)
__HAL_RCC_GPIOC_CLK_ENABLE();
__HAL_RCC_GPIOG_CLK_ENABLE();
__HAL_RCC_GPIOD_CLK_ENABLE();
__HAL_RCC_GPIOA_CLK_ENABLE();
__HAL_RCC_GPIOI_CLK_ENABLE();
__HAL_RCC_GPIOH_CLK_ENABLE();
__HAL_RCC_GPIOF_CLK_ENABLE();
__HAL_RCC_GPIOA_CLK_ENABLE();
__HAL_RCC_GPIOB_CLK_ENABLE();

/*Configure GPIO pin Output Level */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -353,6 +353,91 @@ void HAL_UART_MspDeInit(UART_HandleTypeDef* huart)

}

/**
* @brief PCD MSP Initialization
* This function configures the hardware resources used in this example
* @param hpcd: PCD handle pointer
* @retval None
*/
void HAL_PCD_MspInit(PCD_HandleTypeDef* hpcd)
{
GPIO_InitTypeDef GPIO_InitStruct = {0};
RCC_PeriphCLKInitTypeDef PeriphClkInitStruct = {0};
if(hpcd->Instance==USB_OTG_FS)
{
/* USER CODE BEGIN USB_OTG_FS_MspInit 0 */

/* USER CODE END USB_OTG_FS_MspInit 0 */
/** Initializes the peripherals clock
*/
PeriphClkInitStruct.PeriphClockSelection = RCC_PERIPHCLK_USB;
PeriphClkInitStruct.UsbClockSelection = RCC_USBCLKSOURCE_HSI48;
if (HAL_RCCEx_PeriphCLKConfig(&PeriphClkInitStruct) != HAL_OK)
{
Error_Handler();
}
/** Enable USB Voltage detector
*/
HAL_PWREx_EnableUSBVoltageDetector();

__HAL_RCC_GPIOA_CLK_ENABLE();
/**USB_OTG_FS GPIO Configuration
PA12 ------> USB_OTG_FS_DP
PA11 ------> USB_OTG_FS_DM
*/
GPIO_InitStruct.Pin = GPIO_PIN_12|GPIO_PIN_11;
GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
GPIO_InitStruct.Pull = GPIO_NOPULL;
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_HIGH;
GPIO_InitStruct.Alternate = GPIO_AF10_OTG1_FS;
HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);

/* Peripheral clock enable */
__HAL_RCC_USB_OTG_FS_CLK_ENABLE();
/* USB_OTG_FS interrupt Init */
HAL_NVIC_SetPriority(OTG_FS_EP1_OUT_IRQn, 0, 0);
HAL_NVIC_EnableIRQ(OTG_FS_EP1_OUT_IRQn);
HAL_NVIC_SetPriority(OTG_FS_EP1_IN_IRQn, 0, 0);
HAL_NVIC_EnableIRQ(OTG_FS_EP1_IN_IRQn);
/* USER CODE BEGIN USB_OTG_FS_MspInit 1 */

/* USER CODE END USB_OTG_FS_MspInit 1 */
}

}

/**
* @brief PCD MSP De-Initialization
* This function freeze the hardware resources used in this example
* @param hpcd: PCD handle pointer
* @retval None
*/
void HAL_PCD_MspDeInit(PCD_HandleTypeDef* hpcd)
{
if(hpcd->Instance==USB_OTG_FS)
{
/* USER CODE BEGIN USB_OTG_FS_MspDeInit 0 */

/* USER CODE END USB_OTG_FS_MspDeInit 0 */
/* Peripheral clock disable */
__HAL_RCC_USB_OTG_FS_CLK_DISABLE();

/**USB_OTG_FS GPIO Configuration
PA12 ------> USB_OTG_FS_DP
PA11 ------> USB_OTG_FS_DM
*/
HAL_GPIO_DeInit(GPIOA, GPIO_PIN_12|GPIO_PIN_11);

/* USB_OTG_FS interrupt DeInit */
HAL_NVIC_DisableIRQ(OTG_FS_EP1_OUT_IRQn);
HAL_NVIC_DisableIRQ(OTG_FS_EP1_IN_IRQn);
/* USER CODE BEGIN USB_OTG_FS_MspDeInit 1 */

/* USER CODE END USB_OTG_FS_MspDeInit 1 */
}

}

static uint32_t FMC_Initialized = 0;

static void HAL_FMC_MspInit(void){
Expand Down
Loading

0 comments on commit 34bdc3c

Please sign in to comment.