一 怎么查询主频?
方法一:
stm32 提供了一个全局变量可以查询的,uint32_t SystemCoreClock;
mprintf("freqclk is:%d \n\r ",SystemCoreClock);
方法二:
也可以通过函数:
HAL_RCC_GetClockConfig(&clkconfig, &pFLatency);
这个来获取。、
二 主频和几个分频的关系?
HCLK :AHB总线时钟,由系统时钟SYSCLK 分频得到,一般不分频,等于系统时钟,HCLK是高速外设时钟,是给外部设备的,比如内存,flash。
连接在APB1(低速外设)上的设备有:电源接口、备份接口、CAN、USB、I2C1、I2C2、UART2、UART3、SPI2、窗口看门狗、Timer2、Timer3、Timer4。
连接在APB2(高速外设)上的设备有:UART1、SPI1、Timer1、
ADC1、ADC2、所有普通IO口(PA~PE)、第二功能IO口。
这个不用死记,用的时候i直接查阅代码即可:
/*!< APB1 peripherals */
#define TIM2_BASE (APB1PERIPH_BASE + 0x0000UL)
#define TIM3_BASE (APB1PERIPH_BASE + 0x0400UL)
#define TIM4_BASE (APB1PERIPH_BASE + 0x0800UL)
#define TIM5_BASE (APB1PERIPH_BASE + 0x0C00UL)
#define TIM6_BASE (APB1PERIPH_BASE + 0x1000UL)
#define TIM7_BASE (APB1PERIPH_BASE + 0x1400UL)
#define RTC_BASE (APB1PERIPH_BASE + 0x2800UL)
#define WWDG_BASE (APB1PERIPH_BASE + 0x2C00UL)
#define IWDG_BASE (APB1PERIPH_BASE + 0x3000UL)
#define SPI2_BASE (APB1PERIPH_BASE + 0x3800UL)
#define SPI3_BASE (APB1PERIPH_BASE + 0x3C00UL)
#define USART2_BASE (APB1PERIPH_BASE + 0x4400UL)
#define USART3_BASE (APB1PERIPH_BASE + 0x4800UL)
#define UART4_BASE (APB1PERIPH_BASE + 0x4C00UL)
#define UART5_BASE (APB1PERIPH_BASE + 0x5000UL)
#define I2C1_BASE (APB1PERIPH_BASE + 0x5400UL)
#define I2C2_BASE (APB1PERIPH_BASE + 0x5800UL)
#define I2C3_BASE (APB1PERIPH_BASE + 0x5C00UL)
#define CAN1_BASE (APB1PERIPH_BASE + 0x6400UL)
#define PWR_BASE (APB1PERIPH_BASE + 0x7000UL)
#define DAC_BASE (APB1PERIPH_BASE + 0x7400UL)
#define DAC1_BASE (APB1PERIPH_BASE + 0x7400UL)
#define OPAMP_BASE (APB1PERIPH_BASE + 0x7800UL)
#define OPAMP1_BASE (APB1PERIPH_BASE + 0x7800UL)
#define OPAMP2_BASE (APB1PERIPH_BASE + 0x7810UL)
#define LPTIM1_BASE (APB1PERIPH_BASE + 0x7C00UL)
#define LPUART1_BASE (APB1PERIPH_BASE + 0x8000UL)
#define SWPMI1_BASE (APB1PERIPH_BASE + 0x8800UL)
#define LPTIM2_BASE (APB1PERIPH_BASE + 0x9400UL)
/*!< APB2 peripherals */
#define SYSCFG_BASE (APB2PERIPH_BASE + 0x0000UL)
#define VREFBUF_BASE (APB2PERIPH_BASE + 0x0030UL)
#define COMP1_BASE (APB2PERIPH_BASE + 0x0200UL)
#define COMP2_BASE (APB2PERIPH_BASE + 0x0204UL)
#define EXTI_BASE (APB2PERIPH_BASE + 0x0400UL)
#define FIREWALL_BASE (APB2PERIPH_BASE + 0x1C00UL)
#define SDMMC1_BASE (APB2PERIPH_BASE + 0x2800UL)
#define TIM1_BASE (APB2PERIPH_BASE + 0x2C00UL)
#define SPI1_BASE (APB2PERIPH_BASE + 0x3000UL)
#define TIM8_BASE (APB2PERIPH_BASE + 0x3400UL)
#define USART1_BASE (APB2PERIPH_BASE + 0x3800UL)
#define TIM15_BASE (APB2PERIPH_BASE + 0x4000UL)
#define TIM16_BASE (APB2PERIPH_BASE + 0x4400UL)
#define TIM17_BASE (APB2PERIPH_BASE + 0x4800UL)
#define SAI1_BASE (APB2PERIPH_BASE + 0x5400UL)