Merge pull request #234 from hathach/stm32f4-blackpill

move VBUS sense out of dcd_synosys to bsp
This commit is contained in:
Ha Thach
2019-12-12 10:00:17 +07:00
committed by GitHub
10 changed files with 136 additions and 71 deletions
+16 -8
View File
@@ -38,6 +38,14 @@
#define BUTTON_PIN GPIO_PIN_3
#define BUTTON_STATE_ACTIVE 1
// enable all LED, Button, Uart, USB clock
static void all_rcc_clk_enable(void)
{
__HAL_RCC_GPIOA_CLK_ENABLE(); // USB D+, D-
__HAL_RCC_GPIOB_CLK_ENABLE(); // LED, Button
}
/**
* @brief System Clock Configuration
* The system Clock is configured as follow :
@@ -107,14 +115,11 @@ void board_init(void)
// Notify runtime of frequency change.
SystemCoreClockUpdate();
__HAL_RCC_GPIOA_CLK_ENABLE(); // USB D+/D-
__HAL_RCC_GPIOB_CLK_ENABLE(); // button, LED
all_rcc_clk_enable();
GPIO_InitTypeDef GPIO_InitStruct;
// LED
__HAL_RCC_GPIOD_CLK_ENABLE();
GPIO_InitStruct.Pin = LED_PIN;
GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
GPIO_InitStruct.Pull = GPIO_PULLUP;
@@ -130,12 +135,8 @@ void board_init(void)
GPIO_InitStruct.Speed = GPIO_SPEED_FAST;
HAL_GPIO_Init(BUTTON_PORT, &GPIO_InitStruct);
// Enable USB OTG clock
__HAL_RCC_USB_OTG_FS_CLK_ENABLE();
// USB Pin Init
// PA9- VUSB, PA10- ID, PA11- DM, PA12- DP
__HAL_RCC_GPIOA_CLK_ENABLE();
/* Configure DM DP Pins */
GPIO_InitStruct.Pin = GPIO_PIN_11 | GPIO_PIN_12;
@@ -158,6 +159,13 @@ void board_init(void)
GPIO_InitStruct.Speed = GPIO_SPEED_HIGH;
GPIO_InitStruct.Alternate = GPIO_AF10_OTG_FS;
HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
// Enable USB OTG clock
__HAL_RCC_USB_OTG_FS_CLK_ENABLE();
// Enable VBUS sense (B device) via pin PA9
USB_OTG_FS->GCCFG &= ~USB_OTG_GCCFG_NOVBUSSENS;
USB_OTG_FS->GCCFG |= USB_OTG_GCCFG_VBUSBSEN;
}
//--------------------------------------------------------------------+