summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorhathach <[email protected]>2019-07-20 22:59:24 +0700
committerhathach <[email protected]>2019-07-20 22:59:24 +0700
commitcb8a33ca87a1b2e81c2b441d916f1b085adb335f (patch)
tree840ba9b5a6f82f13d13e2836c69534f4ed809ce1
parented698069d37dbea2146960ceda246c07585747c3 (diff)
able to blink LED with stm32f411
-rw-r--r--hw/bsp/stm32f303disco/board_stm32f303disco.c12
-rw-r--r--hw/bsp/stm32f411disco/board.mk6
-rw-r--r--hw/bsp/stm32f411disco/board_stm32f411disco.c41
3 files changed, 50 insertions, 9 deletions
diff --git a/hw/bsp/stm32f303disco/board_stm32f303disco.c b/hw/bsp/stm32f303disco/board_stm32f303disco.c
index ce56fa7e2..cb370b4ff 100644
--- a/hw/bsp/stm32f303disco/board_stm32f303disco.c
+++ b/hw/bsp/stm32f303disco/board_stm32f303disco.c
@@ -34,6 +34,12 @@
void board_init(void)
{
+ #if CFG_TUSB_OS == OPT_OS_NONE
+ // 1ms tick timer
+ SysTick_Config(SystemCoreClock / 1000);
+ #endif
+
+ /* Configure the system clock to 72 MHz */
RCC_ClkInitTypeDef RCC_ClkInitStruct;
RCC_OscInitTypeDef RCC_OscInitStruct;
@@ -58,11 +64,6 @@ void board_init(void)
// Notify runtime of frequency change.
SystemCoreClockUpdate();
- #if CFG_TUSB_OS == OPT_OS_NONE
- // 1ms tick timer
- SysTick_Config(SystemCoreClock / 1000);
- #endif
-
/* -1- Enable GPIO Clock (to be able to program the configuration registers) */
__HAL_RCC_GPIOE_CLK_ENABLE();
@@ -72,7 +73,6 @@ void board_init(void)
GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
GPIO_InitStruct.Pull = GPIO_PULLUP;
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_HIGH;
-
HAL_GPIO_Init(LED_PORT, &GPIO_InitStruct);
board_led_write(false);
diff --git a/hw/bsp/stm32f411disco/board.mk b/hw/bsp/stm32f411disco/board.mk
index 6b0a0fa2b..a79c2695b 100644
--- a/hw/bsp/stm32f411disco/board.mk
+++ b/hw/bsp/stm32f411disco/board.mk
@@ -14,8 +14,10 @@ LD_FILE = hw/bsp/stm32f411disco/STM32F411VETx_FLASH.ld
SRC_C += \
hw/mcu/st/system-init/system_stm32f4xx.c \
- hw/mcu/st/stm32lib/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_gpio.c \
-
+ hw/mcu/st/stm32lib/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal.c \
+ hw/mcu/st/stm32lib/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_cortex.c \
+ hw/mcu/st/stm32lib/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_rcc.c \
+ hw/mcu/st/stm32lib/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_gpio.c
SRC_S += \
hw/mcu/st/startup/stm32f4/startup_stm32f411xe.s
diff --git a/hw/bsp/stm32f411disco/board_stm32f411disco.c b/hw/bsp/stm32f411disco/board_stm32f411disco.c
index a4a918b05..4871e1380 100644
--- a/hw/bsp/stm32f411disco/board_stm32f411disco.c
+++ b/hw/bsp/stm32f411disco/board_stm32f411disco.c
@@ -34,6 +34,46 @@
void board_init(void)
{
+ #if CFG_TUSB_OS == OPT_OS_NONE
+ // 1ms tick timer
+ SysTick_Config(SystemCoreClock / 1000);
+ #endif
+
+ /* Configure the system clock to 100 MHz */
+ RCC_ClkInitTypeDef RCC_ClkInitStruct;
+ RCC_OscInitTypeDef RCC_OscInitStruct;
+
+ /* Enable Power Control clock */
+ __HAL_RCC_PWR_CLK_ENABLE();
+
+ /* The voltage scaling allows optimizing the power consumption when the device is
+ clocked below the maximum system frequency, to update the voltage scaling value
+ regarding system frequency refer to product datasheet. */
+ __HAL_PWR_VOLTAGESCALING_CONFIG(PWR_REGULATOR_VOLTAGE_SCALE2);
+
+ /* Enable HSI Oscillator and activate PLL with HSI as source */
+ RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSI;
+ RCC_OscInitStruct.HSIState = RCC_HSI_ON;
+ RCC_OscInitStruct.HSICalibrationValue = 0x10;
+ RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON;
+ RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSI;
+ RCC_OscInitStruct.PLL.PLLM = 16;
+ RCC_OscInitStruct.PLL.PLLN = 400;
+ RCC_OscInitStruct.PLL.PLLP = RCC_PLLP_DIV4;
+ RCC_OscInitStruct.PLL.PLLQ = 7;
+ HAL_RCC_OscConfig(&RCC_OscInitStruct);
+
+ /* Select PLL as system clock source and configure the HCLK, PCLK1 and PCLK2 clocks dividers */
+ RCC_ClkInitStruct.ClockType = (RCC_CLOCKTYPE_SYSCLK | RCC_CLOCKTYPE_HCLK | RCC_CLOCKTYPE_PCLK1 | RCC_CLOCKTYPE_PCLK2);
+ RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK;
+ RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1;
+ RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV2;
+ RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV1;
+ HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_3);
+
+ // Notify runtime of frequency change.
+ SystemCoreClockUpdate();
+
/* Configure the GPIO_LED pin */
__HAL_RCC_GPIOD_CLK_ENABLE();
@@ -42,7 +82,6 @@ void board_init(void)
GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
GPIO_InitStruct.Pull = GPIO_PULLUP;
GPIO_InitStruct.Speed = GPIO_SPEED_FAST;
-
HAL_GPIO_Init(LED_PORT, &GPIO_InitStruct);
board_led_write(false);