void HAL_RCC_MCOConfig( uint32_t RCC_MCOx, uint32_t RCC_MCOSource, uint32_t RCC_MCODiv) { GPIO_InitTypeDef GPIO_InitStruct; /* Check the parameters */ assert_param(IS_RCC_MCO(RCC_MCOx)); assert_param(IS_RCC_MCODIV(RCC_MCODiv)); assert_param(IS_RCC_MCO1SOURCE(RCC_MCOSource)); /* MCO Clock Enable */ __MCO1_CLK_ENABLE(); /* Configure the MCO1 pin in alternate function mode */ if (RCC_MCOx == RCC_MCO1) { GPIO_InitStruct.Pin = MCO1_PIN; } else { GPIO_InitStruct.Pin = MCO2_PIN; } GPIO_InitStruct.Mode = GPIO_MODE_AF_PP; GPIO_InitStruct.Speed = GPIO_SPEED_HIGH; GPIO_InitStruct.Pull = GPIO_NOPULL; GPIO_InitStruct.Alternate = GPIO_AF0_MCO; HAL_GPIO_Init(MCO1_GPIO_PORT, &GPIO_InitStruct); /* Mask MCO1 and MCO1PRE[2:0] bits then Select MCO1 clock source and prescaler */ MODIFY_REG(RCC->CFGR, (RCC_CFGR_MCOSEL | RCC_CFGR_MCO_PRE), ((RCC_MCOSource << 24 | RCC_MCODiv ))); }
/** * @brief Selects the clock source to output on MCO pin. * @note MCO pin 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_MCO: Clock source to output on MCO1 pin(PA8). * @param RCC_MCOSource: specifies the clock source to output. * This parameter can be one of the following values: * @arg RCC_MCO1SOURCE_NOCLOCK: No clock selected * @arg RCC_MCO1SOURCE_SYSCLK: System clock selected as MCO source * @arg RCC_MCO1SOURCE_HSI: HSI oscillator clock selected * @arg RCC_MCO1SOURCE_HSE: HSE oscillator clock selected * @arg RCC_MCO1SOURCE_PLLCLK: PLL clock divided by 2 selected as MCO source * @arg RCC_MCO1SOURCE_PLL2CLK: PLL2 clock selected as MCO source (only for connectivity line devices) * @arg RCC_MCO1SOURCE_PLL3CLK_DIV2: PLL3 clock divided by 2 selected as MCO source (only for connectivity line devices) * @arg RCC_MCO1SOURCE_EXT_HSE: XT1 external 3-25 MHz oscillator clock selected as MCO source (only for connectivity line devices) * @arg RCC_MCO1SOURCE_PLL3CLK: PLL3 clock selected as MCO source (only for connectivity line devices) * @param RCC_MCODiv: specifies the MCO DIV. * This parameter can be one of the following values: * @arg RCC_MCODIV_1: no division applied to MCO clock * @retval None */ void HAL_RCC_MCOConfig(uint32_t RCC_MCOx, uint32_t RCC_MCOSource, uint32_t RCC_MCODiv) { GPIO_InitTypeDef gpio; /* Check the parameters */ assert_param(IS_RCC_MCO(RCC_MCOx)); assert_param(IS_RCC_MCODIV(RCC_MCODiv)); assert_param(IS_RCC_MCO1SOURCE(RCC_MCOSource)); /* MCO Clock Enable */ MCO1_CLK_ENABLE(); /* Configure the MCO1 pin in alternate function mode */ gpio.Pin = MCO1_PIN; gpio.Mode = GPIO_MODE_AF_PP; gpio.Speed = GPIO_SPEED_HIGH; gpio.Pull = GPIO_NOPULL; HAL_GPIO_Init(MCO1_GPIO_PORT, &gpio); /* Mask MCO and MCOPRE[2:0] bits then Select MCO clock source and prescaler */ MODIFY_REG(RCC->CFGR, RCC_CFGR_MCO, RCC_MCOSource); }
/** * @brief Selects the clock source to output on MCO pin(such as PA8). * @note MCO pin (such as PA8) 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_MCO: Clock source to output on MCO pin(such as PA8). * @param RCC_MCOSource: specifies the clock source to output. * This parameter can be one of the following values: * @arg RCC_MCOSOURCE_LSI: LSI clock selected as MCO source * @arg RCC_MCOSOURCE_HSI: HSI clock selected as MCO source * @arg RCC_MCOSOURCE_LSE: LSE clock selected as MCO source * @arg RCC_MCOSOURCE_HSE: HSE clock selected as MCO source * @arg RCC_MCOSOURCE_PLLCLK_DIV2: main PLL clock divided by 2 selected as MCO source * @arg RCC_MCOSOURCE_SYSCLK: System clock (SYSCLK) selected as MCO source * @param RCC_MCODiv: specifies the MCOx prescaler. * This parameter can be one of the following values: * @arg RCC_MCO_NODIV: no division applied to MCO clock * @retval None */ void HAL_RCC_MCOConfig(uint32_t RCC_MCOx, uint32_t RCC_MCOSource, uint32_t RCC_MCODiv) { GPIO_InitTypeDef gpio; /* Check the parameters */ assert_param(IS_RCC_MCO(RCC_MCOx)); assert_param(IS_RCC_MCODIV(RCC_MCODiv)); /* RCC_MCO */ assert_param(IS_RCC_MCOSOURCE(RCC_MCOSource)); /* MCO Clock Enable */ __MCO_CLK_ENABLE(); /* Configue the MCO pin in alternate function mode */ gpio.Pin = MCO_PIN; gpio.Mode = GPIO_MODE_AF_PP; gpio.Speed = GPIO_SPEED_HIGH; gpio.Pull = GPIO_NOPULL; gpio.Alternate = GPIO_AF0_MCO; HAL_GPIO_Init(MCO_GPIO_PORT, &gpio); /* Configure the MCO clock source */ __HAL_RCC_MCO_CONFIG(RCC_MCOSource, RCC_MCODiv); }