本帖最后由 xueshawu 于 2017-3-5 17:22 编辑
Usingthe HSE/LSE oscillator pins as GPIOs
在移植PS2手柄程序时,为了方便采用 PC13 PC14 PC15 PF0
以上端口 默认功能都不是GPIO
其中
PC13 RTC_ALARM Output
PC14 OSC32_IN
PC15 OSC32_OUT
PF0 OSC_IN
通过翻阅手册 得知
When the HSE or LSE oscillator is switched OFF(default state after reset), the related
oscillator pins can be used as normal GPIOs.
When the HSE or LSE oscillator is switched ON (by setting the HSEON or LSEON bit in the RCC_CSR register) the oscillator takes control of its associatedpins and the GPIOconfiguration of these pins has no effect.
When the oscillator is configured in auser external clock mode, only the pin is reserved for
clock input and the OSC_OUT or OSC32_OUT pin can still be used as normal GPIO.
意思是 当HSE /LSE 开关处于OFF状态时相应的引脚可以作为普通的GPIO使用; 通过设置HSEON LSEON可以实现这个功能;
但是,这里说的RCC_CSR寄存器上没有这两个位,在RCC_CR上;可能是ST有误!
这里在切换到GPIO时,有前提条件-----系统时钟需要为HSI (内部时钟);
需要先将系统 时钟切换到HIS;
file:///C:/Users/xueshawu/AppData/Local/Temp/msohtmlclip1/01/clip_image002.png
这里系统时钟SYSCLK,可以来源于三种方式:
1、 HSI SW = 00
2、 HSE SW = 01
3、 PLL SW = 10
这里是由RCC_CFGR 的SW[1:0]位决定 一般默认为PLL;
PLL有两种来源
1、 HIS/2
2、 HSE/PREDIV
RCC_CFGR2 的PREDIV[3:0] 决定了 HSE是多少分频
SYSCLK确定了之后,然后需要确定总线频率
这里主要是AHB APB
预分频系数分别 为 RCC_CFGR 的 HRE[7:4] RCC_CFGR 的PPRE[10:8]
HIS配置好了之后,直接关闭HSELSE就行了
RCC_HSEConfig(RCC_HSE_OFF);
RCC_LSEConfig(RCC_LSE_OFF);
其中,LSE是默认关闭的
这里顺便说一个小工具 STM32F0XXSystem Clock Config
file:///C:/Users/xueshawu/AppData/Local/Temp/msohtmlclip1/01/clip_image004.jpg
en.stsw-stm32088.zip
(497.66 KB, 下载次数: 158)
|