STM32F4 Learning note 2--clock and reset system

Source: Internet
Author: User

STM32F4采用了三种不同的时钟用来驱动系统时钟(SYSCLK)    ·HSI振荡器时钟(内部时钟)    ·HSE振荡器时钟(外部时钟)    ·PLL时钟(锁相环时钟)这些设备有以下两种二级时钟源    ·32kHz低速内部RC,可用于驱动独立看门狗和通过程序选择驱动RTC。RTC用于从停机/待机模式下自动唤醒系统。           ·32.768kHz低速外部晶振也可以用来通过程序选择驱动RTC(RTCCLK)。 AHB总线最高支持168MHz的时钟,通过AHB总线分频APB2最高支持84MHz,APB1最高支持42MHz。 所有外设驱动全部来至于SYSCLK除了下面几个:     ·USB OTG FS时钟48MHz,随机信号发生器时钟<=48MHz和SDIO时钟<=48MHz全部来至于PLL48CLK     ·I2S为了达到高性能要求,I2S时钟可用于内部时钟PLLI2S或者使用外部时钟,通过I2S_CLKIN引脚输入得到。     ·USB OTG HS 60MHz需要外部PHY芯片内提供     ·以太网时钟(TX RX RMII)需要外部PHY芯片提供时钟。RCC通过AHB时钟(HCLK)8分频后作为Cortex系统定时器(SysTick)的外部时钟。通过对SysTick控制与状态寄存器设置,可选择上述时钟或Cortex(HCLK)的始终作为SysTick时钟。定时器时钟分配频率分配有硬件安一下两种情况自动设置    ·如果相应APB预分频系数是1,定时器时钟频率与所在APB总线频率一致。    ·否则,定时器的时钟频率被设为与其相连APB总线频率的两倍。

Reset_handler PROC
EXPORT Reset_handler [WEAK]
IMPORT Systeminit
IMPORT __main

             LDR     R0, =SystemInit             BLX     R0             LDR     R0, =__main             BX      R0             ENDP  系统启动默认使用内部16MHz的RC振荡器,启动过程中NRST引脚产生复位信号,从而进入STM32F4的复位中断函数,在里面调用SystemInit()函数将时钟切换到HSE进入main执行。主要的就是SystemInit函数,这个函数在system_stm32f4xx.c里用于简历系统时钟(系统时钟源,PLL分频因子和倍频因子,AHP/ABPx分频,FLASH设置);SystemCoreClock variable也就是HCLK;SystemCoreClockUpdate()在程序执行中内核时钟发生了变化这个函数是必须会被调用的。HSE默认频率是25MHz,HSE_VALUE在文件stm32f4xx.h里面定义。

static void Setsysclock (void)
{

If defined (stm32f40_41xxx) | | Defined (stm32f427_437xx) | | Defined (stm32f429_439xx) | | Defined (stm32f401xx) | | Defined (STM32F446XX)

/********************************************************************/
/* PLL (clocked by HSE) used as System clock source */
/********************************************************************/
__io uint32_t startupcounter = 0, hsestatus = 0;

/* Enable HSE */
RCC->CR |= ((uint32_t) rcc_cr_hseon);
To enable HSE, several functions behind this function wait for the HSE to be ready, and if it times out, jump out of Setsysclock. Waiting for a function timeout is a good programming habit, if the HSE is ready, if you are doing something related, if you fail to add debug code in else to find the cause.

if ((RCC->CR & rcc_cr_hserdy)! = RESET)
{
Hsestatus = (uint32_t) 0x01;
}
Else
{
Hsestatus = (uint32_t) 0x00;
}
The HSE ready configuration process is as follows
HCLK = SYSCLK/1
Plck2=hclk/2
Plck1=hclk/4
Configure the primary PLL and wait for it to be ready
Configuring Flash,prefecth,instruction Cache,data Cache and wait state
Configuring the Mian PLL as the system clock source
To this point, the basic work of the system clock initialization is completed, and the rest can be entered into the Mian function.

STM32F4 Learning note 2--clock and reset system

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.