From de659be83e0c479179a077325371b7c7e2b15e84 Mon Sep 17 00:00:00 2001 From: hathach Date: Wed, 11 Sep 2019 17:37:23 +0700 Subject: [PATCH] tested all the stm32f4 board, work great --- hw/bsp/stm32f072disco/stm32f072disco.c | 1 + hw/bsp/stm32f303disco/stm32f303disco.c | 3 ++- hw/bsp/stm32f407disco/stm32f407disco.c | 14 +++++--------- hw/bsp/stm32f411disco/stm32f411disco.c | 6 +++--- hw/bsp/stm32f412disco/stm32f412disco.c | 8 ++++---- hw/bsp/stm32h743nucleo/board.mk | 7 +++++++ hw/bsp/stm32h743nucleo/stm32h743nucleo.c | 2 ++ 7 files changed, 24 insertions(+), 17 deletions(-) diff --git a/hw/bsp/stm32f072disco/stm32f072disco.c b/hw/bsp/stm32f072disco/stm32f072disco.c index cb9a1ddb5..2faa00db9 100644 --- a/hw/bsp/stm32f072disco/stm32f072disco.c +++ b/hw/bsp/stm32f072disco/stm32f072disco.c @@ -106,6 +106,7 @@ void board_init(void) // USB Pins // Configure USB DM and DP pins. This is optional, and maintained only for user guidance. + __HAL_RCC_GPIOA_CLK_ENABLE(); GPIO_InitStruct.Pin = (GPIO_PIN_11 | GPIO_PIN_12); GPIO_InitStruct.Mode = GPIO_MODE_INPUT; GPIO_InitStruct.Pull = GPIO_NOPULL; diff --git a/hw/bsp/stm32f303disco/stm32f303disco.c b/hw/bsp/stm32f303disco/stm32f303disco.c index f5b3da899..ae369ed5b 100644 --- a/hw/bsp/stm32f303disco/stm32f303disco.c +++ b/hw/bsp/stm32f303disco/stm32f303disco.c @@ -83,7 +83,7 @@ static void SystemClock_Config(void) RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV1; HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_2); - /* Enable Power Clock */ + /* Enable Power Clock */ __HAL_RCC_PWR_CLK_ENABLE(); } @@ -117,6 +117,7 @@ void board_init(void) HAL_GPIO_Init(BUTTON_PORT, &GPIO_InitStruct); /* Configure USB DM and DP pins */ + __HAL_RCC_GPIOA_CLK_ENABLE(); GPIO_InitStruct.Pin = (GPIO_PIN_11 | GPIO_PIN_12); GPIO_InitStruct.Mode = GPIO_MODE_AF_PP; GPIO_InitStruct.Pull = GPIO_NOPULL; diff --git a/hw/bsp/stm32f407disco/stm32f407disco.c b/hw/bsp/stm32f407disco/stm32f407disco.c index 2eb5148d2..16cec3e9a 100644 --- a/hw/bsp/stm32f407disco/stm32f407disco.c +++ b/hw/bsp/stm32f407disco/stm32f407disco.c @@ -106,14 +106,10 @@ void board_init(void) // Notify runtime of frequency change. SystemCoreClockUpdate(); - __HAL_RCC_GPIOA_CLK_ENABLE(); // button, USB D+/D- - __HAL_RCC_GPIOD_CLK_ENABLE(); // LED - 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; @@ -123,20 +119,17 @@ void board_init(void) board_led_write(false); // Button + __HAL_RCC_GPIOA_CLK_ENABLE(); GPIO_InitStruct.Pin = BUTTON_PIN; GPIO_InitStruct.Mode = GPIO_MODE_INPUT; GPIO_InitStruct.Pull = GPIO_PULLDOWN; 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 */ + __HAL_RCC_GPIOA_CLK_ENABLE(); GPIO_InitStruct.Pin = GPIO_PIN_11 | GPIO_PIN_12; GPIO_InitStruct.Speed = GPIO_SPEED_HIGH; GPIO_InitStruct.Mode = GPIO_MODE_AF_PP; @@ -157,6 +150,9 @@ 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(); } //--------------------------------------------------------------------+ diff --git a/hw/bsp/stm32f411disco/stm32f411disco.c b/hw/bsp/stm32f411disco/stm32f411disco.c index 541416c22..ce8753432 100644 --- a/hw/bsp/stm32f411disco/stm32f411disco.c +++ b/hw/bsp/stm32f411disco/stm32f411disco.c @@ -106,12 +106,10 @@ void board_init(void) // Notify runtime of frequency change. SystemCoreClockUpdate(); - __HAL_RCC_GPIOA_CLK_ENABLE(); // button, USB D+/D- - __HAL_RCC_GPIOD_CLK_ENABLE(); // LED - 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; @@ -121,6 +119,7 @@ void board_init(void) board_led_write(false); // Button + __HAL_RCC_GPIOA_CLK_ENABLE(); GPIO_InitStruct.Pin = BUTTON_PIN; GPIO_InitStruct.Mode = GPIO_MODE_INPUT; GPIO_InitStruct.Pull = GPIO_PULLDOWN; @@ -132,6 +131,7 @@ void board_init(void) /* Configure USB FS GPIOs */ /* Configure USB D+ D- Pins */ + __HAL_RCC_GPIOA_CLK_ENABLE(); GPIO_InitStruct.Pin = GPIO_PIN_11 | GPIO_PIN_12; GPIO_InitStruct.Speed = GPIO_SPEED_HIGH; GPIO_InitStruct.Mode = GPIO_MODE_AF_PP; diff --git a/hw/bsp/stm32f412disco/stm32f412disco.c b/hw/bsp/stm32f412disco/stm32f412disco.c index a4a687f95..0a3ae7365 100644 --- a/hw/bsp/stm32f412disco/stm32f412disco.c +++ b/hw/bsp/stm32f412disco/stm32f412disco.c @@ -126,13 +126,10 @@ void board_init(void) //NVIC_SetPriority(USB0_IRQn, configLIBRARY_MAX_SYSCALL_INTERRUPT_PRIORITY ); #endif - __HAL_RCC_GPIOA_CLK_ENABLE(); // button, USB D+/D- - __HAL_RCC_GPIOE_CLK_ENABLE(); // LED - __HAL_RCC_GPIOG_CLK_ENABLE(); // USB power switch IO pin - GPIO_InitTypeDef GPIO_InitStruct; // LED + __HAL_RCC_GPIOE_CLK_ENABLE(); GPIO_InitStruct.Pin = LED_PIN; GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP; GPIO_InitStruct.Pull = GPIO_PULLUP; @@ -142,6 +139,7 @@ void board_init(void) board_led_write(false); // Button + __HAL_RCC_GPIOA_CLK_ENABLE(); GPIO_InitStruct.Pin = BUTTON_PIN; GPIO_InitStruct.Mode = GPIO_MODE_INPUT; GPIO_InitStruct.Pull = GPIO_PULLDOWN; @@ -150,6 +148,7 @@ void board_init(void) /* Configure USB FS GPIOs */ /* Configure USB D+ D- Pins */ + __HAL_RCC_GPIOA_CLK_ENABLE(); GPIO_InitStruct.Pin = GPIO_PIN_11 | GPIO_PIN_12; GPIO_InitStruct.Speed = GPIO_SPEED_HIGH; GPIO_InitStruct.Mode = GPIO_MODE_AF_PP; @@ -172,6 +171,7 @@ void board_init(void) HAL_GPIO_Init(GPIOA, &GPIO_InitStruct); /* Configure POWER_SWITCH IO pin */ + __HAL_RCC_GPIOG_CLK_ENABLE(); GPIO_InitStruct.Pin = GPIO_PIN_8; GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_OD; GPIO_InitStruct.Pull = GPIO_NOPULL; diff --git a/hw/bsp/stm32h743nucleo/board.mk b/hw/bsp/stm32h743nucleo/board.mk index ae1ea4366..8a5013b82 100644 --- a/hw/bsp/stm32h743nucleo/board.mk +++ b/hw/bsp/stm32h743nucleo/board.mk @@ -39,3 +39,10 @@ INC += \ # For TinyUSB port source VENDOR = st CHIP_FAMILY = synopsys + +# Path to STM32 Cube Programmer CLI, should be added into system path +STM32Prog = STM32_Programmer_CLI + +# flash target using on-board stlink +flash: $(BUILD)/$(BOARD)-firmware.elf + $(STM32Prog) --connect port=swd --write $< --go diff --git a/hw/bsp/stm32h743nucleo/stm32h743nucleo.c b/hw/bsp/stm32h743nucleo/stm32h743nucleo.c index 9f4c50692..2e02786ee 100644 --- a/hw/bsp/stm32h743nucleo/stm32h743nucleo.c +++ b/hw/bsp/stm32h743nucleo/stm32h743nucleo.c @@ -158,6 +158,7 @@ void board_init(void) GPIO_InitStruct.Alternate = GPIO_AF10_OTG2_HS; HAL_GPIO_Init(GPIOA, &GPIO_InitStruct); + // LED __HAL_RCC_GPIOB_CLK_ENABLE(); GPIO_InitStruct.Pin = LED_PIN; @@ -166,6 +167,7 @@ void board_init(void) GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_HIGH; HAL_GPIO_Init(LED_PORT, &GPIO_InitStruct); + // Button __HAL_RCC_GPIOC_CLK_ENABLE(); GPIO_InitStruct.Pin = BUTTON_PIN; GPIO_InitStruct.Mode = GPIO_MODE_INPUT;