Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependents: STM32F103variants_example
Revision 4:6568c3b20d29, committed 2017-03-20
- Comitter:
- vargham
- Date:
- Mon Mar 20 13:22:25 2017 +0000
- Parent:
- 3:e149147d7c13
- Commit message:
- .h only implementation. All ifdefs are working now.
Changed in this revision
| stm32f103variants.cpp | Show diff for this revision Revisions of this file |
| stm32f103variants.h | Show annotated file Show diff for this revision Revisions of this file |
diff -r e149147d7c13 -r 6568c3b20d29 stm32f103variants.cpp
--- a/stm32f103variants.cpp Thu Mar 16 12:36:39 2017 +0000
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,92 +0,0 @@
-/*
- ******************************************************************************
- * @file
- * @author Zoltan Hudak
- * @version
- * @date
- * @brief System Clock configuration for STM32F103
- ******************************************************************************
- * @attention
- *
- * <h2><center>© COPYRIGHT(c) 2016 Zoltan Hudak <hudakz@inbox.com>
- *
- * All rights reserved.
-
- This program is free software: you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation, either version 3 of the License, or
- (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program. If not, see <http://www.gnu.org/licenses/>.
-
- Modified by Mark Peter Vargha, 2017
- Added #ifdefs to avoid compile errors, so it is easy to select target board: Bluepill, Maple Mini, Nucleo F103, Nucleo F103 with external 8MHz crystal
-
-*/
-
-#include "stm32f103variants.h"
-
-#if defined USE_BLUEPILL || defined USE_MAPLE_MINI || defined USE_NUCLEO_EXTOSC
-
-bool HSE_SystemClock_Config(void) {
- 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;
- 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;
- PeriphClkInit.AdcClockSelection = RCC_ADCPCLK2_DIV6;
- PeriphClkInit.UsbClockSelection = RCC_USBPLLCLK_DIV1_5;
- if (HAL_RCCEx_PeriphCLKConfig(&PeriphClkInit) != HAL_OK) {
- return false;
- }
- return true;
-}
-
-bool doConfSysClock()
-{
- HAL_RCC_DeInit();
- if (!HSE_SystemClock_Config()) {
- return false;
- }
- SystemCoreClockUpdate();
- return true;
-}
-
-#endif
-
-bool confSysClock(void) {
-#if defined(USE_BLUEPILL) || defined(USE_MAPLE_MINI) || defined(USE_NUCLEO_EXTOSC)
- return doConfSysClock();
-#else
- return false;
-#endif
-}
diff -r e149147d7c13 -r 6568c3b20d29 stm32f103variants.h
--- a/stm32f103variants.h Thu Mar 16 12:36:39 2017 +0000
+++ b/stm32f103variants.h Mon Mar 20 13:22:25 2017 +0000
@@ -33,19 +33,49 @@
* Added #ifdefs to avoid compile errors, so it is easy to select target board: Bluepill, Maple Mini, Nucleo F103, Nucleo F103 with external 8MHz crystal
*
*/
+ /**
+ * Example:
+ * @code
+ #define USE_BOARD USE_MAPLE_MINI
+
+#include "stm32f103variants.h"
+#include "mbed.h"
+
+DigitalOut led1(LED1);
+Serial serialPc(PA_9, PA_10); //Tx, Rx
+
+int main()
+{
+ led1 = 0;
+ confSysClock();
+ serialPc.baud(460800);
+ serialPc.printf("This is a STM32F103 test.\r\n");
+ serialPc.printf("CPU SystemCoreClock is %d Hz\r\n", SystemCoreClock);
+ serialPc.printf("LED=%d\r\n", led1.read());
+
+ while (true)
+ {
+ led1 = !led1;
+ serialPc.printf("LED=%d\r\n", led1.read());
+ wait(1.0);
+ }
+}
+ *
+ */
#ifndef STM32F103variants_H_INCLUDED
#define STM32F103variants_H_INCLUDED
-#include "mbed.h"
-
-bool confSysClock(void);
+#define USE_OTHER 0
+#define USE_BLUEPILL 1
+#define USE_MAPLE_MINI 2
+#define USE_NUCLEO_EXTOSC 3
-#define USE_BLUEPILL
-//#define USE_MAPLE_MINI
-//#define USE_NUCLEO_EXTOSC
+#ifndef USE_BOARD
+#define USE_BOARD USE_OTHER
+#endif
-#ifdef USE_BLUEPILL
+#if (USE_BOARD == USE_BLUEPILL)
#ifndef MBED_PINNAMES_H
#define MBED_PINNAMES_H
@@ -221,7 +251,7 @@
*********************************************************************************************************************
*/
-#ifdef USE_MAPLE_MINI
+#if (USE_BOARD == USE_MAPLE_MINI)
#ifndef MBED_PINNAMES_H
#define MBED_PINNAMES_H
@@ -390,4 +420,63 @@
#endif //USE_MAPLE_MINI
+#if (USE_BOARD > USE_OTHER)
+
+bool HSE_SystemClock_Config(void) {
+ 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;
+ 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;
+ PeriphClkInit.AdcClockSelection = RCC_ADCPCLK2_DIV6;
+ PeriphClkInit.UsbClockSelection = RCC_USBPLLCLK_DIV1_5;
+ if (HAL_RCCEx_PeriphCLKConfig(&PeriphClkInit) != HAL_OK) {
+ return false;
+ }
+ return true;
+}
+
+bool doConfSysClock()
+{
+ HAL_RCC_DeInit();
+ if (!HSE_SystemClock_Config()) {
+ return false;
+ }
+ SystemCoreClockUpdate();
+ return true;
+}
+
+#endif //(USE_BOARD > USE_OTHER)
+
+bool confSysClock(void) {
+#if (USE_BOARD > USE_OTHER)
+ return doConfSysClock();
+#else
+ return false;
+#endif
+}
+
#endif /* STM32F103variants_H_INCLUDED */