LIbreria de soporte para la STM32F103C8T6 "Blue Pill" by Antuliu's Team

Dependents:   STM32-103C8_Plantilla_USB

Revision:
2:534793444c60
Child:
3:a92af4b1ffe1
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/SysClockConf.cpp	Tue Jul 05 18:19:01 2016 +0000
@@ -0,0 +1,69 @@
+#include "SysClockConf.h"
+#include "mbed.h"
+
+bool HSE_SystemClock_Config(int freq) {
+    RCC_OscInitTypeDef RCC_OscInitStruct;
+
+    RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSE;
+    RCC_OscInitStruct.HSEState = RCC_HSE_ON;
+    RCC_OscInitStruct.HSEPredivValue = RCC_HSE_PREDIV_DIV1;
+    RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON;
+    RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSE;
+    switch(freq) {
+    case 36:
+        RCC_OscInitStruct.PLL.PLLMUL = RCC_PLL_MUL9;
+        break;
+    case 48:
+        RCC_OscInitStruct.PLL.PLLMUL = RCC_PLL_MUL6;
+        break;
+    default:
+        RCC_OscInitStruct.PLL.PLLMUL = RCC_PLL_MUL9;
+    }
+
+    if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK) {
+        return false;
+    }
+
+    RCC_ClkInitTypeDef RCC_ClkInitStruct;
+
+    RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK|RCC_CLOCKTYPE_SYSCLK
+                                |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;
+    if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_2) != HAL_OK) {
+        return false;
+    }
+
+    RCC_PeriphCLKInitTypeDef PeriphClkInit;
+
+    PeriphClkInit.PeriphClockSelection = RCC_PERIPHCLK_ADC|RCC_PERIPHCLK_USB;
+    switch(freq) {
+    case 36:
+        PeriphClkInit.AdcClockSelection = RCC_ADCPCLK2_DIV6;
+        break;
+    case 48:
+        PeriphClkInit.AdcClockSelection = RCC_ADCPCLK2_DIV4;
+        break;
+    default:
+        PeriphClkInit.AdcClockSelection = RCC_ADCPCLK2_DIV6;
+    }
+    PeriphClkInit.UsbClockSelection = RCC_USBPLLCLK_DIV1;
+    if (HAL_RCCEx_PeriphCLKConfig(&PeriphClkInit) != HAL_OK) {
+        return false;
+    }
+    return true;
+}
+
+bool configSysClock(int freq) {
+    HAL_RCC_DeInit();
+    if (!HSE_SystemClock_Config(freq)) {
+        return false;
+    }
+    SystemCoreClockUpdate();
+    return true;
+}
+
+
+