mbed support for the Maple Mini boards.

Dependents:   MapleMini_USBSerial MapleMiniPeripherals MapleMini_Hello DHT11_USBSerial ... more

Committer:
hudakz
Date:
Sun Jul 17 08:44:20 2016 +0000
Revision:
0:0ced269d2669
Child:
1:7b9d53d8e473
Initial issue

Who changed what in which revision?

UserRevisionLine numberNew contents of line
hudakz 0:0ced269d2669 1 /*
hudakz 0:0ced269d2669 2 ******************************************************************************
hudakz 0:0ced269d2669 3 * @file SysClockConf.c
hudakz 0:0ced269d2669 4 * @author Zoltan Hudak
hudakz 0:0ced269d2669 5 * @version
hudakz 0:0ced269d2669 6 * @date 05-July-2016
hudakz 0:0ced269d2669 7 * @brief System Clock configuration for STM32F103C8T6
hudakz 0:0ced269d2669 8 ******************************************************************************
hudakz 0:0ced269d2669 9 * @attention
hudakz 0:0ced269d2669 10 *
hudakz 0:0ced269d2669 11 * <h2><center>&copy; COPYRIGHT(c) 2016 Zoltan Hudak <hudakz@inbox.com>
hudakz 0:0ced269d2669 12 *
hudakz 0:0ced269d2669 13 * All rights reserved.
hudakz 0:0ced269d2669 14
hudakz 0:0ced269d2669 15 This program is free software: you can redistribute it and/or modify
hudakz 0:0ced269d2669 16 it under the terms of the GNU General Public License as published by
hudakz 0:0ced269d2669 17 the Free Software Foundation, either version 3 of the License, or
hudakz 0:0ced269d2669 18 (at your option) any later version.
hudakz 0:0ced269d2669 19
hudakz 0:0ced269d2669 20 This program is distributed in the hope that it will be useful,
hudakz 0:0ced269d2669 21 but WITHOUT ANY WARRANTY; without even the implied warranty of
hudakz 0:0ced269d2669 22 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
hudakz 0:0ced269d2669 23 GNU General Public License for more details.
hudakz 0:0ced269d2669 24
hudakz 0:0ced269d2669 25 You should have received a copy of the GNU General Public License
hudakz 0:0ced269d2669 26 along with this program. If not, see <http://www.gnu.org/licenses/>.
hudakz 0:0ced269d2669 27 */
hudakz 0:0ced269d2669 28
hudakz 0:0ced269d2669 29 #include "SysClockConf.h"
hudakz 0:0ced269d2669 30 #include "mbed.h"
hudakz 0:0ced269d2669 31
hudakz 0:0ced269d2669 32 bool HSE_SystemClock_Config(int freq) {
hudakz 0:0ced269d2669 33 RCC_OscInitTypeDef RCC_OscInitStruct;
hudakz 0:0ced269d2669 34
hudakz 0:0ced269d2669 35 RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSE;
hudakz 0:0ced269d2669 36 RCC_OscInitStruct.HSEState = RCC_HSE_ON;
hudakz 0:0ced269d2669 37 RCC_OscInitStruct.HSEPredivValue = RCC_HSE_PREDIV_DIV1;
hudakz 0:0ced269d2669 38 RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON;
hudakz 0:0ced269d2669 39 RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSE;
hudakz 0:0ced269d2669 40 switch(freq) {
hudakz 0:0ced269d2669 41 case 36:
hudakz 0:0ced269d2669 42 RCC_OscInitStruct.PLL.PLLMUL = RCC_PLL_MUL9;
hudakz 0:0ced269d2669 43 break;
hudakz 0:0ced269d2669 44 case 48:
hudakz 0:0ced269d2669 45 RCC_OscInitStruct.PLL.PLLMUL = RCC_PLL_MUL6;
hudakz 0:0ced269d2669 46 break;
hudakz 0:0ced269d2669 47 default:
hudakz 0:0ced269d2669 48 RCC_OscInitStruct.PLL.PLLMUL = RCC_PLL_MUL9;
hudakz 0:0ced269d2669 49 }
hudakz 0:0ced269d2669 50
hudakz 0:0ced269d2669 51 if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK) {
hudakz 0:0ced269d2669 52 return false;
hudakz 0:0ced269d2669 53 }
hudakz 0:0ced269d2669 54
hudakz 0:0ced269d2669 55 RCC_ClkInitTypeDef RCC_ClkInitStruct;
hudakz 0:0ced269d2669 56
hudakz 0:0ced269d2669 57 RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK|RCC_CLOCKTYPE_SYSCLK
hudakz 0:0ced269d2669 58 |RCC_CLOCKTYPE_PCLK1|RCC_CLOCKTYPE_PCLK2;
hudakz 0:0ced269d2669 59 RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK;
hudakz 0:0ced269d2669 60 RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1;
hudakz 0:0ced269d2669 61 RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV2;
hudakz 0:0ced269d2669 62 RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV1;
hudakz 0:0ced269d2669 63 if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_2) != HAL_OK) {
hudakz 0:0ced269d2669 64 return false;
hudakz 0:0ced269d2669 65 }
hudakz 0:0ced269d2669 66
hudakz 0:0ced269d2669 67 RCC_PeriphCLKInitTypeDef PeriphClkInit;
hudakz 0:0ced269d2669 68
hudakz 0:0ced269d2669 69 PeriphClkInit.PeriphClockSelection = RCC_PERIPHCLK_ADC|RCC_PERIPHCLK_USB;
hudakz 0:0ced269d2669 70 switch(freq) {
hudakz 0:0ced269d2669 71 case 36:
hudakz 0:0ced269d2669 72 PeriphClkInit.AdcClockSelection = RCC_ADCPCLK2_DIV6;
hudakz 0:0ced269d2669 73 break;
hudakz 0:0ced269d2669 74 case 48:
hudakz 0:0ced269d2669 75 PeriphClkInit.AdcClockSelection = RCC_ADCPCLK2_DIV4;
hudakz 0:0ced269d2669 76 break;
hudakz 0:0ced269d2669 77 default:
hudakz 0:0ced269d2669 78 PeriphClkInit.AdcClockSelection = RCC_ADCPCLK2_DIV6;
hudakz 0:0ced269d2669 79 }
hudakz 0:0ced269d2669 80 PeriphClkInit.UsbClockSelection = RCC_USBPLLCLK_DIV1;
hudakz 0:0ced269d2669 81 if (HAL_RCCEx_PeriphCLKConfig(&PeriphClkInit) != HAL_OK) {
hudakz 0:0ced269d2669 82 return false;
hudakz 0:0ced269d2669 83 }
hudakz 0:0ced269d2669 84 return true;
hudakz 0:0ced269d2669 85 }
hudakz 0:0ced269d2669 86
hudakz 0:0ced269d2669 87 bool confSysClock(int freq) {
hudakz 0:0ced269d2669 88 HAL_RCC_DeInit();
hudakz 0:0ced269d2669 89 if (!HSE_SystemClock_Config(freq)) {
hudakz 0:0ced269d2669 90 return false;
hudakz 0:0ced269d2669 91 }
hudakz 0:0ced269d2669 92 SystemCoreClockUpdate();
hudakz 0:0ced269d2669 93 return true;
hudakz 0:0ced269d2669 94 }
hudakz 0:0ced269d2669 95
hudakz 0:0ced269d2669 96