前言
- 在嵌入式开发的过程中,很多时候需要主频配置为最高的主频,以保证 MCU 的性能得到最大发挥。那么如何来验证主频的频率,则可以配置 MCO 时钟输出,通过示波器测量其时钟输出波形即可。
一、STM32H7 时钟树
1.MCO1 输出的时钟源
- HSE
- HSI
- LSE
- PLL1QCLK
- HSI48
2.MCO2 输出的时钟源
- SYSCLK
- HSE
- PLLCLK
- PLL2PCLK
- CSICLK
- LSICLK
二、STM32CbueMX 配置
- 找到 MCO2 引脚,并生成代码
三、修改代码
/**
* @brief Selects the clock source to output on MCO1 pin(PA8) or on MCO2 pin(PC9).
* @note PA8/PC9 should be configured in alternate function mode.
* @param RCC_MCOx: specifies the output direction for the clock source.
* This parameter can be one of the following values:
* @arg RCC_MCO1: Clock source to output on MCO1 pin(PA8).
* @arg RCC_MCO2: Clock source to output on MCO2 pin(PC9).
* @param RCC_MCOSource: specifies the clock source to output.
* This parameter can be one of the following values:
* @arg RCC_MCO1SOURCE_HSI: HSI clock selected as MCO1 source
* @arg RCC_MCO1SOURCE_LSE: LSE clock selected as MCO1 source
* @arg RCC_MCO1SOURCE_HSE: HSE clock selected as MCO1 source
* @arg RCC_MCO1SOURCE_PLL1QCLK: PLL1Q clock selected as MCO1 source
* @arg RCC_MCO1SOURCE_HSI48: HSI48 (48MHZ) selected as MCO1 source
* @arg RCC_MCO2SOURCE_SYSCLK: System clock (SYSCLK) selected as MCO2 source
* @arg RCC_MCO2SOURCE_PLL2PCLK: PLL2P clock selected as MCO2 source
* @arg RCC_MCO2SOURCE_HSE: HSE clock selected as MCO2 source
* @arg RCC_MCO2SOURCE_PLLCLK: PLL1P clock selected as MCO2 source
* @arg RCC_MCO2SOURCE_CSICLK: CSI clock selected as MCO2 source
* @arg RCC_MCO2SOURCE_LSICLK: LSI clock selected as MCO2 source
* @param RCC_MCODiv: specifies the MCOx pre-scaler.
* This parameter can be one of the following values:
* @arg RCC_MCODIV_1 up to RCC_MCODIV_15 : divider applied to MCOx clock
* @retval None
*/
//由于IO引脚输出频率有限,所以将系统时钟输出进行10分频处理
HAL_RCC_MCOConfig(RCC_MCO2, RCC_MCO2SOURCE_SYSCLK, RCC_MCODIV_10);
四、验证结果
- 为了达到整数输出结果,则将系统时钟配置为 500MHz,故而进行10分频后输出的结果为 50MHz