118 lines
3.1 KiB
C
118 lines
3.1 KiB
C
/*
|
|
|
|
system_stm32f10x.h - This provides system clock functions and an exported
|
|
variable for System init and clock configuration.
|
|
includes:
|
|
SystemInit, SystemInit_ExtMemCtl, Sys_Sysclk_Update, Sys_GetSysclk_src,
|
|
Sys_SetSysclk_src, Sys_HSI_Cmd, Sys_HSE_Cmd, Sys_ExtClock_Cmd,
|
|
Sys_PLL_Cmd, Sys_SetPLLClock
|
|
|
|
Copyright (C) 2011 Houtouridis Christos (http://houtouridis.blogspot.com/)
|
|
|
|
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/>.
|
|
|
|
Author: Houtouridis Christos <houtouridis.ch@gmail.com>
|
|
Date: 11/2011
|
|
Version: 0.1
|
|
*/
|
|
|
|
#ifndef __stm32f10x_clock_h__
|
|
#define __stm32f10x_clock_h__
|
|
|
|
#ifdef __cplusplus
|
|
extern "C" {
|
|
#endif
|
|
|
|
#include <stm32f10x.h>
|
|
#include "stm32f10x_assert.h"
|
|
|
|
/* ================ User Defines ======================*/
|
|
|
|
#define SYSTEM_STARTUP_TIMEOUT (0x500)
|
|
|
|
/* ================ General Defines ======================*/
|
|
|
|
#define SYSCLK_HSI_FREQ (8000000)
|
|
|
|
#ifndef CLOCK
|
|
#warning "CLOCK is not defined. Used 8000000 as default value"
|
|
#define CLOCK (SYSCLK_HSI_FREQ)
|
|
#endif
|
|
|
|
#if defined (STM32F10X_LD_VL) || (defined STM32F10X_MD_VL) || (defined STM32F10X_HD_VL)
|
|
#define SYSTEM_MAX_CLK (24000000)
|
|
#define SYSTEM_MIN_CLK (8000000)
|
|
#elif defined (STM32F10X_MD)
|
|
#define SYSTEM_MAX_CLK (32000000)
|
|
#define SYSTEM_MIN_CLK (8000000)
|
|
#elif defined (STM32F10X_HD)
|
|
#define SYSTEM_MAX_CLK (36000000)
|
|
//#define SYSTEM_MAX_CLK (48000000)
|
|
//#define SYSTEM_MAX_CLK (72000000)
|
|
#define SYSTEM_MIN_CLK (8000000)
|
|
#endif
|
|
|
|
|
|
typedef uint32_t CLK_t;
|
|
typedef enum
|
|
{
|
|
// DO NOT change the numbers,
|
|
//see STM Reference manual page 83
|
|
HSI=0, HSE, PLLCLK
|
|
}Sys_CLK_src_t;
|
|
|
|
typedef enum
|
|
{
|
|
DIS=0, EN
|
|
}Sys_FunctionalState_t;
|
|
|
|
typedef enum
|
|
{
|
|
HSI_2=0, PREDIV
|
|
}Sys_PLL_src_t;
|
|
|
|
typedef enum
|
|
{
|
|
System_OK=0, System_ERROR
|
|
}Sys_Exit_t;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* ================ Exported Functions ======================*/
|
|
|
|
CLK_t Sys_Sysclk_Update (void);
|
|
|
|
|
|
Sys_CLK_src_t Sys_GetSysclk_src (void);
|
|
Sys_Exit_t Sys_SetSysclk_src (Sys_CLK_src_t cs);
|
|
|
|
Sys_Exit_t Sys_HSI_Cmd (Sys_FunctionalState_t state);
|
|
Sys_Exit_t Sys_HSE_Cmd (Sys_FunctionalState_t state);
|
|
Sys_Exit_t Sys_ExtClock_Cmd (Sys_FunctionalState_t state);
|
|
Sys_Exit_t Sys_PLL_Cmd (Sys_FunctionalState_t state);
|
|
Sys_Exit_t Sys_SetPLLClock (CLK_t clk, Sys_PLL_src_t ps);
|
|
|
|
|
|
|
|
#ifdef __cplusplus
|
|
}
|
|
#endif
|
|
|
|
#endif // #ifndef __stm32f10x_clock_h__
|
|
|
|
|