[303] | 1 | /**
|
---|
| 2 | ******************************************************************************
|
---|
| 3 | * @file Templates/Src/main.c
|
---|
| 4 | * @author MCD Application Team
|
---|
| 5 | * @version V1.1.2
|
---|
| 6 | * @date 09-October-2015
|
---|
| 7 | * @brief Main program body
|
---|
| 8 | ******************************************************************************
|
---|
| 9 | * @attention
|
---|
| 10 | *
|
---|
| 11 | * <h2><center>© COPYRIGHT(c) 2015 STMicroelectronics</center></h2>
|
---|
| 12 | *
|
---|
| 13 | * Redistribution and use in source and binary forms, with or without modification,
|
---|
| 14 | * are permitted provided that the following conditions are met:
|
---|
| 15 | * 1. Redistributions of source code must retain the above copyright notice,
|
---|
| 16 | * this list of conditions and the following disclaimer.
|
---|
| 17 | * 2. Redistributions in binary form must reproduce the above copyright notice,
|
---|
| 18 | * this list of conditions and the following disclaimer in the documentation
|
---|
| 19 | * and/or other materials provided with the distribution.
|
---|
| 20 | * 3. Neither the name of STMicroelectronics nor the names of its contributors
|
---|
| 21 | * may be used to endorse or promote products derived from this software
|
---|
| 22 | * without specific prior written permission.
|
---|
| 23 | *
|
---|
| 24 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
---|
| 25 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
---|
| 26 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
---|
| 27 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
|
---|
| 28 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
---|
| 29 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
---|
| 30 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
---|
| 31 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
---|
| 32 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
---|
| 33 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
---|
| 34 | *
|
---|
| 35 | ******************************************************************************
|
---|
| 36 | */
|
---|
| 37 |
|
---|
| 38 | /* Includes ------------------------------------------------------------------*/
|
---|
| 39 | #include "stm32f4xx_hal.h"
|
---|
| 40 | #include "stm32f4xx_nucleo.h"
|
---|
| 41 |
|
---|
| 42 | extern void Error_Handler();
|
---|
| 43 |
|
---|
| 44 | /**
|
---|
| 45 | * @brief System Clock Configuration
|
---|
| 46 | * The system Clock is configured as follow :
|
---|
| 47 | * System Clock source = PLL (HSI)
|
---|
| 48 | * SYSCLK(Hz) = 84000000
|
---|
| 49 | * HCLK(Hz) = 84000000
|
---|
| 50 | * AHB Prescaler = 1
|
---|
| 51 | * APB1 Prescaler = 2
|
---|
| 52 | * APB2 Prescaler = 1
|
---|
| 53 | * HSI Frequency(Hz) = 16000000
|
---|
| 54 | * PLL_M = 16
|
---|
| 55 | * PLL_N = 336
|
---|
| 56 | * PLL_P = 4
|
---|
| 57 | * PLL_Q = 7
|
---|
| 58 | * VDD(V) = 3.3
|
---|
| 59 | * Main regulator output voltage = Scale2 mode
|
---|
| 60 | * Flash Latency(WS) = 2
|
---|
| 61 | * @param None
|
---|
| 62 | * @retval None
|
---|
| 63 | */
|
---|
| 64 | void SystemClock_Config(void)
|
---|
| 65 | {
|
---|
| 66 | RCC_ClkInitTypeDef RCC_ClkInitStruct;
|
---|
| 67 | RCC_OscInitTypeDef RCC_OscInitStruct;
|
---|
| 68 |
|
---|
| 69 | /* Enable Power Control clock */
|
---|
| 70 | __HAL_RCC_PWR_CLK_ENABLE();
|
---|
| 71 |
|
---|
| 72 | /* The voltage scaling allows optimizing the power consumption when the device is
|
---|
| 73 | clocked below the maximum system frequency, to update the voltage scaling value
|
---|
| 74 | regarding system frequency refer to product datasheet. */
|
---|
| 75 | __HAL_PWR_VOLTAGESCALING_CONFIG(PWR_REGULATOR_VOLTAGE_SCALE2);
|
---|
| 76 |
|
---|
| 77 | /* Enable HSI Oscillator and activate PLL with HSI as source */
|
---|
| 78 | RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSI;
|
---|
| 79 | RCC_OscInitStruct.HSIState = RCC_HSI_ON;
|
---|
| 80 | RCC_OscInitStruct.HSICalibrationValue = 0x10;
|
---|
| 81 | RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON;
|
---|
| 82 | RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSI;
|
---|
| 83 | RCC_OscInitStruct.PLL.PLLM = 16;
|
---|
| 84 | RCC_OscInitStruct.PLL.PLLN = 336;
|
---|
| 85 | RCC_OscInitStruct.PLL.PLLP = RCC_PLLP_DIV4;
|
---|
| 86 | RCC_OscInitStruct.PLL.PLLQ = 7;
|
---|
| 87 | if(HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK)
|
---|
| 88 | {
|
---|
| 89 | Error_Handler();
|
---|
| 90 | }
|
---|
| 91 |
|
---|
| 92 | /* Select PLL as system clock source and configure the HCLK, PCLK1 and PCLK2
|
---|
| 93 | clocks dividers */
|
---|
| 94 | RCC_ClkInitStruct.ClockType = (RCC_CLOCKTYPE_SYSCLK | RCC_CLOCKTYPE_HCLK | RCC_CLOCKTYPE_PCLK1 | RCC_CLOCKTYPE_PCLK2);
|
---|
| 95 | RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK;
|
---|
| 96 | RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1;
|
---|
| 97 | RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV2;
|
---|
| 98 | RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV1;
|
---|
| 99 | if(HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_2) != HAL_OK)
|
---|
| 100 | {
|
---|
| 101 | Error_Handler();
|
---|
| 102 | }
|
---|
| 103 | }
|
---|
| 104 |
|
---|
| 105 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
|
---|