cancel
Showing results for 
Search instead for 
Did you mean: 

Why is RCC MCO config affecting other pins?

ZHama.1
Associate II

0693W00000D1vfoQAB.jpg 

I'm using a nucleo F446RE. I want to set up MCO1 as 42MHz output. CUBEmx generated the the HAL_RCC_MCOConfig function below.

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));
  /* RCC_MCO1 */
  if(RCC_MCOx == RCC_MCO1)
  {
    assert_param(IS_RCC_MCO1SOURCE(RCC_MCOSource));
 
    /* MCO1 Clock Enable */
    __MCO1_CLK_ENABLE();
 
    /* Configure the MCO1 pin in alternate function mode */
    GPIO_InitStruct.Pin = MCO1_PIN;
    GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
    GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_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_MCO1 | RCC_CFGR_MCO1PRE), (RCC_MCOSource | RCC_MCODiv));
  }

Upon debugging line by line, line 25 is where the problem happens. Its setting the prescaler and clock source for MCO1 as (binary) 100 and 11 which is /2 and PLL respectively as shown in the screenshot for SFRs, this is correct according to the reference manual and should give 42MHz.

0693W00000D1vfPQAR.jpg 

Whats happening is that for some reason other pins are pulsing fast too, for example I have an I2C line but SDA and SCL lines have many pulses within their High and low signals.

Below is what the correct I2C looks like when line 25 is removed. (The green squarewave is the default HSI output on MCO, 16MHz):

0693W00000D1vfZQAR.jpg 

Below is what happens when line 25 is left in to make MCO1 42MHz as wanted but other pins are affected and MCO1 (green square wave) isn't even 42MHz.

[SCREENSHOT SHOWN AT TOP OF PAGE FOR SOME REASON]

0 REPLIES 0