注册
登录
电子工程世界-论坛
返回首页
EEWORLD首页
频道
EE大学堂
下载中心
Datasheet
专题
单片机
物联网
汽车电子
嵌入式
手机/便携
模拟电子
家用电子
网络通信
电源管理
工业控制
测试测量
半导体设计/制造
安防电子
传感器
医疗电子
Justice_Gao的个人空间
https://home.eeworld.com.cn/space-uid-784175.html
[收藏]
[复制]
[分享]
[RSS]
空间首页
动态
记录
日志
相册
主题
分享
留言板
个人资料
借用开发板
论坛
淘帖
Collection
查看新帖
最新回复
社区活动
联系管理员
我的空间
帖子
日志
收藏
好友
勋章
积分
安全验证
请完成以下验证码
日志
【GD32F350开发分享二】GD32F350时钟配置,非常重要
已有 5910 次阅读
2018-9-5 19:55
|
个人分类:
GD32系列学习
大家应该都知道,微控制器最重要的就是时钟频率,时钟频率会影响指令周期、定时器、RTC等等所有涉及时钟的总线。
GD32F350开发板的外部高速时钟8MHZ晶振和外部低速时钟32.768KHZ晶振没有焊接,大家有需要自行焊接。
我用的是内部时钟8MHZ,当然,如果需要用时钟频率进行定时器中断设置的,建议使用外部晶振,因为外部晶振精度高,偏移量小,但是缺点在于功耗就大了,内部时钟功耗低,但是精度会差一些;
以下是我的时钟配置
/* system frequency define */
#define __IRC8M (IRC8M_VALUE) /* internal 8 MHz RC oscillator frequency */
#define __HXTAL (HXTAL_VALUE) /* high speed crystal oscillator frequency */
#define __SYS_OSC_CLK (__IRC8M) /* main oscillator frequency */
/* select a system clock by uncommenting the following line */
#if defined (GD32F330)
//#define __SYSTEM_CLOCK_8M_HXTAL (__HXTAL)
//#define __SYSTEM_CLOCK_8M_IRC8M (__IRC8M)
//#define __SYSTEM_CLOCK_72M_PLL_HXTAL (uint32_t)(72000000)
//#define __SYSTEM_CLOCK_72M_PLL_IRC8M_DIV2 (uint32_t)(72000000)
//#define __SYSTEM_CLOCK_72M_PLL_IRC48M_DIV2 (uint32_t)(72000000)
#define __SYSTEM_CLOCK_84M_PLL_HXTAL (uint32_t)(84000000)
//#define __SYSTEM_CLOCK_84M_PLL_IRC8M_DIV2 (uint32_t)(84000000)
#endif /* GD32F330 */
#if defined (GD32F350)
//#define __SYSTEM_CLOCK_8M_HXTAL (__HXTAL)
#define __SYSTEM_CLOCK_8M_IRC8M (__IRC8M)
//#define __SYSTEM_CLOCK_72M_PLL_HXTAL (uint32_t)(72000000)
//#define __SYSTEM_CLOCK_72M_PLL_IRC8M_DIV2 (uint32_t)(72000000)
//#define __SYSTEM_CLOCK_84M_PLL_HXTAL (uint32_t)(84000000)
//#define __SYSTEM_CLOCK_84M_PLL_IRC8M_DIV2 (uint32_t)(84000000)
//#define __SYSTEM_CLOCK_96M_PLL_HXTAL (uint32_t)(96000000)
//#define __SYSTEM_CLOCK_96M_PLL_IRC8M_DIV2 (uint32_t)(96000000)
//#define __SYSTEM_CLOCK_96M_PLL_IRC48M_DIV2 (uint32_t)(96000000)
//#define __SYSTEM_CLOCK_108M_PLL_HXTAL (uint32_t)(108000000)
//#define __SYSTEM_CLOCK_108M_PLL_IRC8M_DIV2 (uint32_t)(108000000)
#endif /* GD32F350 */
#define SEL_IRC8M 0x00
#define SEL_HXTAL 0x01
#define SEL_PLL 0x02
/* set the system clock frequency and declare the system clock configuration function */
#ifdef __SYSTEM_CLOCK_8M_HXTAL
uint32_t SystemCoreClock = __SYSTEM_CLOCK_8M_HXTAL;
static void system_clock_8m_hxtal(void);
#elif defined (__SYSTEM_CLOCK_72M_PLL_HXTAL)
uint32_t SystemCoreClock = __SYSTEM_CLOCK_72M_PLL_HXTAL;
static void system_clock_72m_hxtal(void);
#elif defined (__SYSTEM_CLOCK_72M_PLL_IRC8M_DIV2)
uint32_t SystemCoreClock = __SYSTEM_CLOCK_72M_PLL_IRC8M_DIV2;
static void system_clock_72m_irc8m(void);
#elif defined (__SYSTEM_CLOCK_72M_PLL_IRC48M_DIV2)
uint32_t SystemCoreClock = __SYSTEM_CLOCK_72M_PLL_IRC48M_DIV2;
static void system_clock_72m_irc48m(void);
#elif defined (__SYSTEM_CLOCK_84M_PLL_HXTAL)
uint32_t SystemCoreClock = __SYSTEM_CLOCK_84M_PLL_HXTAL;
static void system_clock_84m_hxtal(void);
#elif defined (__SYSTEM_CLOCK_84M_PLL_IRC8M_DIV2)
uint32_t SystemCoreClock = __SYSTEM_CLOCK_84M_PLL_IRC8M_DIV2;
static void system_clock_84m_irc8m(void);
#elif defined (__SYSTEM_CLOCK_96M_PLL_HXTAL)
uint32_t SystemCoreClock = __SYSTEM_CLOCK_96M_PLL_HXTAL;
static void system_clock_96m_hxtal(void);
#elif defined (__SYSTEM_CLOCK_96M_PLL_IRC8M_DIV2)
uint32_t SystemCoreClock = __SYSTEM_CLOCK_96M_PLL_IRC8M_DIV2;
static void system_clock_96m_irc8m(void);
#elif defined (__SYSTEM_CLOCK_96M_PLL_IRC48M_DIV2)
uint32_t SystemCoreClock = __SYSTEM_CLOCK_96M_PLL_IRC48M_DIV2;
static void system_clock_96m_irc48m(void);
#elif defined (__SYSTEM_CLOCK_108M_PLL_HXTAL)
uint32_t SystemCoreClock = __SYSTEM_CLOCK_108M_PLL_HXTAL;
static void system_clock_108m_hxtal(void);
#elif defined (__SYSTEM_CLOCK_108M_PLL_IRC8M_DIV2)
uint32_t SystemCoreClock = __SYSTEM_CLOCK_108M_PLL_IRC8M_DIV2;
static void system_clock_108m_irc8m(void);
#else
uint32_t SystemCoreClock = __SYSTEM_CLOCK_8M_IRC8M;
static void system_clock_8m_irc8m(void);
#endif /* __SYSTEM_CLOCK_8M_HXTAL */
/* configure the system clock */
static void system_clock_config(void);
/*!
\brief setup the microcontroller system, initialize the system
\param[in] none
\param[out] none
\retval none
*/
void SystemInit (void)
{
/* enable IRC8M */
RCU_CTL0 |= RCU_CTL0_IRC8MEN;
while(0U == (RCU_CTL0 & RCU_CTL0_IRC8MSTB)){
}
/* reset RCU */
RCU_CFG0 &= ~(RCU_CFG0_SCS | RCU_CFG0_AHBPSC | RCU_CFG0_APB1PSC | RCU_CFG0_APB2PSC |\
RCU_CFG0_ADCPSC | RCU_CFG0_CKOUTSEL | RCU_CFG0_CKOUTDIV | RCU_CFG0_PLLDV);
RCU_CFG0 &= ~(RCU_CFG0_PLLSEL | RCU_CFG0_PLLMF | RCU_CFG0_PLLMF4 | RCU_CFG0_PLLDV);
#if (defined(GD32F350))
RCU_CFG0 &= ~(RCU_CFG0_USBFSPSC);
RCU_CFG2 &= ~(RCU_CFG2_CECSEL | RCU_CFG2_USBFSPSC2);
#endif /* GD32F350 */
RCU_CTL0 &= ~(RCU_CTL0_HXTALEN | RCU_CTL0_CKMEN | RCU_CTL0_PLLEN | RCU_CTL0_HXTALBPS);
RCU_CFG1 &= ~(RCU_CFG1_PREDV | RCU_CFG1_PLLMF5 | RCU_CFG1_PLLPRESEL);
RCU_CFG2 &= ~(RCU_CFG2_USART0SEL | RCU_CFG2_ADCSEL);
RCU_CFG2 &= ~RCU_CFG2_IRC28MDIV;
RCU_CFG2 &= ~RCU_CFG2_ADCPSC2;
RCU_CTL1 &= ~RCU_CTL1_IRC28MEN;
RCU_ADDCTL &= ~RCU_ADDCTL_IRC48MEN;
RCU_INT = 0x00000000U;
RCU_ADDINT = 0x00000000U;
/* configure system clock */
system_clock_config();
}
/*!
\brief configure the system clock
\param[in] none
\param[out] none
\retval none
*/
static void system_clock_config(void)
{
#ifdef __SYSTEM_CLOCK_8M_HXTAL
system_clock_8m_hxtal();
#elif defined (__SYSTEM_CLOCK_72M_PLL_HXTAL)
system_clock_72m_hxtal();
#elif defined (__SYSTEM_CLOCK_72M_PLL_IRC8M_DIV2)
system_clock_72m_irc8m();
#elif defined (__SYSTEM_CLOCK_72M_PLL_IRC48M_DIV2)
system_clock_72m_irc48m();
#elif defined (__SYSTEM_CLOCK_84M_PLL_HXTAL)
system_clock_84m_hxtal();
#elif defined (__SYSTEM_CLOCK_84M_PLL_IRC8M_DIV2)
system_clock_84m_irc8m();
#elif defined (__SYSTEM_CLOCK_96M_PLL_HXTAL)
system_clock_96m_hxtal();
#elif defined (__SYSTEM_CLOCK_96M_PLL_IRC8M_DIV2)
system_clock_96m_irc8m();
#elif defined (__SYSTEM_CLOCK_96M_PLL_IRC48M_DIV2)
system_clock_96m_irc48m();
#elif defined (__SYSTEM_CLOCK_108M_PLL_HXTAL)
system_clock_108m_hxtal();
#elif defined (__SYSTEM_CLOCK_108M_PLL_IRC8M_DIV2)
system_clock_108m_irc8m();
#else
system_clock_8m_irc8m();
#endif /* __SYSTEM_CLOCK_8M_HXTAL */
}
复制代码
本文来自论坛,点击查看完整帖子内容。
收藏
邀请
举报
全部
作者的其他最新日志
•
【GD32F350开发分享九】单端输入ADC+定时器单次转换
•
【GD32F350开发分享八】RTC年月日时分秒实时时钟,并显示在TFT屏幕上
•
【GD32F350开发分享七】GPIO模拟I2C驱动
•
【GD32F350开发分享六】USART0和USART1的双串口应用
•
【GD32F350开发分享五】GPIO模拟SPI控制液晶显示屏
•
【GD32F350开发分享四】定时器T0中断:外部高速时钟源8MHz
评论 (
0
个评论)
涂鸦板
您需要登录后才可以评论
登录
|
注册
评论
Justice_Gao
加为好友
给我留言
打个招呼
发送消息
热门文章
头条资讯
苹果在欧洲法院胜诉 小米Mi Pad商标无法在欧洲注册
现场采访 | 抢占制高点,村田“智”造拥抱5G时代
文末福利|距离集齐五福,你还差 Vishay 五牛祝福
指纹识别不好用,谁该为你的手机负责?
【征稿】擎性能之颠,筑安全之底(1-3月征稿)
应用材料公司新年祝福到!
新增数据手册
NM1LMR12D23.5
M55342K09B316ACBS
MXZ-050/100M5X5
TF-596-ARD
ABVFM2-80.000MHZ-N-CM-N150-T
CHP2512K1241DN131
热搜器件
TMMH-125-01-F-T-RA
RNC55H7500FSB14
CC05CG561G
EKZM250
1-1579007-2
12067C472MAT2A
推荐下载
开关电源原理与设计
简单的电池电路扩展以太网供电(PoE)峰值电流
高整合度的雙頻DAB接收器設計
电子电路实验与虚拟技术
单片机学习
工业以太网和ANSI 709
推荐关注
益莱储2025新年回顾展望:租赁赋能客户创新蝶变
益莱储2025新年回顾展望:租赁赋能客户创新蝶变
极海G32R501实时控制 MCU 跨域新境界丨面向新一代高效能高实时控制设备
搓了块国产FPGA遨格芯AG10K的板子,水一下踩坑经历
ATGM336H-5N31:GPS+BDS定位车载导航模块资料,兼容代替 MAX-6/7Q MAX- M8Q
RK3562编译Android13 ROOT固件教程,触觉智能开发板演示