4cv4

Dependencies:   mbed

Committer:
Polanco
Date:
Wed Nov 20 00:26:00 2019 +0000
Revision:
0:cd132d2bd4cd
display

Who changed what in which revision?

UserRevisionLine numberNew contents of line
Polanco 0:cd132d2bd4cd 1 /*
Polanco 0:cd132d2bd4cd 2 ******************************************************************************
Polanco 0:cd132d2bd4cd 3 * @file SysClockConf.c
Polanco 0:cd132d2bd4cd 4 * @version
Polanco 0:cd132d2bd4cd 5 * @date 05-July-2016
Polanco 0:cd132d2bd4cd 6 * @brief System Clock configuration for STM32F103C8T6
Polanco 0:cd132d2bd4cd 7 *****************************************************************************
Polanco 0:cd132d2bd4cd 8 *
Polanco 0:cd132d2bd4cd 9 * All rights reserved.
Polanco 0:cd132d2bd4cd 10
Polanco 0:cd132d2bd4cd 11 This program is free software: you can redistribute it and/or modify
Polanco 0:cd132d2bd4cd 12 it under the terms of the GNU General Public License as published by
Polanco 0:cd132d2bd4cd 13 the Free Software Foundation, either version 3 of the License, or
Polanco 0:cd132d2bd4cd 14 (at your option) any later version.
Polanco 0:cd132d2bd4cd 15
Polanco 0:cd132d2bd4cd 16 This program is distributed in the hope that it will be useful,
Polanco 0:cd132d2bd4cd 17 but WITHOUT ANY WARRANTY; without even the implied warranty of
Polanco 0:cd132d2bd4cd 18 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
Polanco 0:cd132d2bd4cd 19 GNU General Public License for more details.
Polanco 0:cd132d2bd4cd 20
Polanco 0:cd132d2bd4cd 21 You should have received a copy of the GNU General Public License
Polanco 0:cd132d2bd4cd 22 along with this program. If not, see <http://www.gnu.org/licenses/>.
Polanco 0:cd132d2bd4cd 23 */
Polanco 0:cd132d2bd4cd 24
Polanco 0:cd132d2bd4cd 25 #include "SysClockConf.h"
Polanco 0:cd132d2bd4cd 26 #include "mbed.h"
Polanco 0:cd132d2bd4cd 27
Polanco 0:cd132d2bd4cd 28 void HSE_SystemClock_Config(void) {
Polanco 0:cd132d2bd4cd 29 RCC_OscInitTypeDef RCC_OscInitStruct;
Polanco 0:cd132d2bd4cd 30 RCC_ClkInitTypeDef RCC_ClkInitStruct;
Polanco 0:cd132d2bd4cd 31 RCC_PeriphCLKInitTypeDef PeriphClkInit;
Polanco 0:cd132d2bd4cd 32
Polanco 0:cd132d2bd4cd 33 RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSE;
Polanco 0:cd132d2bd4cd 34 RCC_OscInitStruct.HSEState = RCC_HSE_ON;
Polanco 0:cd132d2bd4cd 35 RCC_OscInitStruct.HSEPredivValue = RCC_HSE_PREDIV_DIV1;
Polanco 0:cd132d2bd4cd 36 RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON;
Polanco 0:cd132d2bd4cd 37 RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSE;
Polanco 0:cd132d2bd4cd 38 RCC_OscInitStruct.PLL.PLLMUL = RCC_PLL_MUL9;
Polanco 0:cd132d2bd4cd 39 HAL_RCC_OscConfig(&RCC_OscInitStruct);
Polanco 0:cd132d2bd4cd 40 RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK|RCC_CLOCKTYPE_SYSCLK|RCC_CLOCKTYPE_PCLK1|RCC_CLOCKTYPE_PCLK2;
Polanco 0:cd132d2bd4cd 41 RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK;
Polanco 0:cd132d2bd4cd 42 RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1;
Polanco 0:cd132d2bd4cd 43 RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV2;
Polanco 0:cd132d2bd4cd 44 RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV1;
Polanco 0:cd132d2bd4cd 45 HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_2);
Polanco 0:cd132d2bd4cd 46 PeriphClkInit.PeriphClockSelection = RCC_PERIPHCLK_ADC|RCC_PERIPHCLK_USB;
Polanco 0:cd132d2bd4cd 47 PeriphClkInit.AdcClockSelection = RCC_ADCPCLK2_DIV6;
Polanco 0:cd132d2bd4cd 48 PeriphClkInit.UsbClockSelection = RCC_USBCLKSOURCE_PLL_DIV1_5;
Polanco 0:cd132d2bd4cd 49 HAL_RCCEx_PeriphCLKConfig(&PeriphClkInit);
Polanco 0:cd132d2bd4cd 50 }
Polanco 0:cd132d2bd4cd 51
Polanco 0:cd132d2bd4cd 52 void confSysClock(void) {
Polanco 0:cd132d2bd4cd 53 HAL_RCC_DeInit();
Polanco 0:cd132d2bd4cd 54 HSE_SystemClock_Config();
Polanco 0:cd132d2bd4cd 55 SystemCoreClockUpdate();
Polanco 0:cd132d2bd4cd 56 }